TPssrSafetyValveController.java 10 KB

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