TPssrPipeController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. if (StringUtils.isNotEmpty(tPssrPipe.getConfirmer1())&&tPssrPipe.getConfirmer1().equals(tPssrPipe.getConfirmer2())) {
  207. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  208. }
  209. tPssrPipe.setApproveStatus(0L);
  210. tPssrPipe.setCreatedate(new Date());
  211. tPssrPipe.setCreaterCode(getUserId().toString());
  212. return toAjax(tPssrPipeService.insertTPssrPipe(tPssrPipe));
  213. }
  214. /**
  215. * 修改管道
  216. */
  217. @PreAuthorize("@ss.hasPermi('pssr:pipe:edit')")
  218. @Log(title = "管道", businessType = BusinessType.UPDATE)
  219. @PutMapping
  220. public AjaxResult edit(@RequestBody TPssrPipe tPssrPipe) {
  221. if (tPssrPipe.getConfirmer1().equals(tPssrPipe.getConfirmer2())){
  222. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  223. }
  224. tPssrFileService.updateFileRelevance(tPssrPipe.getFileIds(), "ylgd", tPssrPipe.getId(), tPssrPipe.getSubId());
  225. return toAjax(tPssrPipeService.updateTPssrPipe(tPssrPipe));
  226. }
  227. /**
  228. * 修改管道
  229. */
  230. @PreAuthorize("@ss.hasPermi('pssr:pipe:edit')")
  231. @Log(title = "管道批量修改", businessType = BusinessType.UPDATE)
  232. @PutMapping("/editBatch")
  233. public AjaxResult editBatch(@RequestBody TPssrPipe tPssrPipe) {
  234. if (tPssrPipe.getConfirmer1().equals(tPssrPipe.getConfirmer2())){
  235. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  236. }
  237. logger.info(JSON.toJSONString(tPssrPipe));
  238. return toAjax(tPssrPipeMapper.updateTPssrPipeByIds(tPssrPipe));
  239. }
  240. /**
  241. * 删除管道
  242. */
  243. @PreAuthorize("@ss.hasPermi('pssr:pipe:remove')")
  244. @Log(title = "管道", businessType = BusinessType.DELETE)
  245. @DeleteMapping("/{ids}")
  246. public AjaxResult remove(@PathVariable Long[] ids) {
  247. return toAjax(tPssrPipeService.deleteTPssrPipeByIds(ids));
  248. }
  249. /**
  250. * 确认压力管道
  251. */
  252. @PreAuthorize("@ss.hasPermi('pssr:pipe:edit')")
  253. @Log(title = "确认压力管道", businessType = BusinessType.UPDATE)
  254. @PutMapping("/confirmPipe")
  255. public AjaxResult confirmPipe(@RequestBody TPssrPipe tPssrPipe) {
  256. long queryStatus = 0;
  257. long approveStatus = 0;
  258. Date date = null;
  259. TPssrPipe pipe = new TPssrPipe();
  260. if (tPssrPipe.getTaskType() == 4) {
  261. //确认人1确认
  262. queryStatus = 1;
  263. approveStatus = 3;
  264. pipe.setConfirmer1(getUserId().toString());
  265. date = new Date();
  266. } else if (tPssrPipe.getTaskType() == 5) {
  267. //确认人2确认
  268. queryStatus = 3;
  269. approveStatus = 2;
  270. pipe.setConfirmer2(getUserId().toString());
  271. date = new Date();
  272. }
  273. if (tPssrPipe.getIds() != null && tPssrPipe.getIds().length > 0) {
  274. for (Long id : tPssrPipe.getIds()) {
  275. pipe = tPssrPipeService.selectTPssrPipeById(id);
  276. if (queryStatus == 3) {
  277. pipe.setConfirmationDate(new Date());
  278. }
  279. pipe.setApproveStatus(approveStatus);
  280. pipe.setUpdatedate(new Date());
  281. pipe.setUpdaterCode(String.valueOf(getUserId()));
  282. tPssrPipeService.updateTPssrPipe(pipe);
  283. }
  284. } else {
  285. pipe.setSubId(tPssrPipe.getSubId());
  286. pipe.setApproveStatus(queryStatus);
  287. for (TPssrPipe item : tPssrPipeService.selectTPssrPipeList(pipe)) {
  288. if (queryStatus == 3) {
  289. item.setConfirmationDate(new Date());
  290. }
  291. item.setApproveStatus(approveStatus);
  292. item.setUpdatedate(new Date());
  293. item.setUpdaterCode(String.valueOf(getUserId()));
  294. tPssrPipeService.updateTPssrPipe(item);
  295. }
  296. }
  297. //查询当前待审批的确认人
  298. TPssrPipe entity = new TPssrPipe();
  299. entity.setSubId(tPssrPipe.getSubId());
  300. entity.setApproveStatus(queryStatus);
  301. TPssrPipe pssrPipe = tPssrPipeService.selectAllConfirmedPersonBySubId(entity);
  302. if (pssrPipe != null) {
  303. //如果当前用户还有待审批任务
  304. if (tPssrPipe.getTaskType() == 4 && StringUtils.isNotEmpty(pssrPipe.getConfirmer1())) {
  305. if (pssrPipe.getConfirmer1().contains(getUserId().toString())) {
  306. return AjaxResult.success();
  307. }
  308. }
  309. if (tPssrPipe.getTaskType() == 5 && StringUtils.isNotEmpty(pssrPipe.getConfirmer2())) {
  310. if (pssrPipe.getConfirmer2().contains(getUserId().toString())) {
  311. return AjaxResult.success();
  312. }
  313. }
  314. }
  315. //无待审批任务结束当前用户流程
  316. // 因为流程关系所以approve一定会有且只有一条数据
  317. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrPipe.getSubId());
  318. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  319. return AjaxResult.success();
  320. }
  321. /**
  322. * 驳回压力管道
  323. */
  324. @PutMapping("/turnDownPipe")
  325. public AjaxResult turnDownPipe(@RequestBody List<TPssrPipe> tPssrPipe) {
  326. if (CollectionUtils.isNotEmpty(tPssrPipe)) {
  327. String userId = getUserId().toString();
  328. Long subId = tPssrPipe.get(0).getSubId();
  329. // 修改已选择数据的状态
  330. for (TPssrPipe item : tPssrPipe) {
  331. TPssrPipe blind = new TPssrPipe();
  332. blind.setId(item.getId());
  333. blind.setApproveStatus(1L);
  334. blind.setUpdatedate(new Date());
  335. blind.setUpdaterCode(getUserId().toString());
  336. tPssrPipeService.updateTPssrPipe(blind);
  337. // 新增驳回原因数据
  338. TPssrTurndown turndown = new TPssrTurndown();
  339. turndown.setForShort(forShort);
  340. turndown.setSubId(item.getSubId());
  341. turndown.setItemId(item.getId());
  342. turndown.setReason(item.getReason());
  343. turndown.setCreatedate(new Date());
  344. turndown.setCreaterCode(getUserId().toString());
  345. tPssrTurndownService.insertTPssrTurndown(turndown);
  346. }
  347. // 查询当前流程
  348. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  349. try {
  350. runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr2confirm");
  351. historyService.deleteHistoricProcessInstance(approve.getProcessId());
  352. } catch (Exception e) {
  353. logger.info("无运行时流程");
  354. }
  355. // 驳回 查询所有待审批的人员
  356. //查询确认人
  357. TPssrPipe entity = new TPssrPipe();
  358. entity.setSubId(subId);
  359. entity.setApproveStatus(1L);
  360. TPssrPipe pssrPipe = tPssrPipeService.selectAllConfirmedPersonBySubId(entity);
  361. String confirmer1s = null;
  362. String confirmer2s = null;
  363. if (pssrPipe != null) {
  364. confirmer1s = pssrPipe.getConfirmer1();
  365. confirmer2s = pssrPipe.getConfirmer2();
  366. }
  367. logger.info("=======================confirmer1s:{}", confirmer1s);
  368. logger.info("=======================confirmer2s:{}", confirmer2s);
  369. Set<String> confirmerUsers1 = new HashSet<>();
  370. Set<String> confirmerUsers2 = new HashSet<>();
  371. if (StringUtils.isNotEmpty(confirmer1s)) {
  372. confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
  373. }
  374. if (StringUtils.isNotEmpty(confirmer2s)) {
  375. confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
  376. }
  377. // 开始申请流程
  378. long businessKey = approve.getApproveId();
  379. //开始工作流、监听
  380. Authentication.setAuthenticatedUserId(userId);//设置当前申请人
  381. Map<String, Object> variables = new HashMap<>();
  382. variables.put("applyUser", userId);
  383. variables.put("confirmUsers1", new ArrayList<>(confirmerUsers1));
  384. variables.put("confirmUsers2", new ArrayList<>(confirmerUsers2));
  385. variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
  386. variables.put("chargePerson", approve.getSubCharge());
  387. //采用key来启动流程定义并设置流程变量,返回流程实例
  388. ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr2confirm", String.valueOf(businessKey), variables);
  389. // 修改审批表和sub表
  390. approve.setProcessId(pi.getProcessInstanceId());
  391. approve.setApproveStatus(1L);
  392. approve.setUpdatedate(new Date());
  393. approve.setUpdaterCode(getUserId().toString());
  394. tPssrApproveService.updateTPssrApprove(approve);
  395. TPssrSubcontent subcontent = new TPssrSubcontent();
  396. subcontent.setId(approve.getSubId());
  397. subcontent.setApproveStatus(1L);
  398. subcontent.setUpdatedate(new Date());
  399. subcontent.setUpdaterCode(getUserId().toString());
  400. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  401. return AjaxResult.success();
  402. }
  403. return AjaxResult.error();
  404. }
  405. }