提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.bpm.controller.admin.definition; |
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.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageReqVO; |
|
7 |
import com.iailab.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; |
|
8 |
import com.iailab.module.bpm.convert.definition.BpmProcessDefinitionConvert; |
|
9 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmCategoryDO; |
|
10 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmFormDO; |
|
11 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
|
12 |
import com.iailab.module.bpm.service.definition.BpmCategoryService; |
|
13 |
import com.iailab.module.bpm.service.definition.BpmFormService; |
|
14 |
import com.iailab.module.bpm.service.definition.BpmProcessDefinitionService; |
|
15 |
import io.swagger.v3.oas.annotations.Operation; |
|
16 |
import io.swagger.v3.oas.annotations.Parameter; |
|
17 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
18 |
import org.flowable.bpmn.model.BpmnModel; |
|
19 |
import org.flowable.bpmn.model.UserTask; |
|
20 |
import org.flowable.engine.repository.Deployment; |
|
21 |
import org.flowable.engine.repository.ProcessDefinition; |
|
22 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
23 |
import org.springframework.validation.annotation.Validated; |
|
24 |
import org.springframework.web.bind.annotation.GetMapping; |
|
25 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
26 |
import org.springframework.web.bind.annotation.RequestParam; |
|
27 |
import org.springframework.web.bind.annotation.RestController; |
|
28 |
|
|
29 |
import javax.annotation.Resource; |
|
30 |
import java.util.Collections; |
|
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.convertSet; |
bb2880
|
36 |
import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
e7c126
|
37 |
|
H |
38 |
@Tag(name = "管理后台 - 流程定义") |
|
39 |
@RestController |
|
40 |
@RequestMapping("/bpm/process-definition") |
|
41 |
@Validated |
|
42 |
public class BpmProcessDefinitionController { |
|
43 |
|
|
44 |
@Resource |
|
45 |
private BpmProcessDefinitionService processDefinitionService; |
|
46 |
@Resource |
|
47 |
private BpmFormService formService; |
|
48 |
@Resource |
|
49 |
private BpmCategoryService categoryService; |
|
50 |
|
|
51 |
@GetMapping("/page") |
|
52 |
@Operation(summary = "获得流程定义分页") |
|
53 |
@PreAuthorize("@ss.hasPermission('bpm:process-definition:query')") |
|
54 |
public CommonResult<PageResult<BpmProcessDefinitionRespVO>> getProcessDefinitionPage( |
|
55 |
BpmProcessDefinitionPageReqVO pageReqVO) { |
|
56 |
PageResult<ProcessDefinition> pageResult = processDefinitionService.getProcessDefinitionPage(pageReqVO); |
|
57 |
if (CollUtil.isEmpty(pageResult.getList())) { |
|
58 |
return success(PageResult.empty(pageResult.getTotal())); |
|
59 |
} |
|
60 |
|
|
61 |
// 获得 Category Map |
|
62 |
Map<String, BpmCategoryDO> categoryMap = categoryService.getCategoryMap( |
|
63 |
convertSet(pageResult.getList(), ProcessDefinition::getCategory)); |
|
64 |
// 获得 Deployment Map |
|
65 |
Map<String, Deployment> deploymentMap = processDefinitionService.getDeploymentMap( |
|
66 |
convertSet(pageResult.getList(), ProcessDefinition::getDeploymentId)); |
|
67 |
// 获得 BpmProcessDefinitionInfoDO Map |
|
68 |
Map<String, BpmProcessDefinitionInfoDO> processDefinitionMap = processDefinitionService.getProcessDefinitionInfoMap( |
|
69 |
convertSet(pageResult.getList(), ProcessDefinition::getId)); |
|
70 |
// 获得 Form Map |
|
71 |
Map<Long, BpmFormDO> formMap = formService.getFormMap( |
bb2880
|
72 |
convertSet(processDefinitionMap.values(), BpmProcessDefinitionInfoDO::getFormId)); |
e7c126
|
73 |
return success(BpmProcessDefinitionConvert.INSTANCE.buildProcessDefinitionPage( |
H |
74 |
pageResult, deploymentMap, processDefinitionMap, formMap, categoryMap)); |
|
75 |
} |
|
76 |
|
|
77 |
@GetMapping ("/list") |
|
78 |
@Operation(summary = "获得流程定义列表") |
|
79 |
@Parameter(name = "suspensionState", description = "挂起状态", required = true, example = "1") // 参见 Flowable SuspensionState 枚举 |
|
80 |
public CommonResult<List<BpmProcessDefinitionRespVO>> getProcessDefinitionList( |
bb2880
|
81 |
@RequestParam("suspensionState") Integer suspensionState, @RequestParam(value = "categoryId", required = false) String categoryId) { |
H |
82 |
// 1.1 获得开启的流程定义 |
|
83 |
List<ProcessDefinition> list = processDefinitionService.getProcessDefinitionListBySuspensionState(suspensionState, categoryId); |
e7c126
|
84 |
if (CollUtil.isEmpty(list)) { |
H |
85 |
return success(Collections.emptyList()); |
|
86 |
} |
bb2880
|
87 |
// 1.2 移除不可见的流程定义 |
e7c126
|
88 |
Map<String, BpmProcessDefinitionInfoDO> processDefinitionMap = processDefinitionService.getProcessDefinitionInfoMap( |
H |
89 |
convertSet(list, ProcessDefinition::getId)); |
bb2880
|
90 |
Long userId = getLoginUserId(); |
H |
91 |
list.removeIf(processDefinition -> { |
|
92 |
BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionMap.get(processDefinition.getId()); |
|
93 |
return processDefinitionInfo == null // 不存在 |
|
94 |
|| Boolean.FALSE.equals(processDefinitionInfo.getVisible()) // visible 不可见 |
|
95 |
|| !processDefinitionService.canUserStartProcessDefinition(processDefinitionInfo, userId); // 无权限发起 |
|
96 |
}); |
|
97 |
|
|
98 |
// 2. 拼接 VO 返回 |
e7c126
|
99 |
return success(BpmProcessDefinitionConvert.INSTANCE.buildProcessDefinitionList( |
H |
100 |
list, null, processDefinitionMap, null, null)); |
|
101 |
} |
|
102 |
|
|
103 |
@GetMapping ("/get") |
|
104 |
@Operation(summary = "获得流程定义") |
|
105 |
@Parameter(name = "id", description = "流程编号", required = true, example = "1024") |
|
106 |
@Parameter(name = "key", description = "流程定义标识", required = true, example = "1024") |
|
107 |
public CommonResult<BpmProcessDefinitionRespVO> getProcessDefinition( |
|
108 |
@RequestParam(value = "id", required = false) String id, |
|
109 |
@RequestParam(value = "key", required = false) String key) { |
|
110 |
ProcessDefinition processDefinition = id != null ? processDefinitionService.getProcessDefinition(id) |
|
111 |
: processDefinitionService.getActiveProcessDefinition(key); |
|
112 |
if (processDefinition == null) { |
|
113 |
return success(null); |
|
114 |
} |
4a47e4
|
115 |
BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService.getProcessDefinitionInfo(processDefinition.getId()); |
e7c126
|
116 |
BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(processDefinition.getId()); |
H |
117 |
return success(BpmProcessDefinitionConvert.INSTANCE.buildProcessDefinition( |
bb2880
|
118 |
processDefinition, null, processDefinitionInfo, null, null, bpmnModel)); |
e7c126
|
119 |
} |
H |
120 |
|
|
121 |
} |