TPssrSafetyValveController.java 9.0 KB

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