TPssrOverhaulExchangerController.java 19 KB

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