ProcessInstanceController.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package com.qqflow.engine.domain.flow.controller;
  2. import com.qqflow.engine.common.PageResult;
  3. import com.qqflow.engine.common.Result;
  4. import com.qqflow.engine.common.exception.BusinessException;
  5. import com.qqflow.engine.common.util.SecurityUtils;
  6. import com.qqflow.engine.config.security.LoginUser;
  7. import com.qqflow.engine.domain.flow.dto.AttachmentDTO;
  8. import com.qqflow.engine.domain.flow.dto.ProcessInstanceDTO;
  9. import com.qqflow.engine.domain.flow.dto.ProcessProgressDTO;
  10. import com.qqflow.engine.domain.flow.dto.StartProcessDTO;
  11. import com.qqflow.engine.domain.flow.dto.UpdateFormDataDTO;
  12. import com.qqflow.engine.domain.flow.service.ProcessInstanceService;
  13. import io.swagger.v3.oas.annotations.Operation;
  14. import io.swagger.v3.oas.annotations.tags.Tag;
  15. import jakarta.validation.Valid;
  16. import lombok.RequiredArgsConstructor;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.web.bind.annotation.DeleteMapping;
  19. import org.springframework.web.bind.annotation.GetMapping;
  20. import org.springframework.web.bind.annotation.PathVariable;
  21. import org.springframework.web.bind.annotation.PostMapping;
  22. import org.springframework.web.bind.annotation.RequestBody;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestParam;
  25. import org.springframework.web.bind.annotation.RestController;
  26. import java.util.List;
  27. import java.util.Map;
  28. @RestController
  29. @RequestMapping("/flow/instance")
  30. @RequiredArgsConstructor
  31. @PreAuthorize("isAuthenticated()")
  32. @Tag(name = "流程实例管理")
  33. public class ProcessInstanceController {
  34. private final ProcessInstanceService processInstanceService;
  35. @PostMapping("/start")
  36. @Operation(summary = "发起流程")
  37. public Result<Long> start(@RequestBody @Valid StartProcessDTO dto) {
  38. return Result.ok(this.processInstanceService.startProcess(dto));
  39. }
  40. @GetMapping("/page")
  41. @PreAuthorize("hasAnyRole('super_admin','flow_manager','dept_manager')")
  42. @Operation(summary = "流程实例分页列表(管理员)")
  43. public Result<PageResult<ProcessInstanceDTO>> page(
  44. @RequestParam(defaultValue = "1") Integer pageNum,
  45. @RequestParam(defaultValue = "10") Integer pageSize,
  46. @RequestParam(required = false) Integer status,
  47. @RequestParam(required = false) Long processDefinitionId,
  48. @RequestParam(required = false) String definitionName,
  49. @RequestParam(required = false) String currentNodeName,
  50. @RequestParam(required = false) String applicantName) {
  51. return Result.ok(this.processInstanceService.list(null, status, processDefinitionId, definitionName, currentNodeName, applicantName, pageNum, pageSize));
  52. }
  53. @GetMapping("/mine")
  54. @Operation(summary = "我的流程列表")
  55. public Result<PageResult<ProcessInstanceDTO>> mine(
  56. @RequestParam(defaultValue = "1") Integer pageNum,
  57. @RequestParam(defaultValue = "10") Integer pageSize,
  58. @RequestParam(required = false) Integer status,
  59. @RequestParam(required = false) String definitionName,
  60. @RequestParam(required = false) String currentNodeName) {
  61. Long applicantId = SecurityUtils.getUserId();
  62. return Result.ok(this.processInstanceService.list(applicantId, status, null, definitionName, currentNodeName, null, pageNum, pageSize));
  63. }
  64. @GetMapping("/{id}")
  65. @Operation(summary = "流程实例详情")
  66. public Result<ProcessInstanceDTO> getById(@PathVariable Long id) {
  67. return Result.ok(this.processInstanceService.getDetail(id));
  68. }
  69. @PostMapping("/{id}/revoke")
  70. @Operation(summary = "撤回流程")
  71. public Result<Void> revoke(@PathVariable Long id) {
  72. this.processInstanceService.revoke(id);
  73. return Result.ok();
  74. }
  75. @PostMapping("/batch-revoke")
  76. @Operation(summary = "批量撤回流程")
  77. public Result<Void> batchRevoke(@RequestBody List<Long> ids) {
  78. this.processInstanceService.batchRevoke(ids);
  79. return Result.ok();
  80. }
  81. @DeleteMapping("/{id}")
  82. @Operation(summary = "删除流程实例")
  83. public Result<Void> delete(@PathVariable Long id) {
  84. this.processInstanceService.delete(id);
  85. return Result.ok();
  86. }
  87. @PostMapping("/batch-delete")
  88. @Operation(summary = "批量删除流程实例")
  89. public Result<Void> batchDelete(@RequestBody List<Long> ids) {
  90. this.processInstanceService.batchDelete(ids);
  91. return Result.ok();
  92. }
  93. @GetMapping("/{id}/progress")
  94. @Operation(summary = "流程实例进度")
  95. public Result<ProcessProgressDTO> progress(@PathVariable Long id) {
  96. return Result.ok(this.processInstanceService.getProgress(id));
  97. }
  98. @GetMapping("/{id}/attachments")
  99. @Operation(summary = "流程实例附件列表")
  100. public Result<List<AttachmentDTO>> attachments(@PathVariable Long id) {
  101. return Result.ok(this.processInstanceService.listAttachments(id));
  102. }
  103. @PostMapping("/{id}/form-data")
  104. @Operation(summary = "补充/修正表单数据")
  105. public Result<Void> updateFormData(@PathVariable Long id,
  106. @RequestBody @Valid UpdateFormDataDTO dto) {
  107. this.processInstanceService.supplementFormData(id, dto.getFormData());
  108. return Result.ok();
  109. }
  110. @GetMapping("/participated")
  111. @Operation(summary = "我参与的流程实例列表")
  112. public Result<PageResult<ProcessInstanceDTO>> participated(
  113. @RequestParam(defaultValue = "1") Integer pageNum,
  114. @RequestParam(defaultValue = "10") Integer pageSize) {
  115. Long userId = SecurityUtils.getUserId();
  116. String userType = requireLoginUser().getUserType();
  117. return Result.ok(this.processInstanceService.participatedList(userId, userType, pageNum, pageSize));
  118. }
  119. @PostMapping("/{id}/migrate")
  120. @Operation(summary = "迁移单个流程实例到新版本定义")
  121. @PreAuthorize("hasAnyRole('super_admin','flow_manager')")
  122. public Result<Void> migrate(@PathVariable Long id, @RequestParam Long targetDefinitionId) {
  123. this.processInstanceService.migrateToDefinition(id, targetDefinitionId);
  124. return Result.ok();
  125. }
  126. @PostMapping("/migrate-all")
  127. @Operation(summary = "批量迁移指定定义下所有运行中的实例到新版本定义")
  128. @PreAuthorize("hasAnyRole('super_admin','flow_manager')")
  129. public Result<Map<String, Object>> migrateAll(@RequestParam Long fromDefinitionId, @RequestParam Long toDefinitionId) {
  130. int count = this.processInstanceService.migrateAllToDefinition(fromDefinitionId, toDefinitionId);
  131. Map<String, Object> result = new java.util.LinkedHashMap<>();
  132. result.put("migratedCount", count);
  133. return Result.ok(result);
  134. }
  135. private LoginUser requireLoginUser() {
  136. LoginUser loginUser = SecurityUtils.getLoginUser();
  137. if (loginUser == null) {
  138. throw new BusinessException("未登录");
  139. }
  140. return loginUser;
  141. }
  142. }