TPssrAirtightController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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.TPssrAirtight;
  11. import com.ruoyi.project.pssr.domain.TPssrApprove;
  12. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  13. import com.ruoyi.project.pssr.service.ITPssrAirtightService;
  14. import com.ruoyi.project.pssr.service.ITPssrApproveService;
  15. import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
  16. import com.ruoyi.project.system.domain.SysUser;
  17. import com.ruoyi.project.system.service.ISysUserService;
  18. import org.activiti.engine.ProcessEngine;
  19. import org.activiti.engine.ProcessEngines;
  20. import org.activiti.engine.TaskService;
  21. import org.activiti.engine.task.Task;
  22. import org.apache.poi.ss.usermodel.Cell;
  23. import org.apache.poi.ss.usermodel.CellStyle;
  24. import org.apache.poi.ss.usermodel.Row;
  25. import org.apache.poi.xssf.usermodel.XSSFSheet;
  26. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.security.access.prepost.PreAuthorize;
  29. import org.springframework.web.bind.annotation.*;
  30. import java.io.FileOutputStream;
  31. import java.io.IOException;
  32. import java.io.InputStream;
  33. import java.io.OutputStream;
  34. import java.math.BigDecimal;
  35. import java.util.*;
  36. /**
  37. * 气密Controller
  38. *
  39. * @author ssy
  40. * @date 2024-09-18
  41. */
  42. @RestController
  43. @RequestMapping("/pssr/airtight")
  44. public class TPssrAirtightController extends BaseController {
  45. @Autowired
  46. private ITPssrAirtightService tPssrAirtightService;
  47. @Autowired
  48. private ITPssrApproveService tPssrApproveService;
  49. @Autowired
  50. private ITPssrSubcontentService tPssrSubcontentService;
  51. @Autowired
  52. private ISysUserService sysUserService;
  53. /**
  54. * 查询气密列表
  55. */
  56. @PreAuthorize("@ss.hasPermi('pssr:airtight:list')")
  57. @GetMapping("/list")
  58. public TableDataInfo list(TPssrAirtight tPssrAirtight) {
  59. startPage();
  60. List<TPssrAirtight> list = tPssrAirtightService.selectTPssrAirtightList(tPssrAirtight);
  61. return getDataTable(list);
  62. }
  63. /**
  64. * 导出气密列表
  65. */
  66. @PreAuthorize("@ss.hasPermi('pssr:airtight:export')")
  67. @Log(title = "气密", businessType = BusinessType.EXPORT)
  68. @GetMapping("/export")
  69. public AjaxResult export(TPssrAirtight tPssrAirtight) {
  70. List<TPssrAirtight> list = tPssrAirtightService.selectTPssrAirtightList(tPssrAirtight);
  71. return AjaxResult.success(exportTmpl(list));
  72. }
  73. /**
  74. * 获取气密详细信息
  75. */
  76. @PreAuthorize("@ss.hasPermi('pssr:airtight:query')")
  77. @GetMapping(value = "/{id}")
  78. public AjaxResult getInfo(@PathVariable("id") Long id) {
  79. return AjaxResult.success(tPssrAirtightService.selectTPssrAirtightById(id));
  80. }
  81. /**
  82. * 新增气密
  83. */
  84. @PreAuthorize("@ss.hasPermi('pssr:airtight:add')")
  85. @Log(title = "气密", businessType = BusinessType.INSERT)
  86. @PostMapping
  87. public AjaxResult add(@RequestBody TPssrAirtight tPssrAirtight) {
  88. tPssrAirtight.setApproveStatus(0L);
  89. try {
  90. String initialPressure = tPssrAirtight.getInitialPressure();//初始压力
  91. String finalPressure = tPssrAirtight.getFinalPressure();//最终压力
  92. //泄漏率=(初始压力-最终压力)/初始压力*100%
  93. BigDecimal leakageRate = new BigDecimal(initialPressure).subtract(new BigDecimal(finalPressure)).divide(new BigDecimal(initialPressure), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
  94. tPssrAirtight.setLeakageRate(String.valueOf(leakageRate.doubleValue()));//设置泄漏率
  95. if (leakageRate.compareTo(new BigDecimal(tPssrAirtight.getStandard())) <= 0) {//判断是否满足标准
  96. tPssrAirtight.setUptoStandard("是");
  97. } else {
  98. tPssrAirtight.setUptoStandard("否");
  99. }
  100. } catch (Exception e) {
  101. e.printStackTrace();
  102. }
  103. return toAjax(tPssrAirtightService.insertTPssrAirtight(tPssrAirtight));
  104. }
  105. /**
  106. * 修改气密
  107. */
  108. @PreAuthorize("@ss.hasPermi('pssr:airtight:edit')")
  109. @Log(title = "气密", businessType = BusinessType.UPDATE)
  110. @PutMapping
  111. public AjaxResult edit(@RequestBody TPssrAirtight tPssrAirtight) {
  112. try {
  113. String initialPressure = tPssrAirtight.getInitialPressure();//初始压力
  114. String finalPressure = tPssrAirtight.getFinalPressure();//最终压力
  115. //泄漏率=(初始压力-最终压力)/初始压力*100%
  116. BigDecimal leakageRate = new BigDecimal(initialPressure).subtract(new BigDecimal(finalPressure)).divide(new BigDecimal(initialPressure), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
  117. tPssrAirtight.setLeakageRate(String.valueOf(leakageRate.doubleValue()));//设置泄漏率
  118. if (leakageRate.compareTo(new BigDecimal(tPssrAirtight.getStandard())) <= 0) {//判断是否满足标准
  119. tPssrAirtight.setUptoStandard("是");
  120. } else {
  121. tPssrAirtight.setUptoStandard("否");
  122. }
  123. } catch (Exception e) {
  124. e.printStackTrace();
  125. }
  126. return toAjax(tPssrAirtightService.updateTPssrAirtight(tPssrAirtight));
  127. }
  128. /**
  129. * 删除气密
  130. */
  131. @PreAuthorize("@ss.hasPermi('pssr:airtight:remove')")
  132. @Log(title = "气密", businessType = BusinessType.DELETE)
  133. @DeleteMapping("/{ids}")
  134. public AjaxResult remove(@PathVariable Long[] ids) {
  135. return toAjax(tPssrAirtightService.deleteTPssrAirtightByIds(ids));
  136. }
  137. /**
  138. * 确认气密
  139. */
  140. @PreAuthorize("@ss.hasPermi('pssr:airtight:edit')")
  141. @Log(title = "气密", businessType = BusinessType.UPDATE)
  142. @PutMapping("/confirmAirtight")
  143. public AjaxResult confirmAirtight(@RequestBody TPssrAirtight tPssrAirtight) {
  144. long queryStatus = 0;
  145. long approveStatus = 0;
  146. Date date = null;
  147. if (tPssrAirtight.getTaskType() == 4) {
  148. //拆锁确认
  149. queryStatus = 1;
  150. approveStatus = 3;
  151. date = new Date();
  152. } else if (tPssrAirtight.getTaskType() == 5) {
  153. //上锁确认
  154. queryStatus = 3;
  155. approveStatus = 2;
  156. date = new Date();
  157. }
  158. // 修改状态
  159. if (tPssrAirtight.getIds() != null && tPssrAirtight.getIds().length > 0) {
  160. for (Long id : tPssrAirtight.getIds()) {
  161. TPssrAirtight item = tPssrAirtightService.selectTPssrAirtightById(id);
  162. item.setApproveStatus(approveStatus);
  163. if (item.getConfirmationDate() == null && queryStatus == 3) {
  164. item.setConfirmationDate(date);
  165. }
  166. tPssrAirtightService.updateTPssrAirtight(item);
  167. }
  168. } else {
  169. TPssrAirtight lock = new TPssrAirtight();
  170. lock.setSubId(tPssrAirtight.getSubId());
  171. lock.setApproveStatus(queryStatus);
  172. for (TPssrAirtight item : tPssrAirtightService.selectTPssrAirtightList(lock)) {
  173. if (item.getConfirmationDate() == null && queryStatus == 3) {
  174. item.setConfirmationDate(date);
  175. }
  176. item.setApproveStatus(approveStatus);
  177. tPssrAirtightService.updateTPssrAirtight(item);
  178. }
  179. }
  180. //查询当前待审批的确认人
  181. TPssrAirtight entity = new TPssrAirtight();
  182. entity.setSubId(tPssrAirtight.getSubId());
  183. entity.setApproveStatus(queryStatus);
  184. for (TPssrAirtight item : tPssrAirtightService.selectTPssrAirtightList(entity)) {
  185. if (tPssrAirtight.getTaskType() == 4) {
  186. if (item.getConfirm1().equals(getUserId().toString())) {
  187. return AjaxResult.success();
  188. }
  189. } else if (tPssrAirtight.getTaskType() == 5) {
  190. if (item.getConfirm2().equals(getUserId().toString())) {
  191. return AjaxResult.success();
  192. }
  193. }
  194. }
  195. //无待审批任务结束当前用户流程
  196. // 因为流程关系所以approve一定会有且只有一条数据
  197. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrAirtight.getSubId());
  198. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  199. return AjaxResult.success();
  200. }
  201. /**
  202. * 驳回气密
  203. */
  204. @PutMapping("/turnDownAirtight")
  205. public AjaxResult turnDownAirtight(@RequestBody TPssrAirtight tPssrAirtight) {
  206. if (tPssrAirtight.getIds() != null) {
  207. String userId = getUserId().toString();
  208. // 修改已选择数据的状态
  209. for (Long id : tPssrAirtight.getIds()) {
  210. TPssrAirtight blind = new TPssrAirtight();
  211. blind.setId(id);
  212. blind.setApproveStatus(1L);
  213. blind.setUpdatedate(new Date());
  214. blind.setUpdaterCode(getUserId().toString());
  215. tPssrAirtightService.updateTPssrAirtight(blind);
  216. }
  217. // 查询当前流程
  218. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrAirtight.getSubId());
  219. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  220. TaskService taskService = processEngine.getTaskService();
  221. Task task = processEngine.getTaskService()//获取任务service
  222. .createTaskQuery()//创建查询对象
  223. .taskAssignee(userId)
  224. .processInstanceId(approve.getProcessId()).singleResult();
  225. String taskId = task.getId();
  226. // 驳回 查询所有待审批的人员
  227. TPssrAirtight blind = new TPssrAirtight();
  228. blind.setSubId(tPssrAirtight.getSubId());
  229. blind.setApproveStatus(1L);
  230. Set<String> installer = new HashSet<>();
  231. Set<String> remover = new HashSet<>();
  232. for (TPssrAirtight item : tPssrAirtightService.selectTPssrAirtightList(blind)) {
  233. // 安装人员
  234. installer.add(item.getConfirm1());
  235. //拆除人员
  236. remover.add(item.getConfirm2());
  237. }
  238. //处理流程节点
  239. Map<String, Object> param = new HashMap<>();
  240. param.put("condition", 1);
  241. param.put("confirmUsers1", new ArrayList<>(installer));
  242. param.put("confirmUsers2", new ArrayList<>(remover));
  243. //认领任务
  244. processEngine.getTaskService().claim(taskId, userId);
  245. taskService.addComment(taskId, approve.getProcessId(), "驳回;" + tPssrAirtight.getRemarks());
  246. taskService.complete(taskId, param);
  247. // 修改审批表和sub表
  248. approve.setApproveStatus(1L);
  249. approve.setUpdatedate(new Date());
  250. approve.setUpdaterCode(getUserId().toString());
  251. tPssrApproveService.updateTPssrApprove(approve);
  252. TPssrSubcontent subcontent = new TPssrSubcontent();
  253. subcontent.setId(approve.getSubId());
  254. subcontent.setApproveStatus(1L);
  255. subcontent.setUpdatedate(new Date());
  256. subcontent.setUpdaterCode(getUserId().toString());
  257. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  258. return AjaxResult.success();
  259. }
  260. return AjaxResult.error();
  261. }
  262. public String exportTmpl(List<TPssrAirtight> list) {
  263. OutputStream out = null;
  264. String filename = null;
  265. try {
  266. String tempUrl = "static/word/pssr/qm.xlsx"; // 模板文件
  267. InputStream is = null;
  268. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  269. XSSFWorkbook wb = null;
  270. wb = new XSSFWorkbook(is);
  271. XSSFSheet sheet = wb.getSheetAt(0);
  272. //填充数据
  273. int rowIndex = 3;
  274. int num = 1;
  275. Row originalRow = sheet.getRow(3);
  276. Cell originalcell = originalRow.getCell(0);
  277. // 获取单元格样式
  278. CellStyle originalStyle = originalcell.getCellStyle();
  279. for (TPssrAirtight t : list) {
  280. Row row = sheet.createRow(rowIndex);
  281. row.setHeight((short) 800);
  282. row.createCell(0).setCellValue(num);
  283. row.createCell(1).setCellValue(t.getUnit());
  284. row.createCell(2).setCellValue(t.getSystemName());
  285. row.createCell(3).setCellValue(t.getAirtightMedium());
  286. row.createCell(4).setCellValue(t.getAirtightPressure());
  287. row.createCell(5).setCellValue(t.getInitialPressure());
  288. row.createCell(6).setCellValue(t.getFinalPressure());
  289. row.createCell(7).setCellValue(t.getStandard());
  290. row.createCell(8).setCellValue(t.getUptoStandard());
  291. row.createCell(9);
  292. row.createCell(10);
  293. try {
  294. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
  295. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
  296. String confirm1 = sysUser.getSignUrl();
  297. String confirm2= sysUser2.getSignUrl();
  298. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 9, 1, 1);
  299. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 10, 1, 1);
  300. } catch (NumberFormatException e) {
  301. throw new RuntimeException(e);
  302. }
  303. row.createCell(11).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  304. row.createCell(12).setCellValue(t.getRemarks());
  305. //渲染样式
  306. for (int i = 0; i < 13; i++) {
  307. row.getCell(i).setCellStyle(originalStyle);
  308. }
  309. num++;
  310. rowIndex++;
  311. }
  312. filename = ExcelUtil.encodingFilename("Airtight");
  313. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  314. wb.write(out);
  315. wb.close();
  316. } catch (IOException e) {
  317. e.printStackTrace();
  318. }
  319. return filename;
  320. }
  321. }