TPssrMaterialController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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.listener.pssr.ConfirmTaskCreateListener;
  12. import com.ruoyi.project.pssr.domain.*;
  13. import com.ruoyi.project.pssr.mapper.TPssrMaterialMapper;
  14. import com.ruoyi.project.pssr.service.*;
  15. import com.ruoyi.project.system.domain.SysUser;
  16. import com.ruoyi.project.system.service.ISysUserService;
  17. import org.activiti.engine.HistoryService;
  18. import org.activiti.engine.RuntimeService;
  19. import org.activiti.engine.impl.identity.Authentication;
  20. import org.activiti.engine.runtime.ProcessInstance;
  21. import org.apache.commons.collections4.CollectionUtils;
  22. import org.apache.poi.ss.usermodel.Cell;
  23. import org.apache.poi.ss.usermodel.CellStyle;
  24. import org.apache.poi.ss.usermodel.HorizontalAlignment;
  25. import org.apache.poi.ss.usermodel.Row;
  26. import org.apache.poi.ss.util.CellRangeAddress;
  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-09-18
  43. */
  44. @RestController
  45. @RequestMapping("/pssr/material")
  46. public class TPssrMaterialController extends BaseController {
  47. @Autowired
  48. private ITPssrFileService tPssrFileService;
  49. @Autowired
  50. private ITPssrTurndownService tPssrTurndownService;
  51. @Autowired
  52. private ITPssrMaterialService tPssrMaterialService;
  53. @Autowired
  54. private ITPssrApproveService tPssrApproveService;
  55. @Autowired
  56. private ITPssrSubcontentService tPssrSubcontentService;
  57. @Autowired
  58. private RuntimeService runtimeService;
  59. @Autowired
  60. private HistoryService historyService;
  61. @Resource
  62. private TPssrMaterialMapper tPssrMaterialMapper;
  63. @Autowired
  64. private ISysUserService sysUserService;
  65. private String forShort = "yfl";
  66. @Autowired
  67. private ITPssrMaterialRawService tPssrMaterialRawService;
  68. /**
  69. * 查询原料列表
  70. */
  71. @PreAuthorize("@ss.hasPermi('pssr:material:list')")
  72. @GetMapping("/list")
  73. public TableDataInfo list(TPssrMaterial tPssrMaterial) {
  74. startPage();
  75. List<TPssrMaterial> list = tPssrMaterialService.selectTPssrMaterialList(tPssrMaterial);
  76. list.forEach(item -> {
  77. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "yfl"));
  78. if (item.getApproveStatus() != 2)
  79. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "yfl"));
  80. });
  81. return getDataTable(list);
  82. }
  83. /**
  84. * 导出原料列表
  85. */
  86. @PreAuthorize("@ss.hasPermi('pssr:material:export')")
  87. @Log(title = "原料", businessType = BusinessType.EXPORT)
  88. @GetMapping("/export")
  89. public AjaxResult export(TPssrMaterial tPssrMaterial) {
  90. List<TPssrMaterial> list1 = tPssrMaterialService.selectTPssrMaterialList(tPssrMaterial);
  91. TPssrMaterialRaw materialRaw = new TPssrMaterialRaw();
  92. materialRaw.setSubId(tPssrMaterial.getSubId());
  93. List<TPssrMaterialRaw> list2 = tPssrMaterialRawService.selectTPssrMaterialRawList(materialRaw);
  94. return AjaxResult.success(exportTmpl(list1, list2));
  95. }
  96. public String exportTmpl(List<TPssrMaterial> list1, List<TPssrMaterialRaw> list2) {
  97. OutputStream out = null;
  98. String filename = null;
  99. try {
  100. String tempUrl = "static/word/pssr/yfl.xlsx"; // 模板文件
  101. InputStream is = null;
  102. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  103. XSSFWorkbook wb = null;
  104. wb = new XSSFWorkbook(is);
  105. XSSFSheet sheet = wb.getSheetAt(0);
  106. // Cracker commissioning material quantity
  107. // 填充数据
  108. int rowIndex = 3;
  109. int num = 1;
  110. Row originalRow = sheet.getRow(3);
  111. Cell originalcell = originalRow.getCell(0);
  112. CellStyle originalStyle = originalcell.getCellStyle();
  113. CellStyle originalStyleCopy = wb.createCellStyle();
  114. originalStyleCopy.cloneStyleFrom(originalStyle);
  115. originalStyleCopy.setAlignment(HorizontalAlignment.LEFT);
  116. for (TPssrMaterial t : list1) {
  117. Row row = sheet.createRow(rowIndex);
  118. row.setHeight((short) 800);
  119. row.createCell(0).setCellValue(num);
  120. row.createCell(1).setCellValue(t.getUtilityQuantity());
  121. row.createCell(2).setCellValue(t.getQuantity());
  122. row.createCell(3).setCellValue(t.getUnit());
  123. row.createCell(4).setCellValue(t.getNote());
  124. //渲染样式
  125. for (int i = 0; i < 5; i++) {
  126. row.getCell(i).setCellStyle(originalStyle);
  127. }
  128. num++;
  129. rowIndex++;
  130. }
  131. // Raw materials
  132. // 标题
  133. Row row = sheet.getRow(1);
  134. Cell cell = row.getCell(0);
  135. CellStyle style = cell.getCellStyle();
  136. Row title = sheet.createRow(rowIndex);
  137. title.setHeight((short) 800);
  138. title.createCell(0).setCellValue("Raw materials");
  139. title.createCell(1);
  140. title.createCell(2);
  141. title.createCell(3);
  142. title.createCell(4);
  143. for (int i = 0; i < 5; i++) {
  144. title.getCell(i).setCellStyle(style);
  145. }
  146. CellRangeAddress cellRangeAddress = new CellRangeAddress(rowIndex, rowIndex, 0, 4);
  147. sheet.addMergedRegion(cellRangeAddress);
  148. rowIndex++;
  149. Row row1 = sheet.getRow(2);
  150. Cell cell1 = row1.getCell(0);
  151. CellStyle style1 = cell1.getCellStyle();
  152. Row title1 = sheet.createRow(rowIndex);
  153. title1.setHeight((short) 800);
  154. title1.createCell(0).setCellValue("NO.");
  155. title1.createCell(1).setCellValue("Raw materials");
  156. title1.createCell(2).setCellValue("Quantity");
  157. title1.createCell(3).setCellValue("Unit");
  158. title1.createCell(4).setCellValue("Note");
  159. for (int i = 0; i < 5; i++) {
  160. title1.getCell(i).setCellStyle(style1);
  161. }
  162. rowIndex++;
  163. // 填充数据
  164. num = 1;
  165. for (TPssrMaterialRaw t2 : list2) {
  166. Row row2 = sheet.createRow(rowIndex);
  167. row2.setHeight((short) 800);
  168. row2.createCell(0).setCellValue(num);
  169. row2.createCell(1).setCellValue(t2.getRawMaterial());
  170. row2.createCell(2).setCellValue(t2.getQuantity());
  171. row2.createCell(3).setCellValue(t2.getUnit());
  172. row2.createCell(4).setCellValue(t2.getNote());
  173. //渲染样式
  174. for (int i = 0; i < 5; i++) {
  175. row2.getCell(i).setCellStyle(originalStyle);
  176. }
  177. num++;
  178. rowIndex++;
  179. }
  180. // 备注
  181. Row title2 = sheet.createRow(rowIndex);
  182. title2.setHeight((short) 800);
  183. title2.createCell(0).setCellValue("1. 以上蒸汽裂解装置开车时所需要的物料经确认全部都已获得或具备获得条件,确认人签字。");
  184. title2.createCell(1);
  185. title2.createCell(2);
  186. title2.createCell(3);
  187. title2.createCell(4);
  188. for (int i = 0; i < 5; i++) {
  189. title2.getCell(i).setCellStyle(originalStyleCopy);
  190. }
  191. CellRangeAddress cellRangeAddress1 = new CellRangeAddress(rowIndex, rowIndex, 0, 4);
  192. sheet.addMergedRegion(cellRangeAddress1);
  193. rowIndex++;
  194. Row title3 = sheet.createRow(rowIndex);
  195. title3.setHeight((short) 800);
  196. title3.createCell(0).setCellValue("2. 如果某些物料没有获得或不具备获得条件,请及时联系相关责任人按要求进行整改。");
  197. title3.createCell(1);
  198. title3.createCell(2);
  199. title3.createCell(3);
  200. title3.createCell(4);
  201. for (int i = 0; i < 5; i++) {
  202. title3.getCell(i).setCellStyle(originalStyleCopy);
  203. }
  204. CellRangeAddress cellRangeAddress2 = new CellRangeAddress(rowIndex, rowIndex, 0, 4);
  205. sheet.addMergedRegion(cellRangeAddress2);
  206. rowIndex++;
  207. // 确认人
  208. Row title4 = sheet.createRow(rowIndex);
  209. title4.setHeight((short) 800);
  210. title4.createCell(0);
  211. title4.createCell(1);
  212. title4.createCell(2);
  213. title4.createCell(3).setCellValue("确认人:");
  214. title4.createCell(4);
  215. try {
  216. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(list1.get(0).getConfirm1()));
  217. String confirm = sysUser.getSignUrl();
  218. ExcelUtils.insertPicture(wb, sheet, confirm, rowIndex, 4, 0.25, 1);
  219. } catch (NumberFormatException e) {
  220. throw new RuntimeException(e);
  221. }
  222. for (int i = 0; i < 5; i++) {
  223. title4.getCell(i).setCellStyle(originalStyleCopy);
  224. }
  225. rowIndex++;
  226. // 确认时间
  227. Row title5 = sheet.createRow(rowIndex);
  228. title5.setHeight((short) 800);
  229. title5.createCell(0);
  230. title5.createCell(1);
  231. title5.createCell(2);
  232. title5.createCell(3).setCellValue("确认时间:");
  233. title5.createCell(4).setCellValue(DateUtils.dateTime(list1.get(0).getConfirmationDate()));
  234. for (int i = 0; i < 5; i++) {
  235. title5.getCell(i).setCellStyle(originalStyleCopy);
  236. }
  237. rowIndex++;
  238. filename = "PSSR_19_原辅料" + ".xlsx";
  239. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  240. wb.write(out);
  241. wb.close();
  242. } catch (IOException e) {
  243. e.printStackTrace();
  244. }
  245. return filename;
  246. }
  247. /**
  248. * 获取原料详细信息
  249. */
  250. @PreAuthorize("@ss.hasPermi('pssr:material:query')")
  251. @GetMapping(value = "/{id}")
  252. public AjaxResult getInfo(@PathVariable("id") Long id) {
  253. TPssrMaterial item = tPssrMaterialService.selectTPssrMaterialById(id);
  254. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "yfl"));
  255. if (item.getApproveStatus() != 2)
  256. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "yfl"));
  257. return AjaxResult.success(item);
  258. }
  259. /**
  260. * 新增原料
  261. */
  262. @PreAuthorize("@ss.hasPermi('pssr:material:add')")
  263. @Log(title = "原料", businessType = BusinessType.INSERT)
  264. @PostMapping
  265. public AjaxResult add(@RequestBody TPssrMaterial tPssrMaterial) {
  266. if (StringUtils.isNotEmpty(tPssrMaterial.getConfirm1())&&tPssrMaterial.getConfirm1().equals(tPssrMaterial.getConfirm2())) {
  267. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  268. }
  269. return toAjax(tPssrMaterialService.insertTPssrMaterial(tPssrMaterial));
  270. }
  271. /**
  272. * 修改原料
  273. */
  274. @PreAuthorize("@ss.hasPermi('pssr:material:edit')")
  275. @Log(title = "原料", businessType = BusinessType.UPDATE)
  276. @PutMapping
  277. public AjaxResult edit(@RequestBody TPssrMaterial tPssrMaterial) {
  278. if (tPssrMaterial.getConfirm1().equals(tPssrMaterial.getConfirm2())){
  279. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  280. }
  281. tPssrFileService.updateFileRelevance(tPssrMaterial.getFileIds(), "yfl", tPssrMaterial.getId(), tPssrMaterial.getSubId());
  282. return toAjax(tPssrMaterialService.updateTPssrMaterial(tPssrMaterial));
  283. }
  284. /**
  285. * 修改原料
  286. */
  287. @PreAuthorize("@ss.hasPermi('pssr:material:edit')")
  288. @Log(title = "原料", businessType = BusinessType.UPDATE)
  289. @PutMapping("editBatch")
  290. public AjaxResult editBatch(@RequestBody TPssrMaterial tPssrMaterial) {
  291. if (tPssrMaterial.getConfirm1().equals(tPssrMaterial.getConfirm2())){
  292. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  293. }
  294. return toAjax(tPssrMaterialMapper.updateTPssrMaterialByIds(tPssrMaterial));
  295. }
  296. /**
  297. * 删除原料
  298. */
  299. @PreAuthorize("@ss.hasPermi('pssr:material:remove')")
  300. @Log(title = "原料", businessType = BusinessType.DELETE)
  301. @DeleteMapping("/{ids}")
  302. public AjaxResult remove(@PathVariable Long[] ids) {
  303. return toAjax(tPssrMaterialService.deleteTPssrMaterialByIds(ids));
  304. }
  305. /**
  306. * 确认人身防护
  307. */
  308. @PreAuthorize("@ss.hasPermi('pssr:material:edit')")
  309. @Log(title = "人身防护", businessType = BusinessType.UPDATE)
  310. @PutMapping("/confirmMaterial")
  311. public AjaxResult confirmMaterial(@RequestBody TPssrMaterial tPssrMaterial) {
  312. Date date = null;
  313. TPssrMaterial material = new TPssrMaterial();
  314. if (tPssrMaterial.getIds() != null && tPssrMaterial.getIds().length > 0) {
  315. for (Long id : tPssrMaterial.getIds()) {
  316. material = tPssrMaterialService.selectTPssrMaterialById(id);
  317. if (material.getConfirmationDate() == null) {
  318. material.setConfirmationDate(new Date());
  319. }
  320. material.setApproveStatus(2L);
  321. material.setUpdatedate(new Date());
  322. material.setUpdaterCode(String.valueOf(getUserId()));
  323. tPssrMaterialService.updateTPssrMaterial(material);
  324. }
  325. } else {
  326. material.setSubId(tPssrMaterial.getSubId());
  327. material.setApproveStatus(1L);
  328. for (TPssrMaterial item : tPssrMaterialService.selectTPssrMaterialList(material)) {
  329. if (tPssrMaterial.getTaskType() == 5) {
  330. item.setConfirmationDate(new Date());
  331. }
  332. item.setApproveStatus(2L);
  333. item.setUpdatedate(new Date());
  334. item.setUpdaterCode(String.valueOf(getUserId()));
  335. tPssrMaterialService.updateTPssrMaterial(item);
  336. }
  337. }
  338. //查询当前待审批的确认人
  339. TPssrMaterial entity = new TPssrMaterial();
  340. entity.setSubId(tPssrMaterial.getSubId());
  341. entity.setApproveStatus(1L);
  342. TPssrMaterial Material = tPssrMaterialService.selectAllConfirmedPersonBySubId(entity);
  343. if (Material != null) {
  344. //如果当前用户还有待审批任务
  345. if (tPssrMaterial.getTaskType() == 4 && StringUtils.isNotEmpty(Material.getConfirm1())) {
  346. if (Material.getConfirm1().contains(getUserId().toString())) {
  347. return AjaxResult.success();
  348. }
  349. }
  350. if (tPssrMaterial.getTaskType() == 5 && StringUtils.isNotEmpty(Material.getConfirm2())) {
  351. if (Material.getConfirm2().contains(getUserId().toString())) {
  352. return AjaxResult.success();
  353. }
  354. }
  355. }
  356. //无待审批任务结束当前用户流程
  357. // 因为流程关系所以approve一定会有且只有一条数据
  358. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrMaterial.getSubId());
  359. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  360. return AjaxResult.success();
  361. }
  362. /**
  363. * 驳回人身防护
  364. */
  365. @PutMapping("/turnDownMaterial")
  366. public AjaxResult turnDownMaterial(@RequestBody List<TPssrMaterial> tPssrMaterial) {
  367. if (CollectionUtils.isNotEmpty(tPssrMaterial)) {
  368. String userId = getUserId().toString();
  369. Long subId = tPssrMaterial.get(0).getSubId();
  370. // 修改已选择数据的状态
  371. for (TPssrMaterial item : tPssrMaterial) {
  372. TPssrMaterial blind = new TPssrMaterial();
  373. blind.setId(item.getId());
  374. blind.setApproveStatus(1L);
  375. blind.setUpdatedate(new Date());
  376. blind.setUpdaterCode(getUserId().toString());
  377. tPssrMaterialService.updateTPssrMaterial(blind);
  378. // 新增驳回原因数据
  379. TPssrTurndown turndown = new TPssrTurndown();
  380. turndown.setForShort(forShort);
  381. turndown.setSubId(item.getSubId());
  382. turndown.setItemId(item.getId());
  383. turndown.setReason(item.getReason());
  384. turndown.setCreatedate(new Date());
  385. turndown.setCreaterCode(getUserId().toString());
  386. tPssrTurndownService.insertTPssrTurndown(turndown);
  387. }
  388. // 查询当前流程
  389. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  390. try {
  391. runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr1confirm");
  392. historyService.deleteHistoricProcessInstance(approve.getProcessId());
  393. } catch (Exception e) {
  394. logger.info("无运行时流程");
  395. }
  396. // 驳回 查询所有待审批的人员
  397. // 查询确认人
  398. TPssrMaterial entity = new TPssrMaterial();
  399. entity.setSubId(subId);
  400. entity.setApproveStatus(1L);
  401. TPssrMaterial PssrMaterial = tPssrMaterialService.selectAllConfirmedPersonBySubId(entity);
  402. String confirmer1s = null;
  403. if (PssrMaterial != null) {
  404. confirmer1s = PssrMaterial.getConfirm1();
  405. }
  406. logger.info("=======================confirmer1s:{}", confirmer1s);
  407. Set<String> confirmerUsers1 = new HashSet<>();
  408. if (StringUtils.isNotEmpty(confirmer1s)) {
  409. confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
  410. }
  411. // 开始申请流程
  412. long businessKey = approve.getApproveId();
  413. //开始工作流、监听
  414. Authentication.setAuthenticatedUserId(userId);//设置当前申请人
  415. Map<String, Object> variables = new HashMap<>();
  416. variables.put("applyUser", userId);
  417. variables.put("confirmUsers", new ArrayList<>(confirmerUsers1));
  418. variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
  419. variables.put("chargePerson", approve.getSubCharge());
  420. //采用key来启动流程定义并设置流程变量,返回流程实例
  421. ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr1confirm", String.valueOf(businessKey), variables);
  422. // 修改审批表和sub表
  423. approve.setProcessId(pi.getProcessInstanceId());
  424. approve.setApproveStatus(1L);
  425. approve.setUpdatedate(new Date());
  426. approve.setUpdaterCode(getUserId().toString());
  427. tPssrApproveService.updateTPssrApprove(approve);
  428. TPssrSubcontent subcontent = new TPssrSubcontent();
  429. subcontent.setId(approve.getSubId());
  430. subcontent.setApproveStatus(1L);
  431. subcontent.setUpdatedate(new Date());
  432. subcontent.setUpdaterCode(getUserId().toString());
  433. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  434. return AjaxResult.success();
  435. }
  436. return AjaxResult.error();
  437. }
  438. }