diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java index 2ac7ccec4..7dcc13f8a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java @@ -19,7 +19,7 @@ import java.io.IOException; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -@Api(tags = "流程定义") +@Api(tags = "流程模型") @RestController @RequestMapping("/bpm/model") @Validated diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelBaseVO.java index 2f352eb8c..9ab133b43 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelBaseVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelBaseVO.java @@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; /** -* 流程定义 Base VO,提供给添加、修改、详细的子 VO 使用 +* 流程模型 Base VO,提供给添加、修改、详细的子 VO 使用 * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelCreateReqVO.java index 95c0dea5e..871fb2859 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelCreateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelCreateReqVO.java @@ -8,7 +8,7 @@ import lombok.ToString; import javax.validation.constraints.NotEmpty; -@ApiModel("流程定义的创建 Request VO") +@ApiModel("流程模型的创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @@ -18,6 +18,4 @@ public class BpmModelCreateReqVO extends BpmModelBaseVO { @NotEmpty(message = "BPMN XML 不能为空") private String bpmnXml; -// @ApiModelProperty(value = "版本号") -// private Integer revision; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java index 9cba2b2f6..bee111d1d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java @@ -8,7 +8,7 @@ import lombok.ToString; import java.util.Date; -@ApiModel("流程定义 Response VO") +@ApiModel("流程模型 Response VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @@ -17,13 +17,27 @@ public class BpmModelRespVO extends BpmModelBaseVO { @ApiModelProperty(value = "编号", required = true, example = "1024") private String id; - @ApiModelProperty(value = "版本", required = true, example = "1") - private Integer revision; - @ApiModelProperty(value = "表单名字", example = "请假表单") private String formName; @ApiModelProperty(value = "创建时间", required = true) private Date createTime; + /** + * 最新部署的流程定义 + */ + private ProcessDefinition processDefinition; + + @ApiModel("流程定义") + @Data + public static class ProcessDefinition { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + private String id; + + @ApiModelProperty(value = "版本", required = true, example = "1") + private Integer version; + + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/ModelPageReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/ModelPageReqVO.java index 2fdbac7ec..480b3e202 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/ModelPageReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/ModelPageReqVO.java @@ -8,7 +8,7 @@ import lombok.EqualsAndHashCode; import lombok.ToString; -@ApiModel("流程定义分页 Request VO") +@ApiModel("流程模型分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/ProcessDefinitionController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/ProcessDefinitionController.java index 073f2f5e2..c324d4feb 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/ProcessDefinitionController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/ProcessDefinitionController.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO; -import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmProcessDefinitionService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; @@ -30,7 +30,7 @@ public class ProcessDefinitionController { @Resource private ProcessRuntime processRuntime; @Resource - private BpmProcessDefinitionService bpmProcessDefinitionService; + private BpmDefinitionService bpmProcessDefinitionService; @GetMapping(value = "/getStartForm") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java index 7e2bf26dd..75c8373c7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java @@ -6,8 +6,8 @@ import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import org.activiti.engine.impl.persistence.entity.ModelEntity; import org.activiti.engine.repository.Model; +import org.activiti.engine.repository.ProcessDefinition; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -25,15 +25,17 @@ public interface ModelConvert { ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class); - default List convertList(List list, Map formMap) { + default List convertList(List list, Map formMap, + Map processDefinitionMap) { return CollectionUtils.convertList(list, model -> { BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null; - return convert(model, form); + ProcessDefinition processDefinition = model.getDeploymentId() != null ? processDefinitionMap.get(model.getDeploymentId()) : null; + return convert(model, form, processDefinition); }); } - default BpmModelRespVO convert(Model model, BpmFormDO form) { + default BpmModelRespVO convert(Model model, BpmFormDO form, ProcessDefinition processDefinition) { BpmModelRespVO modelRespVO = new BpmModelRespVO(); modelRespVO.setId(model.getId()); modelRespVO.setName(model.getName()); @@ -48,10 +50,7 @@ public interface ModelConvert { modelRespVO.setFormId(form.getId()); modelRespVO.setFormName(form.getName()); } - if (model instanceof ModelEntity) { - ModelEntity modelEntity = (ModelEntity) model; - modelRespVO.setRevision(modelEntity.getRevision()); - } + modelRespVO.setProcessDefinition(this.convert(processDefinition)); return modelRespVO; } @@ -69,4 +68,6 @@ public interface ModelConvert { return metaInfo; } + BpmModelRespVO.ProcessDefinition convert(ProcessDefinition bean); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmProcessDefinitionService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java similarity index 63% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmProcessDefinitionService.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java index 01a5cd6d0..3d3417056 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmProcessDefinitionService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java @@ -1,15 +1,21 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow; +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import org.activiti.engine.repository.ProcessDefinition; + +import java.util.List; +import java.util.Set; /** * 流程定义接口 + * * @author yunlong.li */ -public interface BpmProcessDefinitionService { +public interface BpmDefinitionService { + /** * 流程定义分页 * @param processDefinitionPageReqVo 分页入参 @@ -23,4 +29,13 @@ public interface BpmProcessDefinitionService { * @return 分页model */ FileResp export(String processDefinitionId); + + /** + * 获得 deploymentId 对应的 ProcessDefinition 数组 + * + * @param deploymentId 部署编号 + * @return 流程定义的数组 + */ + List getProcessDefinitionListByDeploymentIds(Set deploymentId); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java index fc3a3dddf..a648e669c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java @@ -1,35 +1,34 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.model; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import org.activiti.engine.repository.Model; /** - * 流程定义接口 + * 流程模型接口 * * @author yunlongn */ public interface BpmModelService { /** - * 获得流程定义分页 + * 获得流程模型分页 * * @param pageVO 分页查询 - * @return 流程定义分页 + * @return 流程模型分页 */ PageResult getModelPage(ModelPageReqVO pageVO); // TODO @Li:不用返回 CommonResult // TODO @Li:createBpmModal。 /** - * 创建流程定义 + * 创建流程模型 * * @param modelVO 创建信息 - * @return 创建的流程定义的编号 + * @return 创建的流程模型的编号 */ String createModel(BpmModelCreateReqVO modelVO); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmModelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java similarity index 77% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmModelServiceImpl.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java index de50cfa03..2301423b7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmModelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl; +package cn.iocoder.yudao.adminserver.modules.bpm.service.model.impl; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO; @@ -8,6 +8,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.convert.model.ModelConvert; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService; import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService; import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService; import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; @@ -23,6 +24,7 @@ import org.activiti.engine.RepositoryService; import org.activiti.engine.repository.Deployment; import org.activiti.engine.repository.Model; import org.activiti.engine.repository.ModelQuery; +import org.activiti.engine.repository.ProcessDefinition; import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,16 +37,15 @@ import javax.xml.stream.XMLStreamReader; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_MODEL_KEY_EXISTS; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * 流程定义实现 + * 主要进行 Activiti {@link Model} 的维护 * * @author yunlongn */ @@ -53,10 +54,14 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU @Slf4j public class BpmModelServiceImpl implements BpmModelService { + private static final String BPMN_FILE_SUFFIX = ".bpmn"; + @Resource private RepositoryService repositoryService; @Resource private BpmFormService bpmFormService; + @Resource + private BpmDefinitionService bpmDefinitionService; @Override public PageResult getModelPage(ModelPageReqVO pageVO) { @@ -67,7 +72,6 @@ public class BpmModelServiceImpl implements BpmModelService { // 执行查询 List models = modelQuery.orderByCreateTime().desc() .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); - long modelCount = modelQuery.count(); // 获得 Form Map Set formIds = CollectionUtils.convertSet(models, model -> { @@ -75,8 +79,16 @@ public class BpmModelServiceImpl implements BpmModelService { return metaInfo != null ? metaInfo.getFormId() : null; }); Map formMap = bpmFormService.getFormMap(formIds); + + // 获得 ProcessDefinition Map + Set deploymentIds = new HashSet<>(); + models.forEach(model -> CollectionUtils.addIfNotNull(deploymentIds, model.getId())); + List processDefinitions = bpmDefinitionService.getProcessDefinitionListByDeploymentIds(deploymentIds); + Map processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId); + // 拼接结果 - return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap), modelCount); + long modelCount = modelQuery.count(); + return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap, processDefinitionMap), modelCount); } @Override @@ -98,6 +110,38 @@ public class BpmModelServiceImpl implements BpmModelService { return model.getId(); } +// @Override +// @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 +// public String createModel(BpmModelCreateReqVO createReqVO) { +// Deployment deploy = repositoryService.createDeployment() +// .key(createReqVO.getKey()).name(createReqVO.getName()).category(createReqVO.getCategory()) +// .addString(createReqVO.getName() + BPMN_FILE_SUFFIX, createReqVO.getBpmnXml()) +// .deploy(); +// // 设置 ProcessDefinition 的 category 分类 +// ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult(); +// repositoryService.setProcessDefinitionCategory(definition.getId(), createReqVO.getCategory()); +// return definition.getId(); +// } + +// @Override +// @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 +// public String createModel(BpmModelCreateReqVO createReqVO) { +// // 校验流程标识已经存在 +// Model keyModel = this.getModelByKey(createReqVO.getKey()); +// if (keyModel != null) { +// throw exception(BPM_MODEL_KEY_EXISTS); +// } +// +// // 创建流程定义 +// Model model = repositoryService.newModel(); +// ModelConvert.INSTANCE.copy(model, createReqVO); +// // 保存流程定义 +// repositoryService.saveModel(model); +// // 添加 BPMN XML +// repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(createReqVO.getBpmnXml())); +// return model.getId(); +// } + @Override public CommonResult updateModel(BpmModelCreateReqVO modelVO) { // try { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmProcessDefinitionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmProcessDefinitionServiceImpl.java index 75a5b489c..6f835a765 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmProcessDefinitionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmProcessDefinitionServiceImpl.java @@ -1,11 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.processdefinition.ProcessDefinitionRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow.ProcessDefinitionConvert; -import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmProcessDefinitionService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmDefinitionService; import cn.iocoder.yudao.framework.common.pojo.PageResult; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -17,7 +18,9 @@ import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.repository.ProcessDefinitionQuery; import org.springframework.stereotype.Service; +import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; /** @@ -27,7 +30,7 @@ import java.util.stream.Collectors; @Slf4j @Service @RequiredArgsConstructor -public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionService { +public class BpmProcessDefinitionServiceImpl implements BpmDefinitionService { private final RepositoryService repositoryService; @@ -57,4 +60,13 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ fileResp.setFileByte(bpmnBytes); return fileResp; } + + @Override + public List getProcessDefinitionListByDeploymentIds(Set deploymentIds) { + if (CollUtil.isEmpty(deploymentIds)) { + return Collections.emptyList(); + } + return repositoryService.createProcessDefinitionQuery().deploymentIds(deploymentIds).list(); + } + }