TPssrPipeController.java 17 KB

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