TPssrOverhaulExchangerController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 = ExcelUtil.encodingFilename("OverhaulExchanger");
  146. break;
  147. case "2":
  148. filename = ExcelUtil.encodingFilename("OverhaulExchanger2");
  149. break;
  150. case "3":
  151. filename = ExcelUtil.encodingFilename("OverhaulExchanger3");
  152. break;
  153. case "4":
  154. filename = ExcelUtil.encodingFilename("OverhaulExchanger4");
  155. break;
  156. case "5":
  157. filename = ExcelUtil.encodingFilename("OverhaulExchanger5");
  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:remove')")
  204. @Log(title = "检修项目-换热器", businessType = BusinessType.DELETE)
  205. @DeleteMapping("/{ids}")
  206. public AjaxResult remove(@PathVariable Long[] ids) {
  207. return toAjax(tPssrOverhaulExchangerService.deleteTPssrOverhaulExchangerByIds(ids));
  208. }
  209. /**
  210. * 确认检修项目-换热器
  211. */
  212. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
  213. @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
  214. @PutMapping("/confirmExchanger")
  215. public AjaxResult confirmExchanger(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  216. if (tPssrOverhaulExchanger.getIds() != null && tPssrOverhaulExchanger.getIds().length > 0) {
  217. for (Long id : tPssrOverhaulExchanger.getIds()) {
  218. TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id);
  219. if (exchanger.getCompletionDate() == null) {
  220. exchanger.setCompletionDate(new Date());
  221. }
  222. exchanger.setApproveStatus(2L);
  223. exchanger.setUpdatedate(new Date());
  224. exchanger.setUpdaterCode(String.valueOf(getUserId()));
  225. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(exchanger);
  226. }
  227. } else {
  228. TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
  229. exchanger.setSubId(tPssrOverhaulExchanger.getSubId());
  230. exchanger.setConfirmedPerson(getUserId().toString());
  231. exchanger.setApproveStatus(1L);
  232. for (TPssrOverhaulExchanger overhaulExchanger : tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(exchanger)) {
  233. if (overhaulExchanger.getCompletionDate() == null) {
  234. overhaulExchanger.setCompletionDate(new Date());
  235. }
  236. overhaulExchanger.setApproveStatus(2L);
  237. overhaulExchanger.setUpdatedate(new Date());
  238. overhaulExchanger.setUpdaterCode(String.valueOf(getUserId()));
  239. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(overhaulExchanger);
  240. }
  241. }
  242. //查询当前待审批的确认人
  243. TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
  244. entity.setSubId(tPssrOverhaulExchanger.getSubId());
  245. entity.setApproveStatus(1L);
  246. TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(entity);
  247. if (exchanger != null) {
  248. String confirmedPerson = exchanger.getConfirmedPerson();
  249. logger.info("===========confirmedPerson:{}", confirmedPerson);
  250. //如果当前用户还有待审批任务
  251. if (confirmedPerson.contains(getUserId().toString())) {
  252. return AjaxResult.success();
  253. }
  254. }
  255. //无待审批任务结束当前用户流程
  256. // 因为流程关系所以approve一定会有且只有一条数据
  257. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrOverhaulExchanger.getSubId());
  258. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  259. return AjaxResult.success();
  260. }
  261. @PutMapping("/turnDownExchanger")
  262. public AjaxResult turnDownExchanger(@RequestBody List<TPssrOverhaulExchanger> tPssrOverhaulExchanger) {
  263. if (CollectionUtils.isNotEmpty(tPssrOverhaulExchanger)) {
  264. String userId = getUserId().toString();
  265. Long subId = tPssrOverhaulExchanger.get(0).getSubId();
  266. // 修改已选择数据的状态
  267. for (TPssrOverhaulExchanger item : tPssrOverhaulExchanger) {
  268. TPssrOverhaulExchanger blind = new TPssrOverhaulExchanger();
  269. blind.setId(item.getId());
  270. blind.setApproveStatus(1L);
  271. blind.setUpdatedate(new Date());
  272. blind.setUpdaterCode(getUserId().toString());
  273. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(blind);
  274. // 新增驳回原因数据
  275. TPssrTurndown turndown = new TPssrTurndown();
  276. turndown.setForShort(forShort);
  277. turndown.setSubId(item.getSubId());
  278. turndown.setItemId(item.getId());
  279. turndown.setReason(item.getReason());
  280. turndown.setCreatedate(new Date());
  281. turndown.setCreaterCode(getUserId().toString());
  282. tPssrTurndownService.insertTPssrTurndown(turndown);
  283. }
  284. // 查询当前流程
  285. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  286. try {
  287. runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr1confirm");
  288. historyService.deleteHistoricProcessInstance(approve.getProcessId());
  289. } catch (Exception e) {
  290. logger.info("无运行时流程");
  291. }
  292. // 驳回 查询所有待审批的人员
  293. //查询所有确认人
  294. TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
  295. exchanger.setSubId(approve.getSubId());
  296. exchanger.setApproveStatus(1L);
  297. TPssrOverhaulExchanger overhaul = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(exchanger);
  298. String confirmers = null;
  299. if (overhaul != null) {
  300. confirmers = overhaul.getConfirmedPerson();
  301. }
  302. logger.info("=======================confirmers:{}", confirmers);
  303. Set<String> confirmUsers1 = new HashSet<>();
  304. if (StringUtils.isNotEmpty(confirmers)) {
  305. confirmUsers1.addAll(Arrays.asList(confirmers.split(",")));
  306. }
  307. // 开始申请流程
  308. long businessKey = approve.getApproveId();
  309. //开始工作流、监听
  310. Authentication.setAuthenticatedUserId(userId);//设置当前申请人
  311. Map<String, Object> variables = new HashMap<>();
  312. variables.put("applyUser", userId);
  313. variables.put("confirmUsers", new ArrayList<>(confirmUsers1));
  314. variables.put("chargePerson", approve.getSubCharge());
  315. //采用key来启动流程定义并设置流程变量,返回流程实例
  316. ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr1confirm", String.valueOf(businessKey), variables);
  317. // 修改审批表和sub表
  318. approve.setProcessId(pi.getProcessInstanceId());
  319. approve.setApproveStatus(1L);
  320. approve.setUpdatedate(new Date());
  321. approve.setUpdaterCode(getUserId().toString());
  322. tPssrApproveService.updateTPssrApprove(approve);
  323. TPssrSubcontent subcontent = new TPssrSubcontent();
  324. subcontent.setId(approve.getSubId());
  325. subcontent.setApproveStatus(1L);
  326. subcontent.setUpdatedate(new Date());
  327. subcontent.setUpdaterCode(getUserId().toString());
  328. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  329. return AjaxResult.success();
  330. }
  331. return AjaxResult.error();
  332. }
  333. /**
  334. * 批量导入
  335. */
  336. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:add')")
  337. @PostMapping("/importData")
  338. public AjaxResult importInterlockData(MultipartFile file, Long subId, Long devType) throws IOException
  339. {
  340. //获取操作人员ID
  341. Long userId = getUserId();
  342. //报错行数统计
  343. List<Integer> failRow =new ArrayList<Integer>();
  344. Workbook workbook = ExcelUtils.getWorkBook(file);
  345. Sheet sheet = workbook.getSheetAt(0);
  346. List<TPssrOverhaulExchanger> list = new ArrayList<TPssrOverhaulExchanger>();
  347. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  348. //部门查询
  349. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  350. int rowNum = sheet.getPhysicalNumberOfRows();
  351. int failNumber = 0;
  352. for (int i = 2; i <= rowNum; i++) {
  353. try {
  354. logger.info("读取行数:" + i);
  355. Row row = sheet.getRow(i);
  356. int cellNum = row.getPhysicalNumberOfCells();
  357. TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
  358. entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
  359. entity.setSubId(subId);
  360. entity.setDevType(devType);
  361. entity.setApproveStatus(0L);
  362. for (int j = 0; j < cellNum; j++) {
  363. Cell cell = row.getCell(j);
  364. String cellValue = ExcelUtils.getCellValue(cell);
  365. logger.info("cellValue:" + cellValue);
  366. if (j == 0) {
  367. entity.setTagNo(cellValue);
  368. } else if (j == 1) {
  369. entity.setEquipmentName(cellValue);
  370. } else if (j == 2) {
  371. entity.setWorkDes(cellValue);
  372. } else if (j == 3) {
  373. entity.setPidNo(cellValue);
  374. } else if (j == 4) {
  375. entity.setRemarks(cellValue);
  376. }
  377. }
  378. entity.setCreaterCode(userId.toString());
  379. logger.info("entity:" + entity);
  380. list.add(entity);
  381. }catch (Exception e){
  382. failNumber++;
  383. failRow.add(i+1);
  384. }
  385. }
  386. int successNumber = 0;
  387. int failNum = 0;
  388. for (TPssrOverhaulExchanger t : list
  389. ) {
  390. failNum++;
  391. try {
  392. tPssrOverhaulExchangerService.insertTPssrOverhaulExchanger(t);
  393. successNumber++;
  394. }catch (Exception e){
  395. failNumber++;
  396. logger.info("e:" + e);
  397. failRow.add(failNum+1);
  398. }
  399. }
  400. logger.info("list:" + JSON.toJSONString(list));
  401. logger.info("successNumber:" +String.valueOf(successNumber));
  402. logger.info("failNumber:" +String.valueOf(failNumber));
  403. logger.info("failRow:" +String.valueOf(failRow));
  404. return AjaxResult.success("导入成功行数:" + String.valueOf(successNumber));
  405. }
  406. }