TPssrLightingController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. package com.ruoyi.project.pssr.controller;
  2. import java.util.*;
  3. import com.ruoyi.project.pssr.domain.TPssrApprove;
  4. import com.ruoyi.project.pssr.domain.TPssrSubcontent;
  5. import com.ruoyi.project.pssr.domain.TPssrLighting;
  6. import com.ruoyi.project.pssr.service.ITPssrApproveService;
  7. import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
  8. import org.activiti.engine.ProcessEngine;
  9. import org.activiti.engine.ProcessEngines;
  10. import org.activiti.engine.TaskService;
  11. import org.activiti.engine.task.Task;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.PutMapping;
  17. import org.springframework.web.bind.annotation.DeleteMapping;
  18. import org.springframework.web.bind.annotation.PathVariable;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  23. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  24. import com.ruoyi.project.pssr.domain.TPssrLighting;
  25. import com.ruoyi.project.pssr.service.ITPssrLightingService;
  26. import com.ruoyi.framework.web.controller.BaseController;
  27. import com.ruoyi.framework.web.domain.AjaxResult;
  28. import com.ruoyi.common.utils.poi.ExcelUtil;
  29. import com.ruoyi.framework.web.page.TableDataInfo;
  30. /**
  31. * 照明Controller
  32. *
  33. * @author ssy
  34. * @date 2024-09-18
  35. */
  36. @RestController
  37. @RequestMapping("/pssr/lighting")
  38. public class TPssrLightingController extends BaseController
  39. {
  40. @Autowired
  41. private ITPssrLightingService tPssrLightingService;
  42. @Autowired
  43. private ITPssrApproveService tPssrApproveService;
  44. @Autowired
  45. private ITPssrSubcontentService tPssrSubcontentService;
  46. /**
  47. * 查询照明列表
  48. */
  49. @PreAuthorize("@ss.hasPermi('pssr:lighting:list')")
  50. @GetMapping("/list")
  51. public TableDataInfo list(TPssrLighting tPssrLighting)
  52. {
  53. startPage();
  54. List<TPssrLighting> list = tPssrLightingService.selectTPssrLightingList(tPssrLighting);
  55. return getDataTable(list);
  56. }
  57. /**
  58. * 导出照明列表
  59. */
  60. @PreAuthorize("@ss.hasPermi('pssr:lighting:export')")
  61. @Log(title = "照明", businessType = BusinessType.EXPORT)
  62. @GetMapping("/export")
  63. public AjaxResult export(TPssrLighting tPssrLighting)
  64. {
  65. List<TPssrLighting> list = tPssrLightingService.selectTPssrLightingList(tPssrLighting);
  66. ExcelUtil<TPssrLighting> util = new ExcelUtil<TPssrLighting>(TPssrLighting.class);
  67. return util.exportExcel(list, "lighting");
  68. }
  69. /**
  70. * 获取照明详细信息
  71. */
  72. @PreAuthorize("@ss.hasPermi('pssr:lighting:query')")
  73. @GetMapping(value = "/{id}")
  74. public AjaxResult getInfo(@PathVariable("id") Long id)
  75. {
  76. return AjaxResult.success(tPssrLightingService.selectTPssrLightingById(id));
  77. }
  78. /**
  79. * 新增照明
  80. */
  81. @PreAuthorize("@ss.hasPermi('pssr:lighting:add')")
  82. @Log(title = "照明", businessType = BusinessType.INSERT)
  83. @PostMapping
  84. public AjaxResult add(@RequestBody TPssrLighting tPssrLighting)
  85. {
  86. tPssrLighting.setApproveStatus(0L);
  87. return toAjax(tPssrLightingService.insertTPssrLighting(tPssrLighting));
  88. }
  89. /**
  90. * 修改照明
  91. */
  92. @PreAuthorize("@ss.hasPermi('pssr:lighting:edit')")
  93. @Log(title = "照明", businessType = BusinessType.UPDATE)
  94. @PutMapping
  95. public AjaxResult edit(@RequestBody TPssrLighting tPssrLighting)
  96. {
  97. return toAjax(tPssrLightingService.updateTPssrLighting(tPssrLighting));
  98. }
  99. /**
  100. * 删除照明
  101. */
  102. @PreAuthorize("@ss.hasPermi('pssr:lighting:remove')")
  103. @Log(title = "照明", businessType = BusinessType.DELETE)
  104. @DeleteMapping("/{ids}")
  105. public AjaxResult remove(@PathVariable Long[] ids)
  106. {
  107. return toAjax(tPssrLightingService.deleteTPssrLightingByIds(ids));
  108. }
  109. /**
  110. * 确认照明,电伴热
  111. */
  112. @PreAuthorize("@ss.hasPermi('pssr:lighting:edit')")
  113. @Log(title = "照明,电伴热", businessType = BusinessType.UPDATE)
  114. @PutMapping("/confirmLighting")
  115. public AjaxResult Lighting(@RequestBody TPssrLighting tPssrLighting) {
  116. long queryStatus = 0;
  117. long approveStatus = 0;
  118. Date date = null;
  119. if (tPssrLighting.getTaskType() == 4) {
  120. //拆锁确认
  121. queryStatus = 1;
  122. approveStatus = 3;
  123. date = new Date();
  124. } else if (tPssrLighting.getTaskType() == 5) {
  125. //上锁确认
  126. queryStatus = 3;
  127. approveStatus = 2;
  128. date = new Date();
  129. }
  130. // 修改状态
  131. if (tPssrLighting.getIds() != null && tPssrLighting.getIds().length > 0) {
  132. for (Long id : tPssrLighting.getIds()) {
  133. TPssrLighting item = tPssrLightingService.selectTPssrLightingById(id);
  134. item.setApproveStatus(approveStatus);
  135. if (item.getConfirmationDate()==null && queryStatus==3) {
  136. item.setConfirmationDate(date);
  137. }
  138. tPssrLightingService.updateTPssrLighting(item);
  139. }
  140. } else {
  141. TPssrLighting lock = new TPssrLighting();
  142. lock.setSubId(tPssrLighting.getSubId());
  143. lock.setApproveStatus(queryStatus);
  144. lock.setLightingType(tPssrLighting.getLightingType());
  145. for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(lock)) {
  146. if (item.getConfirmationDate()==null && queryStatus==3) {
  147. item.setConfirmationDate(date);
  148. }
  149. item.setApproveStatus(approveStatus);
  150. tPssrLightingService.updateTPssrLighting(item);
  151. }
  152. }
  153. //查询当前待审批的确认人
  154. TPssrLighting entity = new TPssrLighting();
  155. entity.setSubId(tPssrLighting.getSubId());
  156. entity.setApproveStatus(queryStatus);
  157. for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(entity)) {
  158. if (tPssrLighting.getTaskType() == 4) {
  159. if (item.getConfirm1().equals(getUserId().toString())) {
  160. return AjaxResult.success();
  161. }
  162. } else if (tPssrLighting.getTaskType() == 5) {
  163. if (item.getConfirm2().equals(getUserId().toString())) {
  164. return AjaxResult.success();
  165. }
  166. }
  167. }
  168. //无待审批任务结束当前用户流程
  169. TPssrApprove approve = new TPssrApprove();
  170. approve.setSubId(tPssrLighting.getSubId());
  171. // 因为流程关系所以approve一定会有且只有一条数据
  172. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveList(approve).get(0);
  173. TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
  174. return AjaxResult.success();
  175. }
  176. /**
  177. * 驳回照明,电伴热
  178. */
  179. @PutMapping("/turnDownLighting")
  180. public AjaxResult turnDownLighting(@RequestBody TPssrLighting tPssrLighting) {
  181. if (tPssrLighting.getIds() != null) {
  182. String userId = getUserId().toString();
  183. // 修改已选择数据的状态
  184. for (Long id : tPssrLighting.getIds()) {
  185. TPssrLighting blind = new TPssrLighting();
  186. blind.setId(id);
  187. blind.setApproveStatus(1L);
  188. blind.setUpdatedate(new Date());
  189. blind.setUpdaterCode(getUserId().toString());
  190. tPssrLightingService.updateTPssrLighting(blind);
  191. }
  192. // 查询当前流程
  193. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrLighting.getSubId());
  194. ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  195. TaskService taskService = processEngine.getTaskService();
  196. Task task = processEngine.getTaskService()//获取任务service
  197. .createTaskQuery()//创建查询对象
  198. .taskAssignee(userId)
  199. .processInstanceId(approve.getProcessId()).singleResult();
  200. String taskId = task.getId();
  201. // 驳回 查询所有待审批的人员
  202. TPssrLighting blind = new TPssrLighting();
  203. blind.setSubId(tPssrLighting.getSubId());
  204. blind.setApproveStatus(1L);
  205. Set<String> installer = new HashSet<>();
  206. Set<String> remover = new HashSet<>();
  207. for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(blind)) {
  208. // 安装人员
  209. installer.add(item.getConfirm1());
  210. //拆除人员
  211. remover.add(item.getConfirm2());
  212. }
  213. //处理流程节点
  214. Map<String, Object> param = new HashMap<>();
  215. param.put("condition", 1);
  216. param.put("confirmUsers1", new ArrayList<>(installer));
  217. param.put("confirmUsers2", new ArrayList<>(remover));
  218. //认领任务
  219. processEngine.getTaskService().claim(taskId, userId);
  220. taskService.addComment(taskId, approve.getProcessId(), "驳回至拆除;" + tPssrLighting.getRemarks());
  221. taskService.complete(taskId, param);
  222. // 修改审批表和sub表
  223. approve.setApproveStatus(1L);
  224. approve.setUpdatedate(new Date());
  225. approve.setUpdaterCode(getUserId().toString());
  226. tPssrApproveService.updateTPssrApprove(approve);
  227. TPssrSubcontent subcontent = new TPssrSubcontent();
  228. subcontent.setId(approve.getSubId());
  229. subcontent.setApproveStatus(1L);
  230. subcontent.setUpdatedate(new Date());
  231. subcontent.setUpdaterCode(getUserId().toString());
  232. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  233. return AjaxResult.success();
  234. }
  235. return AjaxResult.error();
  236. }
  237. }