TPssrVesselController.java 20 KB

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