【功能新增】Bpm:新增和修改 model 时,增加 bpmnxml 和 simplemodel
This commit is contained in:
parent
b67c2d5ef5
commit
14fad915a6
|
@ -99,7 +99,8 @@ public class BpmModelController {
|
|||
return null;
|
||||
}
|
||||
byte[] bpmnBytes = modelService.getModelBpmnXML(id);
|
||||
return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes));
|
||||
BpmSimpleModelNodeVO simpleModel = modelService.getSimpleModel(id);
|
||||
return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes, simpleModel));
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
|
@ -109,7 +110,6 @@ public class BpmModelController {
|
|||
return success(modelService.createModel(createRetVO));
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "修改模型")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
|
||||
|
@ -143,6 +143,7 @@ public class BpmModelController {
|
|||
return success(true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@PutMapping("/update-bpmn")
|
||||
@Operation(summary = "修改模型的 BPMN")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
|
||||
|
@ -169,6 +170,7 @@ public class BpmModelController {
|
|||
return success(modelService.getSimpleModel(modelId));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@PostMapping("/simple/update")
|
||||
@Operation(summary = "保存仿钉钉流程设计模型")
|
||||
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
@ -35,12 +36,15 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO {
|
|||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "BPMN XML", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String bpmnXml;
|
||||
|
||||
@Schema(description = "可发起的用户数组")
|
||||
private List<UserSimpleBaseVO> startUsers;
|
||||
|
||||
@Schema(description = "BPMN XML")
|
||||
private String bpmnXml;
|
||||
|
||||
@Schema(description = "仿钉钉流程设计模型对象")
|
||||
private BpmSimpleModelNodeVO simpleModel;
|
||||
|
||||
/**
|
||||
* 最新部署的流程定义
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -22,4 +24,11 @@ public class BpmModelSaveReqVO extends BpmModelMetaInfoVO {
|
|||
@Schema(description = "流程分类", example = "1")
|
||||
private String category;
|
||||
|
||||
@Schema(description = "BPMN XML")
|
||||
private String bpmnXml;
|
||||
|
||||
@Schema(description = "仿钉钉流程设计模型对象")
|
||||
@Valid
|
||||
private BpmSimpleModelNodeVO simpleModel;
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
|
|||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
|
||||
|
@ -58,12 +59,13 @@ public interface BpmModelConvert {
|
|||
return result;
|
||||
}
|
||||
|
||||
default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes) {
|
||||
default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) {
|
||||
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
|
||||
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
|
||||
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
|
||||
modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
|
||||
}
|
||||
modelVO.setSimpleModel(simpleModel);
|
||||
return modelVO;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.service.definition;
|
|||
|
||||
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 cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
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
|
|||
import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
|
||||
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
|
||||
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
|
||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
|
||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
||||
|
@ -82,26 +84,54 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
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
|
||||
|
@ -110,7 +140,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
// 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);
|
||||
}
|
||||
|
@ -173,7 +203,8 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
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());
|
||||
|
@ -220,7 +251,8 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
// 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);
|
||||
}
|
||||
|
@ -276,7 +308,8 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
}
|
||||
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;
|
||||
|
@ -323,7 +356,8 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|||
if (oldDefinition == null) {
|
||||
return;
|
||||
}
|
||||
processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode());
|
||||
processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(),
|
||||
SuspensionState.SUSPENDED.getStateCode());
|
||||
}
|
||||
|
||||
private Model getModelByKey(String key) {
|
||||
|
|
Loading…
Reference in New Issue