提交 | 用户 | 时间
|
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.module.bpm.controller.admin.definition.vo.model.*; |
bb2880
|
6 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
H |
7 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO; |
e7c126
|
8 |
import com.iailab.module.bpm.convert.definition.BpmModelConvert; |
H |
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.service.definition.BpmCategoryService; |
|
12 |
import com.iailab.module.bpm.service.definition.BpmFormService; |
|
13 |
import com.iailab.module.bpm.service.definition.BpmModelService; |
|
14 |
import com.iailab.module.bpm.service.definition.BpmProcessDefinitionService; |
|
15 |
import com.iailab.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; |
bb2880
|
16 |
import com.iailab.module.system.api.user.AdminUserApi; |
H |
17 |
import com.iailab.module.system.api.user.dto.AdminUserRespDTO; |
e7c126
|
18 |
import io.swagger.v3.oas.annotations.Operation; |
H |
19 |
import io.swagger.v3.oas.annotations.Parameter; |
|
20 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
21 |
import org.flowable.engine.repository.Deployment; |
|
22 |
import org.flowable.engine.repository.Model; |
|
23 |
import org.flowable.engine.repository.ProcessDefinition; |
|
24 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
25 |
import org.springframework.validation.annotation.Validated; |
|
26 |
import org.springframework.web.bind.annotation.*; |
|
27 |
|
|
28 |
import javax.annotation.Resource; |
|
29 |
import javax.validation.Valid; |
bb2880
|
30 |
import java.util.*; |
H |
31 |
import java.util.stream.Stream; |
e7c126
|
32 |
|
H |
33 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
bb2880
|
34 |
import static com.iailab.framework.common.util.collection.CollectionUtils.*; |
H |
35 |
import static com.iailab.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
e7c126
|
36 |
|
H |
37 |
@Tag(name = "管理后台 - 流程模型") |
|
38 |
@RestController |
|
39 |
@RequestMapping("/bpm/model") |
|
40 |
@Validated |
|
41 |
public class BpmModelController { |
|
42 |
|
|
43 |
@Resource |
|
44 |
private BpmModelService modelService; |
|
45 |
@Resource |
|
46 |
private BpmFormService formService; |
|
47 |
@Resource |
|
48 |
private BpmCategoryService categoryService; |
|
49 |
@Resource |
|
50 |
private BpmProcessDefinitionService processDefinitionService; |
|
51 |
|
bb2880
|
52 |
@Resource |
H |
53 |
private AdminUserApi adminUserApi; |
|
54 |
|
|
55 |
@GetMapping("/list") |
e7c126
|
56 |
@Operation(summary = "获得模型分页") |
bb2880
|
57 |
@Parameter(name = "name", description = "模型名称", example = "芋艿") |
H |
58 |
public CommonResult<List<BpmModelRespVO>> getModelPage(@RequestParam(value = "name", required = false) String name) { |
|
59 |
List<Model> list = modelService.getModelList(name); |
|
60 |
if (CollUtil.isEmpty(list)) { |
|
61 |
return success(Collections.emptyList()); |
e7c126
|
62 |
} |
H |
63 |
|
|
64 |
// 获得 Form 表单 |
bb2880
|
65 |
Set<Long> formIds = convertSet(list, model -> { |
H |
66 |
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model); |
e7c126
|
67 |
return metaInfo != null ? metaInfo.getFormId() : null; |
H |
68 |
}); |
|
69 |
Map<Long, BpmFormDO> formMap = formService.getFormMap(formIds); |
|
70 |
// 获得 Category Map |
|
71 |
Map<String, BpmCategoryDO> categoryMap = categoryService.getCategoryMap( |
bb2880
|
72 |
convertSet(list, Model::getCategory)); |
e7c126
|
73 |
// 获得 Deployment Map |
bb2880
|
74 |
Map<String, Deployment> deploymentMap = processDefinitionService.getDeploymentMap( |
H |
75 |
convertSet(list, Model::getDeploymentId)); |
e7c126
|
76 |
// 获得 ProcessDefinition Map |
bb2880
|
77 |
List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds( |
H |
78 |
deploymentMap.keySet()); |
e7c126
|
79 |
Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId); |
bb2880
|
80 |
// 获得 User Map |
H |
81 |
Set<Long> userIds = convertSetByFlatMap(list, model -> { |
|
82 |
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model); |
|
83 |
return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty(); |
|
84 |
}); |
|
85 |
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds); |
|
86 |
return success(BpmModelConvert.INSTANCE.buildModelList(list, |
|
87 |
formMap, categoryMap, deploymentMap, processDefinitionMap, userMap)); |
e7c126
|
88 |
} |
H |
89 |
|
|
90 |
@GetMapping("/get") |
|
91 |
@Operation(summary = "获得模型") |
|
92 |
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
|
93 |
@PreAuthorize("@ss.hasPermission('bpm:model:query')") |
|
94 |
public CommonResult<BpmModelRespVO> getModel(@RequestParam("id") String id) { |
|
95 |
Model model = modelService.getModel(id); |
|
96 |
if (model == null) { |
|
97 |
return null; |
|
98 |
} |
|
99 |
byte[] bpmnBytes = modelService.getModelBpmnXML(id); |
|
100 |
return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes)); |
|
101 |
} |
|
102 |
|
|
103 |
@PostMapping("/create") |
|
104 |
@Operation(summary = "新建模型") |
|
105 |
@PreAuthorize("@ss.hasPermission('bpm:model:create')") |
bb2880
|
106 |
public CommonResult<String> createModel(@Valid @RequestBody BpmModelSaveReqVO createRetVO) { |
H |
107 |
return success(modelService.createModel(createRetVO)); |
e7c126
|
108 |
} |
bb2880
|
109 |
|
e7c126
|
110 |
|
H |
111 |
@PutMapping("/update") |
|
112 |
@Operation(summary = "修改模型") |
|
113 |
@PreAuthorize("@ss.hasPermission('bpm:model:update')") |
bb2880
|
114 |
public CommonResult<Boolean> updateModel(@Valid @RequestBody BpmModelSaveReqVO modelVO) { |
H |
115 |
modelService.updateModel(getLoginUserId(), modelVO); |
e7c126
|
116 |
return success(true); |
H |
117 |
} |
|
118 |
|
bb2880
|
119 |
@PutMapping("/update-sort-batch") |
H |
120 |
@Operation(summary = "批量修改模型排序") |
|
121 |
@Parameter(name = "ids", description = "编号数组", required = true, example = "1,2,3") |
|
122 |
public CommonResult<Boolean> updateModelSortBatch(@RequestParam("ids") List<String> ids) { |
|
123 |
modelService.updateModelSortBatch(getLoginUserId(), ids); |
|
124 |
return success(true); |
e7c126
|
125 |
} |
H |
126 |
|
|
127 |
@PostMapping("/deploy") |
|
128 |
@Operation(summary = "部署模型") |
|
129 |
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
|
130 |
@PreAuthorize("@ss.hasPermission('bpm:model:deploy')") |
|
131 |
public CommonResult<Boolean> deployModel(@RequestParam("id") String id) { |
bb2880
|
132 |
modelService.deployModel(getLoginUserId(), id); |
e7c126
|
133 |
return success(true); |
H |
134 |
} |
|
135 |
|
|
136 |
@PutMapping("/update-state") |
|
137 |
@Operation(summary = "修改模型的状态", description = "实际更新的部署的流程定义的状态") |
|
138 |
@PreAuthorize("@ss.hasPermission('bpm:model:update')") |
|
139 |
public CommonResult<Boolean> updateModelState(@Valid @RequestBody BpmModelUpdateStateReqVO reqVO) { |
bb2880
|
140 |
modelService.updateModelState(getLoginUserId(), reqVO.getId(), reqVO.getState()); |
H |
141 |
return success(true); |
|
142 |
} |
|
143 |
|
|
144 |
@PutMapping("/update-bpmn") |
|
145 |
@Operation(summary = "修改模型的 BPMN") |
|
146 |
@PreAuthorize("@ss.hasPermission('bpm:model:update')") |
|
147 |
public CommonResult<Boolean> updateModelBpmn(@Valid @RequestBody BpmModeUpdateBpmnReqVO reqVO) { |
|
148 |
modelService.updateModelBpmnXml(reqVO.getId(), reqVO.getBpmnXml()); |
e7c126
|
149 |
return success(true); |
H |
150 |
} |
|
151 |
|
|
152 |
@DeleteMapping("/delete") |
|
153 |
@Operation(summary = "删除模型") |
|
154 |
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
|
155 |
@PreAuthorize("@ss.hasPermission('bpm:model:delete')") |
|
156 |
public CommonResult<Boolean> deleteModel(@RequestParam("id") String id) { |
bb2880
|
157 |
modelService.deleteModel(getLoginUserId(), id); |
e7c126
|
158 |
return success(true); |
H |
159 |
} |
|
160 |
|
bb2880
|
161 |
// ========== 仿钉钉/飞书的精简模型 ========= |
H |
162 |
|
|
163 |
@GetMapping("/simple/get") |
|
164 |
@Operation(summary = "获得仿钉钉流程设计模型") |
|
165 |
@Parameter(name = "modelId", description = "流程模型编号", required = true, example = "a2c5eee0-eb6c-11ee-abf4-0c37967c420a") |
|
166 |
public CommonResult<BpmSimpleModelNodeVO> getSimpleModel(@RequestParam("id") String modelId){ |
|
167 |
return success(modelService.getSimpleModel(modelId)); |
|
168 |
} |
|
169 |
|
|
170 |
@PostMapping("/simple/update") |
|
171 |
@Operation(summary = "保存仿钉钉流程设计模型") |
|
172 |
@PreAuthorize("@ss.hasPermission('bpm:model:update')") |
|
173 |
public CommonResult<Boolean> updateSimpleModel(@Valid @RequestBody BpmSimpleModelUpdateReqVO reqVO) { |
|
174 |
modelService.updateSimpleModel(getLoginUserId(), reqVO); |
|
175 |
return success(Boolean.TRUE); |
|
176 |
} |
|
177 |
|
|
178 |
|
e7c126
|
179 |
} |