TPssrBlindController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. package com.ruoyi.project.pssr.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.ruoyi.common.utils.file.ExcelUtils;
  4. import com.ruoyi.common.utils.poi.ExcelUtil;
  5. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  6. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  7. import com.ruoyi.framework.web.controller.BaseController;
  8. import com.ruoyi.framework.web.domain.AjaxResult;
  9. import com.ruoyi.framework.web.page.TableDataInfo;
  10. import com.ruoyi.project.pssr.domain.TPssrApprove;
  11. import com.ruoyi.project.pssr.domain.TPssrBlind;
  12. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  13. import com.ruoyi.project.pssr.domain.TPssrTurndown;
  14. import com.ruoyi.project.pssr.mapper.TPssrBlindMapper;
  15. import com.ruoyi.project.pssr.service.*;
  16. import com.ruoyi.project.system.domain.SysDept;
  17. import com.ruoyi.project.system.domain.SysUser;
  18. import com.ruoyi.project.system.service.ISysDeptService;
  19. import com.ruoyi.project.system.service.ISysUserService;
  20. import org.activiti.engine.ProcessEngine;
  21. import org.activiti.engine.ProcessEngines;
  22. import org.activiti.engine.TaskService;
  23. import org.activiti.engine.task.Task;
  24. import org.apache.commons.collections4.CollectionUtils;
  25. import org.apache.poi.ss.usermodel.*;
  26. import org.apache.poi.xssf.usermodel.XSSFSheet;
  27. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.security.access.prepost.PreAuthorize;
  30. import org.springframework.web.bind.annotation.*;
  31. import org.springframework.web.multipart.MultipartFile;
  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.text.SimpleDateFormat;
  38. import java.util.*;
  39. /**
  40. * 盲板Controller
  41. *
  42. * @author ssy
  43. * @date 2024-09-18
  44. */
  45. @RestController
  46. @RequestMapping("/pssr/blind")
  47. public class TPssrBlindController extends BaseController {
  48. @Autowired
  49. private ITPssrFileService tPssrFileService;
  50. @Resource
  51. private TPssrBlindMapper tPssrBlindMapper;
  52. @Autowired
  53. private ITPssrTurndownService tPssrTurndownService;
  54. @Autowired
  55. private ITPssrBlindService tPssrBlindService;
  56. @Autowired
  57. private ITPssrApproveService tPssrApproveService;
  58. @Autowired
  59. private ITPssrSubcontentService tPssrSubcontentService;
  60. @Autowired
  61. private ISysUserService sysUserService;
  62. @Autowired
  63. private ISysDeptService iSysDeptService;
  64. @Autowired
  65. private ISysUserService userService;
  66. private String forShort = "mb";
  67. /**
  68. * 批量导入
  69. */
  70. @PreAuthorize("@ss.hasPermi('pssr:blind:add')")
  71. @PostMapping("/importData")
  72. public AjaxResult importInterlockData(MultipartFile file, Long subId) throws IOException
  73. {
  74. //获取操作人员ID
  75. Long userId = getUserId();
  76. //报错行数统计
  77. List<Integer> failRow =new ArrayList<Integer>();
  78. Workbook workbook = ExcelUtils.getWorkBook(file);
  79. Sheet sheet = workbook.getSheetAt(0);
  80. List<TPssrBlind> list = new ArrayList<TPssrBlind>();
  81. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  82. //部门查询
  83. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  84. int rowNum = sheet.getPhysicalNumberOfRows();
  85. int failNumber = 0;
  86. for (int i = 2; i <= rowNum; i++) {
  87. try {
  88. logger.info("读取行数:" + i);
  89. Row row = sheet.getRow(i);
  90. int cellNum = row.getLastCellNum();
  91. TPssrBlind entity = new TPssrBlind();
  92. entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
  93. entity.setSubId(subId);
  94. entity.setApproveStatus(0L);
  95. for (int j = 0; j < cellNum; j++) {
  96. Cell cell = row.getCell(j);
  97. String cellValue = ExcelUtils.getCellValue(cell);
  98. logger.info("cellValue:" + cellValue);
  99. if (j == 0) {
  100. entity.setUnitNo(cellValue);
  101. } else if (j == 1) {
  102. entity.setBlindNo(cellValue);
  103. } else if (j == 2) {
  104. entity.setIsoType(cellValue);
  105. } else if (j == 3) {
  106. entity.setBlindSize(cellValue);
  107. } else if (j == 4) {
  108. entity.setPressureRate(cellValue);
  109. } else if (j == 5) {
  110. entity.setBlindType(cellValue);
  111. } else if (j == 6) {
  112. entity.setMedium(cellValue);
  113. } else if (j == 7) {
  114. entity.setFigure(cellValue);
  115. } else if (j == 8) {
  116. entity.setPidNo(cellValue);
  117. } else if (j == 9) {
  118. entity.setLocation(cellValue);
  119. } else if (j == 10) {
  120. entity.setStartupStatus(cellValue);
  121. } else if (j == 11) {
  122. entity.setActualStatus(cellValue);
  123. } else if (j == 12) {
  124. entity.setSatisfy(cellValue);
  125. } else if (j == 13) {
  126. entity.setRemarks(cellValue);
  127. }
  128. }
  129. entity.setCreaterCode(userId.toString());
  130. logger.info("entity:" + entity);
  131. list.add(entity);
  132. }catch (Exception e){
  133. failNumber++;
  134. failRow.add(i+1);
  135. }
  136. }
  137. int successNumber = 0;
  138. int failNum = 0;
  139. for (TPssrBlind t : list
  140. ) {
  141. failNum++;
  142. try {
  143. tPssrBlindService.insertTPssrBlind(t);
  144. successNumber++;
  145. }catch (Exception e){
  146. failNumber++;
  147. logger.info("e:" + e);
  148. failRow.add(failNum+1);
  149. }
  150. }
  151. logger.info("list:" + JSON.toJSONString(list));
  152. logger.info("successNumber:" +String.valueOf(successNumber));
  153. logger.info("failNumber:" +String.valueOf(failNumber));
  154. logger.info("failRow:" +String.valueOf(failRow));
  155. return AjaxResult.success("导入成功行数:" + String.valueOf(successNumber));
  156. }
  157. /**
  158. * 查询盲板列表
  159. */
  160. @PreAuthorize("@ss.hasPermi('pssr:blind:list')")
  161. @GetMapping("/list")
  162. public TableDataInfo list(TPssrBlind tPssrBlind) {
  163. startPage();
  164. List<TPssrBlind> list = tPssrBlindService.selectTPssrBlindList(tPssrBlind);
  165. list.forEach(item -> {
  166. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), forShort));
  167. if (item.getApproveStatus() != 2)
  168. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), forShort));
  169. });
  170. return getDataTable(list);
  171. }
  172. /**
  173. * 导出盲板列表
  174. */
  175. @Log(title = "盲板", businessType = BusinessType.EXPORT)
  176. @GetMapping("/export")
  177. public AjaxResult export(TPssrBlind tPssrBlind) {
  178. List<TPssrBlind> list = tPssrBlindService.selectTPssrBlindList(tPssrBlind);
  179. return AjaxResult.success(exportTmpl(list));
  180. }
  181. public String exportTmpl(List<TPssrBlind> list) {
  182. OutputStream out = null;
  183. String filename = null;
  184. try {
  185. String tempUrl = "static/word/pssr/mb.xlsx"; // 模板文件
  186. InputStream is = null;
  187. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  188. XSSFWorkbook wb = null;
  189. wb = new XSSFWorkbook(is);
  190. XSSFSheet sheet = wb.getSheetAt(0);
  191. //填充数据
  192. int rowIndex = 3;
  193. int num = 1;
  194. Row originalRow = sheet.getRow(3);
  195. Cell originalcell = originalRow.getCell(0);
  196. // 获取单元格样式
  197. CellStyle originalStyle = originalcell.getCellStyle();
  198. for (TPssrBlind t : list) {
  199. Row row = sheet.createRow(rowIndex);
  200. row.setHeight((short) 800);
  201. row.createCell(0).setCellValue(num);
  202. row.createCell(1).setCellValue(t.getUnitNo());
  203. row.createCell(2).setCellValue(t.getBlindNo());
  204. row.createCell(3).setCellValue(t.getIsoType());
  205. row.createCell(4).setCellValue(t.getBlindSize());
  206. row.createCell(5).setCellValue(t.getPressureRate());
  207. row.createCell(6).setCellValue(t.getBlindType());
  208. row.createCell(7).setCellValue(t.getMedium());
  209. row.createCell(8).setCellValue(t.getFigure());
  210. row.createCell(9).setCellValue(t.getPidNo());
  211. row.createCell(10).setCellValue(t.getLocation());
  212. row.createCell(11).setCellValue(t.getStartupStatus());
  213. row.createCell(12).setCellValue(t.getActualStatus());
  214. row.createCell(13).setCellValue(t.getSatisfy());
  215. row.createCell(14);
  216. row.createCell(15);
  217. try {
  218. SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(t.getInConfirm1()));
  219. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getInConfirm2()));
  220. String confirm1 = sysUser1.getSignUrl();
  221. String confirm2 = sysUser2.getSignUrl();
  222. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 14, 1, 1);
  223. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 15, 1, 1);
  224. } catch (NumberFormatException e) {
  225. throw new RuntimeException(e);
  226. }
  227. row.createCell(16).setCellValue(t.getRemarks());
  228. //渲染样式
  229. for (int i = 0; i < 17; i++) {
  230. row.getCell(i).setCellStyle(originalStyle);
  231. }
  232. num++;
  233. rowIndex++;
  234. }
  235. filename = "PSSR_04_盲板_" + UUID.randomUUID().toString() + ".xlsx";
  236. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  237. wb.write(out);
  238. wb.close();
  239. is.close();
  240. out.close();
  241. } catch (IOException e) {
  242. e.printStackTrace();
  243. }
  244. return filename;
  245. }
  246. /**
  247. * 获取盲板详细信息
  248. */
  249. @PreAuthorize("@ss.hasPermi('pssr:blind:query')")
  250. @GetMapping(value = "/{id}")
  251. public AjaxResult getInfo(@PathVariable("id") Long id) {
  252. TPssrBlind item = tPssrBlindService.selectTPssrBlindById(id);
  253. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), forShort));
  254. if (item.getApproveStatus() != 2)
  255. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), forShort));
  256. return AjaxResult.success(item);
  257. }
  258. /**
  259. * 新增盲板
  260. */
  261. @PreAuthorize("@ss.hasPermi('pssr:blind:add')")
  262. @Log(title = "盲板", businessType = BusinessType.INSERT)
  263. @PostMapping
  264. public AjaxResult add(@RequestBody TPssrBlind tPssrBlind) {
  265. if (tPssrBlind.getInConfirm1().equals(tPssrBlind.getInConfirm2())){
  266. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  267. }
  268. tPssrBlind.setApproveStatus(0L);
  269. return toAjax(tPssrBlindService.insertTPssrBlind(tPssrBlind));
  270. }
  271. /**
  272. * 修改盲板
  273. */
  274. @PreAuthorize("@ss.hasPermi('pssr:blind:edit')")
  275. @Log(title = "盲板", businessType = BusinessType.UPDATE)
  276. @PutMapping
  277. public AjaxResult edit(@RequestBody TPssrBlind tPssrBlind) {
  278. if (tPssrBlind.getInConfirm1().equals(tPssrBlind.getInConfirm2())){
  279. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  280. }
  281. tPssrFileService.updateFileRelevance(tPssrBlind.getFileIds(), forShort, tPssrBlind.getId(), tPssrBlind.getSubId());
  282. return toAjax(tPssrBlindService.updateTPssrBlind(tPssrBlind));
  283. }
  284. /**
  285. * 修改盲板
  286. */
  287. @PreAuthorize("@ss.hasPermi('pssr:blind:edit')")
  288. @Log(title = "盲板", businessType = BusinessType.UPDATE)
  289. @PutMapping("/editBatch")
  290. public AjaxResult editb(@RequestBody TPssrBlind tPssrBlind) {
  291. if (tPssrBlind.getInConfirm1().equals(tPssrBlind.getInConfirm2())){
  292. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  293. }
  294. return toAjax(tPssrBlindMapper.updateTPssrBlindByIds(tPssrBlind));
  295. }
  296. /**
  297. * 删除盲板
  298. */
  299. @PreAuthorize("@ss.hasPermi('pssr:blind:remove')")
  300. @Log(title = "盲板", businessType = BusinessType.DELETE)
  301. @DeleteMapping("/{ids}")
  302. public AjaxResult remove(@PathVariable Long[] ids) {
  303. return toAjax(tPssrBlindService.deleteTPssrBlindByIds(ids));
  304. }
  305. /**
  306. * 确认盲板
  307. */
  308. @PreAuthorize("@ss.hasPermi('pssr:blind:edit')")
  309. @Log(title = "盲板", businessType = BusinessType.UPDATE)
  310. @PutMapping("/confirmBlind")
  311. public AjaxResult confirmBlind(@RequestBody TPssrBlind tPssrBlind) {
  312. // 修改盲板状态
  313. if (tPssrBlind.getIds() != null && tPssrBlind.getIds().length > 0) {
  314. for (Long id : tPssrBlind.getIds()) {
  315. TPssrBlind item = tPssrBlindService.selectTPssrBlindById(id);
  316. if (tPssrBlind.getTaskType() == 4) {
  317. item.setApproveStatus(3L);
  318. } else if (tPssrBlind.getTaskType() == 5) {
  319. item.setApproveStatus(2L);
  320. if (item.getInstallDate() == null) {
  321. item.setInstallDate(new Date());
  322. }
  323. }
  324. tPssrBlindService.updateTPssrBlind(item);
  325. }
  326. } else {
  327. TPssrBlind blind = new TPssrBlind();
  328. blind.setSubId(tPssrBlind.getSubId());
  329. blind.setCurrentUser(getUserId().toString());
  330. if (tPssrBlind.getTaskType() == 4) {
  331. blind.setApproveStatus(1L);
  332. } else if (tPssrBlind.getTaskType() == 5) {
  333. blind.setApproveStatus(3L);
  334. }
  335. for (TPssrBlind item : tPssrBlindService.selectTPssrBlindList(blind)) {
  336. if (tPssrBlind.getTaskType() == 4) {
  337. item.setApproveStatus(3L);
  338. } else if (tPssrBlind.getTaskType() == 5) {
  339. item.setApproveStatus(2L);
  340. if (item.getInstallDate() == null) {
  341. item.setInstallDate(new Date());
  342. }
  343. }
  344. tPssrBlindService.updateTPssrBlind(item);
  345. }
  346. }
  347. //查询当前待审批的确认人
  348. TPssrBlind entity = new TPssrBlind();
  349. entity.setSubId(tPssrBlind.getSubId());
  350. if (tPssrBlind.getTaskType() == 4) {
  351. entity.setApproveStatus(1L);
  352. } else if (tPssrBlind.getTaskType() == 5) {
  353. entity.setApproveStatus(3L);
  354. }
  355. long status = 1;
  356. boolean flag = false;
  357. for (TPssrBlind item : tPssrBlindService.selectTPssrBlindList(entity)) {
  358. item.setTaskType(tPssrBlind.getTaskType());
  359. if (tPssrBlind.getTaskType() == 4) {
  360. if (item.getInConfirm1().equals(getUserId().toString())) {
  361. return AjaxResult.success();
  362. }
  363. } else if (tPssrBlind.getTaskType() == 5) {
  364. if (item.getInConfirm2().equals(getUserId().toString())) {
  365. return AjaxResult.success();
  366. }
  367. }
  368. }
  369. TPssrSubcontent tPssrSubcontent = new TPssrSubcontent();
  370. tPssrSubcontent.setId(tPssrBlind.getSubId());
  371. tPssrSubcontent.setApproveStatus(status);
  372. tPssrSubcontentService.updateTPssrSubcontent(tPssrSubcontent);
  373. //无待审批任务结束当前用户流程
  374. // 因为流程关系所以approve一定会有且只有一条数据
  375. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrBlind.getSubId());
  376. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  377. return AjaxResult.success();
  378. }
  379. @PutMapping("/turnDownBlind")
  380. public AjaxResult turnDownBlind(@RequestBody List<TPssrBlind> tPssrBlind) {
  381. if (CollectionUtils.isNotEmpty(tPssrBlind)){
  382. String userId = getUserId().toString();
  383. Long subId = tPssrBlind.get(0).getSubId();
  384. // 修改已选择数据的状态
  385. for (TPssrBlind pssrBlind : tPssrBlind) {
  386. TPssrBlind blind = new TPssrBlind();
  387. blind.setId(pssrBlind.getId());
  388. blind.setApproveStatus(1L);
  389. blind.setUpdatedate(new Date());
  390. blind.setUpdaterCode(getUserId().toString());
  391. tPssrBlindService.updateTPssrBlind(blind);
  392. // 新增驳回原因数据
  393. TPssrTurndown turndown = new TPssrTurndown();
  394. turndown.setForShort(forShort);
  395. turndown.setSubId(pssrBlind.getSubId());
  396. turndown.setItemId(blind.getId());
  397. turndown.setReason(pssrBlind.getReason());
  398. turndown.setCreatedate(new Date());
  399. turndown.setCreaterCode(getUserId().toString());
  400. tPssrTurndownService.insertTPssrTurndown(turndown);
  401. }
  402. // 查询当前流程
  403. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  404. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  405. TaskService taskService = processEngine.getTaskService();
  406. Task task = processEngine.getTaskService()//获取任务service
  407. .createTaskQuery()//创建查询对象
  408. .taskAssignee(userId)
  409. .processInstanceId(approve.getProcessId()).singleResult();
  410. String taskId = task.getId();
  411. // 驳回 查询所有待审批的人员
  412. TPssrBlind blind = new TPssrBlind();
  413. blind.setSubId(subId);
  414. blind.setApproveStatus(1L);
  415. Set<String> installer = new HashSet<>();
  416. Set<String> remover = new HashSet<>();
  417. for (TPssrBlind item : tPssrBlindService.selectTPssrBlindList(blind)) {
  418. installer.add(item.getInConfirm1());
  419. remover.add(item.getInConfirm2());
  420. }
  421. //处理流程节点
  422. Map<String, Object> param = new HashMap<>();
  423. param.put("condition", 1);
  424. param.put("confirmUsers1", new ArrayList<>(installer));
  425. param.put("confirmUsers2", new ArrayList<>(remover));
  426. //认领任务
  427. processEngine.getTaskService().claim(taskId, userId);
  428. taskService.addComment(taskId, approve.getProcessId(), "驳回");
  429. taskService.complete(taskId, param);
  430. // 修改审批表和sub表
  431. approve.setApproveStatus(1L);
  432. approve.setUpdatedate(new Date());
  433. approve.setUpdaterCode(getUserId().toString());
  434. tPssrApproveService.updateTPssrApprove(approve);
  435. TPssrSubcontent subcontent = new TPssrSubcontent();
  436. subcontent.setId(approve.getSubId());
  437. subcontent.setApproveStatus(1L);
  438. subcontent.setUpdatedate(new Date());
  439. subcontent.setUpdaterCode(getUserId().toString());
  440. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  441. return AjaxResult.success();
  442. }
  443. return AjaxResult.error();
  444. }
  445. }