TPssrSafetyBleedController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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.StringUtils;
  5. import com.ruoyi.common.utils.file.ExcelUtils;
  6. import com.ruoyi.common.utils.poi.ExcelUtil;
  7. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  8. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  9. import com.ruoyi.framework.web.controller.BaseController;
  10. import com.ruoyi.framework.web.domain.AjaxResult;
  11. import com.ruoyi.framework.web.page.TableDataInfo;
  12. import com.ruoyi.project.pssr.domain.TPssrApprove;
  13. import com.ruoyi.project.pssr.domain.TPssrFile;
  14. import com.ruoyi.project.pssr.domain.TPssrSafetyBleed;
  15. import com.ruoyi.project.pssr.mapper.TPssrSafetyBleedMapper;
  16. import com.ruoyi.project.pssr.service.ITPssrApproveService;
  17. import com.ruoyi.project.pssr.service.ITPssrFileService;
  18. import com.ruoyi.project.pssr.service.ITPssrSafetyBleedService;
  19. import com.ruoyi.project.pssr.service.ITPssrTurndownService;
  20. import com.ruoyi.project.system.domain.SysDept;
  21. import com.ruoyi.project.system.domain.SysUser;
  22. import com.ruoyi.project.system.service.ISysDeptService;
  23. import com.ruoyi.project.system.service.ISysUserService;
  24. import org.activiti.engine.ProcessEngine;
  25. import org.activiti.engine.ProcessEngines;
  26. import org.activiti.engine.TaskService;
  27. import org.activiti.engine.task.Task;
  28. import org.apache.commons.collections4.CollectionUtils;
  29. import org.apache.poi.ss.usermodel.*;
  30. import org.apache.poi.xssf.usermodel.XSSFSheet;
  31. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.security.access.prepost.PreAuthorize;
  34. import org.springframework.web.bind.annotation.*;
  35. import org.springframework.web.multipart.MultipartFile;
  36. import javax.annotation.Resource;
  37. import java.io.FileOutputStream;
  38. import java.io.IOException;
  39. import java.io.InputStream;
  40. import java.io.OutputStream;
  41. import java.text.SimpleDateFormat;
  42. import java.util.ArrayList;
  43. import java.util.List;
  44. /**
  45. * 安全设施-紧急泄放阀Controller
  46. *
  47. * @author ssy
  48. * @date 2024-09-18
  49. */
  50. @RestController
  51. @RequestMapping("/pssr/safetyBleed")
  52. public class TPssrSafetyBleedController extends BaseController {
  53. @Resource
  54. private TPssrSafetyBleedMapper tPssrSafetyBleedMapper;
  55. @Autowired
  56. private ITPssrFileService tPssrFileService;
  57. @Autowired
  58. private ITPssrTurndownService tPssrTurndownService;
  59. @Autowired
  60. private ITPssrSafetyBleedService tPssrSafetyBleedService;
  61. @Autowired
  62. private ISysUserService sysUserService;
  63. private String forShort = "aqss-bd";
  64. @Autowired
  65. private ISysDeptService iSysDeptService;
  66. @Autowired
  67. private ISysUserService userService;
  68. @Autowired
  69. private ITPssrApproveService tPssrApproveService;
  70. /**
  71. * 批量导入
  72. */
  73. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:add')")
  74. @PostMapping("/importData")
  75. public AjaxResult importInterlockData(MultipartFile file, Long subId) throws IOException
  76. {
  77. //获取操作人员ID
  78. Long userId = getUserId();
  79. //报错行数统计
  80. List<Integer> failRow =new ArrayList<Integer>();
  81. Workbook workbook = ExcelUtils.getWorkBook(file);
  82. Sheet sheet = workbook.getSheetAt(0);
  83. List<TPssrSafetyBleed> list = new ArrayList<TPssrSafetyBleed>();
  84. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  85. //部门查询
  86. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  87. int rowNum = sheet.getPhysicalNumberOfRows();
  88. int failNumber = 0;
  89. for (int i = 2; i <= rowNum; i++) {
  90. try {
  91. logger.info("读取行数:" + i);
  92. Row row = sheet.getRow(i);
  93. int cellNum = row.getLastCellNum();
  94. TPssrSafetyBleed entity = new TPssrSafetyBleed();
  95. entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
  96. entity.setSubId(subId);
  97. entity.setApproveStatus(0L);
  98. for (int j = 0; j < cellNum; j++) {
  99. Cell cell = row.getCell(j);
  100. String cellValue = ExcelUtils.getCellValue(cell);
  101. logger.info("cellValue:" + cellValue);
  102. if (j == 0) {
  103. entity.setUnit(cellValue);
  104. } else if (j == 1) {
  105. entity.setPidNo(cellValue);
  106. } else if (j == 2) {
  107. entity.setDevNo(cellValue);
  108. } else if (j == 3) {
  109. entity.setInstallLocation(cellValue);
  110. // } else if (j == 4) {
  111. // entity.setSetPressure(cellValue);
  112. } else if (j == 4) {
  113. entity.setConfirmer1(cellValue);
  114. } else if (j == 5) {
  115. entity.setConfirmer2(cellValue);
  116. }
  117. }
  118. entity.setCreaterCode(userId.toString());
  119. logger.info("entity:" + entity);
  120. list.add(entity);
  121. }catch (Exception e){
  122. failNumber++;
  123. failRow.add(i+1);
  124. }
  125. }
  126. int successNumber = 0;
  127. int failNum = 0;
  128. for (TPssrSafetyBleed t : list
  129. ) {
  130. failNum++;
  131. try {
  132. this.add(t);
  133. successNumber++;
  134. }catch (Exception e){
  135. failNumber++;
  136. logger.info("e:" + e);
  137. failRow.add(failNum+1);
  138. }
  139. }
  140. logger.info("list:" + JSON.toJSONString(list));
  141. logger.info("successNumber:" +String.valueOf(successNumber));
  142. logger.info("failNumber:" +String.valueOf(failNumber));
  143. logger.info("failRow:" +String.valueOf(failRow));
  144. return AjaxResult.success("导入成功行数:" + String.valueOf(successNumber));
  145. }
  146. /**
  147. * 查询安全设施-紧急泄放阀列表
  148. */
  149. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:list')")
  150. @GetMapping("/list")
  151. public TableDataInfo list(TPssrSafetyBleed tPssrSafetyBleed) {
  152. try {
  153. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrSafetyBleed.getSubId());
  154. if (approve != null) {
  155. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  156. TaskService taskService = processEngine.getTaskService();
  157. Task task = processEngine.getTaskService()//获取任务service
  158. .createTaskQuery()//创建查询对象
  159. .taskAssignee(getUserId().toString())
  160. .processInstanceId(approve.getProcessId()).singleResult();
  161. if (task != null) {
  162. if (task.getName().equals("确认人1")){
  163. tPssrSafetyBleed.setConfirmer1(getUserId().toString());
  164. }else if (task.getName().equals("确认人2")){
  165. tPssrSafetyBleed.setConfirmer2(getUserId().toString());
  166. }
  167. }
  168. }
  169. } catch (Exception e) {
  170. e.printStackTrace();
  171. logger.error("待办确认人查询报错:{}",e.getMessage());
  172. }
  173. startPage();
  174. List<TPssrSafetyBleed> list = tPssrSafetyBleedService.selectTPssrSafetyBleedList(tPssrSafetyBleed);
  175. list.forEach(item -> {
  176. List<TPssrFile> tPssrFiles = tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), forShort);
  177. item.setFileList(tPssrFiles);
  178. item.setFileNum((long) tPssrFiles.size());
  179. if (item.getApproveStatus() != 2)
  180. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), forShort));
  181. });
  182. return getDataTable(list);
  183. }
  184. /**
  185. * 导出安全设施-紧急泄放阀列表
  186. */
  187. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:export')")
  188. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.EXPORT)
  189. @GetMapping("/export")
  190. public AjaxResult export(TPssrSafetyBleed tPssrSafetyBleed) {
  191. List<TPssrSafetyBleed> list = tPssrSafetyBleedService.selectTPssrSafetyBleedList(tPssrSafetyBleed);
  192. if (list.size() != 0) {
  193. return AjaxResult.success(exportTmpl(list));
  194. } else {
  195. return AjaxResult.error("暂无可导出数据");
  196. }
  197. }
  198. public String exportTmpl(List<TPssrSafetyBleed> list) {
  199. OutputStream out = null;
  200. String filename = null;
  201. try {
  202. String tempUrl = "static/word/pssr/aqssxff.xlsx"; // 模板文件
  203. InputStream is = null;
  204. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  205. XSSFWorkbook wb = null;
  206. wb = new XSSFWorkbook(is);
  207. XSSFSheet sheet = wb.getSheetAt(0);
  208. //填充数据
  209. int rowIndex = 3;
  210. int num = 1;
  211. Row originalRow = sheet.getRow(3);
  212. Cell originalcell = originalRow.getCell(0);
  213. // 获取单元格样式
  214. CellStyle originalStyle = originalcell.getCellStyle();
  215. for (TPssrSafetyBleed t : list) {
  216. Row row = sheet.createRow(rowIndex);
  217. row.setHeight((short) 800);
  218. row.createCell(0).setCellValue(num);
  219. row.createCell(1).setCellValue(t.getUnit());
  220. row.createCell(2).setCellValue(t.getPidNo());
  221. row.createCell(3).setCellValue(t.getDevNo());
  222. row.createCell(4).setCellValue(t.getVerify());
  223. row.createCell(5).setCellValue(t.getInValidity());
  224. row.createCell(6).setCellValue(t.getInstallLocation());
  225. row.createCell(7).setCellValue(t.getInstallAccuracy());
  226. row.createCell(8).setCellValue(t.getPutUse());
  227. // row.createCell(9).setCellValue(t.getSetPressure());
  228. // row.createCell(10).setCellValue(t.getUniformPressure());
  229. row.createCell(9);
  230. row.createCell(10);
  231. try {
  232. SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer1()));
  233. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirmer2()));
  234. String confirm1 = sysUser1.getSignUrl();
  235. String confirm2 = sysUser2.getSignUrl();
  236. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 9, 1, 1);
  237. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 10, 1, 1);
  238. } catch (Exception e) {
  239. }
  240. row.createCell(11).setCellValue(DateUtils.dateTime(t.getConfirmationTime()));
  241. row.createCell(12).setCellValue(t.getRemarks());
  242. //渲染样式
  243. for (int i = 0; i < 13; i++) {
  244. row.getCell(i).setCellStyle(originalStyle);
  245. }
  246. num++;
  247. rowIndex++;
  248. }
  249. filename = "PSSR_14_安全设施_泄放阀" + ".xlsx";
  250. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  251. wb.write(out);
  252. wb.close();
  253. } catch (IOException e) {
  254. e.printStackTrace();
  255. }
  256. return filename;
  257. }
  258. /**
  259. * 获取安全设施-紧急泄放阀详细信息
  260. */
  261. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:query')")
  262. @GetMapping(value = "/{id}")
  263. public AjaxResult getInfo(@PathVariable("id") Long id) {
  264. TPssrSafetyBleed item = tPssrSafetyBleedService.selectTPssrSafetyBleedById(id);
  265. List<TPssrFile> tPssrFiles = tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), forShort);
  266. item.setFileList(tPssrFiles);
  267. item.setFileNum((long) tPssrFiles.size());
  268. if (item.getApproveStatus() != 2)
  269. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), forShort));
  270. return AjaxResult.success(item);
  271. }
  272. /**
  273. * 新增安全设施-紧急泄放阀
  274. */
  275. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:add')")
  276. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.INSERT)
  277. @PostMapping
  278. public AjaxResult add(@RequestBody TPssrSafetyBleed tPssrSafetyBleed) {
  279. if (StringUtils.isNotEmpty(tPssrSafetyBleed.getConfirmer1())&&tPssrSafetyBleed.getConfirmer1().equals(tPssrSafetyBleed.getConfirmer2())) {
  280. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  281. }
  282. tPssrSafetyBleed.setApproveStatus(0L);
  283. return toAjax(tPssrSafetyBleedService.insertTPssrSafetyBleed(tPssrSafetyBleed));
  284. }
  285. //导入时判断更新或新增
  286. private int insertOrUpdate(TPssrSafetyBleed item) {
  287. TPssrSafetyBleed entity = new TPssrSafetyBleed();
  288. entity.setSubId(item.getSubId());
  289. entity.setDevNo(item.getDevNo());
  290. List<TPssrSafetyBleed> list = tPssrSafetyBleedService.selectTPssrSafetyBleedList(entity);
  291. if (CollectionUtils.isNotEmpty(list)) {
  292. item.setId(list.get(0).getId());
  293. return tPssrSafetyBleedService.updateTPssrSafetyBleed(item);
  294. } else {
  295. return tPssrSafetyBleedService.insertTPssrSafetyBleed(item);
  296. }
  297. }
  298. /**
  299. * 修改安全设施-紧急泄放阀
  300. */
  301. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:edit')")
  302. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.UPDATE)
  303. @PutMapping
  304. public AjaxResult edit(@RequestBody TPssrSafetyBleed tPssrSafetyBleed) {
  305. TPssrSafetyBleed entity = tPssrSafetyBleedService.selectTPssrSafetyBleedById(tPssrSafetyBleed.getId());
  306. if (entity.getApproveStatus() != 1 && entity.getApproveStatus() != 0) {
  307. return AjaxResult.error("当前状态不可修改!");
  308. }
  309. if (tPssrSafetyBleed.getConfirmer1().equals(tPssrSafetyBleed.getConfirmer2())){
  310. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  311. }
  312. tPssrFileService.updateFileRelevance(tPssrSafetyBleed.getFileIds(), forShort, tPssrSafetyBleed.getId(), tPssrSafetyBleed.getSubId());
  313. return toAjax(tPssrSafetyBleedService.updateTPssrSafetyBleed(tPssrSafetyBleed));
  314. }
  315. /**
  316. * 修改安全设施-紧急泄放阀
  317. */
  318. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:edit')")
  319. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.UPDATE)
  320. @PutMapping("/editBatch")
  321. public AjaxResult editb(@RequestBody TPssrSafetyBleed tPssrSafetyBleed) {
  322. if (tPssrSafetyBleed.getConfirmer1().equals(tPssrSafetyBleed.getConfirmer2())){
  323. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  324. }
  325. return toAjax(tPssrSafetyBleedMapper.updateTPssrSafetyBleedByIds(tPssrSafetyBleed));
  326. }
  327. /**
  328. * 删除安全设施-紧急泄放阀
  329. */
  330. @PreAuthorize("@ss.hasPermi('pssr:safetyBleed:remove')")
  331. @Log(title = "安全设施-紧急泄放阀", businessType = BusinessType.DELETE)
  332. @DeleteMapping("/{ids}")
  333. public AjaxResult remove(@PathVariable Long[] ids) {
  334. return toAjax(tPssrSafetyBleedService.deleteTPssrSafetyBleedByIds(ids));
  335. }
  336. }