TPssrLockController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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.file.ExcelUtils;
  5. import com.ruoyi.common.utils.poi.ExcelUtil;
  6. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  7. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  8. import com.ruoyi.framework.web.controller.BaseController;
  9. import com.ruoyi.framework.web.domain.AjaxResult;
  10. import com.ruoyi.framework.web.page.TableDataInfo;
  11. import com.ruoyi.project.apply.domain.TApplyLock;
  12. import com.ruoyi.project.apply.service.ITApplyLockService;
  13. import com.ruoyi.project.pssr.domain.TPssrApprove;
  14. import com.ruoyi.project.pssr.domain.TPssrLock;
  15. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  16. import com.ruoyi.project.pssr.domain.TPssrTurndown;
  17. import com.ruoyi.project.pssr.mapper.TPssrLockMapper;
  18. import com.ruoyi.project.pssr.service.*;
  19. import com.ruoyi.project.system.domain.SysUser;
  20. import com.ruoyi.project.system.service.ISysUserService;
  21. import org.activiti.engine.ProcessEngine;
  22. import org.activiti.engine.ProcessEngines;
  23. import org.activiti.engine.TaskService;
  24. import org.activiti.engine.task.Task;
  25. import org.apache.commons.collections4.CollectionUtils;
  26. import org.apache.poi.ss.usermodel.Cell;
  27. import org.apache.poi.ss.usermodel.CellStyle;
  28. import org.apache.poi.ss.usermodel.Row;
  29. import org.apache.poi.xssf.usermodel.XSSFSheet;
  30. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.security.access.prepost.PreAuthorize;
  33. import org.springframework.web.bind.annotation.*;
  34. import javax.annotation.Resource;
  35. import java.io.FileOutputStream;
  36. import java.io.IOException;
  37. import java.io.InputStream;
  38. import java.io.OutputStream;
  39. import java.util.*;
  40. /**
  41. * 锁开锁关阀门状态Controller
  42. *
  43. * @author ssy
  44. * @date 2024-09-18
  45. */
  46. @RestController
  47. @RequestMapping("/pssr/lock")
  48. public class TPssrLockController extends BaseController {
  49. @Autowired
  50. private ITPssrFileService tPssrFileService;
  51. @Resource
  52. private TPssrLockMapper tPssrLockMapper;
  53. @Autowired
  54. private ITPssrTurndownService tPssrTurndownService;
  55. @Autowired
  56. private ITPssrLockService tPssrLockService;
  57. @Autowired
  58. private ITPssrApproveService tPssrApproveService;
  59. @Autowired
  60. private ITPssrSubcontentService tPssrSubcontentService;
  61. @Autowired
  62. private ITPssrAboveallService tPssrAboveallService;
  63. @Autowired
  64. private ITApplyLockService tApplyLockService;
  65. @Autowired
  66. private ISysUserService sysUserService;
  67. private String forShort = "sksgfmzt";
  68. /**
  69. * 查询锁开锁关阀门状态列表
  70. */
  71. @PreAuthorize("@ss.hasPermi('pssr:lock:list')")
  72. @GetMapping("/list")
  73. public TableDataInfo list(TPssrLock tPssrLock) {
  74. try {
  75. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrLock.getSubId());
  76. if (approve != null) {
  77. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  78. TaskService taskService = processEngine.getTaskService();
  79. Task task = processEngine.getTaskService()//获取任务service
  80. .createTaskQuery()//创建查询对象
  81. .taskAssignee(getUserId().toString())
  82. .processInstanceId(approve.getProcessId()).singleResult();
  83. if (task != null) {
  84. if (task.getName().equals("确认人1")){
  85. tPssrLock.setLockeder(getUserId().toString());
  86. }else if (task.getName().equals("确认人2")){
  87. tPssrLock.setConfirm(getUserId().toString());
  88. }
  89. }
  90. }
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. logger.error("待办确认人查询报错:{}",e.getMessage());
  94. }
  95. startPage();
  96. List<TPssrLock> list = tPssrLockService.selectTPssrLockList(tPssrLock);
  97. list.forEach(item -> {
  98. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "sksgfmzt"));
  99. if (item.getApproveStatus() != 2)
  100. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "sksgfmzt"));
  101. });
  102. return getDataTable(list);
  103. }
  104. /**
  105. * 导出锁开锁关阀门状态列表
  106. */
  107. @PreAuthorize("@ss.hasPermi('pssr:lock:export')")
  108. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.EXPORT)
  109. @GetMapping("/export")
  110. public AjaxResult export(TPssrLock tPssrLock) {
  111. List<TPssrLock> list = tPssrLockService.selectTPssrLockList(tPssrLock);
  112. return AjaxResult.success(exportTmpl(list));
  113. }
  114. public String exportTmpl(List<TPssrLock> list) {
  115. OutputStream out = null;
  116. String filename = null;
  117. try {
  118. String tempUrl = "static/word/pssr/sksgfmzt.xlsx"; // 模板文件
  119. InputStream is = null;
  120. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  121. XSSFWorkbook wb = null;
  122. wb = new XSSFWorkbook(is);
  123. XSSFSheet sheet = wb.getSheetAt(0);
  124. //填充数据
  125. int rowIndex = 3;
  126. int num = 1;
  127. Row originalRow = sheet.getRow(3);
  128. Cell originalcell = originalRow.getCell(0);
  129. // 获取单元格样式
  130. CellStyle originalStyle = originalcell.getCellStyle();
  131. for (TPssrLock t : list) {
  132. Row row = sheet.createRow(rowIndex);
  133. row.setHeight((short) 800);
  134. row.createCell(0).setCellValue(num);
  135. row.createCell(1).setCellValue(t.getUnit());
  136. row.createCell(2).setCellValue(t.getLockPost());
  137. row.createCell(3).setCellValue(t.getPidNo());
  138. row.createCell(4).setCellValue(t.getLockCode());
  139. row.createCell(5).setCellValue(t.getMedium());
  140. row.createCell(6).setCellValue(t.getPosition());
  141. row.createCell(7).setCellValue(t.getRiskLevel());
  142. row.createCell(8).setCellValue(t.getLockSize());
  143. row.createCell(9).setCellValue(t.getPidStatus());
  144. row.createCell(10).setCellValue(t.getPositionRight());
  145. row.createCell(11).setCellValue(t.getStatusRight());
  146. row.createCell(12).setCellValue(t.getCodeAccord());
  147. row.createCell(13).setCellValue(t.getFastening());
  148. row.createCell(14).setCellValue(t.getNoDamage());
  149. row.createCell(15);
  150. row.createCell(16);
  151. try {
  152. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getLockeder()));
  153. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm()));
  154. String confirm1 = sysUser.getSignUrl();
  155. String confirm2 = sysUser2.getSignUrl();
  156. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 15, 1, 1);
  157. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 16, 1, 1);
  158. } catch (NumberFormatException e) {
  159. throw new RuntimeException(e);
  160. }
  161. row.createCell(17).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  162. row.createCell(18).setCellValue(t.getRemarks());
  163. //渲染样式
  164. for (int i = 0; i < 19; i++) {
  165. row.getCell(i).setCellStyle(originalStyle);
  166. }
  167. num++;
  168. rowIndex++;
  169. }
  170. filename = "PSSR_09_锁开锁关阀门状态" + ".xlsx";
  171. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  172. wb.write(out);
  173. wb.close();
  174. } catch (IOException e) {
  175. e.printStackTrace();
  176. }
  177. return filename;
  178. }
  179. /**
  180. * 获取锁开锁关阀门状态详细信息
  181. */
  182. @PreAuthorize("@ss.hasPermi('pssr:lock:query')")
  183. @GetMapping(value = "/{id}")
  184. public AjaxResult getInfo(@PathVariable("id") Long id) {
  185. TPssrLock item = tPssrLockService.selectTPssrLockById(id);
  186. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "sksgfmzt"));
  187. if (item.getApproveStatus() != 2)
  188. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "sksgfmzt"));
  189. return AjaxResult.success(item);
  190. }
  191. /**
  192. * 新增锁开锁关阀门状态
  193. */
  194. @PreAuthorize("@ss.hasPermi('pssr:lock:add')")
  195. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.INSERT)
  196. @PostMapping
  197. public AjaxResult add(@RequestBody TPssrLock tPssrLock) {
  198. Set<String> codes = new HashSet<>();
  199. Set<String> pids = new HashSet<>();
  200. boolean flag = true;
  201. for (String pidNo : tPssrLock.getPidNos()) {
  202. TApplyLock tApplyLock = new TApplyLock();
  203. tApplyLock.setPidNo(pidNo);
  204. for (TApplyLock applyLock : tApplyLockService.selectTApplyLockList(tApplyLock)) {
  205. if (applyLock.getStatus() == 0) {
  206. TPssrLock lock = new TPssrLock();
  207. lock.setLockPost(applyLock.getLockPost());
  208. lock.setLockCode(applyLock.getLockCode());
  209. lock.setMedium(applyLock.getMedium());
  210. lock.setRiskLevel(applyLock.getRiskLevel());
  211. lock.setCodeAccord(tPssrLock.getCodeAccord());
  212. lock.setSubId(tPssrLock.getSubId());
  213. lock.setUnit(applyLock.getUnit());
  214. lock.setPidNo(pidNo);
  215. lock.setPosition(applyLock.getPosition());
  216. lock.setLockSize(applyLock.getLockSize());
  217. lock.setPidStatus(applyLock.getValveStatus());
  218. lock.setLockeder(tPssrLock.getLockeder());
  219. lock.setFastening(tPssrLock.getFastening());
  220. lock.setNoDamage(tPssrLock.getNoDamage());
  221. lock.setConfirm(tPssrLock.getConfirm());
  222. lock.setApproveStatus(0L);
  223. insertOrUpdate(lock);
  224. } else {
  225. codes.add(applyLock.getLockCode());
  226. pids.add(pidNo);
  227. flag = false;
  228. }
  229. }
  230. }
  231. if (flag) {
  232. return AjaxResult.success();
  233. } else {
  234. return AjaxResult.success("PID图号为" + JSON.toJSONString(pids) + "中,锁编号为" + JSON.toJSONString(codes) + "的锁未完成锁开锁关流程审批!");
  235. }
  236. }
  237. private void insertOrUpdate(TPssrLock tPssrLock) {
  238. TPssrLock lock = new TPssrLock();
  239. lock.setSubId(tPssrLock.getSubId());
  240. lock.setLockCode(tPssrLock.getLockCode());
  241. List<TPssrLock> tPssrLocks = tPssrLockService.selectTPssrLockList(lock);
  242. if (CollectionUtils.isNotEmpty(tPssrLocks)) {
  243. TPssrLock item = tPssrLocks.get(0);
  244. tPssrLock.setId(item.getId());
  245. tPssrLockService.updateTPssrLock(tPssrLock);
  246. } else {
  247. tPssrLockService.insertTPssrLock(tPssrLock);
  248. }
  249. }
  250. /**
  251. * 修改锁开锁关阀门状态
  252. */
  253. @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
  254. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
  255. @PutMapping
  256. public AjaxResult edit(@RequestBody TPssrLock tPssrLock) {
  257. if (tPssrLock.getLockeder().equals(tPssrLock.getConfirm())){
  258. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  259. }
  260. tPssrFileService.updateFileRelevance(tPssrLock.getFileIds(), "sksgfmzt", tPssrLock.getId(), tPssrLock.getSubId());
  261. return toAjax(tPssrLockService.updateTPssrLock(tPssrLock));
  262. }
  263. /**
  264. * 修改锁开锁关阀门状态
  265. */
  266. @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
  267. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
  268. @PutMapping("/editBatch")
  269. public AjaxResult editb(@RequestBody TPssrLock tPssrLock) {
  270. if (tPssrLock.getLockeder().equals(tPssrLock.getConfirm())){
  271. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  272. }
  273. return toAjax(tPssrLockMapper.updateTPssrLockByIds(tPssrLock));
  274. }
  275. /**
  276. * 锁开锁关确认
  277. */
  278. @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
  279. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
  280. @PutMapping("/confirmLock")
  281. public AjaxResult confirmLock(@RequestBody TPssrLock tPssrLock) {
  282. long queryStatus = 0;
  283. long approveStatus = 0;
  284. Date date = null;
  285. TPssrLock lock = new TPssrLock();
  286. if (tPssrLock.getTaskType() == 4) {
  287. //上锁确认
  288. queryStatus = 1;
  289. approveStatus = 3;
  290. date = new Date();
  291. lock.setLockeder(getUserId().toString());
  292. } else if (tPssrLock.getTaskType() == 5) {
  293. //确认人确认
  294. queryStatus = 3;
  295. approveStatus = 2;
  296. date = new Date();
  297. lock.setConfirm(getUserId().toString());
  298. }
  299. // 修改锁开锁关状态
  300. if (tPssrLock.getIds() != null && tPssrLock.getIds().length > 0) {
  301. for (Long id : tPssrLock.getIds()) {
  302. TPssrLock item = tPssrLockService.selectTPssrLockById(id);
  303. item.setApproveStatus(approveStatus);
  304. if (approveStatus == 2) {
  305. item.setConfirmationDate(date);
  306. }
  307. tPssrLockService.updateTPssrLock(item);
  308. }
  309. } else {
  310. lock.setSubId(tPssrLock.getSubId());
  311. lock.setApproveStatus(queryStatus);
  312. for (TPssrLock item : tPssrLockService.selectTPssrLockList(lock)) {
  313. if (approveStatus == 2) {
  314. item.setConfirmationDate(date);
  315. }
  316. item.setApproveStatus(approveStatus);
  317. tPssrLockService.updateTPssrLock(item);
  318. }
  319. }
  320. //查询当前待审批的确认人
  321. TPssrLock entity = new TPssrLock();
  322. entity.setSubId(tPssrLock.getSubId());
  323. entity.setApproveStatus(queryStatus);
  324. for (TPssrLock item : tPssrLockService.selectTPssrLockList(entity)) {
  325. if (tPssrLock.getTaskType() == 4) {
  326. if (item.getLockeder().equals(getUserId().toString())) {
  327. return AjaxResult.success();
  328. }
  329. } else if (tPssrLock.getTaskType() == 5) {
  330. if (item.getConfirm().equals(getUserId().toString())) {
  331. return AjaxResult.success();
  332. }
  333. }
  334. }
  335. //无待审批任务结束当前用户流程
  336. // 因为流程关系所以approve一定会有且只有一条数据
  337. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrLock.getSubId());
  338. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  339. return AjaxResult.success();
  340. }
  341. /**
  342. * 驳回设计变更
  343. */
  344. @PutMapping("/turnDownLock")
  345. public AjaxResult turnDownLock(@RequestBody List<TPssrLock> tPssrLock) {
  346. if (CollectionUtils.isNotEmpty(tPssrLock)) {
  347. String userId = getUserId().toString();
  348. Long subId = tPssrLock.get(0).getSubId();
  349. // 修改已选择数据的状态
  350. for (TPssrLock item : tPssrLock) {
  351. TPssrLock blind = new TPssrLock();
  352. blind.setId(item.getId());
  353. blind.setApproveStatus(1L);
  354. blind.setUpdatedate(new Date());
  355. blind.setUpdaterCode(getUserId().toString());
  356. tPssrLockService.updateTPssrLock(blind);
  357. // 新增驳回原因数据
  358. TPssrTurndown turndown = new TPssrTurndown();
  359. turndown.setForShort(forShort);
  360. turndown.setSubId(item.getSubId());
  361. turndown.setItemId(item.getId());
  362. turndown.setReason(item.getReason());
  363. turndown.setCreatedate(new Date());
  364. turndown.setCreaterCode(getUserId().toString());
  365. tPssrTurndownService.insertTPssrTurndown(turndown);
  366. }
  367. // 查询当前流程
  368. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  369. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  370. TaskService taskService = processEngine.getTaskService();
  371. Task task = processEngine.getTaskService()//获取任务service
  372. .createTaskQuery()//创建查询对象
  373. .taskAssignee(userId)
  374. .processInstanceId(approve.getProcessId()).singleResult();
  375. String taskId = task.getId();
  376. // 驳回 查询所有待审批的人员
  377. TPssrLock blind = new TPssrLock();
  378. blind.setSubId(subId);
  379. blind.setApproveStatus(1L);
  380. Set<String> confirm1 = new HashSet<>();
  381. Set<String> confirm2 = new HashSet<>();
  382. for (TPssrLock item : tPssrLockService.selectTPssrLockList(blind)) {
  383. // 确认人1
  384. confirm1.add(item.getConfirm());
  385. // 确认人2
  386. confirm2.add(item.getLockeder());
  387. }
  388. //处理流程节点
  389. Map<String, Object> param = new HashMap<>();
  390. param.put("condition", 1);
  391. param.put("confirmUsers1", new ArrayList<>(confirm1));
  392. param.put("confirmUsers2", new ArrayList<>(confirm2));
  393. //认领任务
  394. processEngine.getTaskService().claim(taskId, userId);
  395. taskService.addComment(taskId, approve.getProcessId(), "驳回");
  396. taskService.complete(taskId, param);
  397. // 修改审批表和sub表
  398. approve.setApproveStatus(1L);
  399. approve.setUpdatedate(new Date());
  400. approve.setUpdaterCode(getUserId().toString());
  401. tPssrApproveService.updateTPssrApprove(approve);
  402. TPssrSubcontent subcontent = new TPssrSubcontent();
  403. subcontent.setId(approve.getSubId());
  404. subcontent.setApproveStatus(1L);
  405. subcontent.setUpdatedate(new Date());
  406. subcontent.setUpdaterCode(getUserId().toString());
  407. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  408. return AjaxResult.success();
  409. }
  410. return AjaxResult.error();
  411. }
  412. /**
  413. * 删除锁开锁关阀门状态
  414. */
  415. @PreAuthorize("@ss.hasPermi('pssr:lock:remove')")
  416. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.DELETE)
  417. @DeleteMapping("/{ids}")
  418. public AjaxResult remove(@PathVariable Long[] ids) {
  419. return toAjax(tPssrLockService.deleteTPssrLockByIds(ids));
  420. }
  421. }