TPssrPipeController.java 18 KB

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