TPssrMocController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. package com.ruoyi.project.pssr.controller;
  2. import com.ruoyi.common.utils.DateUtils;
  3. import com.ruoyi.common.utils.StringUtils;
  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.process.domain.TMoc;
  12. import com.ruoyi.project.process.service.ITMocService;
  13. import com.ruoyi.project.pssr.domain.*;
  14. import com.ruoyi.project.pssr.mapper.TPssrMocMapper;
  15. import com.ruoyi.project.pssr.service.*;
  16. import com.ruoyi.project.system.domain.SysUser;
  17. import com.ruoyi.project.system.service.ISysDictDataService;
  18. import com.ruoyi.project.system.service.ISysUserService;
  19. import org.activiti.engine.ProcessEngine;
  20. import org.activiti.engine.ProcessEngines;
  21. import org.activiti.engine.TaskService;
  22. import org.activiti.engine.task.Task;
  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. * MOC完成确认清单Controller
  40. *
  41. * @author ssy
  42. * @date 2024-10-31
  43. */
  44. @RestController
  45. @RequestMapping("/pssr/moc")
  46. public class TPssrMocController extends BaseController {
  47. @Resource
  48. private TPssrMocMapper tPssrMocMapper;
  49. @Autowired
  50. private ITPssrFileService tPssrFileService;
  51. @Autowired
  52. private ITPssrTurndownService tPssrTurndownService;
  53. @Autowired
  54. private ITPssrMocService tPssrMocService;
  55. @Autowired
  56. private ITPssrApproveService tPssrApproveService;
  57. @Autowired
  58. private ITPssrSubcontentService tPssrSubcontentService;
  59. @Autowired
  60. private ITPssrAboveallService tPssraboveallService;
  61. @Autowired
  62. private ITMocService tMocService;
  63. @Autowired
  64. private ISysUserService sysUserService;
  65. private String forShort = "sjbg";
  66. @Autowired
  67. private ISysDictDataService sysDictDataService;
  68. /**
  69. * 查询MOC完成确认清单列表
  70. */
  71. @PreAuthorize("@ss.hasPermi('pssr:moc:list')")
  72. @GetMapping("/list")
  73. public TableDataInfo list(TPssrMoc tPssrMoc) {
  74. try {
  75. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrMoc.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. tPssrMoc.setConfirm1(getUserId().toString());
  86. }else if (task.getName().equals("确认人2")){
  87. tPssrMoc.setConfirm2(getUserId().toString());
  88. }
  89. }
  90. }
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. logger.error("待办确认人查询报错:{}",e.getMessage());
  94. }
  95. startPage();
  96. List<TPssrMoc> list = tPssrMocService.selectTPssrMocList(tPssrMoc);
  97. list.forEach(item -> {
  98. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), forShort));
  99. if (item.getApproveStatus() != 2)
  100. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), forShort));
  101. });
  102. return getDataTable(list);
  103. }
  104. /**
  105. * 导出MOC完成确认清单列表
  106. */
  107. @PreAuthorize("@ss.hasPermi('pssr:moc:export')")
  108. @Log(title = "MOC完成确认清单", businessType = BusinessType.EXPORT)
  109. @GetMapping("/export")
  110. public AjaxResult export(TPssrMoc tPssrMoc) {
  111. List<TPssrMoc> list = tPssrMocService.selectTPssrMocList(tPssrMoc);
  112. return AjaxResult.success(exportTmpl(list));
  113. }
  114. public String exportTmpl(List<TPssrMoc> list) {
  115. OutputStream out = null;
  116. String filename = null;
  117. try {
  118. String tempUrl = "static/word/pssr/sjbg.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 (TPssrMoc 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.getRegion());
  136. row.createCell(2).setCellValue(t.getMocNo());
  137. row.createCell(3).setCellValue(t.getTitle());
  138. row.createCell(4).setCellValue(t.getDocUpdate());
  139. row.createCell(5).setCellValue(t.getTraining());
  140. row.createCell(6).setCellValue(t.getPssr());
  141. row.createCell(7);
  142. row.createCell(8);
  143. try {
  144. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
  145. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
  146. String confirm1 = sysUser.getSignUrl();
  147. String confirm2 = sysUser2.getSignUrl();
  148. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 7, 1, 1);
  149. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 8, 1, 1);
  150. } catch (NumberFormatException e) {
  151. throw new RuntimeException(e);
  152. }
  153. row.createCell(9).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  154. row.createCell(10).setCellValue(t.getRemarks());
  155. //渲染样式
  156. for (int i = 0; i < 11; i++) {
  157. row.getCell(i).setCellStyle(originalStyle);
  158. }
  159. num++;
  160. rowIndex++;
  161. }
  162. filename = "PSSR_03_设计变更" + ".xlsx";
  163. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  164. wb.write(out);
  165. wb.close();
  166. } catch (IOException e) {
  167. e.printStackTrace();
  168. }
  169. return filename;
  170. }
  171. /**
  172. * 获取MOC完成确认清单详细信息
  173. */
  174. @PreAuthorize("@ss.hasPermi('pssr:moc:query')")
  175. @GetMapping(value = "/{id}")
  176. public AjaxResult getInfo(@PathVariable("id") Long id) {
  177. TPssrMoc item = tPssrMocService.selectTPssrMocById(id);
  178. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), forShort));
  179. if (item.getApproveStatus() != 2)
  180. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), forShort));
  181. return AjaxResult.success(item);
  182. }
  183. /**
  184. * 新增MOC完成确认清单
  185. */
  186. @PreAuthorize("@ss.hasPermi('pssr:moc:add')")
  187. @Log(title = "MOC完成确认清单", businessType = BusinessType.INSERT)
  188. @PostMapping
  189. public AjaxResult add(@RequestBody TPssrMoc tPssrMoc) {
  190. if (StringUtils.isNotEmpty(tPssrMoc.getConfirm1())&&tPssrMoc.getConfirm1().equals(tPssrMoc.getConfirm2())) {
  191. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  192. }
  193. return toAjax(tPssrMocService.insertTPssrMoc(tPssrMoc));
  194. }
  195. @PreAuthorize("@ss.hasPermi('pssr:moc:add')")
  196. @Log(title = "MOC完成确认清单", businessType = BusinessType.INSERT)
  197. @PostMapping("/syncMoc")
  198. public AjaxResult syncMoc(@RequestBody TPssrMoc tPssrMoc) {
  199. if (StringUtils.isEmpty(tPssrMoc.getRemarks())) {
  200. tPssrMoc.setRemarks("TRA2025");
  201. }
  202. TPssrSubcontent subcontent = tPssrSubcontentService.selectTPssrSubcontentById(tPssrMoc.getSubId());
  203. TPssrAboveall tPssrAboveall = tPssraboveallService.selectTPssrAboveallById(subcontent.getAboveallId());
  204. TMoc tMoc = new TMoc();
  205. // 永久moc
  206. // tMoc.setTimeliness("1");
  207. if (tPssrAboveall.getRegion().equals("裂解")){
  208. tMoc.setAreas(new String[]{"10","20","21","22"});
  209. }
  210. if (tPssrAboveall.getRegion().equals("压缩")){
  211. tMoc.setAreas(new String[]{"12","20","21","22"});
  212. }
  213. if (tPssrAboveall.getRegion().equals("分离")){
  214. tMoc.setAreas(new String[]{"14","20","21","22"});
  215. }
  216. if (tPssrAboveall.getRegion().equals("AEU")){
  217. tMoc.setAreas(new String[]{"16","20","21","22"});
  218. }
  219. if (tPssrAboveall.getRegion().equals("PGU")){
  220. tMoc.setAreas(new String[]{"18","20","21","22"});
  221. }
  222. tMoc.setRemarks(tPssrMoc.getRemarks());
  223. for (TMoc moc : tMocService.selectTMocList(tMoc)) {
  224. TPssrMoc pssrMoc = new TPssrMoc();
  225. pssrMoc.setSubId(tPssrMoc.getSubId());
  226. pssrMoc.setRegion(sysDictDataService.selectDictLabel("MOC_AREA", moc.getArea()));
  227. pssrMoc.setMocNo(moc.getCompanyMocNo());
  228. pssrMoc.setTitle(moc.getTitle());
  229. pssrMoc.setDocUpdate(!Objects.isNull(moc.getDocUpdate()) ? "Y" : "N");
  230. pssrMoc.setTraining(!Objects.isNull(moc.getTraining()) ? "Y" : "N");
  231. pssrMoc.setPssr(!Objects.isNull(moc.getPssr()) ? "Y" : "N");
  232. pssrMoc.setCreaterCode(getUserId().toString());
  233. pssrMoc.setCreatedate(new Date());
  234. pssrMoc.setApproveStatus(0L);
  235. upOrIn(pssrMoc);
  236. }
  237. return AjaxResult.success();
  238. }
  239. private void upOrIn(TPssrMoc tPssrMoc) {
  240. TPssrMoc moc = new TPssrMoc();
  241. moc.setMocNo(tPssrMoc.getMocNo());
  242. moc.setSubId(tPssrMoc.getSubId());
  243. List<TPssrMoc> tPssrMocs = tPssrMocService.selectTPssrMocList(moc);
  244. if (CollectionUtils.isNotEmpty(tPssrMocs)) {
  245. for (TPssrMoc pssrMoc : tPssrMocs) {
  246. tPssrMoc.setId(pssrMoc.getId());
  247. tPssrMocService.updateTPssrMoc(tPssrMoc);
  248. }
  249. } else {
  250. tPssrMocService.insertTPssrMoc(tPssrMoc);
  251. }
  252. }
  253. /**
  254. * 修改MOC完成确认清单
  255. */
  256. @PreAuthorize("@ss.hasPermi('pssr:moc:edit')")
  257. @Log(title = "MOC完成确认清单", businessType = BusinessType.UPDATE)
  258. @PutMapping
  259. public AjaxResult edit(@RequestBody TPssrMoc tPssrMoc) {
  260. TPssrMoc entity = tPssrMocService.selectTPssrMocById(tPssrMoc.getId());
  261. if (entity.getApproveStatus() != 1 && entity.getApproveStatus() != 0) {
  262. return AjaxResult.error("当前状态不可修改!");
  263. }
  264. if (tPssrMoc.getConfirm1().equals(tPssrMoc.getConfirm2())){
  265. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  266. }
  267. tPssrFileService.updateFileRelevance(tPssrMoc.getFileIds(), forShort, tPssrMoc.getId(), tPssrMoc.getSubId());
  268. return toAjax(tPssrMocService.updateTPssrMoc(tPssrMoc));
  269. }
  270. /**
  271. * 修改MOC完成确认清单
  272. */
  273. @PreAuthorize("@ss.hasPermi('pssr:moc:edit')")
  274. @Log(title = "MOC完成确认清单", businessType = BusinessType.UPDATE)
  275. @PutMapping("/editBatch")
  276. public AjaxResult editb(@RequestBody TPssrMoc tPssrMoc) {
  277. if (tPssrMoc.getConfirm1().equals(tPssrMoc.getConfirm2())){
  278. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  279. }
  280. return toAjax(tPssrMocMapper.updateTPssrMocByIds(tPssrMoc));
  281. }
  282. /**
  283. * 删除MOC完成确认清单
  284. */
  285. @PreAuthorize("@ss.hasPermi('pssr:moc:remove')")
  286. @Log(title = "MOC完成确认清单", businessType = BusinessType.DELETE)
  287. @DeleteMapping("/{ids}")
  288. public AjaxResult remove(@PathVariable Long[] ids) {
  289. return toAjax(tPssrMocService.deleteTPssrMocByIds(ids));
  290. }
  291. /**
  292. * 确认设计变更
  293. */
  294. @PreAuthorize("@ss.hasPermi('pssr:moc:edit')")
  295. @Log(title = "设计变更", businessType = BusinessType.UPDATE)
  296. @PutMapping("/confirmMoc")
  297. public AjaxResult confirmMoc(@RequestBody TPssrMoc tPssrMoc) {
  298. long queryStatus = 0;
  299. long approveStatus = 0;
  300. Date date = null;
  301. TPssrMoc lock = new TPssrMoc();
  302. if (tPssrMoc.getTaskType() == 4) {
  303. //确认人1确认
  304. queryStatus = 1;
  305. approveStatus = 3;
  306. date = new Date();
  307. lock.setConfirm1(getUserId().toString());
  308. } else if (tPssrMoc.getTaskType() == 5) {
  309. //确认人2确认
  310. queryStatus = 3;
  311. approveStatus = 2;
  312. date = new Date();
  313. lock.setConfirm2(getUserId().toString());
  314. }
  315. // 修改状态
  316. if (tPssrMoc.getIds() != null && tPssrMoc.getIds().length > 0) {
  317. for (Long id : tPssrMoc.getIds()) {
  318. TPssrMoc item = tPssrMocService.selectTPssrMocById(id);
  319. item.setApproveStatus(approveStatus);
  320. if (queryStatus == 3) {
  321. item.setConfirmationDate(date);
  322. }
  323. tPssrMocService.updateTPssrMoc(item);
  324. }
  325. } else {
  326. lock.setSubId(tPssrMoc.getSubId());
  327. lock.setApproveStatus(queryStatus);
  328. for (TPssrMoc item : tPssrMocService.selectTPssrMocList(lock)) {
  329. if (queryStatus == 3) {
  330. item.setConfirmationDate(date);
  331. }
  332. item.setApproveStatus(approveStatus);
  333. tPssrMocService.updateTPssrMoc(item);
  334. }
  335. }
  336. //查询当前待审批的确认人
  337. TPssrMoc entity = new TPssrMoc();
  338. entity.setSubId(tPssrMoc.getSubId());
  339. entity.setApproveStatus(queryStatus);
  340. for (TPssrMoc item : tPssrMocService.selectTPssrMocList(entity)) {
  341. if (tPssrMoc.getTaskType() == 4) {
  342. if (item.getConfirm1().equals(getUserId().toString())) {
  343. return AjaxResult.success();
  344. }
  345. } else if (tPssrMoc.getTaskType() == 5) {
  346. if (item.getConfirm2().equals(getUserId().toString())) {
  347. return AjaxResult.success();
  348. }
  349. }
  350. }
  351. //无待审批任务结束当前用户流程
  352. // 因为流程关系所以approve一定会有且只有一条数据
  353. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrMoc.getSubId());
  354. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  355. return AjaxResult.success();
  356. }
  357. /**
  358. * 驳回设计变更
  359. */
  360. @PutMapping("/turnDownMoc")
  361. public AjaxResult turnDownMoc(@RequestBody List<TPssrMoc> tPssrMoc) {
  362. if (CollectionUtils.isNotEmpty(tPssrMoc)) {
  363. String userId = getUserId().toString();
  364. Long subId = tPssrMoc.get(0).getSubId();
  365. // 修改已选择数据的状态
  366. for (TPssrMoc item : tPssrMoc) {
  367. TPssrMoc blind = new TPssrMoc();
  368. blind.setId(item.getId());
  369. blind.setApproveStatus(1L);
  370. blind.setUpdatedate(new Date());
  371. blind.setUpdaterCode(getUserId().toString());
  372. tPssrMocService.updateTPssrMoc(blind);
  373. // 新增驳回原因数据
  374. TPssrTurndown turndown = new TPssrTurndown();
  375. turndown.setForShort(forShort);
  376. turndown.setSubId(item.getSubId());
  377. turndown.setItemId(item.getId());
  378. turndown.setReason(item.getReason());
  379. turndown.setCreatedate(new Date());
  380. turndown.setCreaterCode(getUserId().toString());
  381. tPssrTurndownService.insertTPssrTurndown(turndown);
  382. }
  383. // 查询当前流程
  384. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  385. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  386. TaskService taskService = processEngine.getTaskService();
  387. Task task = processEngine.getTaskService()//获取任务service
  388. .createTaskQuery()//创建查询对象
  389. .taskAssignee(userId)
  390. .processInstanceId(approve.getProcessId()).singleResult();
  391. String taskId = task.getId();
  392. // 驳回 查询所有待审批的人员
  393. TPssrMoc blind = new TPssrMoc();
  394. blind.setSubId(subId);
  395. blind.setApproveStatus(1L);
  396. Set<String> confirm1 = new HashSet<>();
  397. Set<String> confirm2 = new HashSet<>();
  398. for (TPssrMoc item : tPssrMocService.selectTPssrMocList(blind)) {
  399. // 确认人1
  400. confirm1.add(item.getConfirm1());
  401. // 确认人2
  402. confirm2.add(item.getConfirm2());
  403. }
  404. //处理流程节点
  405. Map<String, Object> param = new HashMap<>();
  406. param.put("condition", 1);
  407. param.put("confirmUsers1", new ArrayList<>(confirm1));
  408. param.put("confirmUsers2", new ArrayList<>(confirm2));
  409. //认领任务
  410. processEngine.getTaskService().claim(taskId, userId);
  411. taskService.addComment(taskId, approve.getProcessId(), "驳回");
  412. taskService.complete(taskId, param);
  413. // 修改审批表和sub表
  414. approve.setApproveStatus(1L);
  415. approve.setUpdatedate(new Date());
  416. approve.setUpdaterCode(getUserId().toString());
  417. tPssrApproveService.updateTPssrApprove(approve);
  418. TPssrSubcontent subcontent = new TPssrSubcontent();
  419. subcontent.setId(approve.getSubId());
  420. subcontent.setApproveStatus(1L);
  421. subcontent.setUpdatedate(new Date());
  422. subcontent.setUpdaterCode(getUserId().toString());
  423. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  424. return AjaxResult.success();
  425. }
  426. return AjaxResult.error();
  427. }
  428. }