TPssrFrameController.java 20 KB

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