TPssrLightingController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. package com.ruoyi.project.pssr.controller;
  2. import com.ruoyi.common.utils.DateUtils;
  3. import com.ruoyi.common.utils.StringUtils;
  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.TPssrApprove;
  12. import com.ruoyi.project.pssr.domain.TPssrLighting;
  13. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  14. import com.ruoyi.project.pssr.domain.TPssrTurndown;
  15. import com.ruoyi.project.pssr.mapper.TPssrLightingMapper;
  16. import com.ruoyi.project.pssr.service.*;
  17. import com.ruoyi.project.system.domain.SysUser;
  18. import com.ruoyi.project.system.service.ISysUserService;
  19. import org.activiti.engine.ProcessEngine;
  20. import org.activiti.engine.ProcessEngines;
  21. import org.activiti.engine.TaskService;
  22. import org.activiti.engine.task.Task;
  23. import org.apache.commons.collections4.CollectionUtils;
  24. import org.apache.poi.ss.usermodel.Cell;
  25. import org.apache.poi.ss.usermodel.CellStyle;
  26. import org.apache.poi.ss.usermodel.Row;
  27. import org.apache.poi.xssf.usermodel.XSSFSheet;
  28. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.security.access.prepost.PreAuthorize;
  31. import org.springframework.web.bind.annotation.*;
  32. import javax.annotation.Resource;
  33. import java.io.FileOutputStream;
  34. import java.io.IOException;
  35. import java.io.InputStream;
  36. import java.io.OutputStream;
  37. import java.util.*;
  38. /**
  39. * 照明Controller
  40. *
  41. * @author ssy
  42. * @date 2024-09-18
  43. */
  44. @RestController
  45. @RequestMapping("/pssr/lighting")
  46. public class TPssrLightingController extends BaseController {
  47. @Autowired
  48. private ITPssrFileService tPssrFileService;
  49. @Resource
  50. private TPssrLightingMapper tPssrLightingMapper;
  51. @Autowired
  52. private ITPssrTurndownService tPssrTurndownService;
  53. @Autowired
  54. private ITPssrLightingService tPssrLightingService;
  55. @Autowired
  56. private ITPssrApproveService tPssrApproveService;
  57. @Autowired
  58. private ITPssrSubcontentService tPssrSubcontentService;
  59. @Autowired
  60. private ISysUserService sysUserService;
  61. private String forShort = "zmdbr";
  62. /**
  63. * 查询照明列表
  64. */
  65. @PreAuthorize("@ss.hasPermi('pssr:lighting:list')")
  66. @GetMapping("/list")
  67. public TableDataInfo list(TPssrLighting tPssrLighting) {
  68. try {
  69. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrLighting.getSubId());
  70. if (approve != null) {
  71. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  72. TaskService taskService = processEngine.getTaskService();
  73. Task task = processEngine.getTaskService()//获取任务service
  74. .createTaskQuery()//创建查询对象
  75. .taskAssignee(getUserId().toString())
  76. .processInstanceId(approve.getProcessId()).singleResult();
  77. if (task != null) {
  78. if (task.getName().equals("确认人1")){
  79. tPssrLighting.setConfirm1(getUserId().toString());
  80. }else if (task.getName().equals("确认人2")){
  81. tPssrLighting.setConfirm2(getUserId().toString());
  82. }
  83. }
  84. }
  85. } catch (Exception e) {
  86. e.printStackTrace();
  87. logger.error("待办确认人查询报错:{}",e.getMessage());
  88. }
  89. startPage();
  90. List<TPssrLighting> list = tPssrLightingService.selectTPssrLightingList(tPssrLighting);
  91. list.forEach(item -> {
  92. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "zmdbr"));
  93. if (item.getApproveStatus() != 2)
  94. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "zmdbr"));
  95. });
  96. return getDataTable(list);
  97. }
  98. /**
  99. * 导出照明列表
  100. */
  101. @PreAuthorize("@ss.hasPermi('pssr:lighting:export')")
  102. @Log(title = "照明", businessType = BusinessType.EXPORT)
  103. @GetMapping("/export")
  104. public AjaxResult export(TPssrLighting tPssrLighting) {
  105. List<TPssrLighting> list = tPssrLightingService.selectTPssrLightingList(tPssrLighting);
  106. return AjaxResult.success(exportTmpl(list, tPssrLighting.getLightingType()));
  107. }
  108. public String exportTmpl(List<TPssrLighting> list, String LightingType) {
  109. OutputStream out = null;
  110. String filename = null;
  111. try {
  112. String tempUrl = ""; // 模板文件
  113. if ("1".equals(LightingType)) {
  114. tempUrl = "static/word/pssr/zm.xlsx";
  115. } else {
  116. tempUrl = "static/word/pssr/dbr.xlsx";
  117. }
  118. InputStream is = null;
  119. is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
  120. XSSFWorkbook wb = null;
  121. wb = new XSSFWorkbook(is);
  122. XSSFSheet sheet = wb.getSheetAt(0);
  123. //填充数据
  124. int rowIndex = 2;
  125. int num = 1;
  126. Row originalRow = sheet.getRow(2);
  127. Cell originalcell = originalRow.getCell(0);
  128. // 获取单元格样式
  129. CellStyle originalStyle = originalcell.getCellStyle();
  130. for (TPssrLighting t : list) {
  131. Row row = sheet.createRow(rowIndex);
  132. row.setHeight((short) 800);
  133. row.createCell(0).setCellValue(num);
  134. row.createCell(1).setCellValue(t.getCheckContent());
  135. row.createCell(2).setCellValue(t.getCheckResult());
  136. row.createCell(3);
  137. row.createCell(4);
  138. try {
  139. SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
  140. SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
  141. String confirm1 = sysUser1.getSignUrl();
  142. String confirm2 = sysUser2.getSignUrl();
  143. ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 3, 1, 1);
  144. ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 4, 1, 1);
  145. } catch (NumberFormatException e) {
  146. throw new RuntimeException(e);
  147. }
  148. row.createCell(5).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
  149. row.createCell(6).setCellValue(t.getRemarks());
  150. //渲染样式
  151. for (int i = 0; i < 7; i++) {
  152. row.getCell(i).setCellStyle(originalStyle);
  153. }
  154. num++;
  155. rowIndex++;
  156. }
  157. if ("1".equals(LightingType)) {
  158. filename = "PSSR_28_照明" + ".xlsx";
  159. } else {
  160. filename = "PSSR_28_电伴热" + ".xlsx";
  161. }
  162. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  163. wb.write(out);
  164. wb.close();
  165. } catch (IOException e) {
  166. e.printStackTrace();
  167. }
  168. return filename;
  169. }
  170. /**
  171. * 获取照明详细信息
  172. */
  173. @PreAuthorize("@ss.hasPermi('pssr:lighting:query')")
  174. @GetMapping(value = "/{id}")
  175. public AjaxResult getInfo(@PathVariable("id") Long id) {
  176. TPssrLighting item = tPssrLightingService.selectTPssrLightingById(id);
  177. item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "zmdbr"));
  178. if (item.getApproveStatus() != 2)
  179. item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "zmdbr"));
  180. return AjaxResult.success(item);
  181. }
  182. /**
  183. * 新增照明
  184. */
  185. @PreAuthorize("@ss.hasPermi('pssr:lighting:add')")
  186. @Log(title = "照明", businessType = BusinessType.INSERT)
  187. @PostMapping
  188. public AjaxResult add(@RequestBody TPssrLighting tPssrLighting) {
  189. if (StringUtils.isNotEmpty(tPssrLighting.getConfirm1())&&tPssrLighting.getConfirm1().equals(tPssrLighting.getConfirm2())) {
  190. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  191. }
  192. tPssrLighting.setApproveStatus(0L);
  193. return toAjax(tPssrLightingService.insertTPssrLighting(tPssrLighting));
  194. }
  195. /**
  196. * 修改照明
  197. */
  198. @PreAuthorize("@ss.hasPermi('pssr:lighting:edit')")
  199. @Log(title = "照明", businessType = BusinessType.UPDATE)
  200. @PutMapping
  201. public AjaxResult edit(@RequestBody TPssrLighting tPssrLighting) {
  202. if (tPssrLighting.getConfirm1().equals(tPssrLighting.getConfirm2())){
  203. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  204. }
  205. tPssrFileService.updateFileRelevance(tPssrLighting.getFileIds(), "zmdbr", tPssrLighting.getId(), tPssrLighting.getSubId());
  206. return toAjax(tPssrLightingService.updateTPssrLighting(tPssrLighting));
  207. }
  208. /**
  209. * 修改照明
  210. */
  211. @PreAuthorize("@ss.hasPermi('pssr:lighting:edit')")
  212. @Log(title = "照明", businessType = BusinessType.UPDATE)
  213. @PutMapping("/editBatch")
  214. public AjaxResult editb(@RequestBody TPssrLighting tPssrLighting) {
  215. if (tPssrLighting.getConfirm1().equals(tPssrLighting.getConfirm2())){
  216. return AjaxResult.error("确认人不能为同一人,请重新选择!");
  217. }
  218. return toAjax(tPssrLightingMapper.updateTPssrLightingByIds(tPssrLighting));
  219. }
  220. /**
  221. * 删除照明
  222. */
  223. @PreAuthorize("@ss.hasPermi('pssr:lighting:remove')")
  224. @Log(title = "照明", businessType = BusinessType.DELETE)
  225. @DeleteMapping("/{ids}")
  226. public AjaxResult remove(@PathVariable Long[] ids) {
  227. return toAjax(tPssrLightingService.deleteTPssrLightingByIds(ids));
  228. }
  229. /**
  230. * 确认照明,电伴热
  231. */
  232. @PreAuthorize("@ss.hasPermi('pssr:lighting:edit')")
  233. @Log(title = "照明,电伴热", businessType = BusinessType.UPDATE)
  234. @PutMapping("/confirmLighting")
  235. public AjaxResult Lighting(@RequestBody TPssrLighting tPssrLighting) {
  236. long queryStatus = 0;
  237. long approveStatus = 0;
  238. Date date = null;
  239. TPssrLighting lock = new TPssrLighting();
  240. if (tPssrLighting.getTaskType() == 4) {
  241. //拆锁确认
  242. queryStatus = 1;
  243. approveStatus = 3;
  244. date = new Date();
  245. lock.setConfirm1(getUserId().toString());
  246. } else if (tPssrLighting.getTaskType() == 5) {
  247. //上锁确认
  248. queryStatus = 3;
  249. approveStatus = 2;
  250. date = new Date();
  251. lock.setConfirm2(getUserId().toString());
  252. }
  253. // 修改状态
  254. if (tPssrLighting.getIds() != null && tPssrLighting.getIds().length > 0) {
  255. for (Long id : tPssrLighting.getIds()) {
  256. TPssrLighting item = tPssrLightingService.selectTPssrLightingById(id);
  257. item.setApproveStatus(approveStatus);
  258. if (queryStatus == 3) {
  259. item.setConfirmationDate(date);
  260. }
  261. tPssrLightingService.updateTPssrLighting(item);
  262. }
  263. } else {
  264. lock.setSubId(tPssrLighting.getSubId());
  265. lock.setApproveStatus(queryStatus);
  266. lock.setLightingType(tPssrLighting.getLightingType());
  267. for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(lock)) {
  268. if (queryStatus == 3) {
  269. item.setConfirmationDate(date);
  270. }
  271. item.setApproveStatus(approveStatus);
  272. tPssrLightingService.updateTPssrLighting(item);
  273. }
  274. }
  275. //查询当前待审批的确认人
  276. TPssrLighting entity = new TPssrLighting();
  277. entity.setSubId(tPssrLighting.getSubId());
  278. entity.setApproveStatus(queryStatus);
  279. for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(entity)) {
  280. if (tPssrLighting.getTaskType() == 4) {
  281. if (item.getConfirm1().equals(getUserId().toString())) {
  282. return AjaxResult.success();
  283. }
  284. } else if (tPssrLighting.getTaskType() == 5) {
  285. if (item.getConfirm2().equals(getUserId().toString())) {
  286. return AjaxResult.success();
  287. }
  288. }
  289. }
  290. //无待审批任务结束当前用户流程
  291. // 因为流程关系所以approve一定会有且只有一条数据
  292. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrLighting.getSubId());
  293. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  294. return AjaxResult.success();
  295. }
  296. /**
  297. * 驳回照明,电伴热
  298. */
  299. @PutMapping("/turnDownLighting")
  300. public AjaxResult turnDownLighting(@RequestBody List<TPssrLighting> tPssrLighting) {
  301. if (CollectionUtils.isNotEmpty(tPssrLighting)) {
  302. String userId = getUserId().toString();
  303. Long subId = tPssrLighting.get(0).getSubId();
  304. // 修改已选择数据的状态
  305. for (TPssrLighting item : tPssrLighting) {
  306. TPssrLighting blind = new TPssrLighting();
  307. blind.setId(item.getId());
  308. blind.setApproveStatus(1L);
  309. blind.setUpdatedate(new Date());
  310. blind.setUpdaterCode(getUserId().toString());
  311. tPssrLightingService.updateTPssrLighting(blind);
  312. // 新增驳回原因数据
  313. TPssrTurndown turndown = new TPssrTurndown();
  314. turndown.setForShort(forShort);
  315. turndown.setSubId(item.getSubId());
  316. turndown.setItemId(item.getId());
  317. turndown.setReason(item.getReason());
  318. turndown.setCreatedate(new Date());
  319. turndown.setCreaterCode(getUserId().toString());
  320. tPssrTurndownService.insertTPssrTurndown(turndown);
  321. }
  322. // 查询当前流程
  323. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
  324. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  325. TaskService taskService = processEngine.getTaskService();
  326. Task task = processEngine.getTaskService()//获取任务service
  327. .createTaskQuery()//创建查询对象
  328. .taskAssignee(userId)
  329. .processInstanceId(approve.getProcessId()).singleResult();
  330. String taskId = task.getId();
  331. // 驳回 查询所有待审批的人员
  332. TPssrLighting blind = new TPssrLighting();
  333. blind.setSubId(subId);
  334. blind.setApproveStatus(1L);
  335. Set<String> installer = new HashSet<>();
  336. Set<String> remover = new HashSet<>();
  337. for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(blind)) {
  338. // 安装人员
  339. installer.add(item.getConfirm1());
  340. //拆除人员
  341. remover.add(item.getConfirm2());
  342. }
  343. //处理流程节点
  344. Map<String, Object> param = new HashMap<>();
  345. param.put("condition", 1);
  346. param.put("confirmUsers1", new ArrayList<>(installer));
  347. param.put("confirmUsers2", new ArrayList<>(remover));
  348. //认领任务
  349. processEngine.getTaskService().claim(taskId, userId);
  350. taskService.addComment(taskId, approve.getProcessId(), "驳回");
  351. taskService.complete(taskId, param);
  352. // 修改审批表和sub表
  353. approve.setApproveStatus(1L);
  354. approve.setUpdatedate(new Date());
  355. approve.setUpdaterCode(getUserId().toString());
  356. tPssrApproveService.updateTPssrApprove(approve);
  357. TPssrSubcontent subcontent = new TPssrSubcontent();
  358. subcontent.setId(approve.getSubId());
  359. subcontent.setApproveStatus(1L);
  360. subcontent.setUpdatedate(new Date());
  361. subcontent.setUpdaterCode(getUserId().toString());
  362. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  363. return AjaxResult.success();
  364. }
  365. return AjaxResult.error();
  366. }
  367. }