Commit 526af905defea3cf446b9426af8a9fc13b9dd2ef
Committed by
Gitee
!1572 feat(bpm):新增流程模型操作导出模型json接口
Merge pull request !1572 from nnzb/bpm
Showing
4 changed files
with
92 additions
and
0 deletions
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmModelController.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.controller.admin.definition; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 5 | 7 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; |
| 6 | 8 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 7 | 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO; |
| ... | ... | @@ -18,6 +20,7 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 18 | 20 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 19 | 21 | import io.swagger.v3.oas.annotations.Operation; |
| 20 | 22 | import io.swagger.v3.oas.annotations.Parameter; |
| 23 | +import io.swagger.v3.oas.annotations.Parameters; | |
| 21 | 24 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 22 | 25 | import jakarta.annotation.Resource; |
| 23 | 26 | import jakarta.validation.Valid; |
| ... | ... | @@ -27,7 +30,9 @@ import org.flowable.engine.repository.ProcessDefinition; |
| 27 | 30 | import org.springframework.security.access.prepost.PreAuthorize; |
| 28 | 31 | import org.springframework.validation.annotation.Validated; |
| 29 | 32 | import org.springframework.web.bind.annotation.*; |
| 33 | +import org.springframework.web.multipart.MultipartFile; | |
| 30 | 34 | |
| 35 | +import java.io.IOException; | |
| 31 | 36 | import java.util.Collections; |
| 32 | 37 | import java.util.List; |
| 33 | 38 | import java.util.Map; |
| ... | ... | @@ -112,6 +117,14 @@ public class BpmModelController { |
| 112 | 117 | return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes, simpleModel)); |
| 113 | 118 | } |
| 114 | 119 | |
| 120 | + @GetMapping("/export") | |
| 121 | + @Operation(summary = "导出模型") | |
| 122 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 123 | + @PreAuthorize("@ss.hasPermission('bpm:model:export')") | |
| 124 | + public CommonResult<BpmModelSaveReqVO> exportModel(@RequestParam("id") String id) { | |
| 125 | + return success(modelService.exportModel(id)); | |
| 126 | + } | |
| 127 | + | |
| 115 | 128 | @PostMapping("/create") |
| 116 | 129 | @Operation(summary = "新建模型") |
| 117 | 130 | @PreAuthorize("@ss.hasPermission('bpm:model:create')") |
| ... | ... | @@ -119,6 +132,28 @@ public class BpmModelController { |
| 119 | 132 | return success(modelService.createModel(createRetVO)); |
| 120 | 133 | } |
| 121 | 134 | |
| 135 | + @PostMapping("/import") | |
| 136 | + @Operation(summary = "导入模型") | |
| 137 | + @Parameters({ | |
| 138 | + @Parameter(name = "file", description = "流程模型 JSON 文件", required = true), | |
| 139 | + @Parameter(name = "key", description = "流程标识,替换导入文件中的标识", example = "process_yudao"), | |
| 140 | + @Parameter(name = "name", description = "流程名称,替换导入文件中的名称", example = "芋道") | |
| 141 | + }) | |
| 142 | + @PreAuthorize("@ss.hasPermission('bpm:model:import')") | |
| 143 | + public CommonResult<String> importModel(@RequestParam("file") MultipartFile file, | |
| 144 | + @RequestParam(value = "key", required = false) String key, | |
| 145 | + @RequestParam(value = "name", required = false) String name) throws IOException | |
| 146 | + { | |
| 147 | + BpmModelSaveReqVO reqVO = JsonUtils.parseObject(file.getBytes(), BpmModelSaveReqVO.class); | |
| 148 | + if (StrUtil.isNotEmpty(key)) { | |
| 149 | + reqVO.setKey(key); | |
| 150 | + } | |
| 151 | + if (StrUtil.isNotEmpty(name)) { | |
| 152 | + reqVO.setName(name); | |
| 153 | + } | |
| 154 | + return success(modelService.importModel(reqVO)); | |
| 155 | + } | |
| 156 | + | |
| 122 | 157 | @PutMapping("/update") |
| 123 | 158 | @Operation(summary = "修改模型") |
| 124 | 159 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") | ... | ... |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/convert/definition/BpmModelConvert.java
| ... | ... | @@ -111,6 +111,18 @@ public interface BpmModelConvert { |
| 111 | 111 | model.setMetaInfo(JsonUtils.toJsonString(BeanUtils.toBean(reqVO, BpmModelMetaInfoVO.class))); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | + default BpmModelSaveReqVO convertToSaveReqVO(Model model) { | |
| 115 | + BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); | |
| 116 | + BpmModelSaveReqVO reqVO = new BpmModelSaveReqVO(); | |
| 117 | + reqVO.setKey(model.getKey()); | |
| 118 | + reqVO.setName(model.getName()); | |
| 119 | + reqVO.setCategory(model.getCategory()); | |
| 120 | + if (metaInfo != null) { | |
| 121 | + BeanUtils.copyProperties(metaInfo, reqVO); | |
| 122 | + } | |
| 123 | + return reqVO; | |
| 124 | + } | |
| 125 | + | |
| 114 | 126 | default BpmModelMetaInfoVO parseMetaInfo(Model model) { |
| 115 | 127 | BpmModelMetaInfoVO vo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class); |
| 116 | 128 | if (vo == null) { | ... | ... |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelService.java
| ... | ... | @@ -41,6 +41,22 @@ public interface BpmModelService { |
| 41 | 41 | String createModel(@Valid BpmModelSaveReqVO modelVO); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | + * 导入流程模型 | |
| 45 | + * | |
| 46 | + * @param reqVO 导入信息 | |
| 47 | + * @return 创建的流程模型的编号 | |
| 48 | + */ | |
| 49 | + String importModel(@Valid BpmModelSaveReqVO reqVO); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * 导出流程模型 | |
| 53 | + * | |
| 54 | + * @param id 编号 | |
| 55 | + * @return 导出的流程模型 | |
| 56 | + */ | |
| 57 | + BpmModelSaveReqVO exportModel(String id); | |
| 58 | + | |
| 59 | + /** | |
| 44 | 60 | * 获得流程模块 |
| 45 | 61 | * |
| 46 | 62 | * @param id 编号 | ... | ... |
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
| ... | ... | @@ -120,6 +120,35 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | @Override |
| 123 | + @Transactional(rollbackFor = Exception.class) | |
| 124 | + public String importModel(@Valid BpmModelSaveReqVO reqVO) { | |
| 125 | + if (!ValidationUtils.isXmlNCName(reqVO.getKey())) { | |
| 126 | + throw exception(MODEL_KEY_VALID); | |
| 127 | + } | |
| 128 | + // 1. 校验流程标识已经存在 | |
| 129 | + Model keyModel = getModelByKey(reqVO.getKey()); | |
| 130 | + if (keyModel != null) { | |
| 131 | + throw exception(MODEL_KEY_EXISTS, reqVO.getKey()); | |
| 132 | + } | |
| 133 | + | |
| 134 | + // 2. 创建 Model 对象 | |
| 135 | + reqVO.setSort(System.currentTimeMillis()); | |
| 136 | + Model model = repositoryService.newModel(); | |
| 137 | + BpmModelConvert.INSTANCE.copyToModel(model, reqVO); | |
| 138 | + model.setTenantId(FlowableUtils.getTenantId()); | |
| 139 | + | |
| 140 | + // 3. 保存模型 | |
| 141 | + saveModel(model, reqVO); | |
| 142 | + return model.getId(); | |
| 143 | + } | |
| 144 | + | |
| 145 | + @Override | |
| 146 | + public BpmModelSaveReqVO exportModel(String id) { | |
| 147 | + Model model = validateModelExists(id); | |
| 148 | + return BpmModelConvert.INSTANCE.convertToSaveReqVO(model); | |
| 149 | + } | |
| 150 | + | |
| 151 | + @Override | |
| 123 | 152 | @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务 |
| 124 | 153 | public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) { |
| 125 | 154 | // 1. 校验流程模型存在 | ... | ... |