TPssrPumpCleaningController.java 20 KB

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