TPssrSafetyBleedController.java 13 KB

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