TPssrSafetyValveController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.TPssrApprove;
  12. import com.ruoyi.project.pssr.domain.TPssrSafetyValve;
  13. import com.ruoyi.project.pssr.mapper.TPssrSafetyValveMapper;
  14. import com.ruoyi.project.pssr.service.ITPssrApproveService;
  15. import com.ruoyi.project.pssr.service.ITPssrFileService;
  16. import com.ruoyi.project.pssr.service.ITPssrSafetyValveService;
  17. import com.ruoyi.project.pssr.service.ITPssrTurndownService;
  18. import com.ruoyi.project.system.domain.SysUser;
  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.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.List;
  38. import java.util.UUID;
  39. import java.util.concurrent.CountDownLatch;
  40. import java.util.concurrent.ExecutorService;
  41. import java.util.concurrent.Executors;
  42. /**
  43. * 安全设施-安全阀Controller
  44. *
  45. * @author ssy
  46. * @date 2024-09-18
  47. */
  48. @RestController
  49. @RequestMapping("/pssr/safetyValve")
  50. public class TPssrSafetyValveController extends BaseController {
  51. @Resource
  52. private TPssrSafetyValveMapper tPssrSafetyValveMapper;
  53. @Autowired
  54. private ITPssrFileService tPssrFileService;
  55. @Autowired
  56. private ITPssrApproveService tPssrApproveService;
  57. @Autowired
  58. private ITPssrTurndownService tPssrTurndownService;
  59. @Autowired
  60. private ITPssrSafetyValveService tPssrSafetyValveService;
  61. @Autowired
  62. private ISysUserService sysUserService;
  63. private String forShort = "aqss-v";
  64. /**
  65. * 查询安全设施-安全阀列表
  66. */
  67. @PreAuthorize("@ss.hasPermi('pssr:safetyValve:list')")
  68. @GetMapping("/list")
  69. public TableDataInfo list(TPssrSafetyValve tPssrSafetyValve) {
  70. try {
  71. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrSafetyValve.getSubId());
  72. if (approve != null) {
  73. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  74. TaskService taskService = processEngine.getTaskService();
  75. Task task = processEngine.getTaskService()//获取任务service
  76. .createTaskQuery()//创建查询对象
  77. .taskAssignee(getUserId().toString())
  78. .processInstanceId(approve.getProcessId()).singleResult();
  79. if (task != null) {
  80. if (task.getName().equals("确认人1")){
  81. tPssrSafetyValve.setConfirmer1(getUserId().toString());
  82. }else if (task.getName().equals("确认人2")){
  83. tPssrSafetyValve.setConfirmer2(getUserId().toString());
  84. }
  85. }
  86. }
  87. } catch (Exception e) {
  88. e.printStackTrace();
  89. logger.error("待办确认人查询报错:{}",e.getMessage());
  90. }
  91. startPage();
  92. List<TPssrSafetyValve> list = tPssrSafetyValveService.selectTPssrSafetyValveList(tPssrSafetyValve);
  93. if (list.size() > 0) {
  94. //线程池
  95. ExecutorService executorService = Executors.newFixedThreadPool(30);
  96. final CountDownLatch latch = new CountDownLatch(list.size()); //相同线程数量的计数
  97. for (TPssrSafetyValve item : list
  98. ) {
  99. executorService.submit(() -> {
  100. try {
  101. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-v"));
  102. if (item.getApproveStatus() != 2)
  103. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-v"));
  104. } catch (Exception e) {
  105. logger.error("e:", e);
  106. } finally {
  107. latch.countDown(); //线程计数
  108. }
  109. });
  110. }
  111. try {
  112. latch.await(); //线程计数完毕后继续执行
  113. } catch (InterruptedException e) {
  114. logger.error("e", e);
  115. }
  116. executorService.shutdown();
  117. }
  118. return getDataTable(list);
  119. }
  120. /**
  121. * 导出安全设施-安全阀列表
  122. */
  123. @PreAuthorize("@ss.hasPermi('pssr:safetyValve:export')")
  124. @Log(title = "安全设施-安全阀", businessType = BusinessType.EXPORT)
  125. @GetMapping("/export")
  126. public AjaxResult export(TPssrSafetyValve tPssrSafetyValve) {
  127. List<TPssrSafetyValve> list = tPssrSafetyValveService.selectTPssrSafetyValveList(tPssrSafetyValve);
  128. return AjaxResult.success(exportTmpl(list));
  129. }
  130. public String exportTmpl(List<TPssrSafetyValve> list) {
  131. OutputStream out = null;
  132. String filename = null;
  133. try {
  134. String tempUrl = "static/word/pssr/aqssaqf.xlsx"; // 模板文件
  135. InputStream is = null;
  136. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  137. XSSFWorkbook wb = null;
  138. wb = new XSSFWorkbook(is);
  139. XSSFSheet sheet = wb.getSheetAt(0);
  140. //填充数据
  141. int rowIndex = 3;
  142. int num = 1;
  143. Row originalRow = sheet.getRow(3);
  144. Cell originalcell = originalRow.getCell(0);
  145. // 获取单元格样式
  146. CellStyle originalStyle = originalcell.getCellStyle();
  147. for (TPssrSafetyValve t : list) {
  148. Row row = sheet.createRow(rowIndex);
  149. row.setHeight((short) 800);
  150. row.createCell(0).setCellValue(num);
  151. row.createCell(1).setCellValue(t.getUnit());
  152. row.createCell(2).setCellValue(t.getPidNo());
  153. row.createCell(3).setCellValue(t.getDevNo());
  154. row.createCell(4).setCellValue(t.getSafetyDev());
  155. row.createCell(5).setCellValue(t.getVerify());
  156. row.createCell(6).setCellValue(t.getInValidity());
  157. row.createCell(7).setCellValue(t.getInstallLocation());
  158. row.createCell(8).setCellValue(t.getInstallAccuracy());
  159. row.createCell(9).setCellValue(t.getPutUse());
  160. row.createCell(10).setCellValue(t.getSetPressure());
  161. row.createCell(11).setCellValue(t.getUniformPressure());
  162. row.createCell(12);
  163. row.createCell(13);
  164. try {
  165. SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer1()));
  166. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer2()));
  167. String confirm1 = sysUser1.getSignUrl();
  168. String confirm2 = sysUser2.getSignUrl();
  169. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 12, 1, 1);
  170. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 13, 1, 1);
  171. } catch (NumberFormatException e) {
  172. throw new RuntimeException(e);
  173. }
  174. row.createCell(14).setCellValue(DateUtils.dateTime(t.getConfirmationTime()));
  175. row.createCell(15).setCellValue(t.getRemarks());
  176. //渲染样式
  177. for (int i = 0; i < 16; i++) {
  178. row.getCell(i).setCellStyle(originalStyle);
  179. }
  180. num++;
  181. rowIndex++;
  182. }
  183. filename = "PSSR_14_安全设施_安全阀" + ".xlsx";
  184. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  185. wb.write(out);
  186. wb.close();
  187. } catch (IOException e) {
  188. e.printStackTrace();
  189. }
  190. return filename;
  191. }
  192. /**
  193. * 获取安全设施-安全阀详细信息
  194. */
  195. @PreAuthorize("@ss.hasPermi('pssr:safetyValve:query')")
  196. @GetMapping(value = "/{id}")
  197. public AjaxResult getInfo(@PathVariable("id") Long id) {
  198. TPssrSafetyValve item = tPssrSafetyValveService.selectTPssrSafetyValveById(id);
  199. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-v"));
  200. if (item.getApproveStatus() != 2)
  201. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-v"));
  202. return AjaxResult.success(item);
  203. }
  204. /**
  205. * 新增安全设施-安全阀
  206. */
  207. @PreAuthorize("@ss.hasPermi('pssr:safetyValve:add')")
  208. @Log(title = "安全设施-安全阀", businessType = BusinessType.INSERT)
  209. @PostMapping
  210. public AjaxResult add(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
  211. if (StringUtils.isNotEmpty(tPssrSafetyValve.getConfirmer1())&&tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())) {
  212. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  213. }
  214. tPssrSafetyValve.setApproveStatus(0L);
  215. return toAjax(tPssrSafetyValveService.insertTPssrSafetyValve(tPssrSafetyValve));
  216. }
  217. /**
  218. * 修改安全设施-安全阀
  219. */
  220. @PreAuthorize("@ss.hasPermi('pssr:safetyValve:edit')")
  221. @Log(title = "安全设施-安全阀", businessType = BusinessType.UPDATE)
  222. @PutMapping
  223. public AjaxResult edit(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
  224. if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())) {
  225. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  226. }
  227. tPssrFileService.updateFileRelevance(tPssrSafetyValve.getFileIds(), "aqss-v", tPssrSafetyValve.getId(), tPssrSafetyValve.getSubId());
  228. return toAjax(tPssrSafetyValveService.updateTPssrSafetyValve(tPssrSafetyValve));
  229. }
  230. /**
  231. * 修改安全设施-安全阀
  232. */
  233. @PreAuthorize("@ss.hasPermi('pssr:safetyValve:edit')")
  234. @Log(title = "安全设施-安全阀", businessType = BusinessType.UPDATE)
  235. @PutMapping("/editBatch")
  236. public AjaxResult editb(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
  237. if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())) {
  238. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  239. }
  240. return toAjax(tPssrSafetyValveMapper.updateTPssrSafetyValveByIds(tPssrSafetyValve));
  241. }
  242. /**
  243. * 删除安全设施-安全阀
  244. */
  245. @PreAuthorize("@ss.hasPermi('pssr:safetyValve:remove')")
  246. @Log(title = "安全设施-安全阀", businessType = BusinessType.DELETE)
  247. @DeleteMapping("/{ids}")
  248. public AjaxResult remove(@PathVariable Long[] ids) {
  249. return toAjax(tPssrSafetyValveService.deleteTPssrSafetyValveByIds(ids));
  250. }
  251. }