TPssrMaterialController.java 19 KB

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