Commit 14fad915a60fe35dc5c4d153d65bdeb5728051de

Authored by YunaiV
1 parent b67c2d5e

【功能新增】Bpm:新增和修改 model 时,增加 bpmnxml 和 simplemodel

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmModelController.java
... ... @@ -99,7 +99,8 @@ public class BpmModelController {
99 99 return null;
100 100 }
101 101 byte[] bpmnBytes = modelService.getModelBpmnXML(id);
102   - return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes));
  102 + BpmSimpleModelNodeVO simpleModel = modelService.getSimpleModel(id);
  103 + return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes, simpleModel));
103 104 }
104 105  
105 106 @PostMapping("/create")
... ... @@ -109,7 +110,6 @@ public class BpmModelController {
109 110 return success(modelService.createModel(createRetVO));
110 111 }
111 112  
112   -
113 113 @PutMapping("/update")
114 114 @Operation(summary = "修改模型")
115 115 @PreAuthorize("@ss.hasPermission('bpm:model:update')")
... ... @@ -143,6 +143,7 @@ public class BpmModelController {
143 143 return success(true);
144 144 }
145 145  
  146 + @Deprecated
146 147 @PutMapping("/update-bpmn")
147 148 @Operation(summary = "修改模型的 BPMN")
148 149 @PreAuthorize("@ss.hasPermission('bpm:model:update')")
... ... @@ -169,6 +170,7 @@ public class BpmModelController {
169 170 return success(modelService.getSimpleModel(modelId));
170 171 }
171 172  
  173 + @Deprecated
172 174 @PostMapping("/simple/update")
173 175 @Operation(summary = "保存仿钉钉流程设计模型")
174 176 @PreAuthorize("@ss.hasPermission('bpm:model:update')")
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelRespVO.java
1 1 package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
2 2  
3 3 import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
  4 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
