潘志宝
9 天以前 6b13839488edcd06046e26a41fe897358176689c
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.controller.admin.task;
H 2
3 import cn.hutool.core.collection.CollUtil;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.pojo.PageResult;
6 import com.iailab.framework.common.util.number.NumberUtils;
7 import com.iailab.module.bpm.controller.admin.task.vo.task.*;
8 import com.iailab.module.bpm.convert.task.BpmTaskConvert;
9 import com.iailab.module.bpm.dal.dataobject.definition.BpmFormDO;
10 import com.iailab.module.bpm.service.definition.BpmFormService;
11 import com.iailab.module.bpm.service.task.BpmProcessInstanceService;
12 import com.iailab.module.bpm.service.task.BpmTaskService;
13 import com.iailab.module.system.api.dept.DeptApi;
14 import com.iailab.module.system.api.dept.dto.DeptRespDTO;
15 import com.iailab.module.system.api.user.AdminUserApi;
16 import com.iailab.module.system.api.user.dto.AdminUserRespDTO;
17 import io.swagger.v3.oas.annotations.Operation;
18 import io.swagger.v3.oas.annotations.Parameter;
19 import io.swagger.v3.oas.annotations.tags.Tag;
20 import org.flowable.bpmn.model.UserTask;
21 import org.flowable.engine.history.HistoricProcessInstance;
22 import org.flowable.engine.runtime.ProcessInstance;
23 import org.flowable.task.api.Task;
24 import org.flowable.task.api.history.HistoricTaskInstance;
25 import org.springframework.security.access.prepost.PreAuthorize;
26 import org.springframework.validation.annotation.Validated;
27 import org.springframework.web.bind.annotation.*;
28
29 import javax.annotation.Resource;
30 import javax.validation.Valid;
31 import java.util.Collections;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Set;
35 import java.util.stream.Stream;
36
37 import static com.iailab.framework.common.pojo.CommonResult.success;
38 import static com.iailab.framework.common.util.collection.CollectionUtils.*;
bb2880 39 import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
H 40
e7c126 41
H 42 @Tag(name = "管理后台 - 流程任务实例")
43 @RestController
44 @RequestMapping("/bpm/task")
45 @Validated
46 public class BpmTaskController {
47
48     @Resource
49     private BpmTaskService taskService;
50     @Resource
51     private BpmProcessInstanceService processInstanceService;
52     @Resource
53     private BpmFormService formService;
54
55     @Resource
56     private AdminUserApi adminUserApi;
57     @Resource
58     private DeptApi deptApi;
59
60     @GetMapping("todo-page")
61     @Operation(summary = "获取 Todo 待办任务分页")
62     @PreAuthorize("@ss.hasPermission('bpm:task:query')")
63     public CommonResult<PageResult<BpmTaskRespVO>> getTaskTodoPage(@Valid BpmTaskPageReqVO pageVO) {
64         PageResult<Task> pageResult = taskService.getTaskTodoPage(getLoginUserId(), pageVO);
65         if (CollUtil.isEmpty(pageResult.getList())) {
66             return success(PageResult.empty());
67         }
68
69         // 拼接数据
70         Map<String, ProcessInstance> processInstanceMap = processInstanceService.getProcessInstanceMap(
71                 convertSet(pageResult.getList(), Task::getProcessInstanceId));
72         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
73                 convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
74         return success(BpmTaskConvert.INSTANCE.buildTodoTaskPage(pageResult, processInstanceMap, userMap));
75     }
76
77     @GetMapping("done-page")
78     @Operation(summary = "获取 Done 已办任务分页")
79     @PreAuthorize("@ss.hasPermission('bpm:task:query')")
80     public CommonResult<PageResult<BpmTaskRespVO>> getTaskDonePage(@Valid BpmTaskPageReqVO pageVO) {
81         PageResult<HistoricTaskInstance> pageResult = taskService.getTaskDonePage(getLoginUserId(), pageVO);
82         if (CollUtil.isEmpty(pageResult.getList())) {
83             return success(PageResult.empty());
84         }
85
86         // 拼接数据
87         Map<String, HistoricProcessInstance> processInstanceMap = processInstanceService.getHistoricProcessInstanceMap(
88                 convertSet(pageResult.getList(), HistoricTaskInstance::getProcessInstanceId));
89         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
90                 convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
91         return success(BpmTaskConvert.INSTANCE.buildTaskPage(pageResult, processInstanceMap, userMap, null));
92     }
93
94     @GetMapping("manager-page")
95     @Operation(summary = "获取全部任务的分页", description = "用于【流程任务】菜单")
96     @PreAuthorize("@ss.hasPermission('bpm:task:mananger-query')")
97     public CommonResult<PageResult<BpmTaskRespVO>> getTaskManagerPage(@Valid BpmTaskPageReqVO pageVO) {
98         PageResult<HistoricTaskInstance> pageResult = taskService.getTaskPage(getLoginUserId(), pageVO);
99         if (CollUtil.isEmpty(pageResult.getList())) {
100             return success(PageResult.empty());
101         }
102
103         // 拼接数据
104         Map<String, HistoricProcessInstance> processInstanceMap = processInstanceService.getHistoricProcessInstanceMap(
105                 convertSet(pageResult.getList(), HistoricTaskInstance::getProcessInstanceId));
106         // 获得 User 和 Dept Map
107         Set<Long> userIds = convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId()));
108         userIds.addAll(convertSet(pageResult.getList(), task -> NumberUtils.parseLong(task.getAssignee())));
109         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
110         Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
111                 convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
112         return success(BpmTaskConvert.INSTANCE.buildTaskPage(pageResult, processInstanceMap, userMap, deptMap));
113     }
114
115     @GetMapping("/list-by-process-instance-id")
116     @Operation(summary = "获得指定流程实例的任务列表", description = "包括完成的、未完成的")
117     @Parameter(name = "processInstanceId", description = "流程实例的编号", required = true)
118     @PreAuthorize("@ss.hasPermission('bpm:task:query')")
119     public CommonResult<List<BpmTaskRespVO>> getTaskListByProcessInstanceId(
120             @RequestParam("processInstanceId") String processInstanceId) {
bb2880 121         List<HistoricTaskInstance> taskList = taskService.getTaskListByProcessInstanceId(processInstanceId, true);
e7c126 122         if (CollUtil.isEmpty(taskList)) {
H 123             return success(Collections.emptyList());
124         }
125
126         // 拼接数据
127         Set<Long> userIds = convertSetByFlatMap(taskList, task ->
128                 Stream.of(NumberUtils.parseLong(task.getAssignee()), NumberUtils.parseLong(task.getOwner())));
129         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
130         Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
131                 convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
132         // 获得 Form Map
133         Map<Long, BpmFormDO> formMap = formService.getFormMap(
134                 convertSet(taskList, task -> NumberUtils.parseLong(task.getFormKey())));
bb2880 135         return success(BpmTaskConvert.INSTANCE.buildTaskListByProcessInstanceId(taskList,
e7c126 136                 formMap, userMap, deptMap));
H 137     }
138
139     @PutMapping("/approve")
140     @Operation(summary = "通过任务")
141     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
142     public CommonResult<Boolean> approveTask(@Valid @RequestBody BpmTaskApproveReqVO reqVO) {
143         taskService.approveTask(getLoginUserId(), reqVO);
144         return success(true);
145     }
146
147     @PutMapping("/reject")
148     @Operation(summary = "不通过任务")
149     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
150     public CommonResult<Boolean> rejectTask(@Valid @RequestBody BpmTaskRejectReqVO reqVO) {
151         taskService.rejectTask(getLoginUserId(), reqVO);
152         return success(true);
153     }
154
155     @GetMapping("/list-by-return")
bb2880 156     @Operation(summary = "获取所有可退回的节点", description = "用于【流程详情】的【退回】按钮")
e7c126 157     @Parameter(name = "taskId", description = "当前任务ID", required = true)
H 158     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
159     public CommonResult<List<BpmTaskRespVO>> getTaskListByReturn(@RequestParam("id") String id) {
160         List<UserTask> userTaskList = taskService.getUserTaskListByReturn(id);
161         return success(convertList(userTaskList, userTask -> // 只返回 id 和 name
162                 new BpmTaskRespVO().setName(userTask.getName()).setTaskDefinitionKey(userTask.getId())));
163     }
164
165     @PutMapping("/return")
bb2880 166     @Operation(summary = "退回任务", description = "用于【流程详情】的【退回】按钮")
e7c126 167     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
H 168     public CommonResult<Boolean> returnTask(@Valid @RequestBody BpmTaskReturnReqVO reqVO) {
169         taskService.returnTask(getLoginUserId(), reqVO);
170         return success(true);
171     }
172
173     @PutMapping("/delegate")
174     @Operation(summary = "委派任务", description = "用于【流程详情】的【委派】按钮")
175     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
176     public CommonResult<Boolean> delegateTask(@Valid @RequestBody BpmTaskDelegateReqVO reqVO) {
177         taskService.delegateTask(getLoginUserId(), reqVO);
178         return success(true);
179     }
180
181     @PutMapping("/transfer")
182     @Operation(summary = "转派任务", description = "用于【流程详情】的【转派】按钮")
183     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
184     public CommonResult<Boolean> transferTask(@Valid @RequestBody BpmTaskTransferReqVO reqVO) {
185         taskService.transferTask(getLoginUserId(), reqVO);
186         return success(true);
187     }
188
189     @PutMapping("/create-sign")
190     @Operation(summary = "加签", description = "before 前加签,after 后加签")
191     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
192     public CommonResult<Boolean> createSignTask(@Valid @RequestBody BpmTaskSignCreateReqVO reqVO) {
193         taskService.createSignTask(getLoginUserId(), reqVO);
194         return success(true);
195     }
196
197     @DeleteMapping("/delete-sign")
198     @Operation(summary = "减签")
199     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
200     public CommonResult<Boolean> deleteSignTask(@Valid @RequestBody BpmTaskSignDeleteReqVO reqVO) {
201         taskService.deleteSignTask(getLoginUserId(), reqVO);
202         return success(true);
203     }
204
bb2880 205     @PutMapping("/copy")
H 206     @Operation(summary = "抄送任务")
207     @PreAuthorize("@ss.hasPermission('bpm:task:update')")
208     public CommonResult<Boolean> copyTask(@Valid @RequestBody BpmTaskCopyReqVO reqVO) {
209         taskService.copyTask(getLoginUserId(), reqVO);
210         return success(true);
211     }
212
e7c126 213     @GetMapping("/list-by-parent-task-id")
H 214     @Operation(summary = "获得指定父级任务的子任务列表") // 目前用于,减签的时候,获得子任务列表
215     @Parameter(name = "parentTaskId", description = "父级任务编号", required = true)
216     @PreAuthorize("@ss.hasPermission('bpm:task:query')")
217     public CommonResult<List<BpmTaskRespVO>> getTaskListByParentTaskId(@RequestParam("parentTaskId") String parentTaskId) {
218         List<Task> taskList = taskService.getTaskListByParentTaskId(parentTaskId);
219         if (CollUtil.isEmpty(taskList)) {
220             return success(Collections.emptyList());
221         }
222         // 拼接数据
223         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSetByFlatMap(taskList,
224                 user -> Stream.of(NumberUtils.parseLong(user.getAssignee()), NumberUtils.parseLong(user.getOwner()))));
225         Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
226                 convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
227         return success(BpmTaskConvert.INSTANCE.buildTaskListByParentTaskId(taskList, userMap, deptMap));
228     }
229
230 }