TPssrLockController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. if (list.size() != 0) {
  113. return AjaxResult.success(exportTmpl(list));
  114. } else {
  115. return AjaxResult.error("暂无可导出数据");
  116. }
  117. }
  118. public String exportTmpl(List<TPssrLock> list) {
  119. OutputStream out = null;
  120. String filename = null;
  121. try {
  122. String tempUrl = "static/word/pssr/sksgfmzt.xlsx"; // 模板文件
  123. InputStream is = null;
  124. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  125. XSSFWorkbook wb = null;
  126. wb = new XSSFWorkbook(is);
  127. XSSFSheet sheet = wb.getSheetAt(0);
  128. //填充数据
  129. int rowIndex = 3;
  130. int num = 1;
  131. Row originalRow = sheet.getRow(3);
  132. Cell originalcell = originalRow.getCell(0);
  133. // 获取单元格样式
  134. CellStyle originalStyle = originalcell.getCellStyle();
  135. for (TPssrLock t : list) {
  136. Row row = sheet.createRow(rowIndex);
  137. row.setHeight((short) 800);
  138. row.createCell(0).setCellValue(num);
  139. row.createCell(1).setCellValue(t.getUnit());
  140. row.createCell(2).setCellValue(t.getLockPost());
  141. row.createCell(3).setCellValue(t.getPidNo());
  142. row.createCell(4).setCellValue(t.getLockCode());
  143. row.createCell(5).setCellValue(t.getMedium());
  144. row.createCell(6).setCellValue(t.getPosition());
  145. row.createCell(7).setCellValue(t.getRiskLevel());
  146. row.createCell(8).setCellValue(t.getLockSize());
  147. row.createCell(9).setCellValue(t.getPidStatus());
  148. row.createCell(10).setCellValue(t.getPositionRight());
  149. row.createCell(11).setCellValue(t.getStatusRight());
  150. row.createCell(12).setCellValue(t.getCodeAccord());
  151. row.createCell(13).setCellValue(t.getFastening());
  152. row.createCell(14).setCellValue(t.getNoDamage());
  153. row.createCell(15);
  154. row.createCell(16);
  155. try {
  156. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getLockeder()));
  157. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm()));
  158. String confirm1 = sysUser.getSignUrl();
  159. String confirm2 = sysUser2.getSignUrl();
  160. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 15, 1, 1);
  161. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 16, 1, 1);
  162. } catch (NumberFormatException e) {
  163. throw new RuntimeException(e);
  164. }
  165. row.createCell(17).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  166. row.createCell(18).setCellValue(t.getRemarks());
  167. //渲染样式
  168. for (int i = 0; i < 19; i++) {
  169. row.getCell(i).setCellStyle(originalStyle);
  170. }
  171. num++;
  172. rowIndex++;
  173. }
  174. filename = "PSSR_09_锁开锁关阀门状态" + ".xlsx";
  175. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  176. wb.write(out);
  177. wb.close();
  178. } catch (IOException e) {
  179. e.printStackTrace();
  180. }
  181. return filename;
  182. }
  183. /**
  184. * 获取锁开锁关阀门状态详细信息
  185. */
  186. @PreAuthorize("@ss.hasPermi('pssr:lock:query')")
  187. @GetMapping(value = "/{id}")
  188. public AjaxResult getInfo(@PathVariable("id") Long id) {
  189. TPssrLock item = tPssrLockService.selectTPssrLockById(id);
  190. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "sksgfmzt"));
  191. if (item.getApproveStatus() != 2)
  192. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "sksgfmzt"));
  193. return AjaxResult.success(item);
  194. }
  195. /**
  196. * 新增锁开锁关阀门状态
  197. */
  198. @PreAuthorize("@ss.hasPermi('pssr:lock:add')")
  199. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.INSERT)
  200. @PostMapping
  201. public AjaxResult add(@RequestBody TPssrLock tPssrLock) {
  202. Set<String> codes = new HashSet<>();
  203. Set<String> pids = new HashSet<>();
  204. boolean flag = true;
  205. for (String pidNo : tPssrLock.getPidNos()) {
  206. TApplyLock tApplyLock = new TApplyLock();
  207. tApplyLock.setPidNo(pidNo);
  208. for (TApplyLock applyLock : tApplyLockService.selectTApplyLockList(tApplyLock)) {
  209. if (applyLock.getStatus() == 0) {
  210. TPssrLock lock = new TPssrLock();
  211. lock.setLockPost(applyLock.getLockPost());
  212. lock.setLockCode(applyLock.getLockCode());
  213. lock.setMedium(applyLock.getMedium());
  214. lock.setRiskLevel(applyLock.getRiskLevel());
  215. lock.setCodeAccord(tPssrLock.getCodeAccord());
  216. lock.setSubId(tPssrLock.getSubId());
  217. lock.setUnit(applyLock.getUnit());
  218. lock.setPidNo(pidNo);
  219. lock.setPosition(applyLock.getPosition());
  220. lock.setLockSize(applyLock.getLockSize());
  221. lock.setPidStatus(applyLock.getValveStatus());
  222. lock.setLockeder(tPssrLock.getLockeder());
  223. lock.setFastening(tPssrLock.getFastening());
  224. lock.setNoDamage(tPssrLock.getNoDamage());
  225. lock.setConfirm(tPssrLock.getConfirm());
  226. lock.setApproveStatus(0L);
  227. insertOrUpdate(lock);
  228. } else {
  229. codes.add(applyLock.getLockCode());
  230. pids.add(pidNo);
  231. flag = false;
  232. }
  233. }
  234. }
  235. if (flag) {
  236. return AjaxResult.success();
  237. } else {
  238. return AjaxResult.success("PID图号为" + JSON.toJSONString(pids) + "中,锁编号为" + JSON.toJSONString(codes) + "的锁未完成锁开锁关流程审批!");
  239. }
  240. }
  241. private void insertOrUpdate(TPssrLock tPssrLock) {
  242. TPssrLock lock = new TPssrLock();
  243. lock.setSubId(tPssrLock.getSubId());
  244. lock.setLockCode(tPssrLock.getLockCode());
  245. List<TPssrLock> tPssrLocks = tPssrLockService.selectTPssrLockList(lock);
  246. if (CollectionUtils.isNotEmpty(tPssrLocks)) {
  247. TPssrLock item = tPssrLocks.get(0);
  248. tPssrLock.setId(item.getId());
  249. tPssrLockService.updateTPssrLock(tPssrLock);
  250. } else {
  251. tPssrLockService.insertTPssrLock(tPssrLock);
  252. }
  253. }
  254. /**
  255. * 修改锁开锁关阀门状态
  256. */
  257. @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
  258. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
  259. @PutMapping
  260. public AjaxResult edit(@RequestBody TPssrLock tPssrLock) {
  261. TPssrLock entity = tPssrLockService.selectTPssrLockById(tPssrLock.getId());
  262. if (entity.getApproveStatus() != 1 && entity.getApproveStatus() != 0) {
  263. return AjaxResult.error("当前状态不可修改!");
  264. }
  265. if (tPssrLock.getLockeder().equals(tPssrLock.getConfirm())){
  266. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  267. }
  268. tPssrFileService.updateFileRelevance(tPssrLock.getFileIds(), "sksgfmzt", tPssrLock.getId(), tPssrLock.getSubId());
  269. return toAjax(tPssrLockService.updateTPssrLock(tPssrLock));
  270. }
  271. /**
  272. * 修改锁开锁关阀门状态
  273. */
  274. @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
  275. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
  276. @PutMapping("/editBatch")
  277. public AjaxResult editb(@RequestBody TPssrLock tPssrLock) {
  278. if (tPssrLock.getLockeder().equals(tPssrLock.getConfirm())){
  279. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  280. }
  281. return toAjax(tPssrLockMapper.updateTPssrLockByIds(tPssrLock));
  282. }
  283. /**
  284. * 锁开锁关确认
  285. */
  286. @PreAuthorize("@ss.hasPermi('pssr:lock:edit')")
  287. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.UPDATE)
  288. @PutMapping("/confirmLock")
  289. public AjaxResult confirmLock(@RequestBody TPssrLock tPssrLock) {
  290. long queryStatus = 0;
  291. long approveStatus = 0;
  292. Date date = null;
  293. TPssrLock lock = new TPssrLock();
  294. if (tPssrLock.getTaskType() == 4) {
  295. //上锁确认
  296. queryStatus = 1;
  297. approveStatus = 3;
  298. date = new Date();
  299. lock.setLockeder(getUserId().toString());
  300. } else if (tPssrLock.getTaskType() == 5) {
  301. //确认人确认
  302. queryStatus = 3;
  303. approveStatus = 2;
  304. date = new Date();
  305. lock.setConfirm(getUserId().toString());
  306. }
  307. // 修改锁开锁关状态
  308. if (tPssrLock.getIds() != null && tPssrLock.getIds().length > 0) {
  309. for (Long id : tPssrLock.getIds()) {
  310. TPssrLock item = tPssrLockService.selectTPssrLockById(id);
  311. item.setApproveStatus(approveStatus);
  312. if (approveStatus == 2) {
  313. item.setConfirmationDate(date);
  314. }
  315. tPssrLockService.updateTPssrLock(item);
  316. }
  317. } else {
  318. lock.setSubId(tPssrLock.getSubId());
  319. lock.setApproveStatus(queryStatus);
  320. for (TPssrLock item : tPssrLockService.selectTPssrLockList(lock)) {
  321. if (approveStatus == 2) {
  322. item.setConfirmationDate(date);
  323. }
  324. item.setApproveStatus(approveStatus);
  325. tPssrLockService.updateTPssrLock(item);
  326. }
  327. }
  328. //查询当前待审批的确认人
  329. TPssrLock entity = new TPssrLock();
  330. entity.setSubId(tPssrLock.getSubId());
  331. entity.setApproveStatus(queryStatus);
  332. for (TPssrLock item : tPssrLockService.selectTPssrLockList(entity)) {
  333. if (tPssrLock.getTaskType() == 4) {
  334. if (item.getLockeder().equals(getUserId().toString())) {
  335. return AjaxResult.success();
  336. }
  337. } else if (tPssrLock.getTaskType() == 5) {
  338. if (item.getConfirm().equals(getUserId().toString())) {
  339. return AjaxResult.success();
  340. }
  341. }
  342. }
  343. //无待审批任务结束当前用户流程
  344. // 因为流程关系所以approve一定会有且只有一条数据
  345. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrLock.getSubId());
  346. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  347. return AjaxResult.success();
  348. }
  349. /**
  350. * 驳回设计变更
  351. */
  352. @PutMapping("/turnDownLock")
  353. public AjaxResult turnDownLock(@RequestBody List<TPssrLock> tPssrLock) {
  354. if (CollectionUtils.isNotEmpty(tPssrLock)) {
  355. String userId = getUserId().toString();
  356. Long subId = tPssrLock.get(0).getSubId();
  357. // 修改已选择数据的状态
  358. for (TPssrLock item : tPssrLock) {
  359. TPssrLock blind = new TPssrLock();
  360. blind.setId(item.getId());
  361. blind.setApproveStatus(1L);
  362. blind.setUpdatedate(new Date());
  363. blind.setUpdaterCode(getUserId().toString());
  364. tPssrLockService.updateTPssrLock(blind);
  365. // 新增驳回原因数据
  366. TPssrTurndown turndown = new TPssrTurndown();
  367. turndown.setForShort(forShort);
  368. turndown.setSubId(item.getSubId());
  369. turndown.setItemId(item.getId());
  370. turndown.setReason(item.getReason());
  371. turndown.setCreatedate(new Date());
  372. turndown.setCreaterCode(getUserId().toString());
  373. tPssrTurndownService.insertTPssrTurndown(turndown);
  374. }
  375. // 查询当前流程
  376. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  377. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  378. TaskService taskService = processEngine.getTaskService();
  379. Task task = processEngine.getTaskService()//获取任务service
  380. .createTaskQuery()//创建查询对象
  381. .taskAssignee(userId)
  382. .processInstanceId(approve.getProcessId()).singleResult();
  383. String taskId = task.getId();
  384. // 驳回 查询所有待审批的人员
  385. TPssrLock blind = new TPssrLock();
  386. blind.setSubId(subId);
  387. blind.setApproveStatus(1L);
  388. Set<String> confirm1 = new HashSet<>();
  389. Set<String> confirm2 = new HashSet<>();
  390. for (TPssrLock item : tPssrLockService.selectTPssrLockList(blind)) {
  391. // 确认人1
  392. confirm1.add(item.getConfirm());
  393. // 确认人2
  394. confirm2.add(item.getLockeder());
  395. }
  396. //处理流程节点
  397. Map<String, Object> param = new HashMap<>();
  398. param.put("condition", 1);
  399. param.put("confirmUsers1", new ArrayList<>(confirm1));
  400. param.put("confirmUsers2", new ArrayList<>(confirm2));
  401. //认领任务
  402. processEngine.getTaskService().claim(taskId, userId);
  403. taskService.addComment(taskId, approve.getProcessId(), "驳回");
  404. taskService.complete(taskId, param);
  405. // 修改审批表和sub表
  406. approve.setApproveStatus(1L);
  407. approve.setUpdatedate(new Date());
  408. approve.setUpdaterCode(getUserId().toString());
  409. tPssrApproveService.updateTPssrApprove(approve);
  410. TPssrSubcontent subcontent = new TPssrSubcontent();
  411. subcontent.setId(approve.getSubId());
  412. subcontent.setApproveStatus(1L);
  413. subcontent.setUpdatedate(new Date());
  414. subcontent.setUpdaterCode(getUserId().toString());
  415. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  416. return AjaxResult.success();
  417. }
  418. return AjaxResult.error();
  419. }
  420. /**
  421. * 删除锁开锁关阀门状态
  422. */
  423. @PreAuthorize("@ss.hasPermi('pssr:lock:remove')")
  424. @Log(title = "锁开锁关阀门状态", businessType = BusinessType.DELETE)
  425. @DeleteMapping("/{ids}")
  426. public AjaxResult remove(@PathVariable Long[] ids) {
  427. return toAjax(tPssrLockService.deleteTPssrLockByIds(ids));
  428. }
  429. }