提交 | 用户 | 时间
|
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; |
bb2880
|
7 |
import com.iailab.module.bpm.controller.admin.task.vo.instance.*; |
e7c126
|
8 |
import com.iailab.module.bpm.convert.task.BpmProcessInstanceConvert; |
H |
9 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmCategoryDO; |
|
10 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
|
11 |
import com.iailab.module.bpm.service.definition.BpmCategoryService; |
|
12 |
import com.iailab.module.bpm.service.definition.BpmProcessDefinitionService; |
|
13 |
import com.iailab.module.bpm.service.task.BpmProcessInstanceService; |
|
14 |
import com.iailab.module.bpm.service.task.BpmTaskService; |
|
15 |
import com.iailab.module.system.api.dept.DeptApi; |
|
16 |
import com.iailab.module.system.api.dept.dto.DeptRespDTO; |
|
17 |
import com.iailab.module.system.api.user.AdminUserApi; |
|
18 |
import com.iailab.module.system.api.user.dto.AdminUserRespDTO; |
|
19 |
import io.swagger.v3.oas.annotations.Operation; |
|
20 |
import io.swagger.v3.oas.annotations.Parameter; |
|
21 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
22 |
import org.flowable.engine.history.HistoricProcessInstance; |
|
23 |
import org.flowable.engine.repository.ProcessDefinition; |
|
24 |
import org.flowable.task.api.Task; |
|
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.List; |
|
32 |
import java.util.Map; |
|
33 |
|
|
34 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
35 |
import static com.iailab.framework.common.util.collection.CollectionUtils.convertList; |
|
36 |
import static com.iailab.framework.common.util.collection.CollectionUtils.convertSet; |
|
37 |
import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
bb2880
|
38 |
|
e7c126
|
39 |
|
H |
40 |
@Tag(name = "管理后台 - 流程实例") // 流程实例,通过流程定义创建的一次“申请” |
|
41 |
@RestController |
|
42 |
@RequestMapping("/bpm/process-instance") |
|
43 |
@Validated |
|
44 |
public class BpmProcessInstanceController { |
|
45 |
|
|
46 |
@Resource |
|
47 |
private BpmProcessInstanceService processInstanceService; |
|
48 |
@Resource |
|
49 |
private BpmTaskService taskService; |
|
50 |
@Resource |
|
51 |
private BpmProcessDefinitionService processDefinitionService; |
|
52 |
@Resource |
|
53 |
private BpmCategoryService categoryService; |
|
54 |
|
|
55 |
@Resource |
|
56 |
private AdminUserApi adminUserApi; |
|
57 |
@Resource |
|
58 |
private DeptApi deptApi; |
|
59 |
|
|
60 |
@GetMapping("/my-page") |
|
61 |
@Operation(summary = "获得我的实例分页列表", description = "在【我的流程】菜单中,进行调用") |
|
62 |
@PreAuthorize("@ss.hasPermission('bpm:process-instance:query')") |
|
63 |
public CommonResult<PageResult<BpmProcessInstanceRespVO>> getProcessInstanceMyPage( |
|
64 |
@Valid BpmProcessInstancePageReqVO pageReqVO) { |
|
65 |
PageResult<HistoricProcessInstance> pageResult = processInstanceService.getProcessInstancePage( |
|
66 |
getLoginUserId(), pageReqVO); |
|
67 |
if (CollUtil.isEmpty(pageResult.getList())) { |
|
68 |
return success(PageResult.empty(pageResult.getTotal())); |
|
69 |
} |
|
70 |
|
|
71 |
// 拼接返回 |
|
72 |
Map<String, List<Task>> taskMap = taskService.getTaskMapByProcessInstanceIds( |
|
73 |
convertList(pageResult.getList(), HistoricProcessInstance::getId)); |
|
74 |
Map<String, ProcessDefinition> processDefinitionMap = processDefinitionService.getProcessDefinitionMap( |
|
75 |
convertSet(pageResult.getList(), HistoricProcessInstance::getProcessDefinitionId)); |
|
76 |
Map<String, BpmCategoryDO> categoryMap = categoryService.getCategoryMap( |
|
77 |
convertSet(processDefinitionMap.values(), ProcessDefinition::getCategory)); |
|
78 |
return success(BpmProcessInstanceConvert.INSTANCE.buildProcessInstancePage(pageResult, |
|
79 |
processDefinitionMap, categoryMap, taskMap, null, null)); |
|
80 |
} |
|
81 |
|
|
82 |
@GetMapping("/manager-page") |
|
83 |
@Operation(summary = "获得管理流程实例的分页列表", description = "在【流程实例】菜单中,进行调用") |
|
84 |
@PreAuthorize("@ss.hasPermission('bpm:process-instance:manager-query')") |
|
85 |
public CommonResult<PageResult<BpmProcessInstanceRespVO>> getProcessInstanceManagerPage( |
|
86 |
@Valid BpmProcessInstancePageReqVO pageReqVO) { |
|
87 |
PageResult<HistoricProcessInstance> pageResult = processInstanceService.getProcessInstancePage( |
|
88 |
null, pageReqVO); |
|
89 |
if (CollUtil.isEmpty(pageResult.getList())) { |
|
90 |
return success(PageResult.empty(pageResult.getTotal())); |
|
91 |
} |
|
92 |
|
|
93 |
// 拼接返回 |
|
94 |
Map<String, List<Task>> taskMap = taskService.getTaskMapByProcessInstanceIds( |
|
95 |
convertList(pageResult.getList(), HistoricProcessInstance::getId)); |
|
96 |
Map<String, ProcessDefinition> processDefinitionMap = processDefinitionService.getProcessDefinitionMap( |
|
97 |
convertSet(pageResult.getList(), HistoricProcessInstance::getProcessDefinitionId)); |
|
98 |
Map<String, BpmCategoryDO> categoryMap = categoryService.getCategoryMap( |
|
99 |
convertSet(processDefinitionMap.values(), ProcessDefinition::getCategory)); |
|
100 |
// 发起人信息 |
|
101 |
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( |
|
102 |
convertSet(pageResult.getList(), processInstance -> NumberUtils.parseLong(processInstance.getStartUserId()))); |
|
103 |
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap( |
|
104 |
convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); |
|
105 |
return success(BpmProcessInstanceConvert.INSTANCE.buildProcessInstancePage(pageResult, |
|
106 |
processDefinitionMap, categoryMap, taskMap, userMap, deptMap)); |
|
107 |
} |
|
108 |
|
|
109 |
@PostMapping("/create") |
|
110 |
@Operation(summary = "新建流程实例") |
|
111 |
@PreAuthorize("@ss.hasPermission('bpm:process-instance:query')") |
|
112 |
public CommonResult<String> createProcessInstance(@Valid @RequestBody BpmProcessInstanceCreateReqVO createReqVO) { |
|
113 |
return success(processInstanceService.createProcessInstance(getLoginUserId(), createReqVO)); |
|
114 |
} |
|
115 |
|
|
116 |
@GetMapping("/get") |
|
117 |
@Operation(summary = "获得指定流程实例", description = "在【流程详细】界面中,进行调用") |
|
118 |
@Parameter(name = "id", description = "流程实例的编号", required = true) |
|
119 |
@PreAuthorize("@ss.hasPermission('bpm:process-instance:query')") |
|
120 |
public CommonResult<BpmProcessInstanceRespVO> getProcessInstance(@RequestParam("id") String id) { |
|
121 |
HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(id); |
|
122 |
if (processInstance == null) { |
|
123 |
return success(null); |
|
124 |
} |
|
125 |
|
|
126 |
// 拼接返回 |
|
127 |
ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition( |
|
128 |
processInstance.getProcessDefinitionId()); |
|
129 |
BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService.getProcessDefinitionInfo( |
|
130 |
processInstance.getProcessDefinitionId()); |
|
131 |
AdminUserRespDTO startUser = adminUserApi.getUser(NumberUtils.parseLong(processInstance.getStartUserId())).getCheckedData(); |
|
132 |
DeptRespDTO dept = null; |
bb2880
|
133 |
if (startUser != null && startUser.getDeptId() != null) { |
e7c126
|
134 |
dept = deptApi.getDept(startUser.getDeptId()).getCheckedData(); |
H |
135 |
} |
|
136 |
return success(BpmProcessInstanceConvert.INSTANCE.buildProcessInstance(processInstance, |
bb2880
|
137 |
processDefinition, processDefinitionInfo, startUser, dept)); |
e7c126
|
138 |
} |
H |
139 |
|
|
140 |
@DeleteMapping("/cancel-by-start-user") |
|
141 |
@Operation(summary = "用户取消流程实例", description = "取消发起的流程") |
|
142 |
@PreAuthorize("@ss.hasPermission('bpm:process-instance:cancel')") |
|
143 |
public CommonResult<Boolean> cancelProcessInstanceByStartUser( |
|
144 |
@Valid @RequestBody BpmProcessInstanceCancelReqVO cancelReqVO) { |
|
145 |
processInstanceService.cancelProcessInstanceByStartUser(getLoginUserId(), cancelReqVO); |
|
146 |
return success(true); |
|
147 |
} |
|
148 |
|
|
149 |
@DeleteMapping("/cancel-by-admin") |
|
150 |
@Operation(summary = "管理员取消流程实例", description = "管理员撤回流程") |
|
151 |
@PreAuthorize("@ss.hasPermission('bpm:process-instance:cancel-by-admin')") |
|
152 |
public CommonResult<Boolean> cancelProcessInstanceByManager( |
|
153 |
@Valid @RequestBody BpmProcessInstanceCancelReqVO cancelReqVO) { |
|
154 |
processInstanceService.cancelProcessInstanceByAdmin(getLoginUserId(), cancelReqVO); |
|
155 |
return success(true); |
|
156 |
} |
|
157 |
|
bb2880
|
158 |
@GetMapping("/get-approval-detail") |
H |
159 |
@Operation(summary = "获得审批详情") |
|
160 |
@Parameter(name = "id", description = "流程实例的编号", required = true) |
|
161 |
@PreAuthorize("@ss.hasPermission('bpm:process-instance:query')") |
|
162 |
public CommonResult<BpmApprovalDetailRespVO> getApprovalDetail(@Valid BpmApprovalDetailReqVO reqVO) { |
|
163 |
return success(processInstanceService.getApprovalDetail(getLoginUserId(), reqVO)); |
|
164 |
} |
|
165 |
|
|
166 |
@GetMapping("/get-bpmn-model-view") |
|
167 |
@Operation(summary = "获取流程实例的 BPMN 模型视图", description = "在【流程详细】界面中,进行调用") |
|
168 |
@Parameter(name = "id", description = "流程实例的编号", required = true) |
|
169 |
public CommonResult<BpmProcessInstanceBpmnModelViewRespVO> getProcessInstanceBpmnModelView(@RequestParam(value = "id") String id) { |
|
170 |
return success(processInstanceService.getProcessInstanceBpmnModelView(id)); |
|
171 |
} |
|
172 |
|
e7c126
|
173 |
} |