TPssrPipeController.java 18 KB

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