TPssrSafetyBleedController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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.TPssrSafetyBleed;
  12. import com.ruoyi.project.pssr.service.ITPssrFileService;
  13. import com.ruoyi.project.pssr.service.ITPssrSafetyBleedService;
  14. import com.ruoyi.project.pssr.service.ITPssrTurndownService;
  15. import com.ruoyi.project.system.domain.SysDept;
  16. import com.ruoyi.project.system.domain.SysUser;
  17. import com.ruoyi.project.system.service.ISysDeptService;
  18. import com.ruoyi.project.system.service.ISysUserService;
  19. import org.apache.poi.ss.usermodel.*;
  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 org.springframework.web.multipart.MultipartFile;
  26. import java.io.FileOutputStream;
  27. import java.io.IOException;
  28. import java.io.InputStream;
  29. import java.io.OutputStream;
  30. import java.text.SimpleDateFormat;
  31. import java.util.ArrayList;
  32. import java.util.List;
  33. /**
  34. * 安全设施-紧急泄放阀Controller
  35. *
  36. * @author ssy
  37. * @date 2024-09-18
  38. */
  39. @RestController
  40. @RequestMapping("/pssr/safetyBleed")
  41. public class TPssrSafetyBleedController extends BaseController {
  42. @Resource
  43. private TPssrSafetyBleedMapper tPssrSafetyBleedMapper;
  44. @Autowired
  45. private ITPssrFileService tPssrFileService;
  46. @Autowired
  47. private ITPssrTurndownService tPssrTurndownService;
  48. @Autowired
  49. private ITPssrSafetyBleedService tPssrSafetyBleedService;
  50. @Autowired
  51. private ISysUserService sysUserService;
  52. private String forShort = "aqss-bd";
  53. @Autowired
  54. private ISysDeptService iSysDeptService;
  55. @Autowired
  56. private ISysUserService userService;
  57. /**
  58. * 批量导入
  59. */
  60. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:add')")
  61. @PostMapping("/importData")
  62. public AjaxResult importInterlockData(MultipartFile file, Long subId) throws IOException
  63. {
  64. //获取操作人员ID
  65. Long userId = getUserId();
  66. //报错行数统计
  67. List<Integer> failRow =new ArrayList<Integer>();
  68. Workbook workbook = ExcelUtils.getWorkBook(file);
  69. Sheet sheet = workbook.getSheetAt(0);
  70. List<TPssrSafetyBleed> list = new ArrayList<TPssrSafetyBleed>();
  71. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  72. //部门查询
  73. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  74. int rowNum = sheet.getPhysicalNumberOfRows();
  75. int failNumber = 0;
  76. for (int i = 2; i <= rowNum; i++) {
  77. try {
  78. logger.info("读取行数:" + i);
  79. Row row = sheet.getRow(i);
  80. int cellNum = row.getPhysicalNumberOfCells();
  81. TPssrSafetyBleed entity = new TPssrSafetyBleed();
  82. entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
  83. entity.setSubId(subId);
  84. entity.setApproveStatus(0L);
  85. for (int j = 0; j < cellNum; j++) {
  86. Cell cell = row.getCell(j);
  87. String cellValue = ExcelUtils.getCellValue(cell);
  88. logger.info("cellValue:" + cellValue);
  89. if (j == 0) {
  90. entity.setUnit(cellValue);
  91. } else if (j == 1) {
  92. entity.setPidNo(cellValue);
  93. } else if (j == 2) {
  94. entity.setDevNo(cellValue);
  95. } else if (j == 3) {
  96. entity.setVerify(cellValue);
  97. } else if (j == 4) {
  98. entity.setInValidity(cellValue);
  99. } else if (j == 5) {
  100. entity.setInstallLocation(cellValue);
  101. } else if (j == 6) {
  102. entity.setInstallAccuracy(cellValue);
  103. } else if (j == 7) {
  104. entity.setPutUse(cellValue);
  105. } else if (j == 8) {
  106. entity.setSetPressure(cellValue);
  107. } else if (j == 9) {
  108. entity.setUniformPressure(cellValue);
  109. } else if (j == 10) {
  110. if (cellValue.length() > 3) {
  111. entity.setConfirmationTime(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  112. }
  113. } else if (j == 11) {
  114. entity.setRemarks(cellValue);
  115. }
  116. }
  117. entity.setCreaterCode(userId.toString());
  118. logger.info("entity:" + entity);
  119. list.add(entity);
  120. }catch (Exception e){
  121. failNumber++;
  122. failRow.add(i+1);
  123. }
  124. }
  125. int successNumber = 0;
  126. int failNum = 0;
  127. for (TPssrSafetyBleed t : list
  128. ) {
  129. failNum++;
  130. try {
  131. tPssrSafetyBleedService.insertTPssrSafetyBleed(t);
  132. successNumber++;
  133. }catch (Exception e){
  134. failNumber++;
  135. logger.info("e:" + e);
  136. failRow.add(failNum+1);
  137. }
  138. }
  139. logger.info("list:" + JSON.toJSONString(list));
  140. logger.info("successNumber:" +String.valueOf(successNumber));
  141. logger.info("failNumber:" +String.valueOf(failNumber));
  142. logger.info("failRow:" +String.valueOf(failRow));
  143. return AjaxResult.success("导入成功行数:" + String.valueOf(successNumber));
  144. }
  145. /**
  146. * 查询安全设施-紧急泄放阀列表
  147. */
  148. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:list')")
  149. @GetMapping("/list")
  150. public TableDataInfo list(TPssrSafetyBleed tPssrSafetyBleed) {
  151. startPage();
  152. List<TPssrSafetyBleed> list = tPssrSafetyBleedService.selectTPssrSafetyBleedList(tPssrSafetyBleed);
  153. list.forEach(item -> {
  154. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), forShort));
  155. if (item.getApproveStatus() != 2)
  156. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), forShort));
  157. });
  158. return getDataTable(list);
  159. }
  160. /**
  161. * 导出安全设施-紧急泄放阀列表
  162. */
  163. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:export')")
  164. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.EXPORT)
  165. @GetMapping("/export")
  166. public AjaxResult export(TPssrSafetyBleed tPssrSafetyBleed) {
  167. List<TPssrSafetyBleed> list = tPssrSafetyBleedService.selectTPssrSafetyBleedList(tPssrSafetyBleed);
  168. return AjaxResult.success(exportTmpl(list));
  169. }
  170. public String exportTmpl(List<TPssrSafetyBleed> list) {
  171. OutputStream out = null;
  172. String filename = null;
  173. try {
  174. String tempUrl = "static/word/pssr/aqssxff.xlsx"; // 模板文件
  175. InputStream is = null;
  176. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  177. XSSFWorkbook wb = null;
  178. wb = new XSSFWorkbook(is);
  179. XSSFSheet sheet = wb.getSheetAt(0);
  180. //填充数据
  181. int rowIndex = 3;
  182. int num = 1;
  183. Row originalRow = sheet.getRow(3);
  184. Cell originalcell = originalRow.getCell(0);
  185. // 获取单元格样式
  186. CellStyle originalStyle = originalcell.getCellStyle();
  187. for (TPssrSafetyBleed t : list) {
  188. Row row = sheet.createRow(rowIndex);
  189. row.setHeight((short) 800);
  190. row.createCell(0).setCellValue(num);
  191. row.createCell(1).setCellValue(t.getUnit());
  192. row.createCell(2).setCellValue(t.getPidNo());
  193. row.createCell(3).setCellValue(t.getDevNo());
  194. row.createCell(4).setCellValue(t.getVerify());
  195. row.createCell(5).setCellValue(t.getInValidity());
  196. row.createCell(6).setCellValue(t.getInstallLocation());
  197. row.createCell(7).setCellValue(t.getInstallAccuracy());
  198. row.createCell(8).setCellValue(t.getPutUse());
  199. row.createCell(9).setCellValue(t.getSetPressure());
  200. row.createCell(10).setCellValue(t.getUniformPressure());
  201. row.createCell(11);
  202. row.createCell(12);
  203. try {
  204. SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer1()));
  205. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer2()));
  206. String confirm1 = sysUser1.getSignUrl();
  207. String confirm2 = sysUser2.getSignUrl();
  208. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 11, 1, 1);
  209. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 12, 1, 1);
  210. } catch (NumberFormatException e) {
  211. throw new RuntimeException(e);
  212. }
  213. row.createCell(13).setCellValue(DateUtils.dateTime(t.getConfirmationTime()));
  214. row.createCell(14).setCellValue(t.getRemarks());
  215. //渲染样式
  216. for (int i = 0; i < 15; i++) {
  217. row.getCell(i).setCellStyle(originalStyle);
  218. }
  219. num++;
  220. rowIndex++;
  221. }
  222. filename = ExcelUtil.encodingFilename("SafetyBleed");
  223. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  224. wb.write(out);
  225. wb.close();
  226. } catch (IOException e) {
  227. e.printStackTrace();
  228. }
  229. return filename;
  230. }
  231. /**
  232. * 获取安全设施-紧急泄放阀详细信息
  233. */
  234. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:query')")
  235. @GetMapping(value = "/{id}")
  236. public AjaxResult getInfo(@PathVariable("id") Long id) {
  237. TPssrSafetyBleed item = tPssrSafetyBleedService.selectTPssrSafetyBleedById(id);
  238. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), forShort));
  239. if (item.getApproveStatus() != 2)
  240. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), forShort));
  241. return AjaxResult.success(item);
  242. }
  243. /**
  244. * 新增安全设施-紧急泄放阀
  245. */
  246. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:add')")
  247. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.INSERT)
  248. @PostMapping
  249. public AjaxResult add(@RequestBody TPssrSafetyBleed tPssrSafetyBleed) {
  250. tPssrSafetyBleed.setApproveStatus(0L);
  251. return toAjax(tPssrSafetyBleedService.insertTPssrSafetyBleed(tPssrSafetyBleed));
  252. }
  253. /**
  254. * 修改安全设施-紧急泄放阀
  255. */
  256. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:edit')")
  257. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.UPDATE)
  258. @PutMapping
  259. public AjaxResult edit(@RequestBody TPssrSafetyBleed tPssrSafetyBleed) {
  260. tPssrFileService.updateFileRelevance(tPssrSafetyBleed.getFileIds(), forShort, tPssrSafetyBleed.getId(), tPssrSafetyBleed.getSubId());
  261. return toAjax(tPssrSafetyBleedService.updateTPssrSafetyBleed(tPssrSafetyBleed));
  262. }
  263. /**
  264. * 删除安全设施-紧急泄放阀
  265. */
  266. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:remove')")
  267. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.DELETE)
  268. @DeleteMapping("/{ids}")
  269. public AjaxResult remove(@PathVariable Long[] ids) {
  270. return toAjax(tPssrSafetyBleedService.deleteTPssrSafetyBleedByIds(ids));
  271. }
  272. }