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 dd89eaad2..2ac7ccec4 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 @@ -1,15 +1,15 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.model; -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.service.workflow.BpmModelService; +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.adminserver.modules.bpm.service.model.BpmModelService; 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; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.activiti.engine.repository.Model; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -32,7 +32,7 @@ public class BpmModelController { @GetMapping ("/page") @ApiOperation(value = "分页数据") - public CommonResult> getModelPage(ModelPageReqVO pageVO) { + public CommonResult> getModelPage(ModelPageReqVO pageVO) { return success(bpmModelService.getModelPage(pageVO)); } 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 9755efe64..2f352eb8c 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 @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; /** * 流程定义 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -12,6 +13,10 @@ import javax.validation.constraints.NotEmpty; @Data public class BpmModelBaseVO { + @ApiModelProperty(value = "流程标识", required = true, example = "process_yudao") + @NotEmpty(message = "流程标识不能为空") + private String key; + @ApiModelProperty(value = "流程名称", required = true, example = "芋道") @NotEmpty(message = "流程名称不能为空") private String name; @@ -20,4 +25,12 @@ public class BpmModelBaseVO { @NotEmpty(message = "流程描述不能为空") private String description; + @ApiModelProperty(value = "流程分类", notes = "参见 bpm_model_category 数据字典", example = "1") + @NotEmpty(message = "流程分类不能为空") + private String category; + + @ApiModelProperty(value = "表单编号", example = "1024") + @NotNull(message = "表单编号不能为空") + private Long formId; + } 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 85c9c95ef..95c0dea5e 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 @@ -14,10 +14,6 @@ import javax.validation.constraints.NotEmpty; @ToString(callSuper = true) public class BpmModelCreateReqVO extends BpmModelBaseVO { - @ApiModelProperty(value = "流程标识", required = true, example = "process_yudao") - @NotEmpty(message = "流程标识不能为空") - private String key; - @ApiModelProperty(value = "BPMN XML", required = true) @NotEmpty(message = "BPMN XML 不能为空") private String bpmnXml; 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 c02b8a2b9..9cba2b2f6 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 @@ -6,6 +6,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import java.util.Date; + @ApiModel("流程定义 Response VO") @Data @EqualsAndHashCode(callSuper = true) @@ -15,4 +17,13 @@ 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; + } 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 new file mode 100644 index 000000000..7e2bf26dd --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java @@ -0,0 +1,72 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.convert.model; + +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.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.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; +import java.util.Map; + + +/** + * 流程定义 Convert + * + * @author yunlongn + */ +@Mapper +public interface ModelConvert { + + ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class); + + default List convertList(List list, Map formMap) { + 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); + }); + } + + default BpmModelRespVO convert(Model model, BpmFormDO form) { + BpmModelRespVO modelRespVO = new BpmModelRespVO(); + modelRespVO.setId(model.getId()); + modelRespVO.setName(model.getName()); + modelRespVO.setKey(model.getKey()); + modelRespVO.setCategory(model.getCategory()); + modelRespVO.setCreateTime(model.getCreateTime()); + BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); + if (metaInfo != null) { + modelRespVO.setDescription(metaInfo.getDescription()); + } + if (form != null) { + modelRespVO.setFormId(form.getId()); + modelRespVO.setFormName(form.getName()); + } + if (model instanceof ModelEntity) { + ModelEntity modelEntity = (ModelEntity) model; + modelRespVO.setRevision(modelEntity.getRevision()); + } + return modelRespVO; + } + + default void copy(Model model, BpmModelCreateReqVO bean) { + model.setName(bean.getName()); + model.setKey(bean.getKey()); + model.setCategory(bean.getCategory()); + model.setMetaInfo(JsonUtils.toJsonString(this.buildMetaInfo(bean.getDescription(), bean.getFormId()))); + } + + default BpmModelMetaInfoRespDTO buildMetaInfo(String description, Long formId) { + BpmModelMetaInfoRespDTO metaInfo = new BpmModelMetaInfoRespDTO(); + metaInfo.setDescription(description); + metaInfo.setFormId(formId); + return metaInfo; + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/ModelConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/ModelConvert.java deleted file mode 100644 index da49ac3cf..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/ModelConvert.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow; - -import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; -import org.activiti.engine.repository.Model; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - - -/** - * @author yunlongn - */ -@Mapper -public interface ModelConvert { - ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class); - - BpmModelRespVO convert(Model model); -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java index bf4368782..cdfc0266d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java @@ -5,32 +5,34 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; /** * 工作流 错误码枚举类 * - * 工作流系统,使用 1-003-000-000 段 + * 工作流系统,使用 1-009-000-000 段 */ public interface BpmErrorCodeConstants { - // ========== 通用流程处理 模块 1-003-000-000 ========== - ErrorCode PROCESS_INSTANCE_NOT_EXISTS = new ErrorCode(1003000001, "流程实例不存在"); - ErrorCode HIGHLIGHT_IMG_ERROR = new ErrorCode(1003000002, "获取高亮流程图异常"); + // ========== 通用流程处理 模块 1-009-000-000 ========== + ErrorCode PROCESS_INSTANCE_NOT_EXISTS = new ErrorCode(1009000001, "流程实例不存在"); + ErrorCode HIGHLIGHT_IMG_ERROR = new ErrorCode(1009000002, "获取高亮流程图异常"); - // ========== OA 流程模块 1-003-001-000 ========== - ErrorCode OA_LEAVE_NOT_EXISTS = new ErrorCode(1003001001, "请假申请不存在"); - ErrorCode OA_PM_POST_NOT_EXISTS = new ErrorCode(1003001002, "项目经理岗位未设置"); - ErrorCode OA_DEPART_PM_POST_NOT_EXISTS = new ErrorCode(1003001003, "部门的项目经理不存在"); - ErrorCode OA_BM_POST_NOT_EXISTS = new ErrorCode(1003001004, "部门经理岗位未设置"); - ErrorCode OA_DEPART_BM_POST_NOT_EXISTS = new ErrorCode(1003001005, "部门的部门经理不存在"); - ErrorCode OA_HR_POST_NOT_EXISTS = new ErrorCode(1003001006, "HR岗位未设置"); - ErrorCode OA_DAY_LEAVE_ERROR = new ErrorCode(1003001007, "请假天数必须>=1"); + // ========== OA 流程模块 1-009-001-000 ========== + ErrorCode OA_LEAVE_NOT_EXISTS = new ErrorCode(1009001001, "请假申请不存在"); + ErrorCode OA_PM_POST_NOT_EXISTS = new ErrorCode(1009001002, "项目经理岗位未设置"); + ErrorCode OA_DEPART_PM_POST_NOT_EXISTS = new ErrorCode(1009001009, "部门的项目经理不存在"); + ErrorCode OA_BM_POST_NOT_EXISTS = new ErrorCode(1009001004, "部门经理岗位未设置"); + ErrorCode OA_DEPART_BM_POST_NOT_EXISTS = new ErrorCode(1009001005, "部门的部门经理不存在"); + ErrorCode OA_HR_POST_NOT_EXISTS = new ErrorCode(1009001006, "HR岗位未设置"); + ErrorCode OA_DAY_LEAVE_ERROR = new ErrorCode(1009001007, "请假天数必须>=1"); + + // ========== OA 工作流模块 1-009-002-000 ========== + ErrorCode BPM_MODEL_KEY_EXISTS = new ErrorCode(1009002000, "已经存在流程标识为【{}】的流程"); - // ========== OA 工作流模块 1-003-002-000 ========== ErrorCode BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS = new ErrorCode(1004001001, "模型数据为空,请先成功设计流程并保存"); ErrorCode BPMN_MODEL_ERROR = new ErrorCode(1004001002, "工作流模型异常"); - ErrorCode BPMN_MODEL_PROCESS_NOT_EXISTS = new ErrorCode(1004001003, "流程数据为空"); + ErrorCode BPMN_MODEL_PROCESS_NOT_EXISTS = new ErrorCode(1004001009, "流程数据为空"); ErrorCode BPMN_PROCESS_DEFINITION_NOT_EXISTS = new ErrorCode(1004001004, "流程定义不存在"); - // ========== 动态表单模块 1-003-003-000 ========== - ErrorCode BPM_FORM_NOT_EXISTS = new ErrorCode(1003003000, "动态表单不存在"); - ErrorCode BPM_FORM_FIELD_REPEAT = new ErrorCode(1003003000, "表单项({}) 和 ({}) 使用了相同的字段名({})"); + // ========== 动态表单模块 1-009-003-000 ========== + ErrorCode BPM_FORM_NOT_EXISTS = new ErrorCode(1009003000, "动态表单不存在"); + ErrorCode BPM_FORM_FIELD_REPEAT = new ErrorCode(1009003000, "表单项({}) 和 ({}) 使用了相同的字段名({})"); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java index a69e7d4f9..c073db628 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java @@ -1,14 +1,18 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.form; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormCreateReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import javax.validation.Valid; import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.Map; /** @@ -56,6 +60,19 @@ public interface BpmFormService { */ List getFormList(Collection ids); + /** + * 获得动态表单 Map + * + * @param ids 编号 + * @return 动态表单 Map + */ + default Map getFormMap(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyMap(); + } + return CollectionUtils.convertMap(this.getFormList(ids), BpmFormDO::getId); + } + /** * 获得动态表单分页 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmModelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java similarity index 87% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmModelService.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java index bfc779852..fc3a3dddf 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmModelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java @@ -1,5 +1,6 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow; +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; @@ -20,7 +21,7 @@ public interface BpmModelService { * @param pageVO 分页查询 * @return 流程定义分页 */ - PageResult getModelPage(ModelPageReqVO pageVO); + PageResult getModelPage(ModelPageReqVO pageVO); // TODO @Li:不用返回 CommonResult // TODO @Li:createBpmModal。 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/dto/BpmModelMetaInfoRespDTO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/dto/BpmModelMetaInfoRespDTO.java new file mode 100644 index 000000000..a3f97002c --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/dto/BpmModelMetaInfoRespDTO.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto; + +import lombok.Data; + +/** + * BPM 流程 MetaInfo Response DTO + * 主要用于 {@link org.activiti.engine.repository.Model#setMetaInfo(String)} 的存储 + * + * @author 芋道源码 + */ +@Data +public class BpmModelMetaInfoRespDTO { + + /** + * 流程描述 + */ + private String description; + /** + * 表单编号 + */ + private Long formId; + +} 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/workflow/impl/BpmModelServiceImpl.java index 1fa220b12..de50cfa03 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/workflow/impl/BpmModelServiceImpl.java @@ -2,13 +2,18 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl; import cn.hutool.core.util.StrUtil; 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.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.workflow.BpmModelService; -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; +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; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.object.PageUtils; import lombok.extern.slf4j.Slf4j; @@ -20,6 +25,7 @@ import org.activiti.engine.repository.Model; import org.activiti.engine.repository.ModelQuery; import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; @@ -30,7 +36,12 @@ 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 static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_MODEL_KEY_EXISTS; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 流程定义实现 @@ -44,9 +55,11 @@ public class BpmModelServiceImpl implements BpmModelService { @Resource private RepositoryService repositoryService; + @Resource + private BpmFormService bpmFormService; @Override - public PageResult getModelPage(ModelPageReqVO pageVO) { + public PageResult getModelPage(ModelPageReqVO pageVO) { ModelQuery modelQuery = repositoryService.createModelQuery(); if (StrUtil.isNotBlank(pageVO.getName())) { modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配 @@ -55,18 +68,29 @@ public class BpmModelServiceImpl implements BpmModelService { List models = modelQuery.orderByCreateTime().desc() .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); long modelCount = modelQuery.count(); - return new PageResult<>(models, modelCount); + + // 获得 Form Map + Set formIds = CollectionUtils.convertSet(models, model -> { + BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); + return metaInfo != null ? metaInfo.getFormId() : null; + }); + Map formMap = bpmFormService.getFormMap(formIds); + // 拼接结果 + return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap), modelCount); } @Override + @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 public String createModel(BpmModelCreateReqVO createReqVO) { - // TODO 芋艿:校验 key 是否重复 + // 校验流程标识已经存在 + Model keyModel = this.getModelByKey(createReqVO.getKey()); + if (keyModel != null) { + throw exception(BPM_MODEL_KEY_EXISTS); + } + // 创建流程定义 Model model = repositoryService.newModel(); - model.setName(createReqVO.getName()); - model.setKey(createReqVO.getKey()); - // TODO 芋艿:metaInfo,description、category、formId - model.setMetaInfo(JsonUtils.toJsonString(createReqVO)); + ModelConvert.INSTANCE.copy(model, createReqVO); // 保存流程定义 repositoryService.saveModel(model); // 添加 BPMN XML @@ -109,11 +133,11 @@ public class BpmModelServiceImpl implements BpmModelService { try { Model modelData = repositoryService.getModel(modelId); if (ObjectUtils.isEmpty(modelData)) { - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); + throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); } byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); if (bytes == null) { - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); + throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); } // 将xml转换为流 // TODO @Li:这里是标准逻辑,看看 hutool 有没工具类提供。如果没有,咱自己封装一个 @@ -124,7 +148,7 @@ public class BpmModelServiceImpl implements BpmModelService { // 流数据转化为 model BpmnModel model = new BpmnXMLConverter().convertToBpmnModel(xtr); if(ObjectUtils.isEmpty(model.getProcesses())){ - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS); + throw exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS); } byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model); // 部署发布模型流程 @@ -137,7 +161,7 @@ public class BpmModelServiceImpl implements BpmModelService { return CommonResult.success(deployment.getId()); } catch (Exception e) { log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e)); - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); + throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); } } @@ -146,7 +170,7 @@ public class BpmModelServiceImpl implements BpmModelService { try { Model modelData = repositoryService.getModel(modelId); if (ObjectUtils.isEmpty(modelData)) { - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); + throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); } byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); FileResp fileResp = new FileResp(); @@ -155,7 +179,7 @@ public class BpmModelServiceImpl implements BpmModelService { return fileResp; } catch (Exception e) { log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e)); - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); + throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); } } @@ -166,4 +190,8 @@ public class BpmModelServiceImpl implements BpmModelService { return CommonResult.success("删除成功"); } + private Model getModelByKey(String key) { + return repositoryService.createModelQuery().modelKey(key).singleResult(); + } + } diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index f8b983b2a..c2d963033 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -1,5 +1,7 @@