TSpecdevYlrqController.java 30 KB

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