TPssrOverhaulExchangerController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. package com.ruoyi.project.pssr.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.ruoyi.common.utils.DateUtils;
  4. import com.ruoyi.common.utils.StringUtils;
  5. import com.ruoyi.common.utils.file.ExcelUtils;
  6. import com.ruoyi.common.utils.poi.ExcelUtil;
  7. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  8. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  9. import com.ruoyi.framework.web.controller.BaseController;
  10. import com.ruoyi.framework.web.domain.AjaxResult;
  11. import com.ruoyi.framework.web.page.TableDataInfo;
  12. import com.ruoyi.project.listener.pssr.ConfirmTaskCreateListener;
  13. import com.ruoyi.project.pssr.domain.TPssrApprove;
  14. import com.ruoyi.project.pssr.domain.TPssrOverhaulExchanger;
  15. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  16. import com.ruoyi.project.pssr.domain.TPssrTurndown;
  17. import com.ruoyi.project.pssr.mapper.TPssrOverhaulExchangerMapper;
  18. import com.ruoyi.project.pssr.service.*;
  19. import com.ruoyi.project.system.domain.SysDept;
  20. import com.ruoyi.project.system.domain.SysUser;
  21. import com.ruoyi.project.system.service.ISysDeptService;
  22. import com.ruoyi.project.system.service.ISysUserService;
  23. import org.activiti.engine.HistoryService;
  24. import org.activiti.engine.RuntimeService;
  25. import org.activiti.engine.impl.identity.Authentication;
  26. import org.activiti.engine.runtime.ProcessInstance;
  27. import org.apache.commons.collections4.CollectionUtils;
  28. import org.apache.poi.ss.usermodel.*;
  29. import org.apache.poi.xssf.usermodel.XSSFSheet;
  30. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.security.access.prepost.PreAuthorize;
  33. import org.springframework.web.bind.annotation.*;
  34. import org.springframework.web.multipart.MultipartFile;
  35. import javax.annotation.Resource;
  36. import java.io.FileOutputStream;
  37. import java.io.IOException;
  38. import java.io.InputStream;
  39. import java.io.OutputStream;
  40. import java.text.SimpleDateFormat;
  41. import java.util.*;
  42. /**
  43. * 检修项目-换热器Controller
  44. *
  45. * @author ssy
  46. * @date 2024-09-18
  47. */
  48. @RestController
  49. @RequestMapping("/pssr/overhaulExchanger")
  50. public class TPssrOverhaulExchangerController extends BaseController {
  51. @Resource
  52. private TPssrOverhaulExchangerMapper tPssrOverhaulExchangerMapper;
  53. @Autowired
  54. private ITPssrFileService tPssrFileService;
  55. @Autowired
  56. private ITPssrTurndownService tPssrTurndownService;
  57. @Autowired
  58. private ITPssrOverhaulExchangerService tPssrOverhaulExchangerService;
  59. @Autowired
  60. private ITPssrApproveService tPssrApproveService;
  61. @Autowired
  62. private RuntimeService runtimeService;
  63. @Autowired
  64. private HistoryService historyService;
  65. @Autowired
  66. private ITPssrSubcontentService tPssrSubcontentService;
  67. @Autowired
  68. private ISysUserService sysUserService;
  69. private String forShort = "jxxm-hrq";
  70. @Autowired
  71. private ISysDeptService iSysDeptService;
  72. @Autowired
  73. private ISysUserService userService;
  74. /**
  75. * 查询检修项目-换热器列表
  76. */
  77. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:list')")
  78. @GetMapping("/list")
  79. public TableDataInfo list(TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  80. if ("1".equals(tPssrOverhaulExchanger.getConfirmedPerson())) {
  81. tPssrOverhaulExchanger.setConfirmedPerson(getUserId().toString());
  82. }
  83. startPage();
  84. List<TPssrOverhaulExchanger> list = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(tPssrOverhaulExchanger);
  85. list.forEach(item -> {
  86. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "jxxm-hrq"));
  87. if (item.getApproveStatus() != 2)
  88. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "jxxm-hrq"));
  89. });
  90. return getDataTable(list);
  91. }
  92. /**
  93. * 导出检修项目-换热器列表
  94. */
  95. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:export')")
  96. @Log(title = "检修项目-换热器", businessType = BusinessType.EXPORT)
  97. @GetMapping("/export")
  98. public AjaxResult export(TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  99. List<TPssrOverhaulExchanger> list = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(tPssrOverhaulExchanger);
  100. return AjaxResult.success(exportTmpl(list, tPssrOverhaulExchanger.getDevType()));
  101. }
  102. public String exportTmpl(List<TPssrOverhaulExchanger> list, Long devType) {
  103. OutputStream out = null;
  104. String filename = null;
  105. try {
  106. String tempUrl = "static/word/pssr/jxxmhrq.xlsx"; // 模板文件
  107. InputStream is = null;
  108. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  109. XSSFWorkbook wb = null;
  110. wb = new XSSFWorkbook(is);
  111. XSSFSheet sheet = wb.getSheetAt(0);
  112. switch (devType.toString()) {
  113. case "1":
  114. filename = "PSSR_01_检修项目_换热器" + ".xlsx";
  115. sheet.getRow(0).getCell(0).setCellValue("换热器检修清单");
  116. break;
  117. case "2":
  118. filename = "PSSR_01_检修项目_电仪" + ".xlsx";
  119. sheet.getRow(0).getCell(0).setCellValue("电仪检修清单");
  120. break;
  121. case "3":
  122. filename = "PSSR_01_检修项目_反应器" + ".xlsx";
  123. sheet.getRow(0).getCell(0).setCellValue("反应器检修清单");
  124. break;
  125. case "4":
  126. filename = "PSSR_01_检修项目_裂解炉" + ".xlsx";
  127. sheet.getRow(0).getCell(0).setCellValue("裂解炉检修清单");
  128. break;
  129. case "5":
  130. filename = "PSSR_01_检修项目_其他" + ".xlsx";
  131. sheet.getRow(0).getCell(0).setCellValue("其他检修清单");
  132. break;
  133. }
  134. //填充数据
  135. int rowIndex = 2;
  136. int num = 1;
  137. Row originalRow = sheet.getRow(2);
  138. Cell originalcell = originalRow.getCell(0);
  139. // 获取单元格样式
  140. CellStyle originalStyle = originalcell.getCellStyle();
  141. for (TPssrOverhaulExchanger t : list) {
  142. Row row = sheet.createRow(rowIndex);
  143. row.setHeight((short) 800);
  144. row.createCell(0).setCellValue(num);
  145. row.createCell(1).setCellValue(t.getTagNo());
  146. row.createCell(2).setCellValue(t.getEquipmentName());
  147. row.createCell(3).setCellValue(t.getPidNo());
  148. row.createCell(4).setCellValue(t.getWorkDes());
  149. row.createCell(5).setCellValue(t.getCompletionStatus());
  150. row.createCell(6);
  151. try {
  152. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirmedPerson()));
  153. String confirm1 = sysUser.getSignUrl();
  154. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 6, 1, 1);
  155. } catch (NumberFormatException e) {
  156. throw new RuntimeException(e);
  157. }
  158. row.createCell(7).setCellValue(DateUtils.dateTime(t.getCompletionDate()));
  159. row.createCell(8).setCellValue(t.getRemarks());
  160. //渲染样式
  161. for (int i = 0; i < 9; i++) {
  162. row.getCell(i).setCellStyle(originalStyle);
  163. }
  164. num++;
  165. rowIndex++;
  166. }
  167. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  168. wb.write(out);
  169. wb.close();
  170. } catch (IOException e) {
  171. e.printStackTrace();
  172. }
  173. return filename;
  174. }
  175. /**
  176. * 获取检修项目-换热器详细信息
  177. */
  178. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:query')")
  179. @GetMapping(value = "/{id}")
  180. public AjaxResult getInfo(@PathVariable("id") Long id) {
  181. TPssrOverhaulExchanger item = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id);
  182. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "jxxm-hrq"));
  183. if (item.getApproveStatus() != 2)
  184. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "jxxm-hrq"));
  185. return AjaxResult.success(item);
  186. }
  187. /**
  188. * 新增检修项目-换热器
  189. */
  190. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:add')")
  191. @Log(title = "检修项目-换热器", businessType = BusinessType.INSERT)
  192. @PostMapping
  193. public AjaxResult add(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  194. tPssrOverhaulExchanger.setApproveStatus(0L);
  195. return toAjax(tPssrOverhaulExchangerService.insertTPssrOverhaulExchanger(tPssrOverhaulExchanger));
  196. }
  197. /**
  198. * 修改检修项目-换热器
  199. */
  200. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
  201. @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
  202. @PutMapping
  203. public AjaxResult edit(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  204. tPssrFileService.updateFileRelevance(tPssrOverhaulExchanger.getFileIds(), "jxxm-hrq", tPssrOverhaulExchanger.getId(), tPssrOverhaulExchanger.getSubId());
  205. return toAjax(tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(tPssrOverhaulExchanger));
  206. }
  207. /**
  208. * 修改检修项目-换热器
  209. */
  210. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
  211. @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
  212. @PutMapping("/editBatch")
  213. public AjaxResult editb(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  214. return toAjax(tPssrOverhaulExchangerMapper.updateTPssrOverhaulExchangerByIds(tPssrOverhaulExchanger));
  215. }
  216. /**
  217. * 删除检修项目-换热器
  218. */
  219. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:remove')")
  220. @Log(title = "检修项目-换热器", businessType = BusinessType.DELETE)
  221. @DeleteMapping("/{ids}")
  222. public AjaxResult remove(@PathVariable Long[] ids) {
  223. return toAjax(tPssrOverhaulExchangerService.deleteTPssrOverhaulExchangerByIds(ids));
  224. }
  225. /**
  226. * 确认检修项目-换热器
  227. */
  228. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
  229. @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
  230. @PutMapping("/confirmExchanger")
  231. public AjaxResult confirmExchanger(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  232. if (tPssrOverhaulExchanger.getIds() != null && tPssrOverhaulExchanger.getIds().length > 0) {
  233. for (Long id : tPssrOverhaulExchanger.getIds()) {
  234. TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id);
  235. exchanger.setCompletionDate(new Date());
  236. exchanger.setApproveStatus(2L);
  237. exchanger.setUpdatedate(new Date());
  238. exchanger.setUpdaterCode(String.valueOf(getUserId()));
  239. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(exchanger);
  240. }
  241. } else {
  242. TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
  243. exchanger.setSubId(tPssrOverhaulExchanger.getSubId());
  244. exchanger.setConfirmedPerson(getUserId().toString());
  245. exchanger.setApproveStatus(1L);
  246. for (TPssrOverhaulExchanger overhaulExchanger : tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(exchanger)) {
  247. overhaulExchanger.setCompletionDate(new Date());
  248. overhaulExchanger.setApproveStatus(2L);
  249. overhaulExchanger.setUpdatedate(new Date());
  250. overhaulExchanger.setUpdaterCode(String.valueOf(getUserId()));
  251. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(overhaulExchanger);
  252. }
  253. }
  254. //查询当前待审批的确认人
  255. TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
  256. entity.setSubId(tPssrOverhaulExchanger.getSubId());
  257. entity.setApproveStatus(1L);
  258. TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(entity);
  259. if (exchanger != null) {
  260. String confirmedPerson = exchanger.getConfirmedPerson();
  261. logger.info("===========confirmedPerson:{}", confirmedPerson);
  262. //如果当前用户还有待审批任务
  263. if (confirmedPerson.contains(getUserId().toString())) {
  264. return AjaxResult.success();
  265. }
  266. }
  267. //无待审批任务结束当前用户流程
  268. // 因为流程关系所以approve一定会有且只有一条数据
  269. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrOverhaulExchanger.getSubId());
  270. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  271. return AjaxResult.success();
  272. }
  273. @PutMapping("/turnDownExchanger")
  274. public AjaxResult turnDownExchanger(@RequestBody List<TPssrOverhaulExchanger> tPssrOverhaulExchanger) {
  275. if (CollectionUtils.isNotEmpty(tPssrOverhaulExchanger)) {
  276. String userId = getUserId().toString();
  277. Long subId = tPssrOverhaulExchanger.get(0).getSubId();
  278. // 修改已选择数据的状态
  279. for (TPssrOverhaulExchanger item : tPssrOverhaulExchanger) {
  280. TPssrOverhaulExchanger blind = new TPssrOverhaulExchanger();
  281. blind.setId(item.getId());
  282. blind.setApproveStatus(1L);
  283. blind.setUpdatedate(new Date());
  284. blind.setUpdaterCode(getUserId().toString());
  285. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(blind);
  286. // 新增驳回原因数据
  287. TPssrTurndown turndown = new TPssrTurndown();
  288. turndown.setForShort(forShort);
  289. turndown.setSubId(item.getSubId());
  290. turndown.setItemId(item.getId());
  291. turndown.setReason(item.getReason());
  292. turndown.setCreatedate(new Date());
  293. turndown.setCreaterCode(getUserId().toString());
  294. tPssrTurndownService.insertTPssrTurndown(turndown);
  295. }
  296. // 查询当前流程
  297. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  298. try {
  299. runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr1confirm");
  300. historyService.deleteHistoricProcessInstance(approve.getProcessId());
  301. } catch (Exception e) {
  302. logger.info("无运行时流程");
  303. }
  304. // 驳回 查询所有待审批的人员
  305. //查询所有确认人
  306. TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
  307. exchanger.setSubId(approve.getSubId());
  308. exchanger.setApproveStatus(1L);
  309. TPssrOverhaulExchanger overhaul = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(exchanger);
  310. String confirmers = null;
  311. if (overhaul != null) {
  312. confirmers = overhaul.getConfirmedPerson();
  313. }
  314. logger.info("=======================confirmers:{}", confirmers);
  315. Set<String> confirmUsers1 = new HashSet<>();
  316. if (StringUtils.isNotEmpty(confirmers)) {
  317. confirmUsers1.addAll(Arrays.asList(confirmers.split(",")));
  318. }
  319. // 开始申请流程
  320. long businessKey = approve.getApproveId();
  321. //开始工作流、监听
  322. Authentication.setAuthenticatedUserId(userId);//设置当前申请人
  323. Map<String, Object> variables = new HashMap<>();
  324. variables.put("applyUser", userId);
  325. variables.put("confirmUsers", new ArrayList<>(confirmUsers1));
  326. variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
  327. variables.put("chargePerson", approve.getSubCharge());
  328. //采用key来启动流程定义并设置流程变量,返回流程实例
  329. ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr1confirm", String.valueOf(businessKey), variables);
  330. // 修改审批表和sub表
  331. approve.setProcessId(pi.getProcessInstanceId());
  332. approve.setApproveStatus(1L);
  333. approve.setUpdatedate(new Date());
  334. approve.setUpdaterCode(getUserId().toString());
  335. tPssrApproveService.updateTPssrApprove(approve);
  336. TPssrSubcontent subcontent = new TPssrSubcontent();
  337. subcontent.setId(approve.getSubId());
  338. subcontent.setApproveStatus(1L);
  339. subcontent.setUpdatedate(new Date());
  340. subcontent.setUpdaterCode(getUserId().toString());
  341. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  342. return AjaxResult.success();
  343. }
  344. return AjaxResult.error();
  345. }
  346. /**
  347. * 批量导入
  348. */
  349. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:add')")
  350. @PostMapping("/importData")
  351. public AjaxResult importInterlockData(MultipartFile file, Long subId, Long devType) throws IOException {
  352. //获取操作人员ID
  353. Long userId = getUserId();
  354. //报错行数统计
  355. List<Integer> failRow = new ArrayList<Integer>();
  356. Workbook workbook = ExcelUtils.getWorkBook(file);
  357. Sheet sheet = workbook.getSheetAt(0);
  358. List<TPssrOverhaulExchanger> list = new ArrayList<TPssrOverhaulExchanger>();
  359. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  360. //部门查询
  361. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  362. int rowNum = sheet.getPhysicalNumberOfRows();
  363. int failNumber = 0;
  364. for (int i = 2; i <= rowNum; i++) {
  365. try {
  366. logger.info("读取行数:" + i);
  367. Row row = sheet.getRow(i);
  368. int cellNum = row.getLastCellNum();
  369. TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
  370. entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
  371. entity.setSubId(subId);
  372. entity.setDevType(devType);
  373. entity.setApproveStatus(0L);
  374. for (int j = 0; j < cellNum; j++) {
  375. Cell cell = row.getCell(j);
  376. String cellValue = ExcelUtils.getCellValue(cell);
  377. logger.info("cellValue:" + cellValue);
  378. if (j == 0) {
  379. entity.setTagNo(cellValue);
  380. } else if (j == 1) {
  381. entity.setEquipmentName(cellValue);
  382. } else if (j == 2) {
  383. entity.setWorkDes(cellValue);
  384. } else if (j == 3) {
  385. entity.setPidNo(cellValue);
  386. }
  387. }
  388. entity.setCreaterCode(userId.toString());
  389. logger.info("entity:" + entity);
  390. list.add(entity);
  391. } catch (Exception e) {
  392. failNumber++;
  393. failRow.add(i + 1);
  394. }
  395. }
  396. int successNumber = 0;
  397. int failNum = 0;
  398. for (TPssrOverhaulExchanger t : list
  399. ) {
  400. failNum++;
  401. try {
  402. this.add(t);
  403. successNumber++;
  404. } catch (Exception e) {
  405. failNumber++;
  406. logger.info("e:" + e);
  407. failRow.add(failNum + 1);
  408. }
  409. }
  410. logger.info("list:" + JSON.toJSONString(list));
  411. logger.info("successNumber:" + String.valueOf(successNumber));
  412. logger.info("failNumber:" + String.valueOf(failNumber));
  413. logger.info("failRow:" + String.valueOf(failRow));
  414. return AjaxResult.success("导入成功行数:" + String.valueOf(successNumber));
  415. }
  416. }