TPssrOverhaulExchangerController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package com.ruoyi.project.pssr.controller;
  2. import com.ruoyi.common.utils.StringUtils;
  3. import com.ruoyi.common.utils.poi.ExcelUtil;
  4. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  5. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  6. import com.ruoyi.framework.web.controller.BaseController;
  7. import com.ruoyi.framework.web.domain.AjaxResult;
  8. import com.ruoyi.framework.web.page.TableDataInfo;
  9. import com.ruoyi.project.pssr.domain.*;
  10. import com.ruoyi.project.pssr.domain.TPssrOverhaulExchanger;
  11. import com.ruoyi.project.pssr.service.ITPssrApproveService;
  12. import com.ruoyi.project.pssr.service.ITPssrOverhaulExchangerService;
  13. import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
  14. import org.activiti.engine.*;
  15. import org.activiti.engine.impl.identity.Authentication;
  16. import org.activiti.engine.runtime.ProcessInstance;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.security.access.prepost.PreAuthorize;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.*;
  21. /**
  22. * 检修项目-换热器Controller
  23. *
  24. * @author ssy
  25. * @date 2024-09-18
  26. */
  27. @RestController
  28. @RequestMapping("/pssr/overhaulExchanger")
  29. public class TPssrOverhaulExchangerController extends BaseController {
  30. @Autowired
  31. private ITPssrOverhaulExchangerService tPssrOverhaulExchangerService;
  32. @Autowired
  33. private ITPssrApproveService tPssrApproveService;
  34. @Autowired
  35. private RuntimeService runtimeService;
  36. @Autowired
  37. private HistoryService historyService;
  38. @Autowired
  39. private ITPssrSubcontentService tPssrSubcontentService;
  40. /**
  41. * 查询检修项目-换热器列表
  42. */
  43. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:list')")
  44. @GetMapping("/list")
  45. public TableDataInfo list(TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  46. if ("1".equals(tPssrOverhaulExchanger.getConfirmedPerson())){
  47. tPssrOverhaulExchanger.setConfirmedPerson(getUserId().toString());
  48. }
  49. startPage();
  50. List<TPssrOverhaulExchanger> list = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(tPssrOverhaulExchanger);
  51. return getDataTable(list);
  52. }
  53. /**
  54. * 导出检修项目-换热器列表
  55. */
  56. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:export')")
  57. @Log(title = "检修项目-换热器", businessType = BusinessType.EXPORT)
  58. @GetMapping("/export")
  59. public AjaxResult export(TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  60. List<TPssrOverhaulExchanger> list = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(tPssrOverhaulExchanger);
  61. ExcelUtil<TPssrOverhaulExchanger> util = new ExcelUtil<TPssrOverhaulExchanger>(TPssrOverhaulExchanger.class);
  62. return util.exportExcel(list, "overhaulExchanger");
  63. }
  64. /**
  65. * 获取检修项目-换热器详细信息
  66. */
  67. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:query')")
  68. @GetMapping(value = "/{id}")
  69. public AjaxResult getInfo(@PathVariable("id") Long id) {
  70. return AjaxResult.success(tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id));
  71. }
  72. /**
  73. * 新增检修项目-换热器
  74. */
  75. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:add')")
  76. @Log(title = "检修项目-换热器", businessType = BusinessType.INSERT)
  77. @PostMapping
  78. public AjaxResult add(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  79. tPssrOverhaulExchanger.setApproveStatus(0L);
  80. return toAjax(tPssrOverhaulExchangerService.insertTPssrOverhaulExchanger(tPssrOverhaulExchanger));
  81. }
  82. /**
  83. * 修改检修项目-换热器
  84. */
  85. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
  86. @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
  87. @PutMapping
  88. public AjaxResult edit(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  89. return toAjax(tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(tPssrOverhaulExchanger));
  90. }
  91. /**
  92. * 删除检修项目-换热器
  93. */
  94. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:remove')")
  95. @Log(title = "检修项目-换热器", businessType = BusinessType.DELETE)
  96. @DeleteMapping("/{ids}")
  97. public AjaxResult remove(@PathVariable Long[] ids) {
  98. return toAjax(tPssrOverhaulExchangerService.deleteTPssrOverhaulExchangerByIds(ids));
  99. }
  100. /**
  101. * 确认检修项目-换热器
  102. */
  103. @PreAuthorize("@ss.hasPermi('pssr:overhaulExchanger:edit')")
  104. @Log(title = "检修项目-换热器", businessType = BusinessType.UPDATE)
  105. @PutMapping("/confirmExchanger")
  106. public AjaxResult confirmExchanger(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  107. if (tPssrOverhaulExchanger.getIds() != null && tPssrOverhaulExchanger.getIds().length > 0) {
  108. for (Long id : tPssrOverhaulExchanger.getIds()) {
  109. TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerById(id);
  110. if (exchanger.getCompletionDate()==null){
  111. exchanger.setCompletionDate(new Date());
  112. }
  113. exchanger.setApproveStatus(2L);
  114. exchanger.setUpdatedate(new Date());
  115. exchanger.setUpdaterCode(String.valueOf(getUserId()));
  116. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(exchanger);
  117. }
  118. } else {
  119. TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
  120. exchanger.setSubId(tPssrOverhaulExchanger.getSubId());
  121. exchanger.setConfirmedPerson(getUserId().toString());
  122. exchanger.setApproveStatus(1L);
  123. for (TPssrOverhaulExchanger overhaulExchanger : tPssrOverhaulExchangerService.selectTPssrOverhaulExchangerList(exchanger)) {
  124. if (overhaulExchanger.getCompletionDate()==null){
  125. overhaulExchanger.setCompletionDate(new Date());
  126. }
  127. overhaulExchanger.setApproveStatus(2L);
  128. overhaulExchanger.setUpdatedate(new Date());
  129. overhaulExchanger.setUpdaterCode(String.valueOf(getUserId()));
  130. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(overhaulExchanger);
  131. }
  132. }
  133. //查询当前待审批的确认人
  134. TPssrOverhaulExchanger entity = new TPssrOverhaulExchanger();
  135. entity.setSubId(tPssrOverhaulExchanger.getSubId());
  136. entity.setApproveStatus(1L);
  137. TPssrOverhaulExchanger exchanger = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(entity);
  138. if (exchanger!=null) {
  139. String confirmedPerson = exchanger.getConfirmedPerson();
  140. logger.info("===========confirmedPerson:{}", confirmedPerson);
  141. //如果当前用户还有待审批任务
  142. if (confirmedPerson.contains(getUserId().toString())) {
  143. return AjaxResult.success();
  144. }
  145. }
  146. //无待审批任务结束当前用户流程
  147. TPssrApprove approve = new TPssrApprove();
  148. approve.setSubId(tPssrOverhaulExchanger.getSubId());
  149. // 因为流程关系所以approve一定会有且只有一条数据
  150. TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveList(approve).get(0);
  151. TPssrApproveController.handleConfirmApprove(tPssrApprove,getUserId().toString());
  152. return AjaxResult.success();
  153. }
  154. @PutMapping("/turnDownExchanger")
  155. public AjaxResult turnDownExchanger(@RequestBody TPssrOverhaulExchanger tPssrOverhaulExchanger) {
  156. if (tPssrOverhaulExchanger.getIds() != null) {
  157. String userId = getUserId().toString();
  158. // 修改已选择数据的状态
  159. for (Long id : tPssrOverhaulExchanger.getIds()) {
  160. TPssrOverhaulExchanger blind = new TPssrOverhaulExchanger();
  161. blind.setId(id);
  162. blind.setApproveStatus(1L);
  163. blind.setUpdatedate(new Date());
  164. blind.setUpdaterCode(getUserId().toString());
  165. tPssrOverhaulExchangerService.updateTPssrOverhaulExchanger(blind);
  166. }
  167. // 查询当前流程
  168. TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrOverhaulExchanger.getSubId());
  169. try {
  170. runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr1confirm");
  171. historyService.deleteHistoricProcessInstance(approve.getProcessId());
  172. } catch (Exception e) {
  173. logger.info("无运行时流程");
  174. }
  175. // 驳回 查询所有待审批的人员
  176. //查询所有确认人
  177. TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
  178. exchanger.setSubId(approve.getSubId());
  179. exchanger.setApproveStatus(1L);
  180. TPssrOverhaulExchanger overhaul = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(exchanger);
  181. String confirmers = null;
  182. if (overhaul != null) {
  183. confirmers = overhaul.getConfirmedPerson();
  184. }
  185. logger.info("=======================confirmers:{}", confirmers);
  186. Set<String> confirmUsers1 = new HashSet<>();
  187. if (StringUtils.isNotEmpty(confirmers)) {
  188. confirmUsers1.addAll(Arrays.asList(confirmers.split(",")));
  189. }
  190. // 开始申请流程
  191. long businessKey = approve.getApproveId();
  192. //开始工作流、监听
  193. Authentication.setAuthenticatedUserId(userId);//设置当前申请人
  194. Map<String, Object> variables = new HashMap<>();
  195. variables.put("applyUser", userId);
  196. variables.put("confirmUsers", new ArrayList<>(confirmUsers1));
  197. variables.put("chargePerson", approve.getSubCharge());
  198. //采用key来启动流程定义并设置流程变量,返回流程实例
  199. ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr1confirm", String.valueOf(businessKey), variables);
  200. // 修改审批表和sub表
  201. approve.setProcessId(pi.getProcessInstanceId());
  202. approve.setApproveStatus(1L);
  203. approve.setUpdatedate(new Date());
  204. approve.setUpdaterCode(getUserId().toString());
  205. tPssrApproveService.updateTPssrApprove(approve);
  206. TPssrSubcontent subcontent = new TPssrSubcontent();
  207. subcontent.setId(approve.getSubId());
  208. subcontent.setApproveStatus(1L);
  209. subcontent.setUpdatedate(new Date());
  210. subcontent.setUpdaterCode(getUserId().toString());
  211. tPssrSubcontentService.updateTPssrSubcontent(subcontent);
  212. return AjaxResult.success();
  213. }
  214. return AjaxResult.error();
  215. }
  216. }