From f4f9405f99cb35e2fd6cfeae4c54617304228fda Mon Sep 17 00:00:00 2001 From: houzhongjian <houzhongyi@126.com> Date: 星期一, 06 一月 2025 13:21:16 +0800 Subject: [PATCH] 工作流程功能升级 --- iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/service/definition/BpmModelServiceImpl.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 46 insertions(+), 14 deletions(-) diff --git a/iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/service/definition/BpmModelServiceImpl.java b/iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/service/definition/BpmModelServiceImpl.java index 49bd31f..e8d4e2a 100644 --- a/iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/service/definition/BpmModelServiceImpl.java +++ b/iailab-module-bpm/iailab-module-bpm-biz/src/main/java/com/iailab/module/bpm/service/definition/BpmModelServiceImpl.java @@ -2,6 +2,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; import com.iailab.framework.common.util.json.JsonUtils; import com.iailab.framework.common.util.validation.ValidationUtils; @@ -12,11 +13,11 @@ import com.iailab.module.bpm.convert.definition.BpmModelConvert; import com.iailab.module.bpm.dal.dataobject.definition.BpmFormDO; import com.iailab.module.bpm.enums.definition.BpmModelFormTypeEnum; +import com.iailab.module.bpm.enums.definition.BpmModelTypeEnum; import com.iailab.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker; import com.iailab.module.bpm.framework.flowable.core.util.BpmnModelUtils; import com.iailab.module.bpm.framework.flowable.core.util.FlowableUtils; import com.iailab.module.bpm.framework.flowable.core.util.SimpleModelUtils; -import com.iailab.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; import lombok.extern.slf4j.Slf4j; import org.flowable.bpmn.model.BpmnModel; import org.flowable.bpmn.model.StartEvent; @@ -28,7 +29,6 @@ import org.flowable.engine.repository.ProcessDefinition; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; @@ -66,7 +66,7 @@ public List<Model> getModelList(String name) { ModelQuery modelQuery = repositoryService.createModelQuery(); if (StrUtil.isNotEmpty(name)) { - modelQuery.modelNameLike(name); + modelQuery.modelNameLike("%" + name + "%"); } return modelQuery.list(); } @@ -83,26 +83,54 @@ throw exception(MODEL_KEY_EXISTS, createReqVO.getKey()); } - // 2.1 创建流程定义 + // 2. 创建 Model 对象 createReqVO.setSort(System.currentTimeMillis()); // 使用当前时间,作为排序 Model model = repositoryService.newModel(); BpmModelConvert.INSTANCE.copyToModel(model, createReqVO); model.setTenantId(FlowableUtils.getTenantId()); - // 2.2 保存流程定义 - repositoryService.saveModel(model); + + // 3. 保存模型 + saveModel(model, createReqVO); return model.getId(); } @Override @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务 - public void updateModel(Long userId, @Valid BpmModelSaveReqVO updateReqVO) { + public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) { // 1. 校验流程模型存在 Model model = validateModelManager(updateReqVO.getId(), userId); - // 修改流程定义 + // 2. 填充 Model 信息 BpmModelConvert.INSTANCE.copyToModel(model, updateReqVO); - // 更新模型 + + // 3. 保存模型 + saveModel(model, updateReqVO); + } + + /** + * 保存模型的基本信息、流程图 + * + * @param model 模型 + * @param saveReqVO 保存信息 + */ + private void saveModel(Model model, BpmModelSaveReqVO saveReqVO) { + // 1. 保存模型的基础信息 repositoryService.saveModel(model); + + // 2. 保存流程图 + if (ObjUtil.equals(BpmModelTypeEnum.BPMN.getType(), saveReqVO.getType()) + && StrUtil.isNotEmpty(saveReqVO.getBpmnXml())) { + updateModelBpmnXml(model.getId(), saveReqVO.getBpmnXml()); + } else if (ObjUtil.equals(BpmModelTypeEnum.SIMPLE.getType(), saveReqVO.getType()) + && saveReqVO.getSimpleModel() != null) { + // JSON 转换成 bpmnModel + BpmnModel bpmnModel = SimpleModelUtils.buildBpmnModel(model.getKey(), model.getName(), + saveReqVO.getSimpleModel()); + // 保存 Bpmn XML + updateModelBpmnXml(model.getId(), BpmnModelUtils.getBpmnXml(bpmnModel)); + // 保存 JSON 数据 + updateModelSimpleJson(model.getId(), saveReqVO.getSimpleModel()); + } } @Override @@ -111,7 +139,7 @@ // 1.1 校验流程模型存在 List<Model> models = repositoryService.createModelQuery() .modelTenantId(FlowableUtils.getTenantId()).list(); - models.removeIf(model ->!ids.contains(model.getId())); + models.removeIf(model -> !ids.contains(model.getId())); if (ids.size() != models.size()) { throw exception(MODEL_NOT_EXISTS); } @@ -174,7 +202,8 @@ String simpleJson = getModelSimpleJson(model.getId()); // 2.1 创建流程定义 - String definitionId = processDefinitionService.createProcessDefinition(model, metaInfo, bpmnBytes, simpleJson, form); + String definitionId = processDefinitionService.createProcessDefinition(model, metaInfo, bpmnBytes, simpleJson, + form); // 2.2 将老的流程定义进行挂起。也就是说,只有最新部署的流程定义,才可以发起任务。 updateProcessDefinitionSuspended(model.getDeploymentId()); @@ -221,7 +250,8 @@ // 1.1 校验流程模型存在 Model model = validateModelManager(id, userId); // 1.2 校验流程定义存在 - ProcessDefinition definition = processDefinitionService.getProcessDefinitionByDeploymentId(model.getDeploymentId()); + ProcessDefinition definition = processDefinitionService + .getProcessDefinitionByDeploymentId(model.getDeploymentId()); if (definition == null) { throw exception(PROCESS_DEFINITION_NOT_EXISTS); } @@ -277,7 +307,8 @@ } return form; } else { - if (StrUtil.isEmpty(metaInfo.getFormCustomCreatePath()) || StrUtil.isEmpty(metaInfo.getFormCustomViewPath())) { + if (StrUtil.isEmpty(metaInfo.getFormCustomCreatePath()) + || StrUtil.isEmpty(metaInfo.getFormCustomViewPath())) { throw exception(MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG); } return null; @@ -324,7 +355,8 @@ if (oldDefinition == null) { return; } - processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode()); + processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(), + SuspensionState.SUSPENDED.getStateCode()); } private Model getModelByKey(String key) { -- Gitblit v1.9.3