Commit 14fad915a60fe35dc5c4d153d65bdeb5728051de
1 parent
b67c2d5e
【功能新增】Bpm:新增和修改 model 时,增加 bpmnxml 和 simplemodel
Showing
5 changed files
with
68 additions
and
17 deletions
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,7 +99,8 @@ public class BpmModelController { | ||
| 99 | return null; | 99 | return null; |
| 100 | } | 100 | } |
| 101 | byte[] bpmnBytes = modelService.getModelBpmnXML(id); | 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 | @PostMapping("/create") | 106 | @PostMapping("/create") |
| @@ -109,7 +110,6 @@ public class BpmModelController { | @@ -109,7 +110,6 @@ public class BpmModelController { | ||
| 109 | return success(modelService.createModel(createRetVO)); | 110 | return success(modelService.createModel(createRetVO)); |
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | - | ||
| 113 | @PutMapping("/update") | 113 | @PutMapping("/update") |
| 114 | @Operation(summary = "修改模型") | 114 | @Operation(summary = "修改模型") |
| 115 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") | 115 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") |
| @@ -143,6 +143,7 @@ public class BpmModelController { | @@ -143,6 +143,7 @@ public class BpmModelController { | ||
| 143 | return success(true); | 143 | return success(true); |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | + @Deprecated | ||
| 146 | @PutMapping("/update-bpmn") | 147 | @PutMapping("/update-bpmn") |
| 147 | @Operation(summary = "修改模型的 BPMN") | 148 | @Operation(summary = "修改模型的 BPMN") |
| 148 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") | 149 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") |
| @@ -169,6 +170,7 @@ public class BpmModelController { | @@ -169,6 +170,7 @@ public class BpmModelController { | ||
| 169 | return success(modelService.getSimpleModel(modelId)); | 170 | return success(modelService.getSimpleModel(modelId)); |
| 170 | } | 171 | } |
| 171 | 172 | ||
| 173 | + @Deprecated | ||
| 172 | @PostMapping("/simple/update") | 174 | @PostMapping("/simple/update") |
| 173 | @Operation(summary = "保存仿钉钉流程设计模型") | 175 | @Operation(summary = "保存仿钉钉流程设计模型") |
| 174 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") | 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 | package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model; | 1 | package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO; | 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 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; | 5 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; |
| 5 | import io.swagger.v3.oas.annotations.media.Schema; | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | import lombok.Data; | 7 | import lombok.Data; |
| @@ -35,12 +36,15 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO { | @@ -35,12 +36,15 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO { | ||
| 35 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | 36 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 36 | private LocalDateTime createTime; | 37 | private LocalDateTime createTime; |
| 37 | 38 | ||
| 38 | - @Schema(description = "BPMN XML", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 39 | - private String bpmnXml; | ||
| 40 | - | ||
| 41 | @Schema(description = "可发起的用户数组") | 39 | @Schema(description = "可发起的用户数组") |
| 42 | private List<UserSimpleBaseVO> startUsers; | 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 | package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model; | 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 | import io.swagger.v3.oas.annotations.media.Schema; | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | +import jakarta.validation.Valid; | ||
| 4 | import jakarta.validation.constraints.NotEmpty; | 6 | import jakarta.validation.constraints.NotEmpty; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | 8 | ||
| @@ -22,4 +24,11 @@ public class BpmModelSaveReqVO extends BpmModelMetaInfoVO { | @@ -22,4 +24,11 @@ public class BpmModelSaveReqVO extends BpmModelMetaInfoVO { | ||
| 22 | @Schema(description = "流程分类", example = "1") | 24 | @Schema(description = "流程分类", example = "1") |
| 23 | private String category; | 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,6 +8,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO; | ||
| 8 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; | 8 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; |
| 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO; | 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO; |
| 10 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO; | 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 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; | 12 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; |
| 12 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO; | 13 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO; |
| 13 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; | 14 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| @@ -58,12 +59,13 @@ public interface BpmModelConvert { | @@ -58,12 +59,13 @@ public interface BpmModelConvert { | ||
| 58 | return result; | 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 | BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); | 63 | BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); |
| 63 | BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null); | 64 | BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null); |
| 64 | if (ArrayUtil.isNotEmpty(bpmnBytes)) { | 65 | if (ArrayUtil.isNotEmpty(bpmnBytes)) { |
| 65 | modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes)); | 66 | modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes)); |
| 66 | } | 67 | } |
| 68 | + modelVO.setSimpleModel(simpleModel); | ||
| 67 | return modelVO; | 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,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.service.definition; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.ArrayUtil; | 4 | import cn.hutool.core.util.ArrayUtil; |
| 5 | +import cn.hutool.core.util.ObjUtil; | ||
| 5 | import cn.hutool.core.util.StrUtil; | 6 | import cn.hutool.core.util.StrUtil; |
| 6 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 7 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 7 | import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; | 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,6 +13,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.B | ||
| 12 | import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert; | 13 | import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert; |
| 13 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; | 14 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| 14 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; | 15 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; |
| 16 | +import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; | ||
| 15 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker; | 17 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker; |
| 16 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; | 18 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; |
| 17 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; | 19 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; |
| @@ -82,26 +84,54 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -82,26 +84,54 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 82 | throw exception(MODEL_KEY_EXISTS, createReqVO.getKey()); | 84 | throw exception(MODEL_KEY_EXISTS, createReqVO.getKey()); |
| 83 | } | 85 | } |
| 84 | 86 | ||
| 85 | - // 2.1 创建流程定义 | 87 | + // 2. 创建 Model 对象 |
| 86 | createReqVO.setSort(System.currentTimeMillis()); // 使用当前时间,作为排序 | 88 | createReqVO.setSort(System.currentTimeMillis()); // 使用当前时间,作为排序 |
| 87 | Model model = repositoryService.newModel(); | 89 | Model model = repositoryService.newModel(); |
| 88 | BpmModelConvert.INSTANCE.copyToModel(model, createReqVO); | 90 | BpmModelConvert.INSTANCE.copyToModel(model, createReqVO); |
| 89 | model.setTenantId(FlowableUtils.getTenantId()); | 91 | model.setTenantId(FlowableUtils.getTenantId()); |
| 90 | - // 2.2 保存流程定义 | ||
| 91 | - repositoryService.saveModel(model); | 92 | + |
| 93 | + // 3. 保存模型 | ||
| 94 | + saveModel(model, createReqVO); | ||
| 92 | return model.getId(); | 95 | return model.getId(); |
| 93 | } | 96 | } |
| 94 | 97 | ||
| 95 | @Override | 98 | @Override |
| 96 | @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务 | 99 | @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务 |
| 97 | - public void updateModel(Long userId, @Valid BpmModelSaveReqVO updateReqVO) { | 100 | + public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) { |
| 98 | // 1. 校验流程模型存在 | 101 | // 1. 校验流程模型存在 |
| 99 | Model model = validateModelManager(updateReqVO.getId(), userId); | 102 | Model model = validateModelManager(updateReqVO.getId(), userId); |
| 100 | 103 | ||
| 101 | - // 修改流程定义 | 104 | + // 2. 填充 Model 信息 |
| 102 | BpmModelConvert.INSTANCE.copyToModel(model, updateReqVO); | 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 | repositoryService.saveModel(model); | 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 | @Override | 137 | @Override |
| @@ -110,7 +140,7 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -110,7 +140,7 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 110 | // 1.1 校验流程模型存在 | 140 | // 1.1 校验流程模型存在 |
| 111 | List<Model> models = repositoryService.createModelQuery() | 141 | List<Model> models = repositoryService.createModelQuery() |
| 112 | .modelTenantId(FlowableUtils.getTenantId()).list(); | 142 | .modelTenantId(FlowableUtils.getTenantId()).list(); |
| 113 | - models.removeIf(model ->!ids.contains(model.getId())); | 143 | + models.removeIf(model -> !ids.contains(model.getId())); |
| 114 | if (ids.size() != models.size()) { | 144 | if (ids.size() != models.size()) { |
| 115 | throw exception(MODEL_NOT_EXISTS); | 145 | throw exception(MODEL_NOT_EXISTS); |
| 116 | } | 146 | } |
| @@ -173,7 +203,8 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -173,7 +203,8 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 173 | String simpleJson = getModelSimpleJson(model.getId()); | 203 | String simpleJson = getModelSimpleJson(model.getId()); |
| 174 | 204 | ||
| 175 | // 2.1 创建流程定义 | 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 | // 2.2 将老的流程定义进行挂起。也就是说,只有最新部署的流程定义,才可以发起任务。 | 209 | // 2.2 将老的流程定义进行挂起。也就是说,只有最新部署的流程定义,才可以发起任务。 |
| 179 | updateProcessDefinitionSuspended(model.getDeploymentId()); | 210 | updateProcessDefinitionSuspended(model.getDeploymentId()); |
| @@ -220,7 +251,8 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -220,7 +251,8 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 220 | // 1.1 校验流程模型存在 | 251 | // 1.1 校验流程模型存在 |
| 221 | Model model = validateModelManager(id, userId); | 252 | Model model = validateModelManager(id, userId); |
| 222 | // 1.2 校验流程定义存在 | 253 | // 1.2 校验流程定义存在 |
| 223 | - ProcessDefinition definition = processDefinitionService.getProcessDefinitionByDeploymentId(model.getDeploymentId()); | 254 | + ProcessDefinition definition = processDefinitionService |
| 255 | + .getProcessDefinitionByDeploymentId(model.getDeploymentId()); | ||
| 224 | if (definition == null) { | 256 | if (definition == null) { |
| 225 | throw exception(PROCESS_DEFINITION_NOT_EXISTS); | 257 | throw exception(PROCESS_DEFINITION_NOT_EXISTS); |
| 226 | } | 258 | } |
| @@ -276,7 +308,8 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -276,7 +308,8 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 276 | } | 308 | } |
| 277 | return form; | 309 | return form; |
| 278 | } else { | 310 | } else { |
| 279 | - if (StrUtil.isEmpty(metaInfo.getFormCustomCreatePath()) || StrUtil.isEmpty(metaInfo.getFormCustomViewPath())) { | 311 | + if (StrUtil.isEmpty(metaInfo.getFormCustomCreatePath()) |
| 312 | + || StrUtil.isEmpty(metaInfo.getFormCustomViewPath())) { | ||
| 280 | throw exception(MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG); | 313 | throw exception(MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG); |
| 281 | } | 314 | } |
| 282 | return null; | 315 | return null; |
| @@ -323,7 +356,8 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -323,7 +356,8 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 323 | if (oldDefinition == null) { | 356 | if (oldDefinition == null) { |
| 324 | return; | 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 | private Model getModelByKey(String key) { | 363 | private Model getModelByKey(String key) { |