TPssrSafetyValveController.java 12 KB

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