TPssrOverhaulExchangerController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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.TPssrOverhaulExchanger;
  14. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  15. import com.ruoyi.project.pssr.service.ITPssrApproveService;
  16. import com.ruoyi.project.pssr.service.ITPssrFileService;
  17. import com.ruoyi.project.pssr.service.ITPssrOverhaulExchangerService;
  18. import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
  19. import com.ruoyi.project.system.domain.SysDept;
  20. import com.ruoyi.project.system.domain.SysUser;
  21. import com.ruoyi.project.system.service.ISysDeptService;
  22. import com.ruoyi.project.system.service.ISysUserService;
  23. import org.activiti.engine.HistoryService;
  24. import org.activiti.engine.RuntimeService;
  25. import org.activiti.engine.impl.identity.Authentication;
  26. import org.activiti.engine.runtime.ProcessInstance;
  27. import org.apache.poi.ss.usermodel.*;
  28. import org.apache.poi.xssf.usermodel.XSSFSheet;
  29. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.security.access.prepost.PreAuthorize;
  32. import org.springframework.web.bind.annotation.*;
  33. import org.springframework.web.multipart.MultipartFile;
  34. import java.io.FileOutputStream;
  35. import java.io.IOException;
  36. import java.io.InputStream;
  37. import java.io.OutputStream;
  38. import java.text.SimpleDateFormat;
  39. import java.util.*;
  40. /**
  41. * 检修项目-换热器Controller
  42. *
  43. * @author ssy
  44. * @date 2024-09-18
  45. */
  46. @RestController
  47. @RequestMapping("/pssr/overhaulExchanger")
  48. public class TPssrOverhaulExchangerController extends BaseController {
  49. @Autowired
  50. private ITPssrFileService tPssrFileService;
  51. @Autowired
  52. private ITPssrOverhaulExchangerService tPssrOverhaulExchangerService;
  53. @Autowired
  54. private ITPssrApproveService tPssrApproveService;
  55. @Autowired
  56. private RuntimeService runtimeService;
  57. @Autowired
  58. private HistoryService historyService;
  59. @Autowired
  60. private ITPssrSubcontentService tPssrSubcontentService;
  61. @Autowired
  62. private ISysUserService sysUserService;
  63. @Autowired
  64. private ISysDeptService iSysDeptService;
  65. @Autowired
  66. private ISysUserService userService;
  67. /**
  68. * 查询检修项目-换热器列表
  69. */
  70. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:list')")
  71. @GetMapping("/list")
  72. public TableDataInfo list(TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  73. if ("1".equals(tPssrOverhaulExchanger.getConfirmedPerson())) {
  74. tPssrOverhaulExchanger.setConfirmedPerson(getUserId().toString());
  75. }
  76. startPage();
  77. List<TPssrOverhaulExchanger> list = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(tPssrOverhaulExchanger);
  78. list.forEach(item -> {
  79. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "jxxm-hrq"));
  80. });
  81. return getDataTable(list);
  82. }
  83. /**
  84. * 导出检修项目-换热器列表
  85. */
  86. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:export')")
  87. @Log(title = "检修项目-换热器", businessType = BusinessType.EXPORT)
  88. @GetMapping("/export")
  89. public AjaxResult export(TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  90. List<TPssrOverhaulExchanger> list = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(tPssrOverhaulExchanger);
  91. return AjaxResult.success(exportTmpl(list));
  92. }
  93. public String exportTmpl(List<TPssrOverhaulExchanger> list) {
  94. OutputStream out = null;
  95. String filename = null;
  96. try {
  97. String tempUrl = "static/word/pssr/jxxmhrq.xlsx"; // 模板文件
  98. InputStream is = null;
  99. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  100. XSSFWorkbook wb = null;
  101. wb = new XSSFWorkbook(is);
  102. XSSFSheet sheet = wb.getSheetAt(0);
  103. //填充数据
  104. int rowIndex = 2;
  105. int num = 1;
  106. Row originalRow = sheet.getRow(2);
  107. Cell originalcell = originalRow.getCell(0);
  108. // 获取单元格样式
  109. CellStyle originalStyle = originalcell.getCellStyle();
  110. for (TPssrOverhaulExchanger t : list) {
  111. Row row = sheet.createRow(rowIndex);
  112. row.setHeight((short) 800);
  113. row.createCell(0).setCellValue(num);
  114. row.createCell(1).setCellValue(t.getTagNo());
  115. row.createCell(2).setCellValue(t.getEquipmentName());
  116. row.createCell(3).setCellValue(t.getWorkDes());
  117. row.createCell(4).setCellValue(t.getPidNo());
  118. row.createCell(5).setCellValue(DateUtils.dateTime(t.getCompletionDate()));
  119. row.createCell(6);
  120. try {
  121. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirmedPerson()));
  122. String confirm1 = sysUser.getSignUrl();
  123. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 6, 1, 1);
  124. } catch (NumberFormatException e) {
  125. throw new RuntimeException(e);
  126. }
  127. row.createCell(7).setCellValue(t.getRemarks());
  128. //渲染样式
  129. for (int i = 0; i < 8; i++) {
  130. row.getCell(i).setCellStyle(originalStyle);
  131. }
  132. num++;
  133. rowIndex++;
  134. }
  135. filename = ExcelUtil.encodingFilename("OverhaulExchanger");
  136. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  137. wb.write(out);
  138. wb.close();
  139. } catch (IOException e) {
  140. e.printStackTrace();
  141. }
  142. return filename;
  143. }
  144. /**
  145. * 获取检修项目-换热器详细信息
  146. */
  147. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:query')")
  148. @GetMapping(value = "/{id}")
  149. public AjaxResult getInfo(@PathVariable("id") Long id) {
  150. TPssrOverhaulExchanger item = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id);
  151. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "jxxm-hrq"));
  152. return AjaxResult.success(item);
  153. }
  154. /**
  155. * 新增检修项目-换热器
  156. */
  157. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:add')")
  158. @Log(title = "检修项目-换热器", businessType = BusinessType.INSERT)
  159. @PostMapping
  160. public AjaxResult add(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  161. tPssrOverhaulExchanger.setApproveStatus(0L);
  162. return toAjax(tPssrOverhaulExchangerService.insertTPssrOverhaulExchanger(tPssrOverhaulExchanger));
  163. }
  164. /**
  165. * 修改检修项目-换热器
  166. */
  167. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
  168. @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
  169. @PutMapping
  170. public AjaxResult edit(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  171. tPssrFileService.updateFileRelevance(tPssrOverhaulExchanger.getFileIds(), "jxxm-hrq", tPssrOverhaulExchanger.getId(), tPssrOverhaulExchanger.getSubId());
  172. return toAjax(tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(tPssrOverhaulExchanger));
  173. }
  174. /**
  175. * 删除检修项目-换热器
  176. */
  177. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:remove')")
  178. @Log(title = "检修项目-换热器", businessType = BusinessType.DELETE)
  179. @DeleteMapping("/{ids}")
  180. public AjaxResult remove(@PathVariable Long[] ids) {
  181. return toAjax(tPssrOverhaulExchangerService.deleteTPssrOverhaulExchangerByIds(ids));
  182. }
  183. /**
  184. * 确认检修项目-换热器
  185. */
  186. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
  187. @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
  188. @PutMapping("/confirmExchanger")
  189. public AjaxResult confirmExchanger(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  190. if (tPssrOverhaulExchanger.getIds() != null && tPssrOverhaulExchanger.getIds().length > 0) {
  191. for (Long id : tPssrOverhaulExchanger.getIds()) {
  192. TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id);
  193. if (exchanger.getCompletionDate() == null) {
  194. exchanger.setCompletionDate(new Date());
  195. }
  196. exchanger.setApproveStatus(2L);
  197. exchanger.setUpdatedate(new Date());
  198. exchanger.setUpdaterCode(String.valueOf(getUserId()));
  199. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(exchanger);
  200. }
  201. } else {
  202. TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
  203. exchanger.setSubId(tPssrOverhaulExchanger.getSubId());
  204. exchanger.setConfirmedPerson(getUserId().toString());
  205. exchanger.setApproveStatus(1L);
  206. for (TPssrOverhaulExchanger overhaulExchanger : tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(exchanger)) {
  207. if (overhaulExchanger.getCompletionDate() == null) {
  208. overhaulExchanger.setCompletionDate(new Date());
  209. }
  210. overhaulExchanger.setApproveStatus(2L);
  211. overhaulExchanger.setUpdatedate(new Date());
  212. overhaulExchanger.setUpdaterCode(String.valueOf(getUserId()));
  213. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(overhaulExchanger);
  214. }
  215. }
  216. //查询当前待审批的确认人
  217. TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
  218. entity.setSubId(tPssrOverhaulExchanger.getSubId());
  219. entity.setApproveStatus(1L);
  220. TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(entity);
  221. if (exchanger != null) {
  222. String confirmedPerson = exchanger.getConfirmedPerson();
  223. logger.info("===========confirmedPerson:{}", confirmedPerson);
  224. //如果当前用户还有待审批任务
  225. if (confirmedPerson.contains(getUserId().toString())) {
  226. return AjaxResult.success();
  227. }
  228. }
  229. //无待审批任务结束当前用户流程
  230. // 因为流程关系所以approve一定会有且只有一条数据
  231. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrOverhaulExchanger.getSubId());
  232. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  233. return AjaxResult.success();
  234. }
  235. @PutMapping("/turnDownExchanger")
  236. public AjaxResult turnDownExchanger(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  237. if (tPssrOverhaulExchanger.getIds() != null) {
  238. String userId = getUserId().toString();
  239. // 修改已选择数据的状态
  240. for (Long id : tPssrOverhaulExchanger.getIds()) {
  241. TPssrOverhaulExchanger blind = new TPssrOverhaulExchanger();
  242. blind.setId(id);
  243. blind.setApproveStatus(1L);
  244. blind.setUpdatedate(new Date());
  245. blind.setUpdaterCode(getUserId().toString());
  246. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(blind);
  247. }
  248. // 查询当前流程
  249. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrOverhaulExchanger.getSubId());
  250. try {
  251. runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr1confirm");
  252. historyService.deleteHistoricProcessInstance(approve.getProcessId());
  253. } catch (Exception e) {
  254. logger.info("无运行时流程");
  255. }
  256. // 驳回 查询所有待审批的人员
  257. //查询所有确认人
  258. TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
  259. exchanger.setSubId(approve.getSubId());
  260. exchanger.setApproveStatus(1L);
  261. TPssrOverhaulExchanger overhaul = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(exchanger);
  262. String confirmers = null;
  263. if (overhaul != null) {
  264. confirmers = overhaul.getConfirmedPerson();
  265. }
  266. logger.info("=======================confirmers:{}", confirmers);
  267. Set<String> confirmUsers1 = new HashSet<>();
  268. if (StringUtils.isNotEmpty(confirmers)) {
  269. confirmUsers1.addAll(Arrays.asList(confirmers.split(",")));
  270. }
  271. // 开始申请流程
  272. long businessKey = approve.getApproveId();
  273. //开始工作流、监听
  274. Authentication.setAuthenticatedUserId(userId);//设置当前申请人
  275. Map<String, Object> variables = new HashMap<>();
  276. variables.put("applyUser", userId);
  277. variables.put("confirmUsers", new ArrayList<>(confirmUsers1));
  278. variables.put("chargePerson", approve.getSubCharge());
  279. //采用key来启动流程定义并设置流程变量,返回流程实例
  280. ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr1confirm", String.valueOf(businessKey), variables);
  281. // 修改审批表和sub表
  282. approve.setProcessId(pi.getProcessInstanceId());
  283. approve.setApproveStatus(1L);
  284. approve.setUpdatedate(new Date());
  285. approve.setUpdaterCode(getUserId().toString());
  286. tPssrApproveService.updateTPssrApprove(approve);
  287. TPssrSubcontent subcontent = new TPssrSubcontent();
  288. subcontent.setId(approve.getSubId());
  289. subcontent.setApproveStatus(1L);
  290. subcontent.setUpdatedate(new Date());
  291. subcontent.setUpdaterCode(getUserId().toString());
  292. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  293. return AjaxResult.success();
  294. }
  295. return AjaxResult.error();
  296. }
  297. /**
  298. * 批量导入
  299. */
  300. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:add')")
  301. @PostMapping("/importData")
  302. public AjaxResult importInterlockData(MultipartFile file, Long subId) throws IOException
  303. {
  304. //获取操作人员ID
  305. Long userId = getUserId();
  306. //报错行数统计
  307. List<Integer> failRow =new ArrayList<Integer>();
  308. Workbook workbook = ExcelUtils.getWorkBook(file);
  309. Sheet sheet = workbook.getSheetAt(0);
  310. List<TPssrOverhaulExchanger> list = new ArrayList<TPssrOverhaulExchanger>();
  311. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  312. //部门查询
  313. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  314. int rowNum = sheet.getPhysicalNumberOfRows();
  315. int failNumber = 0;
  316. for (int i = 2; i <= rowNum; i++) {
  317. try {
  318. logger.info("读取行数:" + i);
  319. Row row = sheet.getRow(i);
  320. int cellNum = row.getPhysicalNumberOfCells();
  321. TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
  322. entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
  323. entity.setSubId(subId);
  324. for (int j = 0; j < cellNum; j++) {
  325. Cell cell = row.getCell(j);
  326. String cellValue = ExcelUtils.getCellValue(cell);
  327. logger.info("cellValue:" + cellValue);
  328. if (j == 0) {
  329. entity.setTagNo(cellValue);
  330. } else if (j == 1) {
  331. entity.setEquipmentName(cellValue);
  332. } else if (j == 2) {
  333. entity.setWorkDes(cellValue);
  334. } else if (j == 3) {
  335. entity.setPidNo(cellValue);
  336. } else if (j == 4) {
  337. entity.setRemarks(cellValue);
  338. }
  339. }
  340. entity.setCreaterCode(userId.toString());
  341. logger.info("entity:" + entity);
  342. list.add(entity);
  343. }catch (Exception e){
  344. failNumber++;
  345. failRow.add(i+1);
  346. }
  347. }
  348. int successNumber = 0;
  349. int failNum = 0;
  350. for (TPssrOverhaulExchanger t : list
  351. ) {
  352. failNum++;
  353. try {
  354. tPssrOverhaulExchangerService.insertTPssrOverhaulExchanger(t);
  355. successNumber++;
  356. }catch (Exception e){
  357. failNumber++;
  358. logger.info("e:" + e);
  359. failRow.add(failNum+1);
  360. }
  361. }
  362. logger.info("list:" + JSON.toJSONString(list));
  363. logger.info("successNumber:" +String.valueOf(successNumber));
  364. logger.info("failNumber:" +String.valueOf(failNumber));
  365. logger.info("failRow:" +String.valueOf(failRow));
  366. return AjaxResult.success("导入成功行数:" + String.valueOf(successNumber));
  367. }
  368. }