潘志宝
2024-11-11 31bd2c17088ec34072deabe106ff1d695c8b2b49
提交 | 用户 | 时间
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.framework.flowable.core.candidate.strategy.BpmTaskCandidateStartUserSelectStrategy;
13 import com.iailab.module.bpm.service.definition.BpmCategoryService;
14 import com.iailab.module.bpm.service.definition.BpmFormService;
15 import com.iailab.module.bpm.service.definition.BpmProcessDefinitionService;
16 import io.swagger.v3.oas.annotations.Operation;
17 import io.swagger.v3.oas.annotations.Parameter;
18 import io.swagger.v3.oas.annotations.tags.Tag;
19 import org.flowable.bpmn.model.BpmnModel;
20 import org.flowable.bpmn.model.UserTask;
21 import org.flowable.engine.repository.Deployment;
22 import org.flowable.engine.repository.ProcessDefinition;
23 import org.springframework.security.access.prepost.PreAuthorize;
24 import org.springframework.validation.annotation.Validated;
25 import org.springframework.web.bind.annotation.GetMapping;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.RequestParam;
28 import org.springframework.web.bind.annotation.RestController;
29
30 import javax.annotation.Resource;
31 import java.util.Collections;
32 import java.util.List;
33 import java.util.Map;
34
35 import static com.iailab.framework.common.pojo.CommonResult.success;
36 import static com.iailab.framework.common.util.collection.CollectionUtils.convertSet;
37
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(
72                convertSet(processDefinitionMap.values(), BpmProcessDefinitionInfoDO::getFormId));
73         return success(BpmProcessDefinitionConvert.INSTANCE.buildProcessDefinitionPage(
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(
81             @RequestParam("suspensionState") Integer suspensionState) {
82         List<ProcessDefinition> list = processDefinitionService.getProcessDefinitionListBySuspensionState(suspensionState);
83         if (CollUtil.isEmpty(list)) {
84             return success(Collections.emptyList());
85         }
86
87         // 获得 BpmProcessDefinitionInfoDO Map
88         Map<String, BpmProcessDefinitionInfoDO> processDefinitionMap = processDefinitionService.getProcessDefinitionInfoMap(
89                 convertSet(list, ProcessDefinition::getId));
90         return success(BpmProcessDefinitionConvert.INSTANCE.buildProcessDefinitionList(
91                 list, null, processDefinitionMap, null, null));
92     }
93
94     @GetMapping ("/get")
95     @Operation(summary = "获得流程定义")
96     @Parameter(name = "id", description = "流程编号", required = true, example = "1024")
97     @Parameter(name = "key", description = "流程定义标识", required = true, example = "1024")
98     public CommonResult<BpmProcessDefinitionRespVO> getProcessDefinition(
99             @RequestParam(value = "id", required = false) String id,
100             @RequestParam(value = "key", required = false) String key) {
101         ProcessDefinition processDefinition = id != null ? processDefinitionService.getProcessDefinition(id)
102                 : processDefinitionService.getActiveProcessDefinition(key);
103         if (processDefinition == null) {
104             return success(null);
105         }
4a47e4 106         BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService.getProcessDefinitionInfo(processDefinition.getId());
e7c126 107         BpmnModel bpmnModel = processDefinitionService.getProcessDefinitionBpmnModel(processDefinition.getId());
H 108         List<UserTask> userTaskList = BpmTaskCandidateStartUserSelectStrategy.getStartUserSelectUserTaskList(bpmnModel);
109         return success(BpmProcessDefinitionConvert.INSTANCE.buildProcessDefinition(
4a47e4 110                 processDefinition, null, processDefinitionInfo, null, null, bpmnModel, userTaskList));
e7c126 111     }
H 112
113 }