TSpecdevYlrqController.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. package com.ruoyi.project.sems.controller;
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.*;
  8. import java.util.concurrent.CopyOnWriteArrayList;
  9. import java.util.concurrent.CountDownLatch;
  10. import java.util.concurrent.ExecutorService;
  11. import java.util.concurrent.Executors;
  12. import com.alibaba.fastjson.JSON;
  13. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  14. import com.ruoyi.common.utils.DateUtils;
  15. import com.ruoyi.common.utils.ServletUtils;
  16. import com.ruoyi.common.utils.file.ExcelUtils;
  17. import com.ruoyi.common.utils.spring.SpringUtils;
  18. import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
  19. import com.ruoyi.framework.security.LoginUser;
  20. import com.ruoyi.framework.security.service.TokenService;
  21. import com.ruoyi.project.sems.domain.ParamData;
  22. import com.ruoyi.project.sems.domain.TSpecCheck;
  23. import com.ruoyi.project.sems.domain.TSpecdevYlgd;
  24. import com.ruoyi.project.sems.his.controller.TApproveSpecModifyController;
  25. import com.ruoyi.project.sems.his.controller.TSpechiYlgdController;
  26. import com.ruoyi.project.sems.his.controller.TSpechiYlrqController;
  27. import com.ruoyi.project.sems.his.domain.TApproveSpecModify;
  28. import com.ruoyi.project.sems.his.service.ITApproveSpecModifyService;
  29. import com.ruoyi.project.sems.service.ITSpecCheckService;
  30. import com.ruoyi.project.system.domain.SysDept;
  31. import com.ruoyi.project.system.domain.SysDictData;
  32. import com.ruoyi.project.system.service.ISysDeptService;
  33. import com.ruoyi.project.system.service.ISysDictTypeService;
  34. import org.activiti.engine.RuntimeService;
  35. import org.activiti.engine.impl.identity.Authentication;
  36. import org.activiti.engine.runtime.ProcessInstance;
  37. import org.apache.commons.lang.StringUtils;
  38. import org.apache.poi.ss.usermodel.*;
  39. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  40. import org.springframework.security.access.prepost.PreAuthorize;
  41. import org.springframework.beans.factory.annotation.Autowired;
  42. import org.springframework.web.bind.annotation.*;
  43. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  44. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  45. import com.ruoyi.project.sems.domain.TSpecdevYlrq;
  46. import com.ruoyi.project.sems.service.ITSpecdevYlrqService;
  47. import com.ruoyi.framework.web.controller.BaseController;
  48. import com.ruoyi.framework.web.domain.AjaxResult;
  49. import com.ruoyi.common.utils.poi.ExcelUtil;
  50. import com.ruoyi.framework.web.page.TableDataInfo;
  51. import org.springframework.web.multipart.MultipartFile;
  52. /**
  53. * 特种设备压力容器台账Controller
  54. *
  55. * @author ruoyi
  56. * @date 2021-06-30
  57. */
  58. @RestController
  59. @RequestMapping("/sems/specYlrq")
  60. public class TSpecdevYlrqController extends BaseController {
  61. @Autowired
  62. private ITSpecdevYlrqService tSpecdevYlrqService;
  63. @Autowired
  64. private ITSpecCheckService tSpecCheckService;
  65. @Autowired
  66. private ISysDeptService iSysDeptService;
  67. @Autowired
  68. private ISysDictTypeService iSysDictTypeService;
  69. @Autowired
  70. private ITApproveSpecModifyService tApproveSpecModifyService;
  71. @Autowired
  72. private RuntimeService runtimeService;
  73. @Autowired
  74. private TApproveSpecModifyController approveSpecModifyController;
  75. @Autowired
  76. private TSpechiYlrqController tSpechiYlrqController;
  77. /**
  78. * 查询特种设备压力容器台账列表
  79. */
  80. @PreAuthorize("@ss.hasPermi('sems:specYlrq:list')")
  81. @GetMapping("/list")
  82. public TableDataInfo list(TSpecdevYlrq tSpecdevYlrq) {
  83. startPage();
  84. List<TSpecdevYlrq> list = tSpecdevYlrqService.selectTSpecdevYlrqList(tSpecdevYlrq);
  85. //
  86. // SpecOverLifeThead specOverLifeThead = new SpecOverLifeThead(tSpecdevYlrqService);
  87. // Thread t = new Thread(specOverLifeThead);
  88. // t.start();
  89. // SpecDevYlrqThread specDevYlgdThread = new SpecDevYlrqThread(tSpecdevYlrqService);
  90. // Thread t2 = new Thread(specDevYlgdThread);
  91. // t2.start();
  92. return getDataTable(list);
  93. }
  94. /**
  95. * 导出特种设备压力容器台账列表
  96. */
  97. @PreAuthorize("@ss.hasPermi('sems:specYlrq:export')")
  98. @Log(title = "特种设备压力容器台账", businessType = BusinessType.EXPORT)
  99. @GetMapping("/export")
  100. public AjaxResult export(TSpecdevYlrq tSpecdevYlrq) {
  101. List<TSpecdevYlrq> list = tSpecdevYlrqService.selectTSpecdevYlrqList(tSpecdevYlrq);
  102. ExcelUtil<TSpecdevYlrq> util = new ExcelUtil<TSpecdevYlrq>(TSpecdevYlrq.class);
  103. return util.exportExcel(list, "specYlrq");
  104. }
  105. /**
  106. * 获取特种设备压力容器台账详细信息
  107. */
  108. @PreAuthorize("@ss.hasPermi('sems:specYlrq:query')")
  109. @GetMapping(value = "/{id}")
  110. public AjaxResult getInfo(@PathVariable("id") Long id) {
  111. return AjaxResult.success(tSpecdevYlrqService.selectTSpecdevYlrqById(id));
  112. }
  113. /**
  114. * 新增特种设备压力容器台账
  115. */
  116. @PreAuthorize("@ss.hasPermi('sems:specYlrq:add')")
  117. @Log(title = "特种设备压力容器台账", businessType = BusinessType.INSERT)
  118. @PostMapping
  119. public AjaxResult add(@RequestBody TSpecdevYlrq tSpecdevYlrq) {
  120. tSpecdevYlrq.setApproveStatus(22l);
  121. tSpecdevYlrqService.insertTSpecdevYlrq(tSpecdevYlrq);
  122. TApproveSpecModify tApproveSpecModify = new TApproveSpecModify();
  123. Long userid = getUserId();
  124. tApproveSpecModify.setUserId(userid);
  125. tApproveSpecModify.setApproveType(3l);
  126. tApproveSpecModify.setDevType(1l);
  127. tApproveSpecModify.setDevId(String.valueOf(tSpecdevYlrq.getId()));
  128. //审批编号
  129. Date dt = new Date();
  130. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  131. String data = sdf.format(dt) + userid;
  132. tApproveSpecModify.setApNo(data);
  133. //
  134. Authentication.setAuthenticatedUserId(userid.toString());
  135. tApproveSpecModifyService.insertTApproveSpecModify(tApproveSpecModify);
  136. long bussniseeKey = tApproveSpecModify.getId();
  137. //开始工作流、监听
  138. Map<String, Object> variables = new HashMap<>();
  139. variables.put("applyUser", userid.toString());
  140. variables.put("wxjlusers", tSpecdevYlrq.getWxjl());
  141. //采用key来启动流程定义并设置流程变量,返回流程实例
  142. ProcessInstance pi = runtimeService.startProcessInstanceByKey("semsAddDelProcess", String.valueOf(bussniseeKey), variables);
  143. logger.info("流程部署id:" + pi.getDeploymentId());
  144. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  145. logger.info("流程实例id:" + pi.getProcessInstanceId());
  146. tApproveSpecModify.setProcessId(pi.getProcessInstanceId());
  147. new Thread(() -> {
  148. approveSpecModifyController.sendMail(tApproveSpecModify , tSpecdevYlrq.getWxjl());
  149. },"发送邮件").start();
  150. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  151. String userName =loginUser != null? loginUser.getUsername(): "";
  152. new Thread(() -> {
  153. tSpechiYlrqController.addOperLog(String.valueOf(tSpecdevYlrq.getId()),userName,new Date() , "新增申请" );
  154. },"特种设备操作日志").start();
  155. return AjaxResult.success();
  156. }
  157. /**
  158. * 修改特种设备压力容器台账
  159. */
  160. @PreAuthorize("@ss.hasPermi('sems:specYlrq:edit')")
  161. @Log(title = "特种设备压力容器台账", businessType = BusinessType.UPDATE)
  162. @PutMapping
  163. public AjaxResult edit(@RequestBody TSpecdevYlrq tSpecdevYlrq) {
  164. TSpecdevYlrq old = tSpecdevYlrqService.selectTSpecdevYlrqById(tSpecdevYlrq.getId());
  165. if (StringUtils.isNotEmpty(tSpecdevYlrq.getReportNo()) && !tSpecdevYlrq.getReportNo().equals(old.getReportNo())) {
  166. TSpecCheck tc = new TSpecCheck();
  167. tc.setDevType(1l);
  168. tc.setCheckUnit(tSpecdevYlrq.getCheckUnit());
  169. tc.setDevId(tSpecdevYlrq.getId());
  170. tc.setNextWarnDate(tSpecdevYlrq.getNextWarnDate());
  171. tc.setReportNo(tSpecdevYlrq.getReportNo());
  172. tc.setWarnDate(tSpecdevYlrq.getWarnDate());
  173. tc.setYearNextWarnDate(tSpecdevYlrq.getYearNextWarnDate());
  174. tc.setYearWarnDate(tSpecdevYlrq.getYearWarnDate());
  175. tc.setYearReportNo(tSpecdevYlrq.getReportNo());
  176. tc.setSafeClass(tSpecdevYlrq.getSafeClass());
  177. tc.setCheckConclusion(tSpecdevYlrq.getCheckConclusion());
  178. tSpecCheckService.insertTSpecCheck(tc);
  179. }
  180. tSpecdevYlrqService.updateTSpecdevYlrq(tSpecdevYlrq);
  181. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  182. String userName =loginUser != null? loginUser.getUsername(): "";
  183. new Thread(() -> {
  184. tSpechiYlrqController.addOperLog(String.valueOf(tSpecdevYlrq.getId()),userName,new Date() , "修改" );
  185. },"特种设备操作日志").start();
  186. return AjaxResult.success();
  187. }
  188. /**
  189. * 修改特种设备压力容器台账
  190. */
  191. @PreAuthorize("@ss.hasPermi('sems:specYlrq:edit')")
  192. @Log(title = "特种设备压力容器台账", businessType = BusinessType.UPDATE)
  193. @PutMapping("/pre")
  194. public AjaxResult editPre(@RequestBody TSpecdevYlrq tSpecdevYlrq) {
  195. return toAjax(tSpecdevYlrqService.updateTSpecdevYlrq(tSpecdevYlrq));
  196. }
  197. /**
  198. * 删除特种设备压力容器台账
  199. */
  200. @PreAuthorize("@ss.hasPermi('sems:specYlrq:remove')")
  201. @Log(title = "特种设备压力容器台账", businessType = BusinessType.DELETE)
  202. @DeleteMapping("/{ids}")
  203. public AjaxResult remove(@PathVariable Long[] ids) {
  204. return toAjax(tSpecdevYlrqService.deleteTSpecdevYlrqByIds(ids));
  205. }
  206. /**
  207. * 去重
  208. */
  209. @PreAuthorize("@ss.hasPermi('sems:plant:remove')")
  210. @Log(title = "特种设备压力容器台账去重", businessType = BusinessType.OTHER)
  211. @GetMapping("/duplicate")
  212. public AjaxResult duplicate() {
  213. tSpecdevYlrqService.duplicateTSpecdevYlrq();
  214. return AjaxResult.success();
  215. }
  216. /**
  217. * 批量导入
  218. */
  219. @PreAuthorize("@ss.hasPermi('sems:specYlrq:add')")
  220. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  221. @PostMapping("/importData")
  222. public AjaxResult importData(@RequestParam("file") MultipartFile file,@RequestParam("wxjl") String wxjl) throws IOException, ParseException {
  223. //获取操作人员ID
  224. Long userId = getUserId();
  225. //报错行数统计
  226. List<Integer> failRow = new ArrayList<Integer>();
  227. Workbook workbook = ExcelUtils.getWorkBook(file);
  228. Sheet sheet = workbook.getSheetAt(0);
  229. List<TSpecdevYlrq> list = new ArrayList<TSpecdevYlrq>();
  230. //字典查询
  231. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  232. //部门查询
  233. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  234. int rowNum = sheet.getPhysicalNumberOfRows();
  235. int failNumber = 0;
  236. for (int i = 1; i < rowNum; i++) {
  237. try {
  238. logger.info("读取行数:" + i);
  239. Row row = sheet.getRow(i);
  240. int cellNum = row.getLastCellNum();
  241. TSpecdevYlrq entity = new TSpecdevYlrq();
  242. for (int j = 0; j < cellNum; j++) {
  243. Cell cell = row.getCell(j);
  244. if (cell == null) {
  245. continue;
  246. }
  247. cell.getCellType();
  248. String cellValue = ExcelUtils.getCellValue(cell);
  249. if (StringUtils.trim(cellValue) == "") {
  250. continue;
  251. }
  252. logger.info("cellValue:" + cellValue);
  253. if (j == 0) {
  254. //序号
  255. } else if (j == 1) {
  256. entity.setPlantCode(cellValue);//装置名称
  257. } else if (j == 2) {
  258. entity.setUnit(cellValue);//单元
  259. } else if (j == 3) {
  260. entity.setPlantMaint(cellValue);//装置维修组
  261. } else if (j == 4) {
  262. entity.setEngineer(cellValue);//装置维修工程师
  263. } else if (j == 5) {
  264. entity.setDevno(cellValue);//位号
  265. } else if (j == 6) {
  266. entity.setDevname(cellValue);//设备名称
  267. } else if (j == 7) {
  268. entity.setFactoryNo(cellValue);//出厂编号
  269. } else if (j == 8) {
  270. entity.setUseno(cellValue);//使用证编号
  271. } else if (j == 9) {
  272. entity.setRegno(cellValue);//注册编号
  273. } else if (j == 10) {
  274. entity.setVesselType(cellValue);//容器类别
  275. } else if (j == 11) {
  276. entity.setCreateUnit(cellValue);//制造单位
  277. } else if (j == 12) {
  278. entity.setNation(cellValue);//国家
  279. } else if (j == 13) {
  280. entity.setOutSize(cellValue);//外形尺寸
  281. } else if (j == 14) {
  282. entity.setMaterial(cellValue);//材料
  283. } else if (j == 15) {
  284. entity.setMedium(cellValue);//介质
  285. } else if (j == 16) {
  286. entity.setDesPressure(cellValue);//设计压力
  287. } else if (j == 17) {
  288. entity.setOptPressure(cellValue);//操作压力
  289. } else if (j == 18) {
  290. entity.setDesTemp(cellValue);//设计温度
  291. } else if (j == 19) {
  292. entity.setOptTemp(cellValue);//操作温度
  293. } else if (j == 20) {
  294. logger.info("日期格式:" + cellValue);
  295. if (cellValue.length() > 3) {//投用日期
  296. entity.setSubmitdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  297. }
  298. } else if (j == 21) {
  299. //是否涉危化品
  300. entity.setIsDanger(cellValue);
  301. } else if (j == 22) {
  302. //是否涉危化品
  303. entity.setDesYear(cellValue);
  304. } else if (j == 23) {
  305. //是否超设计使用寿命
  306. entity.setIsOverlife(cellValue);
  307. } else if (j == 24) {
  308. entity.setCheckUnit(cellValue);//检验单位
  309. } else if (j == 25) {
  310. logger.info("日期格式:" + cellValue);
  311. if (cellValue.length() > 3) {//检验日期
  312. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  313. }
  314. } else if (j == 26) {
  315. entity.setSafeClass(cellValue);//安全状况等级
  316. } else if (j == 27) {
  317. if (cellValue.length() > 3) {//下次检验日期
  318. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  319. }
  320. } else if (j == 28) {
  321. entity.setReportNo(cellValue);//报告编号
  322. } else if (j == 29) {
  323. if (cellValue.length() > 3) {//检验日期
  324. entity.setYearWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  325. }
  326. } else if (j == 30) {
  327. entity.setCheckConclusion(cellValue);//年度结论
  328. } else if (j == 31) {
  329. if (cellValue.length() > 3) {//下次年度检验日期
  330. entity.setYearNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  331. }
  332. } else if (j == 32) {
  333. entity.setYearReportNo(cellValue);//报告编号
  334. } else if (j == 33) {
  335. entity.setRemarks(cellValue);//备注
  336. }/*else if (j == 33) {
  337. for (SysDept d : dept) {
  338. if (d.getDeptName().equals(cellValue)) {
  339. entity.setDeptId(d.getDeptId());//部门编号
  340. }
  341. }
  342. }*/
  343. }
  344. entity.setCreaterCode(userId);
  345. logger.info("entity:" + entity);
  346. list.add(entity);
  347. } catch (Exception e) {
  348. failNumber++;
  349. logger.info("e:" + JSON.toJSONString(e));
  350. failRow.add(i + 1);
  351. }
  352. }
  353. int successNumber = 0;
  354. int failNum = 0;
  355. CopyOnWriteArrayList<String> ids = new CopyOnWriteArrayList();
  356. for (TSpecdevYlrq t : list
  357. ) {
  358. failNum++;
  359. try {
  360. t.setApproveStatus(22l);
  361. tSpecdevYlrqService.insertTSpecdevYlrq(t);
  362. ids.add(t.getId().toString());
  363. successNumber++;
  364. } catch (Exception e) {
  365. failNumber++;
  366. logger.info("e:" + e);
  367. failRow.add(failNum + 1);
  368. }
  369. }
  370. //申请流程
  371. String devIds = StringUtils.join(ids.toArray(),",");
  372. TApproveSpecModify tApproveSpecModify = new TApproveSpecModify();
  373. Long userid = getUserId();
  374. tApproveSpecModify.setUserId(userid);
  375. tApproveSpecModify.setApproveType(3l);
  376. tApproveSpecModify.setDevType(1l);
  377. tApproveSpecModify.setDevId(devIds);
  378. //审批编号
  379. Date dt = new Date();
  380. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  381. String data = sdf.format(dt) + userid;
  382. tApproveSpecModify.setApNo(data);
  383. //
  384. Authentication.setAuthenticatedUserId(userid.toString());
  385. tApproveSpecModifyService.insertTApproveSpecModify(tApproveSpecModify);
  386. long bussniseeKey = tApproveSpecModify.getId();
  387. //开始工作流、监听
  388. Map<String, Object> variables = new HashMap<>();
  389. variables.put("applyUser", userid.toString());
  390. variables.put("wxjlusers", wxjl);
  391. //采用key来启动流程定义并设置流程变量,返回流程实例
  392. ProcessInstance pi = runtimeService.startProcessInstanceByKey("semsAddDelProcess", String.valueOf(bussniseeKey), variables);
  393. logger.info("流程部署id:" + pi.getDeploymentId());
  394. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  395. logger.info("流程实例id:" + pi.getProcessInstanceId());
  396. tApproveSpecModify.setProcessId(pi.getProcessInstanceId());
  397. new Thread(() -> {
  398. approveSpecModifyController.sendMail(tApproveSpecModify , wxjl);
  399. },"发送邮件").start();
  400. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  401. String userName =loginUser != null? loginUser.getUsername(): "";
  402. new Thread(() -> {
  403. tSpechiYlrqController.addOperLog(ids.toArray(),userName,new Date() , "新增申请" );
  404. },"特种设备操作日志").start();
  405. logger.info("list:" + JSON.toJSONString(list));
  406. logger.info("successNumber:" + String.valueOf(successNumber));
  407. logger.info("failNumber:" + String.valueOf(failNumber));
  408. logger.info("failRow:" + String.valueOf(failRow));
  409. return AjaxResult.success(String.valueOf(successNumber), failRow);
  410. }
  411. /**
  412. * 批量导入
  413. * 检验更新功能中的批量导入
  414. */
  415. @PreAuthorize("@ss.hasPermi('sems:specYlrq:add')")
  416. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  417. @PostMapping("/updateData")
  418. public AjaxResult updateData(@RequestParam("file") MultipartFile file) throws IOException {
  419. //获取操作人员ID
  420. Long userId = getUserId();
  421. //报错行数统计
  422. List<Integer> failRow = new ArrayList<Integer>();
  423. Workbook workbook = ExcelUtils.getWorkBook(file);
  424. Sheet sheet = workbook.getSheetAt(0);
  425. List<TSpecdevYlrq> list = new ArrayList<TSpecdevYlrq>();
  426. List<TSpecdevYlrq> oldList = new ArrayList<TSpecdevYlrq>();
  427. //字典查询
  428. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  429. //部门查询
  430. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  431. int rowNum = sheet.getPhysicalNumberOfRows();
  432. int failNumber = 0;
  433. long devId = 0l;
  434. TSpecdevYlrq oldEntity = new TSpecdevYlrq();
  435. for (int i = 1; i < rowNum; i++) {
  436. try {
  437. logger.info("读取行数:" + i);
  438. Row row = sheet.getRow(i);
  439. int cellNum = row.getLastCellNum();
  440. TSpecdevYlrq entity = new TSpecdevYlrq();
  441. for (int j = 0; j < cellNum; j++) {
  442. Cell cell = row.getCell(j);
  443. if (cell == null) {
  444. continue;
  445. }
  446. String cellValue = ExcelUtils.getCellValue(cell);
  447. logger.info("cellValue:" + cellValue);
  448. if (j == 0) {
  449. //序号
  450. Double d = Double.parseDouble(cellValue);
  451. long s = new Double(d).longValue();
  452. entity.setId(s);
  453. } else if (j == 1) {
  454. entity.setPlantCode(cellValue);//装置名称
  455. } else if (j == 2) {
  456. entity.setDevno(cellValue);//位号
  457. } else if (j == 3) {
  458. entity.setDevname(cellValue);//设备名称
  459. } else if (j == 4) {
  460. entity.setUseno(cellValue);//使用证编号
  461. } else if (j == 5) {
  462. entity.setCheckUnit(cellValue);//检验单位
  463. } else if (j == 6) {
  464. logger.info("日期格式:" + cellValue);
  465. if (cellValue.length() > 3) {//检验日期
  466. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  467. }
  468. } else if (j == 7) {
  469. entity.setSafeClass(cellValue);//安全状况等级
  470. } else if (j == 8) {
  471. logger.info("日期格式:" + cellValue);
  472. if (cellValue.length() > 3) {//下次检验日期
  473. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  474. }
  475. } else if (j == 9) {
  476. entity.setReportNo(cellValue);//报告编号
  477. } else if (j == 10) { //年度检查日期
  478. logger.info("日期格式:" + cellValue);
  479. if (cellValue.length() > 3) {
  480. entity.setYearWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  481. }
  482. } else if (j == 11) {//年度检查结论
  483. entity.setCheckConclusion(cellValue);
  484. } else if (j == 12) {//下次年度检查日期
  485. logger.info("日期格式:" + cellValue);
  486. if (cellValue.length() > 3) {
  487. entity.setYearNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  488. }
  489. } else if (j == 13) {//年度检查编号
  490. entity.setYearReportNo(cellValue);
  491. }
  492. }
  493. logger.info("entity:" + entity);
  494. list.add(entity);
  495. oldEntity = entity;
  496. oldList.add(oldEntity);
  497. /*for (TSpecdevYlrq e :list){
  498. e.setId(null);
  499. }*/
  500. } catch (Exception e) {
  501. failNumber++;
  502. e.printStackTrace();
  503. logger.info("e:" + JSON.toJSONString(e));
  504. failRow.add(i + 1);
  505. }
  506. }
  507. int successNumber = 0;
  508. int failNum = 0;
  509. for (TSpecdevYlrq t : list
  510. ) {
  511. failNum++;
  512. try {
  513. tSpecdevYlrqService.update(t,
  514. new QueryWrapper<TSpecdevYlrq>().eq("USENO", t.getUseno())
  515. .eq("PLANT_CODE", t.getPlantCode())
  516. .eq("DEVNO", t.getDevno()));
  517. successNumber++;
  518. } catch (Exception e) {
  519. e.printStackTrace();
  520. failNumber++;
  521. logger.info("e:" + e);
  522. failRow.add(failNum + 1);
  523. }
  524. }
  525. for (TSpecdevYlrq t : oldList) {
  526. // TSpecdevYlrq old = tSpecdevYlrqService.selectTSpecdevYlrqById(t.getId());
  527. // if (!old.getReportNo().equals(t.getReportNo())) {
  528. TSpecCheck tc = new TSpecCheck();
  529. tc.setDevType(1l);
  530. tc.setCheckUnit(t.getCheckUnit());
  531. tc.setDevId(t.getId());
  532. tc.setNextWarnDate(t.getNextWarnDate());
  533. tc.setReportNo(t.getReportNo());
  534. tc.setWarnDate(t.getWarnDate());
  535. tc.setYearNextWarnDate(t.getYearNextWarnDate());
  536. tc.setYearWarnDate(t.getYearWarnDate());
  537. tc.setYearReportNo(t.getReportNo());
  538. tc.setSafeClass(t.getSafeClass());
  539. tc.setCheckConclusion(t.getCheckConclusion());
  540. tSpecCheckService.insertTSpecCheck(tc);
  541. // }
  542. }
  543. logger.info("list:" + JSON.toJSONString(list));
  544. logger.info("successNumber:" + String.valueOf(successNumber));
  545. logger.info("failNumber:" + String.valueOf(failNumber));
  546. logger.info("failRow:" + String.valueOf(failRow));
  547. return AjaxResult.success(String.valueOf(successNumber), failRow);
  548. }
  549. @PostMapping("/exportDevList")
  550. @RepeatSubmit
  551. public AjaxResult exportDevList(@RequestBody ParamData params) throws IOException {
  552. logger.info(JSON.toJSONString(params));
  553. String id = params.getIds();
  554. String[] ids = id.split(",");
  555. CopyOnWriteArrayList<TSpecdevYlrq> list = new CopyOnWriteArrayList<>();
  556. //线程池
  557. ExecutorService executorService = Executors.newFixedThreadPool(40);
  558. final CountDownLatch latch = new CountDownLatch(ids.length); //相同线程数量的计数
  559. for (String i : ids
  560. ) {
  561. executorService.execute(() -> {
  562. //-- 业务模块
  563. try {
  564. TSpecdevYlrq t = tSpecdevYlrqService.getById(i);
  565. list.add(t);
  566. } catch (Exception e) {
  567. logger.info("e:" + e);
  568. } finally {
  569. latch.countDown(); //线程计数
  570. }
  571. });
  572. }
  573. try {
  574. latch.await(); //线程计数完毕后继续执行
  575. } catch (InterruptedException e) {
  576. e.printStackTrace();
  577. }
  578. executorService.shutdown();
  579. SXSSFWorkbook wb = new SXSSFWorkbook(1000);
  580. CellStyle wrapStyle = wb.createCellStyle();
  581. wrapStyle.setWrapText(true); //设置自动换行
  582. //创建sheet页
  583. Sheet sheet = wb.createSheet("sheet1");
  584. //设置列的宽度,第一个参数为列的序号,从0开始,第二参数为列宽,单位1/256个字节
  585. sheet.setColumnWidth(0, 12 * 256);
  586. sheet.setColumnWidth(1, 26 * 256);
  587. sheet.setColumnWidth(2, 26 * 256);
  588. sheet.setColumnWidth(3, 26 * 256);
  589. sheet.setColumnWidth(4, 26 * 256);
  590. sheet.setColumnWidth(5, 26 * 256);
  591. sheet.setColumnWidth(6, 26 * 256);
  592. sheet.setColumnWidth(7, 26 * 256);
  593. sheet.setColumnWidth(8, 40 * 256);
  594. sheet.setColumnWidth(9, 40 * 256);
  595. sheet.setColumnWidth(10, 26 * 256);
  596. sheet.setColumnWidth(11, 26 * 256);
  597. sheet.setColumnWidth(12, 40 * 256);
  598. sheet.setColumnWidth(13, 40 * 256);
  599. //设置开始行和开始列
  600. Row row0 = sheet.createRow(0);
  601. CellStyle style = wb.createCellStyle();
  602. style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
  603. style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  604. // Font headerFont = wb.createFont();
  605. // headerFont.setFontName("Arial");
  606. // headerFont.setFontHeightInPoints((short) 12);
  607. // headerFont.setBold(false);
  608. // headerFont.setColor(IndexedColors.BLACK.getIndex());
  609. // style.setFont(headerFont);
  610. Cell cell0 = row0.createCell(0);
  611. row0.createCell(0).setCellValue("序号");
  612. row0.createCell(1).setCellValue("装置");
  613. row0.createCell(2).setCellValue("位号");
  614. row0.createCell(3).setCellValue("设备名称");
  615. row0.createCell(4).setCellValue("使用证号码");
  616. row0.createCell(5).setCellValue("检验单位");
  617. row0.getCell(5).setCellStyle(style);
  618. row0.createCell(6).setCellValue("定期检验日期");
  619. row0.getCell(6).setCellStyle(style);
  620. row0.createCell(7).setCellValue("安全状况等级");
  621. row0.getCell(7).setCellStyle(style);
  622. row0.createCell(8).setCellValue("下次定期检验日期");
  623. row0.getCell(8).setCellStyle(style);
  624. row0.createCell(9).setCellValue("定期检验报告编号");
  625. row0.getCell(9).setCellStyle(style);
  626. row0.createCell(10).setCellValue("年度检查日期");
  627. row0.getCell(10).setCellStyle(style);
  628. row0.createCell(11).setCellValue("年度检查结论");
  629. row0.getCell(11).setCellStyle(style);
  630. row0.createCell(12).setCellValue("下次年度检查日期");
  631. row0.getCell(12).setCellStyle(style);
  632. row0.createCell(13).setCellValue("年度检查报告编号");
  633. row0.getCell(13).setCellStyle(style);
  634. //填充数据
  635. int rowIndex = 1;
  636. int columnIndex = 1;
  637. for (TSpecdevYlrq t : list
  638. ) {
  639. Row row = sheet.createRow(rowIndex);
  640. row.createCell(0).setCellValue(t.getId());
  641. row.createCell(1).setCellValue(t.getPlantCode());
  642. row.createCell(2).setCellValue(t.getDevno());
  643. row.createCell(3).setCellValue(t.getDevname());
  644. row.createCell(4).setCellValue(t.getUseno());
  645. row.createCell(5).setCellValue(t.getCheckUnit());
  646. if (t.getWarnDate() != null) {
  647. row.createCell(6).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
  648. }
  649. row.createCell(7).setCellValue(t.getSafeClass());
  650. if (t.getNextWarnDate() != null) {
  651. row.createCell(8).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
  652. }
  653. row.createCell(9).setCellValue(t.getReportNo());
  654. if (t.getYearWarnDate() != null) {
  655. row.createCell(10).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearWarnDate()));
  656. }
  657. row.createCell(11).setCellValue(t.getCheckConclusion());
  658. if (t.getYearNextWarnDate() != null) {
  659. row.createCell(12).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearNextWarnDate()));
  660. }
  661. row.createCell(13).setCellValue(t.getYearReportNo());
  662. rowIndex++;
  663. }
  664. OutputStream out = null;
  665. String filename = ExcelUtil.encodingFilename("压力容器批量更新");
  666. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  667. wb.write(out);
  668. wb.close();
  669. out.close();
  670. return AjaxResult.success(filename);
  671. }
  672. }