TPssrVesselController.java 18 KB

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