4 5 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
5 6 import io.swagger.v3.oas.annotations.media.Schema;
6 7 import lombok.Data;
... ... @@ -35,12 +36,15 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO {
35 36 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
36 37 private LocalDateTime createTime;
37 38  
38   - @Schema(description = "BPMN XML", requiredMode = Schema.RequiredMode.REQUIRED)
39   - private String bpmnXml;
40   -
41 39 @Schema(description = "可发起的用户数组")
42 40 private List<UserSimpleBaseVO> startUsers;
43 41  
  42 + @Schema(description = "BPMN XML")
  43 + private String bpmnXml;
  44 +
  45 + @Schema(description = "仿钉钉流程设计模型对象")
  46 + private BpmSimpleModelNodeVO simpleModel;
  47 +
44 48 /**
45 49 * 最新部署的流程定义
46 50 */
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelSaveReqVO.java
1 1 package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
2 2  
  3 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
3 4 import io.swagger.v3.oas.annotations.media.Schema;
  5 +import jakarta.validation.Valid;
4 6 import jakarta.validation.constraints.NotEmpty;
5 7 import lombok.Data;
6 8  
... ... @@ -22,4 +24,11 @@ public class BpmModelSaveReqVO extends BpmModelMetaInfoVO {
22 24 @Schema(description = "流程分类", example = "1")
23 25 private String category;
24 26  
  27 + @Schema(description = "BPMN XML")
  28 + private String bpmnXml;
  29 +
  30 + @Schema(description = "仿钉钉流程设计模型对象")
  31 + @Valid
  32 + private BpmSimpleModelNodeVO simpleModel;
  33 +
25 34 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/convert/definition/BpmModelConvert.java
... ... @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
8 8 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
9 9 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
10 10 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
  11 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
11 12 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
12 13 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
13 14 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
... ... @@ -58,12 +59,13 @@ public interface BpmModelConvert {
58 59 return result;
59 60 }
60 61  
61   - default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes) {
  62 + default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) {
62 63 BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
63 64 BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
64 65 if (ArrayUtil.isNotEmpty(bpmnBytes)) {
65 66 modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
66 67 }
  68 + modelVO.setSimpleModel(simpleModel);
67 69 return modelVO;
68 70 }
69 71  
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.service.definition;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.ArrayUtil;
  5 +import cn.hutool.core.util.ObjUtil;
5 6 import cn.hutool.core.util.StrUtil;
6 7 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
7 8 import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
... ... @@ -12,6 +13,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.B
12 13 import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
13 14 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
14 15 import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
  16 +import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
15 17 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
16 18 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
17 19 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
... ... @@ -82,26 +84,54 @@ public class BpmModelServiceImpl implements BpmModelService {
82 84 throw exception(MODEL_KEY_EXISTS, createReqVO.getKey());
83 85 }
84 86  
85   - // 2.1 创建流程定义
  87 + // 2. 创建 Model 对象
86 88 createReqVO.setSort(System.currentTimeMillis()); // 使用当前时间,作为排序
87 89 Model model = repositoryService.newModel();
88 90 BpmModelConvert.INSTANCE.copyToModel(model, createReqVO);
89 91 model.setTenantId(FlowableUtils.getTenantId());
90   - // 2.2 保存流程定义
91   - repositoryService.saveModel(model);
  92 +
  93 + // 3. 保存模型
  94 + saveModel(model, createReqVO);
92 95 return model.getId();
93 96 }
94 97  
95 98 @Override
96 99 @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务
97   - public void updateModel(Long userId, @Valid BpmModelSaveReqVO updateReqVO) {
  100 + public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) {
98 101 // 1. 校验流程模型存在
99 102 Model model = validateModelManager(updateReqVO.getId(), userId);
100 103  
101   - // 修改流程定义
  104 + // 2. 填充 Model 信息
102 105 BpmModelConvert.INSTANCE.copyToModel(model, updateReqVO);
103   - // 更新模型
  106 +
  107 + // 3. 保存模型
  108 + saveModel(model, updateReqVO);
  109 + }
  110 +
  111 + /**
  112 + * 保存模型的基本信息、流程图
  113 + *
  114 + * @param model 模型
  115 + * @param saveReqVO 保存信息
  116 + */
  117 + private void saveModel(Model model, BpmModelSaveReqVO saveReqVO) {
  118 + // 1. 保存模型的基础信息
104 119 repositoryService.saveModel(model);
  120 +
  121 + // 2. 保存流程图
  122 + if (ObjUtil.equals(BpmModelTypeEnum.BPMN.getType(), saveReqVO.getType())
  123 + && StrUtil.isNotEmpty(saveReqVO.getBpmnXml())) {
  124 + updateModelBpmnXml(model.getId(), saveReqVO.getBpmnXml());
  125 + } else if (ObjUtil.equals(BpmModelTypeEnum.SIMPLE.getType(), saveReqVO.getType())
  126 + && saveReqVO.getSimpleModel() != null) {
  127 + // JSON 转换成 bpmnModel
  128 + BpmnModel bpmnModel = SimpleModelUtils.buildBpmnModel(model.getKey(), model.getName(),
  129 + saveReqVO.getSimpleModel());
  130 + // 保存 Bpmn XML
  131 + updateModelBpmnXml(model.getId(), BpmnModelUtils.getBpmnXml(bpmnModel));
  132 + // 保存 JSON 数据
  133 + updateModelSimpleJson(model.getId(), saveReqVO.getSimpleModel());
  134 + }
105 135 }
106 136  
107 137 @Override
... ... @@ -110,7 +140,7 @@ public class BpmModelServiceImpl implements BpmModelService {
110 140 // 1.1 校验流程模型存在
111 141 List<Model> models = repositoryService.createModelQuery()
112 142 .modelTenantId(FlowableUtils.getTenantId()).list();
113   - models.removeIf(model ->!ids.contains(model.getId()));
  143 + models.removeIf(model -> !ids.contains(model.getId()));
114 144 if (ids.size() != models.size()) {
115 145 throw exception(MODEL_NOT_EXISTS);
116 146 }
... ... @@ -173,7 +203,8 @@ public class BpmModelServiceImpl implements BpmModelService {
173 203 String simpleJson = getModelSimpleJson(model.getId());
174 204  
175 205 // 2.1 创建流程定义
176   - String definitionId = processDefinitionService.createProcessDefinition(model, metaInfo, bpmnBytes, simpleJson, form);
  206 + String definitionId = processDefinitionService.createProcessDefinition(model, metaInfo, bpmnBytes, simpleJson,
  207 + form);
177 208  
178 209 // 2.2 将老的流程定义进行挂起。也就是说,只有最新部署的流程定义,才可以发起任务。
179 210 updateProcessDefinitionSuspended(model.getDeploymentId());
... ... @@ -220,7 +251,8 @@ public class BpmModelServiceImpl implements BpmModelService {
220 251 // 1.1 校验流程模型存在
221 252 Model model = validateModelManager(id, userId);
222 253 // 1.2 校验流程定义存在
223   - ProcessDefinition definition = processDefinitionService.getProcessDefinitionByDeploymentId(model.getDeploymentId());
  254 + ProcessDefinition definition = processDefinitionService
  255 + .getProcessDefinitionByDeploymentId(model.getDeploymentId());
224 256 if (definition == null) {
225 257 throw exception(PROCESS_DEFINITION_NOT_EXISTS);
226 258 }
... ... @@ -276,7 +308,8 @@ public class BpmModelServiceImpl implements BpmModelService {
276 308 }
277 309 return form;
278 310 } else {
279   - if (StrUtil.isEmpty(metaInfo.getFormCustomCreatePath()) || StrUtil.isEmpty(metaInfo.getFormCustomViewPath())) {
  311 + if (StrUtil.isEmpty(metaInfo.getFormCustomCreatePath())
  312 + || StrUtil.isEmpty(metaInfo.getFormCustomViewPath())) {
280 313 throw exception(MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG);
281 314 }
282 315 return null;
... ... @@ -323,7 +356,8 @@ public class BpmModelServiceImpl implements BpmModelService {
323 356 if (oldDefinition == null) {
324 357 return;
325 358 }
326   - processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode());
  359 + processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(),
  360 + SuspensionState.SUSPENDED.getStateCode());
327 361 }
328 362  
329 363 private Model getModelByKey(String key) {
... ...