TPssrInstrumentCalibrationController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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.listener.pssr.ConfirmTaskCreateListener;
  13. import com.ruoyi.project.pssr.domain.TPssrApprove;
  14. import com.ruoyi.project.pssr.domain.TPssrInstrumentCalibration;
  15. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  16. import com.ruoyi.project.pssr.domain.TPssrTurndown;
  17. import com.ruoyi.project.pssr.mapper.TPssrInstrumentCalibrationMapper;
  18. import com.ruoyi.project.pssr.service.*;
  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.*;
  24. import org.activiti.engine.impl.identity.Authentication;
  25. import org.activiti.engine.runtime.ProcessInstance;
  26. import org.activiti.engine.task.Task;
  27. import org.apache.commons.collections4.CollectionUtils;
  28. import org.apache.poi.ss.usermodel.*;
  29. import org.apache.poi.xssf.usermodel.XSSFSheet;
  30. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.security.access.prepost.PreAuthorize;
  33. import org.springframework.web.bind.annotation.*;
  34. import org.springframework.web.multipart.MultipartFile;
  35. import javax.annotation.Resource;
  36. import java.io.FileOutputStream;
  37. import java.io.IOException;
  38. import java.io.InputStream;
  39. import java.io.OutputStream;
  40. import java.text.SimpleDateFormat;
  41. import java.util.*;
  42. /**
  43. * 仪表校验Controller
  44. *
  45. * @author ssy
  46. * @date 2024-09-18
  47. */
  48. @RestController
  49. @RequestMapping("/pssr/instrumentCalibration")
  50. public class TPssrInstrumentCalibrationController extends BaseController {
  51. @Autowired
  52. private ITPssrFileService tPssrFileService;
  53. @Resource
  54. private TPssrInstrumentCalibrationMapper tPssrInstrumentCalibrationMapper;
  55. @Autowired
  56. private ITPssrTurndownService tPssrTurndownService;
  57. @Autowired
  58. private ITPssrInstrumentCalibrationService tPssrInstrumentCalibrationService;
  59. @Autowired
  60. private ITPssrApproveService tPssrApproveService;
  61. @Autowired
  62. private ITPssrSubcontentService tPssrSubcontentService;
  63. @Autowired
  64. private ISysUserService sysUserService;
  65. private String forShort = "ybjy";
  66. @Autowired
  67. private ISysDeptService iSysDeptService;
  68. @Autowired
  69. private ISysUserService userService;
  70. @Autowired
  71. private RuntimeService runtimeService;
  72. @Autowired
  73. private HistoryService historyService;
  74. /**
  75. * 批量导入
  76. */
  77. @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:add')")
  78. @PostMapping("/importData")
  79. public AjaxResult importInterlockData(MultipartFile file, Long subId) throws IOException {
  80. //获取操作人员ID
  81. Long userId = getUserId();
  82. //报错行数统计
  83. List<Integer> failRow = new ArrayList<Integer>();
  84. Workbook workbook = ExcelUtils.getWorkBook(file);
  85. Sheet sheet = workbook.getSheetAt(0);
  86. List<TPssrInstrumentCalibration> list = new ArrayList<TPssrInstrumentCalibration>();
  87. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  88. //部门查询
  89. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  90. int rowNum = sheet.getPhysicalNumberOfRows();
  91. int failNumber = 0;
  92. for (int i = 2; i <= rowNum; i++) {
  93. try {
  94. logger.info("读取行数:" + i);
  95. Row row = sheet.getRow(i);
  96. int cellNum = row.getLastCellNum();
  97. TPssrInstrumentCalibration entity = new TPssrInstrumentCalibration();
  98. entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
  99. entity.setSubId(subId);
  100. entity.setApproveStatus(0L);
  101. for (int j = 0; j < cellNum; j++) {
  102. Cell cell = row.getCell(j);
  103. String cellValue = ExcelUtils.getCellValue(cell);
  104. logger.info("cellValue:" + cellValue);
  105. if (j == 0) {
  106. entity.setUnit(cellValue);
  107. } else if (j == 1) {
  108. entity.setDevNo(cellValue);
  109. } else if (j == 2) {
  110. if ("流量计".equals(cellValue)) {
  111. entity.setDevType("1");
  112. } else if ("调节阀".equals(cellValue)) {
  113. entity.setDevType("3");
  114. } else if ("液位计".equals(cellValue)) {
  115. entity.setDevType("2");
  116. }
  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 (TPssrInstrumentCalibration t : list
  130. ) {
  131. failNum++;
  132. try {
  133. this.add(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:instrumentCalibration:list')")
  151. @GetMapping("/list")
  152. public TableDataInfo list(TPssrInstrumentCalibration tPssrInstrumentCalibration) {
  153. try {
  154. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrInstrumentCalibration.getSubId());
  155. if (approve != null) {
  156. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  157. TaskService taskService = processEngine.getTaskService();
  158. Task task = processEngine.getTaskService()//获取任务service
  159. .createTaskQuery()//创建查询对象
  160. .taskAssignee(getUserId().toString())
  161. .processInstanceId(approve.getProcessId()).singleResult();
  162. if (task != null) {
  163. if (task.getName().equals("确认人1")){
  164. tPssrInstrumentCalibration.setConfirm1(getUserId().toString());
  165. }else if (task.getName().equals("确认人2")){
  166. tPssrInstrumentCalibration.setConfirm2(getUserId().toString());
  167. }
  168. }
  169. }
  170. } catch (Exception e) {
  171. e.printStackTrace();
  172. logger.error("待办确认人查询报错:{}",e.getMessage());
  173. }
  174. startPage();
  175. List<TPssrInstrumentCalibration> list = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(tPssrInstrumentCalibration);
  176. list.forEach(item -> {
  177. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "ybjy"));
  178. if (item.getApproveStatus() != 2)
  179. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "ybjy"));
  180. });
  181. return getDataTable(list);
  182. }
  183. /**
  184. * 导出仪表校验列表
  185. */
  186. @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:export')")
  187. @Log(title = "仪表校验", businessType = BusinessType.EXPORT)
  188. @GetMapping("/export")
  189. public AjaxResult export(TPssrInstrumentCalibration tPssrInstrumentCalibration) {
  190. List<TPssrInstrumentCalibration> list = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(tPssrInstrumentCalibration);
  191. if (tPssrInstrumentCalibration.getDevType().equals("1")) {
  192. if (list.size() != 0) {
  193. return AjaxResult.success(exportTmpl3(list));
  194. } else {
  195. return AjaxResult.error("暂无可导出数据");
  196. }
  197. } else if (tPssrInstrumentCalibration.getDevType().equals("2")) {
  198. if (list.size() != 0) {
  199. return AjaxResult.success(exportTmpl2(list));
  200. } else {
  201. return AjaxResult.error("暂无可导出数据");
  202. }
  203. } else if (tPssrInstrumentCalibration.getDevType().equals("3")) {
  204. if (list.size() != 0) {
  205. return AjaxResult.success(exportTmpl1(list));
  206. } else {
  207. return AjaxResult.error("暂无可导出数据");
  208. }
  209. }
  210. return AjaxResult.error("导出失败,请联系管理员!");
  211. }
  212. public String exportTmpl1(List<TPssrInstrumentCalibration> list) {
  213. OutputStream out = null;
  214. String filename = null;
  215. try {
  216. String tempUrl = "static/word/pssr/ybjytjf.xlsx"; // 模板文件
  217. InputStream is = null;
  218. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  219. XSSFWorkbook wb = null;
  220. wb = new XSSFWorkbook(is);
  221. XSSFSheet sheet = wb.getSheetAt(0);
  222. //填充数据
  223. int rowIndex = 2;
  224. int num = 1;
  225. Row originalRow = sheet.getRow(2);
  226. Cell originalcell = originalRow.getCell(0);
  227. // 获取单元格样式
  228. CellStyle originalStyle = originalcell.getCellStyle();
  229. for (TPssrInstrumentCalibration t : list) {
  230. Row row = sheet.createRow(rowIndex);
  231. row.setHeight((short) 800);
  232. row.createCell(0).setCellValue(num);
  233. row.createCell(1).setCellValue(t.getUnit());
  234. row.createCell(2).setCellValue(t.getDevNo());
  235. row.createCell(3).setCellValue(t.getVisualInspection());
  236. row.createCell(4).setCellValue(t.getFlowCheck());
  237. row.createCell(5).setCellValue(t.getFileCheck());
  238. row.createCell(6).setCellValue(t.getFunctionalCheck());
  239. row.createCell(7);
  240. row.createCell(8);
  241. try {
  242. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
  243. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
  244. String confirm1 = sysUser.getSignUrl();
  245. String confirm2 = sysUser2.getSignUrl();
  246. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 7, 1, 1);
  247. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 8, 1, 1);
  248. } catch (NumberFormatException e) {
  249. throw new RuntimeException(e);
  250. }
  251. row.createCell(9).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  252. row.createCell(10).setCellValue(t.getRemarks());
  253. //渲染样式
  254. for (int i = 0; i < 11; i++) {
  255. row.getCell(i).setCellStyle(originalStyle);
  256. }
  257. num++;
  258. rowIndex++;
  259. }
  260. filename = "PSSR_23_仪表校验_调节阀" + ".xlsx";
  261. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  262. wb.write(out);
  263. wb.close();
  264. } catch (IOException e) {
  265. e.printStackTrace();
  266. }
  267. return filename;
  268. }
  269. public String exportTmpl2(List<TPssrInstrumentCalibration> list) {
  270. OutputStream out = null;
  271. String filename = null;
  272. try {
  273. String tempUrl = "static/word/pssr/ybjyywj.xlsx"; // 模板文件
  274. InputStream is = null;
  275. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  276. XSSFWorkbook wb = null;
  277. wb = new XSSFWorkbook(is);
  278. XSSFSheet sheet = wb.getSheetAt(0);
  279. //填充数据
  280. int rowIndex = 3;
  281. int num = 1;
  282. Row originalRow = sheet.getRow(3);
  283. Cell originalcell = originalRow.getCell(0);
  284. // 获取单元格样式
  285. CellStyle originalStyle = originalcell.getCellStyle();
  286. for (TPssrInstrumentCalibration t : list) {
  287. Row row = sheet.createRow(rowIndex);
  288. row.setHeight((short) 800);
  289. row.createCell(0).setCellValue(num);
  290. row.createCell(1).setCellValue(t.getUnit());
  291. row.createCell(2).setCellValue(t.getDevNo());
  292. row.createCell(3).setCellValue(t.getVisualInspection());
  293. row.createCell(4).setCellValue(t.getInstallationInspection());
  294. row.createCell(5).setCellValue(t.getFunctionalCheck());
  295. row.createCell(6);
  296. row.createCell(7);
  297. try {
  298. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
  299. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
  300. String confirm1 = sysUser.getSignUrl();
  301. String confirm2 = sysUser2.getSignUrl();
  302. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 6, 1, 1);
  303. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 7, 1, 1);
  304. } catch (NumberFormatException e) {
  305. throw new RuntimeException(e);
  306. }
  307. row.createCell(8).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  308. row.createCell(9).setCellValue(t.getRemarks());
  309. //渲染样式
  310. for (int i = 0; i < 10; i++) {
  311. row.getCell(i).setCellStyle(originalStyle);
  312. }
  313. num++;
  314. rowIndex++;
  315. }
  316. filename = "PSSR_23_仪表校验_液位计" + ".xlsx";
  317. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  318. wb.write(out);
  319. wb.close();
  320. } catch (IOException e) {
  321. e.printStackTrace();
  322. }
  323. return filename;
  324. }
  325. public String exportTmpl3(List<TPssrInstrumentCalibration> list) {
  326. OutputStream out = null;
  327. String filename = null;
  328. try {
  329. String tempUrl = "static/word/pssr/ybjyllj.xlsx"; // 模板文件
  330. InputStream is = null;
  331. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  332. XSSFWorkbook wb = null;
  333. wb = new XSSFWorkbook(is);
  334. XSSFSheet sheet = wb.getSheetAt(0);
  335. //填充数据
  336. int rowIndex = 2;
  337. int num = 1;
  338. Row originalRow = sheet.getRow(2);
  339. Cell originalcell = originalRow.getCell(0);
  340. // 获取单元格样式
  341. CellStyle originalStyle = originalcell.getCellStyle();
  342. for (TPssrInstrumentCalibration t : list) {
  343. Row row = sheet.createRow(rowIndex);
  344. row.setHeight((short) 800);
  345. row.createCell(0).setCellValue(num);
  346. row.createCell(1).setCellValue(t.getUnit());
  347. row.createCell(2).setCellValue(t.getDevNo());
  348. row.createCell(3).setCellValue(t.getVisualInspection());
  349. row.createCell(4).setCellValue(t.getInstallationInspection());
  350. row.createCell(5).setCellValue(t.getFunctionalCheck());
  351. row.createCell(6);
  352. row.createCell(7);
  353. try {
  354. SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
  355. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
  356. String confirm1 = sysUser.getSignUrl();
  357. String confirm2 = sysUser2.getSignUrl();
  358. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 6, 1, 1);
  359. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 7, 1, 1);
  360. } catch (NumberFormatException e) {
  361. throw new RuntimeException(e);
  362. }
  363. row.createCell(8).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  364. row.createCell(9).setCellValue(t.getRemarks());
  365. //渲染样式
  366. for (int i = 0; i < 10; i++) {
  367. row.getCell(i).setCellStyle(originalStyle);
  368. }
  369. num++;
  370. rowIndex++;
  371. }
  372. filename = "PSSR_23_仪表校验_流量计" + ".xlsx";
  373. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  374. wb.write(out);
  375. wb.close();
  376. } catch (IOException e) {
  377. e.printStackTrace();
  378. }
  379. return filename;
  380. }
  381. /**
  382. * 获取仪表校验详细信息
  383. */
  384. @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:query')")
  385. @GetMapping(value = "/{id}")
  386. public AjaxResult getInfo(@PathVariable("id") Long id) {
  387. TPssrInstrumentCalibration item = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationById(id);
  388. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "ybjy"));
  389. if (item.getApproveStatus() != 2)
  390. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "ybjy"));
  391. return AjaxResult.success(item);
  392. }
  393. /**
  394. * 新增仪表校验
  395. */
  396. @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:add')")
  397. @Log(title = "仪表校验", businessType = BusinessType.INSERT)
  398. @PostMapping
  399. public AjaxResult add(@RequestBody TPssrInstrumentCalibration tPssrInstrumentCalibration) {
  400. if (StringUtils.isNotEmpty(tPssrInstrumentCalibration.getConfirm1()) && tPssrInstrumentCalibration.getConfirm1().equals(tPssrInstrumentCalibration.getConfirm2())) {
  401. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  402. }
  403. tPssrInstrumentCalibration.setApproveStatus(0L);
  404. return toAjax(insertOrUpdate(tPssrInstrumentCalibration));
  405. }
  406. //导入时判断更新或新增
  407. private int insertOrUpdate(TPssrInstrumentCalibration item) {
  408. TPssrInstrumentCalibration entity = new TPssrInstrumentCalibration();
  409. entity.setSubId(item.getSubId());
  410. entity.setDevNo(item.getDevNo());
  411. List<TPssrInstrumentCalibration> list = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(entity);
  412. if (CollectionUtils.isNotEmpty(list)) {
  413. item.setId(list.get(0).getId());
  414. return tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(item);
  415. } else {
  416. return tPssrInstrumentCalibrationService.insertTPssrInstrumentCalibration(item);
  417. }
  418. }
  419. /**
  420. * 修改仪表校验
  421. */
  422. @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:edit')")
  423. @Log(title = "仪表校验", businessType = BusinessType.UPDATE)
  424. @PutMapping
  425. public AjaxResult edit(@RequestBody TPssrInstrumentCalibration tPssrInstrumentCalibration) {
  426. TPssrInstrumentCalibration entity = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationById(tPssrInstrumentCalibration.getId());
  427. if (entity.getApproveStatus() != 1 && entity.getApproveStatus() != 0) {
  428. return AjaxResult.error("当前状态不可修改!");
  429. }
  430. if (tPssrInstrumentCalibration.getConfirm1().equals(tPssrInstrumentCalibration.getConfirm2())) {
  431. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  432. }
  433. tPssrFileService.updateFileRelevance(tPssrInstrumentCalibration.getFileIds(), "ybjy", tPssrInstrumentCalibration.getId(), tPssrInstrumentCalibration.getSubId());
  434. return toAjax(tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(tPssrInstrumentCalibration));
  435. }
  436. /**
  437. * 修改仪表校验
  438. */
  439. @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:edit')")
  440. @Log(title = "仪表校验", businessType = BusinessType.UPDATE)
  441. @PutMapping("/editBatch")
  442. public AjaxResult editb(@RequestBody TPssrInstrumentCalibration tPssrInstrumentCalibration) {
  443. if (tPssrInstrumentCalibration.getConfirm1().equals(tPssrInstrumentCalibration.getConfirm2())) {
  444. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  445. }
  446. return toAjax(tPssrInstrumentCalibrationMapper.updateTPssrInstrumentCalibrationByIds(tPssrInstrumentCalibration));
  447. }
  448. /**
  449. * 删除仪表校验
  450. */
  451. @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:remove')")
  452. @Log(title = "仪表校验", businessType = BusinessType.DELETE)
  453. @DeleteMapping("/{ids}")
  454. public AjaxResult remove(@PathVariable Long[] ids) {
  455. return toAjax(tPssrInstrumentCalibrationService.deleteTPssrInstrumentCalibrationByIds(ids));
  456. }
  457. /**
  458. * 确认仪表校验
  459. */
  460. @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:edit')")
  461. @Log(title = "仪表校验", businessType = BusinessType.UPDATE)
  462. @PutMapping("/confirmInstrumentCalibration")
  463. public AjaxResult confirmInstrumentCalibration(@RequestBody TPssrInstrumentCalibration
  464. tPssrInstrumentCalibration) {
  465. long queryStatus = 0;
  466. long approveStatus = 0;
  467. Date date = null;
  468. TPssrInstrumentCalibration lock = new TPssrInstrumentCalibration();
  469. if (tPssrInstrumentCalibration.getTaskType() == 4) {
  470. //拆锁确认
  471. queryStatus = 1;
  472. approveStatus = 3;
  473. lock.setConfirm1(getUserId().toString());
  474. date = new Date();
  475. } else if (tPssrInstrumentCalibration.getTaskType() == 5) {
  476. //上锁确认
  477. queryStatus = 3;
  478. approveStatus = 2;
  479. lock.setConfirm2(getUserId().toString());
  480. date = new Date();
  481. }
  482. // 修改状态
  483. if (tPssrInstrumentCalibration.getIds() != null && tPssrInstrumentCalibration.getIds().length > 0) {
  484. for (Long id : tPssrInstrumentCalibration.getIds()) {
  485. TPssrInstrumentCalibration item = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationById(id);
  486. item.setApproveStatus(approveStatus);
  487. if (queryStatus == 3) {
  488. item.setConfirmationDate(date);
  489. }
  490. tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(item);
  491. }
  492. } else {
  493. lock.setSubId(tPssrInstrumentCalibration.getSubId());
  494. lock.setApproveStatus(queryStatus);
  495. lock.setDevType(tPssrInstrumentCalibration.getDevType());
  496. for (TPssrInstrumentCalibration item : tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(lock)) {
  497. if (queryStatus == 3) {
  498. item.setConfirmationDate(date);
  499. }
  500. item.setApproveStatus(approveStatus);
  501. tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(item);
  502. }
  503. }
  504. //查询当前待审批的确认人
  505. TPssrInstrumentCalibration entity = new TPssrInstrumentCalibration();
  506. entity.setSubId(tPssrInstrumentCalibration.getSubId());
  507. entity.setApproveStatus(queryStatus);
  508. for (TPssrInstrumentCalibration item : tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(entity)) {
  509. if (tPssrInstrumentCalibration.getTaskType() == 4) {
  510. if (item.getConfirm1().equals(getUserId().toString())) {
  511. return AjaxResult.success();
  512. }
  513. } else if (tPssrInstrumentCalibration.getTaskType() == 5) {
  514. if (item.getConfirm2().equals(getUserId().toString())) {
  515. return AjaxResult.success();
  516. }
  517. }
  518. }
  519. //无待审批任务结束当前用户流程
  520. // 因为流程关系所以approve一定会有且只有一条数据
  521. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrInstrumentCalibration.getSubId());
  522. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  523. return AjaxResult.success();
  524. }
  525. /**
  526. * 驳回仪表校验
  527. */
  528. @PutMapping("/turnDownInstrumentCalibration")
  529. public AjaxResult turnDownInstrumentCalibration
  530. (@RequestBody List<TPssrInstrumentCalibration> tPssrInstrumentCalibration) {
  531. if (CollectionUtils.isNotEmpty(tPssrInstrumentCalibration)) {
  532. String userId = getUserId().toString();
  533. Long subId = tPssrInstrumentCalibration.get(0).getSubId();
  534. // 修改已选择数据的状态
  535. for (TPssrInstrumentCalibration item : tPssrInstrumentCalibration) {
  536. TPssrInstrumentCalibration blind = new TPssrInstrumentCalibration();
  537. blind.setId(item.getId());
  538. blind.setApproveStatus(1L);
  539. blind.setUpdatedate(new Date());
  540. blind.setUpdaterCode(getUserId().toString());
  541. tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(blind);
  542. // 新增驳回原因数据
  543. TPssrTurndown turndown = new TPssrTurndown();
  544. turndown.setForShort(forShort);
  545. turndown.setSubId(item.getSubId());
  546. turndown.setItemId(item.getId());
  547. turndown.setReason(item.getReason());
  548. turndown.setCreatedate(new Date());
  549. turndown.setCreaterCode(getUserId().toString());
  550. tPssrTurndownService.insertTPssrTurndown(turndown);
  551. }
  552. // 查询当前流程
  553. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  554. try {
  555. runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr2confirm");
  556. historyService.deleteHistoricProcessInstance(approve.getProcessId());
  557. } catch (Exception e) {
  558. logger.info("无运行时流程");
  559. }
  560. // 驳回 查询所有待审批的人员
  561. TPssrInstrumentCalibration blind = new TPssrInstrumentCalibration();
  562. blind.setSubId(subId);
  563. blind.setApproveStatus(1L);
  564. Set<String> installer = new HashSet<>();
  565. Set<String> remover = new HashSet<>();
  566. for (TPssrInstrumentCalibration item : tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(blind)) {
  567. // 安装人员
  568. installer.add(item.getConfirm1());
  569. //拆除人员
  570. remover.add(item.getConfirm2());
  571. }
  572. //处理流程节点
  573. // 开始申请流程
  574. long businessKey = approve.getApproveId();
  575. //开始工作流、监听
  576. Authentication.setAuthenticatedUserId(userId);//设置当前申请人
  577. Map<String, Object> variables = new HashMap<>();
  578. variables.put("applyUser", userId);
  579. variables.put("confirmUsers1", installer);
  580. variables.put("confirmUsers2", remover);
  581. variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
  582. variables.put("chargePerson", approve.getSubCharge());
  583. //采用key来启动流程定义并设置流程变量,返回流程实例
  584. ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr2confirm", String.valueOf(businessKey), variables);
  585. approve.setProcessId(pi.getProcessInstanceId());
  586. tPssrApproveService.updateTPssrApprove(approve);
  587. // 修改审批表和sub表
  588. approve.setApproveStatus(1L);
  589. approve.setUpdatedate(new Date());
  590. approve.setUpdaterCode(getUserId().toString());
  591. tPssrApproveService.updateTPssrApprove(approve);
  592. TPssrSubcontent subcontent = new TPssrSubcontent();
  593. subcontent.setId(approve.getSubId());
  594. subcontent.setApproveStatus(1L);
  595. subcontent.setUpdatedate(new Date());
  596. subcontent.setUpdaterCode(getUserId().toString());
  597. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  598. return AjaxResult.success();
  599. }
  600. return AjaxResult.error();
  601. }
  602. }