Commit a207412e8cdabe8a04eb517896f484d12d07adef
1 parent
9c452ee6
工作流 Flowable 流程模型接口 部分实现
Showing
5 changed files
with
180 additions
and
35 deletions
yudao-module-bpm/yudao-module-bpm-base/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelCommonService.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.service.definition; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageItemRespVO; | |
| 5 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO; | |
| 4 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; | |
| 5 | + | |
| 6 | +import javax.validation.Valid; | |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * 流程模型通用接口 |
| ... | ... | @@ -19,4 +20,28 @@ public interface BpmModelCommonService { |
| 19 | 20 | * @return 流程模型分页 |
| 20 | 21 | */ |
| 21 | 22 | PageResult<BpmModelPageItemRespVO> getModelPage(BpmModelPageReqVO pageVO); |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 创建流程模型 | |
| 26 | + * | |
| 27 | + * @param modelVO 创建信息 | |
| 28 | + * @param bpmnXml BPMN XML | |
| 29 | + * @return 创建的流程模型的编号 | |
| 30 | + */ | |
| 31 | + String createModel(@Valid BpmModelCreateReqVO modelVO, String bpmnXml); | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * 获得流程模块 | |
| 35 | + * | |
| 36 | + * @param id 编号 | |
| 37 | + * @return 流程模型 | |
| 38 | + */ | |
| 39 | + BpmModelRespVO getModel(String id); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 修改流程模型 | |
| 43 | + * | |
| 44 | + * @param updateReqVO 更新信息 | |
| 45 | + */ | |
| 46 | + void updateModel(@Valid BpmModelUpdateReqVO updateReqVO); | |
| 22 | 47 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-activiti/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelService.java
| ... | ... | @@ -13,29 +13,6 @@ import javax.validation.Valid; |
| 13 | 13 | */ |
| 14 | 14 | public interface BpmModelService extends BpmModelCommonService { |
| 15 | 15 | |
| 16 | - /** | |
| 17 | - * 获得流程模块 | |
| 18 | - * | |
| 19 | - * @param id 编号 | |
| 20 | - * @return 流程模型 | |
| 21 | - */ | |
| 22 | - BpmModelRespVO getModel(String id); | |
| 23 | - | |
| 24 | - /** | |
| 25 | - * 创建流程模型 | |
| 26 | - * | |
| 27 | - * @param modelVO 创建信息 | |
| 28 | - * @param bpmnXml BPMN XML | |
| 29 | - * @return 创建的流程模型的编号 | |
| 30 | - */ | |
| 31 | - String createModel(@Valid BpmModelCreateReqVO modelVO, String bpmnXml); | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * 修改流程模型 | |
| 35 | - * | |
| 36 | - * @param updateReqVO 更新信息 | |
| 37 | - */ | |
| 38 | - void updateModel(@Valid BpmModelUpdateReqVO updateReqVO); | |
| 39 | 16 | |
| 40 | 17 | /** |
| 41 | 18 | * 将流程模型,部署成一个流程定义 | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/FlowableModelController.java
| ... | ... | @@ -2,17 +2,21 @@ package cn.iocoder.yudao.module.bpm.controller.admin.definition; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageItemRespVO; | |
| 6 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.io.IoUtils; | |
| 6 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; | |
| 7 | +import cn.iocoder.yudao.module.bpm.convert.definition.ModelConvert; | |
| 7 | 8 | import cn.iocoder.yudao.module.bpm.service.definition.FlowableModelService; |
| 8 | 9 | import io.swagger.annotations.Api; |
| 10 | +import io.swagger.annotations.ApiImplicitParam; | |
| 9 | 11 | import io.swagger.annotations.ApiOperation; |
| 12 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 10 | 13 | import org.springframework.validation.annotation.Validated; |
| 11 | -import org.springframework.web.bind.annotation.GetMapping; | |
| 12 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 13 | -import org.springframework.web.bind.annotation.RestController; | |
| 14 | +import org.springframework.web.bind.annotation.*; | |
| 14 | 15 | |
| 15 | 16 | import javax.annotation.Resource; |
| 17 | +import javax.validation.Valid; | |
| 18 | + | |
| 19 | +import java.io.IOException; | |
| 16 | 20 | |
| 17 | 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 18 | 22 | |
| ... | ... | @@ -30,4 +34,37 @@ public class FlowableModelController { |
| 30 | 34 | public CommonResult<PageResult<BpmModelPageItemRespVO>> getModelPage(BpmModelPageReqVO pageVO) { |
| 31 | 35 | return success(modelService.getModelPage(pageVO)); |
| 32 | 36 | } |
| 37 | + | |
| 38 | + @GetMapping("/get") | |
| 39 | + @ApiOperation("获得模型") | |
| 40 | + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class) | |
| 41 | + @PreAuthorize("@ss.hasPermission('bpm:model:query')") | |
| 42 | + public CommonResult<BpmModelRespVO> getModel(@RequestParam("id") String id) { | |
| 43 | + BpmModelRespVO model = modelService.getModel(id); | |
| 44 | + return success(model); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @PostMapping("/create") | |
| 48 | + @ApiOperation(value = "新建模型") | |
| 49 | + @PreAuthorize("@ss.hasPermission('bpm:model:create')") | |
| 50 | + public CommonResult<String> createModel(@Valid @RequestBody BpmModelCreateReqVO createRetVO) { | |
| 51 | + return success(modelService.createModel(createRetVO, null)); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @PutMapping("/update") | |
| 55 | + @ApiOperation(value = "修改模型") | |
| 56 | + @PreAuthorize("@ss.hasPermission('bpm:model:update')") | |
| 57 | + public CommonResult<Boolean> updateModel(@Valid @RequestBody BpmModelUpdateReqVO modelVO) { | |
| 58 | + modelService.updateModel(modelVO); | |
| 59 | + return success(true); | |
| 60 | + } | |
| 61 | + | |
| 62 | + @PostMapping("/import") | |
| 63 | + @ApiOperation(value = "导入模型") | |
| 64 | + public CommonResult<String> importModel(@Valid BpmModeImportReqVO importReqVO) throws IOException { | |
| 65 | + BpmModelCreateReqVO createReqVO = ModelConvert.INSTANCE.convert(importReqVO); | |
| 66 | + // 读取文件 | |
| 67 | + String bpmnXml = IoUtils.readUtf8(importReqVO.getBpmnFile().getInputStream(), false); | |
| 68 | + return success(modelService.createModel(createReqVO, bpmnXml)); | |
| 69 | + } | |
| 33 | 70 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/convert/definition/ModelConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.convert.definition; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.StrUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 5 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelBaseVO; | |
| 6 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageItemRespVO; | |
| 7 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO; | |
| 6 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; | |
| 8 | 7 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| 9 | 8 | import cn.iocoder.yudao.module.bpm.service.definition.dto.ModelMetaInfoRespDTO; |
| 10 | 9 | import org.flowable.common.engine.impl.db.SuspensionState; |
| ... | ... | @@ -17,6 +16,7 @@ import org.mapstruct.factory.Mappers; |
| 17 | 16 | |
| 18 | 17 | import java.util.List; |
| 19 | 18 | import java.util.Map; |
| 19 | +import java.util.Objects; | |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * 流程模型 Convert |
| ... | ... | @@ -78,8 +78,42 @@ public interface ModelConvert { |
| 78 | 78 | ModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), ModelMetaInfoRespDTO.class); |
| 79 | 79 | copyTo(metaInfo, to); |
| 80 | 80 | } |
| 81 | + BpmModelCreateReqVO convert(BpmModeImportReqVO bean); | |
| 81 | 82 | |
| 82 | 83 | void copyTo(ModelMetaInfoRespDTO from, @MappingTarget BpmModelBaseVO to); |
| 83 | 84 | |
| 84 | 85 | BpmModelPageItemRespVO.ProcessDefinition convert(ProcessDefinition bean); |
| 86 | + | |
| 87 | + default void copy(Model model, BpmModelCreateReqVO bean) { | |
| 88 | + model.setName(bean.getName()); | |
| 89 | + model.setKey(bean.getKey()); | |
| 90 | + model.setMetaInfo(buildMetaInfoStr(null, bean.getDescription(), null, null, | |
| 91 | + null, null)); | |
| 92 | + } | |
| 93 | + | |
| 94 | + default void copy(Model model, BpmModelUpdateReqVO bean) { | |
| 95 | + model.setName(bean.getName()); | |
| 96 | + model.setCategory(bean.getCategory()); | |
| 97 | + model.setMetaInfo(buildMetaInfoStr(JsonUtils.parseObject(model.getMetaInfo(), ModelMetaInfoRespDTO.class), | |
| 98 | + bean.getDescription(), bean.getFormType(), bean.getFormId(), | |
| 99 | + bean.getFormCustomCreatePath(), bean.getFormCustomViewPath())); | |
| 100 | + } | |
| 101 | + | |
| 102 | + default String buildMetaInfoStr(ModelMetaInfoRespDTO metaInfo, String description, Integer formType, | |
| 103 | + Long formId, String formCustomCreatePath, String formCustomViewPath) { | |
| 104 | + if (metaInfo == null) { | |
| 105 | + metaInfo = new ModelMetaInfoRespDTO(); | |
| 106 | + } | |
| 107 | + // 只有非空,才进行设置,避免更新时的覆盖 | |
| 108 | + if (StrUtil.isNotEmpty(description)) { | |
| 109 | + metaInfo.setDescription(description); | |
| 110 | + } | |
| 111 | + if (Objects.nonNull(formType)) { | |
| 112 | + metaInfo.setFormType(formType); | |
| 113 | + metaInfo.setFormId(formId); | |
| 114 | + metaInfo.setFormCustomCreatePath(formCustomCreatePath); | |
| 115 | + metaInfo.setFormCustomViewPath(formCustomViewPath); | |
| 116 | + } | |
| 117 | + return JsonUtils.toJsonString(metaInfo); | |
| 118 | + } | |
| 85 | 119 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/FlowableModelServiceImpl.java
| ... | ... | @@ -5,8 +5,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; |
| 8 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageItemRespVO; | |
| 9 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO; | |
| 8 | +import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; | |
| 9 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; | |
| 10 | 10 | import cn.iocoder.yudao.module.bpm.convert.definition.ModelConvert; |
| 11 | 11 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| 12 | 12 | import cn.iocoder.yudao.module.bpm.service.definition.dto.ModelMetaInfoRespDTO; |
| ... | ... | @@ -17,21 +17,27 @@ import org.flowable.engine.repository.Model; |
| 17 | 17 | import org.flowable.engine.repository.ModelQuery; |
| 18 | 18 | import org.flowable.engine.repository.ProcessDefinition; |
| 19 | 19 | import org.springframework.stereotype.Service; |
| 20 | +import org.springframework.transaction.annotation.Transactional; | |
| 20 | 21 | import org.springframework.validation.annotation.Validated; |
| 21 | 22 | |
| 22 | 23 | import javax.annotation.Resource; |
| 24 | +import javax.validation.Valid; | |
| 23 | 25 | import java.util.HashSet; |
| 24 | 26 | import java.util.List; |
| 25 | 27 | import java.util.Map; |
| 26 | 28 | import java.util.Set; |
| 27 | 29 | |
| 30 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 28 | 31 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| 32 | +import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; | |
| 33 | + | |
| 29 | 34 | /** |
| 30 | 35 | * Flowable流程模型实现 |
| 31 | 36 | * 主要进行 Flowable {@link Model} 的维护 |
| 32 | 37 | * |
| 33 | 38 | * @author yunlongn |
| 34 | 39 | * @author 芋道源码 |
| 40 | + * @author jason | |
| 35 | 41 | */ |
| 36 | 42 | @Service |
| 37 | 43 | @Validated |
| ... | ... | @@ -80,4 +86,70 @@ public class FlowableModelServiceImpl implements FlowableModelService { |
| 80 | 86 | long modelCount = modelQuery.count(); |
| 81 | 87 | return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap, deploymentMap, processDefinitionMap), modelCount); |
| 82 | 88 | } |
| 89 | + | |
| 90 | + @Override | |
| 91 | + @Transactional(rollbackFor = Exception.class) | |
| 92 | + public String createModel(@Valid BpmModelCreateReqVO createReqVO, String bpmnXml) { | |
| 93 | + checkKeyNCName(createReqVO.getKey()); | |
| 94 | + // 校验流程标识已经存在 | |
| 95 | + Model keyModel = this.getModelByKey(createReqVO.getKey()); | |
| 96 | + if (keyModel != null) { | |
| 97 | + throw exception(MODEL_KEY_EXISTS, createReqVO.getKey()); | |
| 98 | + } | |
| 99 | + | |
| 100 | + // 创建流程定义 | |
| 101 | + Model model = repositoryService.newModel(); | |
| 102 | + ModelConvert.INSTANCE.copy(model, createReqVO); | |
| 103 | + // 保存流程定义 | |
| 104 | + repositoryService.saveModel(model); | |
| 105 | + // 保存 BPMN XML | |
| 106 | + saveModelBpmnXml(model, bpmnXml); | |
| 107 | + return model.getId(); | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + public BpmModelRespVO getModel(String id) { | |
| 112 | + Model model = repositoryService.getModel(id); | |
| 113 | + if (model == null) { | |
| 114 | + return null; | |
| 115 | + } | |
| 116 | + BpmModelRespVO modelRespVO = ModelConvert.INSTANCE.convert(model); | |
| 117 | + // 拼接 bpmn XML | |
| 118 | + byte[] bpmnBytes = repositoryService.getModelEditorSource(id); | |
| 119 | + modelRespVO.setBpmnXml(StrUtil.utf8Str(bpmnBytes)); | |
| 120 | + return modelRespVO; | |
| 121 | + } | |
| 122 | + | |
| 123 | + @Override | |
| 124 | + public void updateModel(@Valid BpmModelUpdateReqVO updateReqVO) { | |
| 125 | + // 校验流程模型存在 | |
| 126 | + Model model = repositoryService.getModel(updateReqVO.getId()); | |
| 127 | + if (model == null) { | |
| 128 | + throw exception(MODEL_NOT_EXISTS); | |
| 129 | + } | |
| 130 | + | |
| 131 | + // 修改流程定义 | |
| 132 | + ModelConvert.INSTANCE.copy(model, updateReqVO); | |
| 133 | + // 更新模型 | |
| 134 | + repositoryService.saveModel(model); | |
| 135 | + // 更新 BPMN XML | |
| 136 | + saveModelBpmnXml(model, updateReqVO.getBpmnXml()); | |
| 137 | + } | |
| 138 | + | |
| 139 | + private Model getModelByKey(String key) { | |
| 140 | + return repositoryService.createModelQuery().modelKey(key).singleResult(); | |
| 141 | + } | |
| 142 | + | |
| 143 | + private void checkKeyNCName(String key) { | |
| 144 | + if (!ValidationUtils.isXmlNCName(key)) { | |
| 145 | + throw exception(MODEL_KEY_VALID); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + | |
| 149 | + private void saveModelBpmnXml(Model model, String bpmnXml) { | |
| 150 | + if (StrUtil.isEmpty(bpmnXml)) { | |
| 151 | + return; | |
| 152 | + } | |
| 153 | + repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(bpmnXml)); | |
| 154 | + } | |
| 83 | 155 | } | ... | ... |