Commit dc7a43438041b4ada0caabc2df8ba395823b359e
1 parent
a0c7692c
增加流程定义的 VO
Showing
12 changed files
with
223 additions
and
80 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.bpm.controller.model; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; | |
| 4 | -import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO; | |
| 5 | 3 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService; | |
| 4 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; | |
| 5 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO; | |
| 6 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; | |
| 7 | +import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService; | |
| 7 | 8 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 8 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | 10 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 10 | 11 | import io.swagger.annotations.Api; |
| 11 | 12 | import io.swagger.annotations.ApiOperation; |
| 12 | -import org.activiti.engine.repository.Model; | |
| 13 | 13 | import org.springframework.validation.annotation.Validated; |
| 14 | 14 | import org.springframework.web.bind.annotation.*; |
| 15 | 15 | |
| ... | ... | @@ -32,7 +32,7 @@ public class BpmModelController { |
| 32 | 32 | |
| 33 | 33 | @GetMapping ("/page") |
| 34 | 34 | @ApiOperation(value = "分页数据") |
| 35 | - public CommonResult<PageResult<Model>> getModelPage(ModelPageReqVO pageVO) { | |
| 35 | + public CommonResult<PageResult<BpmModelRespVO>> getModelPage(ModelPageReqVO pageVO) { | |
| 36 | 36 | return success(bpmModelService.getModelPage(pageVO)); |
| 37 | 37 | } |
| 38 | 38 | ... | ... |
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; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | |
| 6 | 6 | import javax.validation.constraints.NotEmpty; |
| 7 | +import javax.validation.constraints.NotNull; | |
| 7 | 8 | |
| 8 | 9 | /** |
| 9 | 10 | * 流程定义 Base VO,提供给添加、修改、详细的子 VO 使用 |
| ... | ... | @@ -12,6 +13,10 @@ import javax.validation.constraints.NotEmpty; |
| 12 | 13 | @Data |
| 13 | 14 | public class BpmModelBaseVO { |
| 14 | 15 | |
| 16 | + @ApiModelProperty(value = "流程标识", required = true, example = "process_yudao") | |
| 17 | + @NotEmpty(message = "流程标识不能为空") | |
| 18 | + private String key; | |
| 19 | + | |
| 15 | 20 | @ApiModelProperty(value = "流程名称", required = true, example = "芋道") |
| 16 | 21 | @NotEmpty(message = "流程名称不能为空") |
| 17 | 22 | private String name; |
| ... | ... | @@ -20,4 +25,12 @@ public class BpmModelBaseVO { |
| 20 | 25 | @NotEmpty(message = "流程描述不能为空") |
| 21 | 26 | private String description; |
| 22 | 27 | |
| 28 | + @ApiModelProperty(value = "流程分类", notes = "参见 bpm_model_category 数据字典", example = "1") | |
| 29 | + @NotEmpty(message = "流程分类不能为空") | |
| 30 | + private String category; | |
| 31 | + | |
| 32 | + @ApiModelProperty(value = "表单编号", example = "1024") | |
| 33 | + @NotNull(message = "表单编号不能为空") | |
| 34 | + private Long formId; | |
| 35 | + | |
| 23 | 36 | } | ... | ... |
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; |
| 14 | 14 | @ToString(callSuper = true) |
| 15 | 15 | public class BpmModelCreateReqVO extends BpmModelBaseVO { |
| 16 | 16 | |
| 17 | - @ApiModelProperty(value = "流程标识", required = true, example = "process_yudao") | |
| 18 | - @NotEmpty(message = "流程标识不能为空") | |
| 19 | - private String key; | |
| 20 | - | |
| 21 | 17 | @ApiModelProperty(value = "BPMN XML", required = true) |
| 22 | 18 | @NotEmpty(message = "BPMN XML 不能为空") |
| 23 | 19 | private String bpmnXml; | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelRespVO.java
| ... | ... | @@ -6,6 +6,8 @@ import lombok.Data; |
| 6 | 6 | import lombok.EqualsAndHashCode; |
| 7 | 7 | import lombok.ToString; |
| 8 | 8 | |
| 9 | +import java.util.Date; | |
| 10 | + | |
| 9 | 11 | @ApiModel("流程定义 Response VO") |
| 10 | 12 | @Data |
| 11 | 13 | @EqualsAndHashCode(callSuper = true) |
| ... | ... | @@ -15,4 +17,13 @@ public class BpmModelRespVO extends BpmModelBaseVO { |
| 15 | 17 | @ApiModelProperty(value = "编号", required = true, example = "1024") |
| 16 | 18 | private String id; |
| 17 | 19 | |
| 20 | + @ApiModelProperty(value = "版本", required = true, example = "1") | |
| 21 | + private Integer revision; | |
| 22 | + | |
| 23 | + @ApiModelProperty(value = "表单名字", example = "请假表单") | |
| 24 | + private String formName; | |
| 25 | + | |
| 26 | + @ApiModelProperty(value = "创建时间", required = true) | |
| 27 | + private Date createTime; | |
| 28 | + | |
| 18 | 29 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/ModelConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.bpm.convert.model; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO; | |
| 4 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; | |
| 5 | +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; | |
| 6 | +import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 8 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 9 | +import org.activiti.engine.impl.persistence.entity.ModelEntity; | |
| 10 | +import org.activiti.engine.repository.Model; | |
| 11 | +import org.mapstruct.Mapper; | |
| 12 | +import org.mapstruct.factory.Mappers; | |
| 13 | + | |
| 14 | +import java.util.List; | |
| 15 | +import java.util.Map; | |
| 16 | + | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * 流程定义 Convert | |
| 20 | + * | |
| 21 | + * @author yunlongn | |
| 22 | + */ | |
| 23 | +@Mapper | |
| 24 | +public interface ModelConvert { | |
| 25 | + | |
| 26 | + ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class); | |
| 27 | + | |
| 28 | + default List<BpmModelRespVO> convertList(List<Model> list, Map<Long, BpmFormDO> formMap) { | |
| 29 | + return CollectionUtils.convertList(list, model -> { | |
| 30 | + BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); | |
| 31 | + BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null; | |
| 32 | + return convert(model, form); | |
| 33 | + }); | |
| 34 | + } | |
| 35 | + | |
| 36 | + default BpmModelRespVO convert(Model model, BpmFormDO form) { | |
| 37 | + BpmModelRespVO modelRespVO = new BpmModelRespVO(); | |
| 38 | + modelRespVO.setId(model.getId()); | |
| 39 | + modelRespVO.setName(model.getName()); | |
| 40 | + modelRespVO.setKey(model.getKey()); | |
| 41 | + modelRespVO.setCategory(model.getCategory()); | |
| 42 | + modelRespVO.setCreateTime(model.getCreateTime()); | |
| 43 | + BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); | |
| 44 | + if (metaInfo != null) { | |
| 45 | + modelRespVO.setDescription(metaInfo.getDescription()); | |
| 46 | + } | |
| 47 | + if (form != null) { | |
| 48 | + modelRespVO.setFormId(form.getId()); | |
| 49 | + modelRespVO.setFormName(form.getName()); | |
| 50 | + } | |
| 51 | + if (model instanceof ModelEntity) { | |
| 52 | + ModelEntity modelEntity = (ModelEntity) model; | |
| 53 | + modelRespVO.setRevision(modelEntity.getRevision()); | |
| 54 | + } | |
| 55 | + return modelRespVO; | |
| 56 | + } | |
| 57 | + | |
| 58 | + default void copy(Model model, BpmModelCreateReqVO bean) { | |
| 59 | + model.setName(bean.getName()); | |
| 60 | + model.setKey(bean.getKey()); | |
| 61 | + model.setCategory(bean.getCategory()); | |
| 62 | + model.setMetaInfo(JsonUtils.toJsonString(this.buildMetaInfo(bean.getDescription(), bean.getFormId()))); | |
| 63 | + } | |
| 64 | + | |
| 65 | + default BpmModelMetaInfoRespDTO buildMetaInfo(String description, Long formId) { | |
| 66 | + BpmModelMetaInfoRespDTO metaInfo = new BpmModelMetaInfoRespDTO(); | |
| 67 | + metaInfo.setDescription(description); | |
| 68 | + metaInfo.setFormId(formId); | |
| 69 | + return metaInfo; | |
| 70 | + } | |
| 71 | + | |
| 72 | +} | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/ModelConvert.java deleted
| 1 | -package cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; | |
| 4 | -import org.activiti.engine.repository.Model; | |
| 5 | -import org.mapstruct.Mapper; | |
| 6 | -import org.mapstruct.factory.Mappers; | |
| 7 | - | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * @author yunlongn | |
| 11 | - */ | |
| 12 | -@Mapper | |
| 13 | -public interface ModelConvert { | |
| 14 | - ModelConvert INSTANCE = Mappers.getMapper(ModelConvert.class); | |
| 15 | - | |
| 16 | - BpmModelRespVO convert(Model model); | |
| 17 | -} |
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; |
| 5 | 5 | /** |
| 6 | 6 | * 工作流 错误码枚举类 |
| 7 | 7 | * |
| 8 | - * 工作流系统,使用 1-003-000-000 段 | |
| 8 | + * 工作流系统,使用 1-009-000-000 段 | |
| 9 | 9 | */ |
| 10 | 10 | public interface BpmErrorCodeConstants { |
| 11 | 11 | |
| 12 | - // ========== 通用流程处理 模块 1-003-000-000 ========== | |
| 13 | - ErrorCode PROCESS_INSTANCE_NOT_EXISTS = new ErrorCode(1003000001, "流程实例不存在"); | |
| 14 | - ErrorCode HIGHLIGHT_IMG_ERROR = new ErrorCode(1003000002, "获取高亮流程图异常"); | |
| 12 | + // ========== 通用流程处理 模块 1-009-000-000 ========== | |
| 13 | + ErrorCode PROCESS_INSTANCE_NOT_EXISTS = new ErrorCode(1009000001, "流程实例不存在"); | |
| 14 | + ErrorCode HIGHLIGHT_IMG_ERROR = new ErrorCode(1009000002, "获取高亮流程图异常"); | |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - // ========== OA 流程模块 1-003-001-000 ========== | |
| 18 | - ErrorCode OA_LEAVE_NOT_EXISTS = new ErrorCode(1003001001, "请假申请不存在"); | |
| 19 | - ErrorCode OA_PM_POST_NOT_EXISTS = new ErrorCode(1003001002, "项目经理岗位未设置"); | |
| 20 | - ErrorCode OA_DEPART_PM_POST_NOT_EXISTS = new ErrorCode(1003001003, "部门的项目经理不存在"); | |
| 21 | - ErrorCode OA_BM_POST_NOT_EXISTS = new ErrorCode(1003001004, "部门经理岗位未设置"); | |
| 22 | - ErrorCode OA_DEPART_BM_POST_NOT_EXISTS = new ErrorCode(1003001005, "部门的部门经理不存在"); | |
| 23 | - ErrorCode OA_HR_POST_NOT_EXISTS = new ErrorCode(1003001006, "HR岗位未设置"); | |
| 24 | - ErrorCode OA_DAY_LEAVE_ERROR = new ErrorCode(1003001007, "请假天数必须>=1"); | |
| 17 | + // ========== OA 流程模块 1-009-001-000 ========== | |
| 18 | + ErrorCode OA_LEAVE_NOT_EXISTS = new ErrorCode(1009001001, "请假申请不存在"); | |
| 19 | + ErrorCode OA_PM_POST_NOT_EXISTS = new ErrorCode(1009001002, "项目经理岗位未设置"); | |
| 20 | + ErrorCode OA_DEPART_PM_POST_NOT_EXISTS = new ErrorCode(1009001009, "部门的项目经理不存在"); | |
| 21 | + ErrorCode OA_BM_POST_NOT_EXISTS = new ErrorCode(1009001004, "部门经理岗位未设置"); | |
| 22 | + ErrorCode OA_DEPART_BM_POST_NOT_EXISTS = new ErrorCode(1009001005, "部门的部门经理不存在"); | |
| 23 | + ErrorCode OA_HR_POST_NOT_EXISTS = new ErrorCode(1009001006, "HR岗位未设置"); | |
| 24 | + ErrorCode OA_DAY_LEAVE_ERROR = new ErrorCode(1009001007, "请假天数必须>=1"); | |
| 25 | + | |
| 26 | + // ========== OA 工作流模块 1-009-002-000 ========== | |
| 27 | + ErrorCode BPM_MODEL_KEY_EXISTS = new ErrorCode(1009002000, "已经存在流程标识为【{}】的流程"); | |
| 25 | 28 | |
| 26 | - // ========== OA 工作流模块 1-003-002-000 ========== | |
| 27 | 29 | ErrorCode BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS = new ErrorCode(1004001001, "模型数据为空,请先成功设计流程并保存"); |
| 28 | 30 | ErrorCode BPMN_MODEL_ERROR = new ErrorCode(1004001002, "工作流模型异常"); |
| 29 | - ErrorCode BPMN_MODEL_PROCESS_NOT_EXISTS = new ErrorCode(1004001003, "流程数据为空"); | |
| 31 | + ErrorCode BPMN_MODEL_PROCESS_NOT_EXISTS = new ErrorCode(1004001009, "流程数据为空"); | |
| 30 | 32 | ErrorCode BPMN_PROCESS_DEFINITION_NOT_EXISTS = new ErrorCode(1004001004, "流程定义不存在"); |
| 31 | 33 | |
| 32 | - // ========== 动态表单模块 1-003-003-000 ========== | |
| 33 | - ErrorCode BPM_FORM_NOT_EXISTS = new ErrorCode(1003003000, "动态表单不存在"); | |
| 34 | - ErrorCode BPM_FORM_FIELD_REPEAT = new ErrorCode(1003003000, "表单项({}) 和 ({}) 使用了相同的字段名({})"); | |
| 34 | + // ========== 动态表单模块 1-009-003-000 ========== | |
| 35 | + ErrorCode BPM_FORM_NOT_EXISTS = new ErrorCode(1009003000, "动态表单不存在"); | |
| 36 | + ErrorCode BPM_FORM_FIELD_REPEAT = new ErrorCode(1009003000, "表单项({}) 和 ({}) 使用了相同的字段名({})"); | |
| 35 | 37 | |
| 36 | 38 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.bpm.service.form; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormCreateReqVO; |
| 4 | 5 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormPageReqVO; |
| 5 | 6 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormUpdateReqVO; |
| 6 | 7 | import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; |
| 7 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 8 | 10 | |
| 9 | 11 | import javax.validation.Valid; |
| 10 | 12 | import java.util.Collection; |
| 13 | +import java.util.Collections; | |
| 11 | 14 | import java.util.List; |
| 15 | +import java.util.Map; | |
| 12 | 16 | |
| 13 | 17 | |
| 14 | 18 | /** |
| ... | ... | @@ -57,6 +61,19 @@ public interface BpmFormService { |
| 57 | 61 | List<BpmFormDO> getFormList(Collection<Long> ids); |
| 58 | 62 | |
| 59 | 63 | /** |
| 64 | + * 获得动态表单 Map | |
| 65 | + * | |
| 66 | + * @param ids 编号 | |
| 67 | + * @return 动态表单 Map | |
| 68 | + */ | |
| 69 | + default Map<Long, BpmFormDO> getFormMap(Collection<Long> ids) { | |
| 70 | + if (CollUtil.isEmpty(ids)) { | |
| 71 | + return Collections.emptyMap(); | |
| 72 | + } | |
| 73 | + return CollectionUtils.convertMap(this.getFormList(ids), BpmFormDO::getId); | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 60 | 77 | * 获得动态表单分页 |
| 61 | 78 | * |
| 62 | 79 | * @param pageReqVO 分页查询 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmModelService.java renamed to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow; | |
| 1 | +package cn.iocoder.yudao.adminserver.modules.bpm.service.model; | |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; | |
| 3 | 4 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; |
| 4 | 5 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO; |
| 5 | 6 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO; |
| ... | ... | @@ -20,7 +21,7 @@ public interface BpmModelService { |
| 20 | 21 | * @param pageVO 分页查询 |
| 21 | 22 | * @return 流程定义分页 |
| 22 | 23 | */ |
| 23 | - PageResult<Model> getModelPage(ModelPageReqVO pageVO); | |
| 24 | + PageResult<BpmModelRespVO> getModelPage(ModelPageReqVO pageVO); | |
| 24 | 25 | |
| 25 | 26 | // TODO @Li:不用返回 CommonResult |
| 26 | 27 | // TODO @Li:createBpmModal。 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/dto/BpmModelMetaInfoRespDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * BPM 流程 MetaInfo Response DTO | |
| 7 | + * 主要用于 {@link org.activiti.engine.repository.Model#setMetaInfo(String)} 的存储 | |
| 8 | + * | |
| 9 | + * @author 芋道源码 | |
| 10 | + */ | |
| 11 | +@Data | |
| 12 | +public class BpmModelMetaInfoRespDTO { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 流程描述 | |
| 16 | + */ | |
| 17 | + private String description; | |
| 18 | + /** | |
| 19 | + * 表单编号 | |
| 20 | + */ | |
| 21 | + private Long formId; | |
| 22 | + | |
| 23 | +} | ... | ... |
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; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | 4 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO; |
| 5 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO; | |
| 5 | 6 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO; |
| 6 | 7 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; |
| 8 | +import cn.iocoder.yudao.adminserver.modules.bpm.convert.model.ModelConvert; | |
| 9 | +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; | |
| 7 | 10 | import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants; |
| 8 | -import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService; | |
| 9 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | |
| 11 | +import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService; | |
| 12 | +import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService; | |
| 13 | +import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; | |
| 10 | 14 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 11 | 15 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 16 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 12 | 17 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 13 | 18 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; |
| 14 | 19 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -20,6 +25,7 @@ import org.activiti.engine.repository.Model; |
| 20 | 25 | import org.activiti.engine.repository.ModelQuery; |
| 21 | 26 | import org.apache.commons.lang3.exception.ExceptionUtils; |
| 22 | 27 | import org.springframework.stereotype.Service; |
| 28 | +import org.springframework.transaction.annotation.Transactional; | |
| 23 | 29 | import org.springframework.util.ObjectUtils; |
| 24 | 30 | import org.springframework.validation.annotation.Validated; |
| 25 | 31 | |
| ... | ... | @@ -30,7 +36,12 @@ import java.io.ByteArrayInputStream; |
| 30 | 36 | import java.io.InputStreamReader; |
| 31 | 37 | import java.nio.charset.StandardCharsets; |
| 32 | 38 | import java.util.List; |
| 39 | +import java.util.Map; | |
| 33 | 40 | import java.util.Optional; |
| 41 | +import java.util.Set; | |
| 42 | + | |
| 43 | +import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_MODEL_KEY_EXISTS; | |
| 44 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 34 | 45 | |
| 35 | 46 | /** |
| 36 | 47 | * 流程定义实现 |
| ... | ... | @@ -44,9 +55,11 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 44 | 55 | |
| 45 | 56 | @Resource |
| 46 | 57 | private RepositoryService repositoryService; |
| 58 | + @Resource | |
| 59 | + private BpmFormService bpmFormService; | |
| 47 | 60 | |
| 48 | 61 | @Override |
| 49 | - public PageResult<Model> getModelPage(ModelPageReqVO pageVO) { | |
| 62 | + public PageResult<BpmModelRespVO> getModelPage(ModelPageReqVO pageVO) { | |
| 50 | 63 | ModelQuery modelQuery = repositoryService.createModelQuery(); |
| 51 | 64 | if (StrUtil.isNotBlank(pageVO.getName())) { |
| 52 | 65 | modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配 |
| ... | ... | @@ -55,18 +68,29 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 55 | 68 | List<Model> models = modelQuery.orderByCreateTime().desc() |
| 56 | 69 | .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); |
| 57 | 70 | long modelCount = modelQuery.count(); |
| 58 | - return new PageResult<>(models, modelCount); | |
| 71 | + | |
| 72 | + // 获得 Form Map | |
| 73 | + Set<Long> formIds = CollectionUtils.convertSet(models, model -> { | |
| 74 | + BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); | |
| 75 | + return metaInfo != null ? metaInfo.getFormId() : null; | |
| 76 | + }); | |
| 77 | + Map<Long, BpmFormDO> formMap = bpmFormService.getFormMap(formIds); | |
| 78 | + // 拼接结果 | |
| 79 | + return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap), modelCount); | |
| 59 | 80 | } |
| 60 | 81 | |
| 61 | 82 | @Override |
| 83 | + @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 | |
| 62 | 84 | public String createModel(BpmModelCreateReqVO createReqVO) { |
| 63 | - // TODO 芋艿:校验 key 是否重复 | |
| 85 | + // 校验流程标识已经存在 | |
| 86 | + Model keyModel = this.getModelByKey(createReqVO.getKey()); | |
| 87 | + if (keyModel != null) { | |
| 88 | + throw exception(BPM_MODEL_KEY_EXISTS); | |
| 89 | + } | |
| 90 | + | |
| 64 | 91 | // 创建流程定义 |
| 65 | 92 | Model model = repositoryService.newModel(); |
| 66 | - model.setName(createReqVO.getName()); | |
| 67 | - model.setKey(createReqVO.getKey()); | |
| 68 | - // TODO 芋艿:metaInfo,description、category、formId | |
| 69 | - model.setMetaInfo(JsonUtils.toJsonString(createReqVO)); | |
| 93 | + ModelConvert.INSTANCE.copy(model, createReqVO); | |
| 70 | 94 | // 保存流程定义 |
| 71 | 95 | repositoryService.saveModel(model); |
| 72 | 96 | // 添加 BPMN XML |
| ... | ... | @@ -109,11 +133,11 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 109 | 133 | try { |
| 110 | 134 | Model modelData = repositoryService.getModel(modelId); |
| 111 | 135 | if (ObjectUtils.isEmpty(modelData)) { |
| 112 | - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); | |
| 136 | + throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); | |
| 113 | 137 | } |
| 114 | 138 | byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); |
| 115 | 139 | if (bytes == null) { |
| 116 | - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); | |
| 140 | + throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); | |
| 117 | 141 | } |
| 118 | 142 | // 将xml转换为流 |
| 119 | 143 | // TODO @Li:这里是标准逻辑,看看 hutool 有没工具类提供。如果没有,咱自己封装一个 |
| ... | ... | @@ -124,7 +148,7 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 124 | 148 | // 流数据转化为 model |
| 125 | 149 | BpmnModel model = new BpmnXMLConverter().convertToBpmnModel(xtr); |
| 126 | 150 | if(ObjectUtils.isEmpty(model.getProcesses())){ |
| 127 | - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS); | |
| 151 | + throw exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS); | |
| 128 | 152 | } |
| 129 | 153 | byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model); |
| 130 | 154 | // 部署发布模型流程 |
| ... | ... | @@ -137,7 +161,7 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 137 | 161 | return CommonResult.success(deployment.getId()); |
| 138 | 162 | } catch (Exception e) { |
| 139 | 163 | log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e)); |
| 140 | - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); | |
| 164 | + throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); | |
| 141 | 165 | } |
| 142 | 166 | } |
| 143 | 167 | |
| ... | ... | @@ -146,7 +170,7 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 146 | 170 | try { |
| 147 | 171 | Model modelData = repositoryService.getModel(modelId); |
| 148 | 172 | if (ObjectUtils.isEmpty(modelData)) { |
| 149 | - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); | |
| 173 | + throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); | |
| 150 | 174 | } |
| 151 | 175 | byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); |
| 152 | 176 | FileResp fileResp = new FileResp(); |
| ... | ... | @@ -155,7 +179,7 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 155 | 179 | return fileResp; |
| 156 | 180 | } catch (Exception e) { |
| 157 | 181 | log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e)); |
| 158 | - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); | |
| 182 | + throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); | |
| 159 | 183 | } |
| 160 | 184 | } |
| 161 | 185 | |
| ... | ... | @@ -166,4 +190,8 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 166 | 190 | return CommonResult.success("删除成功"); |
| 167 | 191 | } |
| 168 | 192 | |
| 193 | + private Model getModelByKey(String key) { | |
| 194 | + return repositoryService.createModelQuery().modelKey(key).singleResult(); | |
| 195 | + } | |
| 196 | + | |
| 169 | 197 | } | ... | ... |
yudao-admin-ui/src/views/bpm/model/index.vue
| 1 | 1 | <template> |
| 2 | 2 | <div class="app-container"> |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 3 | 5 | <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> |
| 4 | 6 | <el-form-item label="模型名字" prop="name"> |
| 5 | 7 | <el-input v-model="queryParams.name" placeholder="请输入模型名字" clearable style="width: 240px;" size="small" |
| ... | ... | @@ -10,36 +12,31 @@ |
| 10 | 12 | <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> |
| 11 | 13 | </el-form-item> |
| 12 | 14 | </el-form> |
| 15 | + | |
| 16 | + <!-- 操作工具栏 --> | |
| 13 | 17 | <el-row :gutter="10" class="mb8"> |
| 14 | 18 | <el-col :span="1.5"> |
| 15 | - <el-button | |
| 16 | - type="primary" | |
| 17 | - icon="el-icon-plus" | |
| 18 | - size="mini" | |
| 19 | - @click="openBpmn" | |
| 20 | - v-hasPermi="['infra:config:create']" | |
| 21 | - >新建流程</el-button> | |
| 19 | + <el-button type="primary" icon="el-icon-plus" size="mini" @click="openBpmn" | |
| 20 | + v-hasPermi="['infra:config:create']">新建流程</el-button> | |
| 22 | 21 | </el-col> |
| 23 | 22 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 24 | 23 | </el-row> |
| 24 | + | |
| 25 | + <!-- 列表 --> | |
| 25 | 26 | <el-table v-loading="loading" :data="list"> |
| 26 | - <el-table-column label="ID" align="center" prop="id" /> | |
| 27 | - <el-table-column label="name" align="center" prop="metaInfo" > | |
| 28 | - <template slot-scope="scope"> | |
| 29 | - <span>{{ scope.row.metaInfo ? JSON.parse(scope.row.metaInfo).name : "" }}</span> | |
| 30 | - </template> | |
| 31 | - </el-table-column> | |
| 32 | - <el-table-column label="description" align="center" prop="metaInfo" > | |
| 33 | - <template slot-scope="scope"> | |
| 34 | - <span>{{ JSON.parse(scope.row.metaInfo).description }}</span> | |
| 35 | - </template> | |
| 36 | - </el-table-column> | |
| 37 | - <el-table-column label="创建时间" align="center" prop="createTime" > | |
| 27 | + <el-table-column label="流程编号" align="center" prop="id" :show-overflow-tooltip="true" /> | |
| 28 | + <el-table-column label="流程标识" align="center" prop="key" /> | |
| 29 | + <el-table-column label="流程名称" align="center" prop="name" /> | |
| 30 | + <el-table-column label="流程分类" align="center" prop="category" /> | |
| 31 | + <el-table-column label="表单信息" align="center" prop="formName" /> | |
| 32 | + <el-table-column label="流程版本" align="center" prop="revision" /> | |
| 33 | + <el-table-column label="状态" align="center" prop="rversion" /> | |
| 34 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 38 | 35 | <template slot-scope="scope"> |
| 39 | 36 | <span>{{ parseTime(scope.row.createTime) }}</span> |
| 40 | 37 | </template> |
| 41 | 38 | </el-table-column> |
| 42 | - <el-table-column label="操作" align="center" > | |
| 39 | + <el-table-column label="操作" align="center" width="240"> | |
| 43 | 40 | <template slot-scope="scope"> |
| 44 | 41 | <el-button size="mini" type="text" icon="el-icon-setting" @click="change(scope.row)">设计流程</el-button> |
| 45 | 42 | <el-button size="mini" type="text" icon="el-icon-delete" @click="modelDelete(scope.row)">删除</el-button> | ... | ... |