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 | package cn.iocoder.yudao.module.bpm.controller.admin.definition; | 1 | package cn.iocoder.yudao.module.bpm.controller.admin.definition; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.util.StrUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 5 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; | 7 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; |
| 6 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; | 8 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 7 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO; | 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,6 +20,7 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 18 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 20 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 19 | import io.swagger.v3.oas.annotations.Operation; | 21 | import io.swagger.v3.oas.annotations.Operation; |
| 20 | import io.swagger.v3.oas.annotations.Parameter; | 22 | import io.swagger.v3.oas.annotations.Parameter; |
| 23 | +import io.swagger.v3.oas.annotations.Parameters; | ||
| 21 | import io.swagger.v3.oas.annotations.tags.Tag; | 24 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 22 | import jakarta.annotation.Resource; | 25 | import jakarta.annotation.Resource; |
| 23 | import jakarta.validation.Valid; | 26 | import jakarta.validation.Valid; |
| @@ -27,7 +30,9 @@ import org.flowable.engine.repository.ProcessDefinition; | @@ -27,7 +30,9 @@ import org.flowable.engine.repository.ProcessDefinition; | ||
| 27 | import org.springframework.security.access.prepost.PreAuthorize; | 30 | import org.springframework.security.access.prepost.PreAuthorize; |
| 28 | import org.springframework.validation.annotation.Validated; | 31 | import org.springframework.validation.annotation.Validated; |
| 29 | import org.springframework.web.bind.annotation.*; | 32 | import org.springframework.web.bind.annotation.*; |
| 33 | +import org.springframework.web.multipart.MultipartFile; | ||
| 30 | 34 | ||
| 35 | +import java.io.IOException; | ||
| 31 | import java.util.Collections; | 36 | import java.util.Collections; |
| 32 | import java.util.List; | 37 | import java.util.List; |
| 33 | import java.util.Map; | 38 | import java.util.Map; |
| @@ -112,6 +117,14 @@ public class BpmModelController { | @@ -112,6 +117,14 @@ public class BpmModelController { | ||
| 112 | return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes, simpleModel)); | 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 | @PostMapping("/create") | 128 | @PostMapping("/create") |
| 116 | @Operation(summary = "新建模型") | 129 | @Operation(summary = "新建模型") |
| 117 | @PreAuthorize("@ss.hasPermission('bpm:model:create')") | 130 | @PreAuthorize("@ss.hasPermission('bpm:model:create')") |
| @@ -119,6 +132,28 @@ public class BpmModelController { | @@ -119,6 +132,28 @@ public class BpmModelController { | ||
| 119 | return success(modelService.createModel(createRetVO)); | 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 | @PutMapping("/update") | 157 | @PutMapping("/update") |
| 123 | @Operation(summary = "修改模型") | 158 | @Operation(summary = "修改模型") |
| 124 | @PreAuthorize("@ss.hasPermission('bpm:model:update')") | 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,6 +111,18 @@ public interface BpmModelConvert { | ||
| 111 | model.setMetaInfo(JsonUtils.toJsonString(BeanUtils.toBean(reqVO, BpmModelMetaInfoVO.class))); | 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 | default BpmModelMetaInfoVO parseMetaInfo(Model model) { | 126 | default BpmModelMetaInfoVO parseMetaInfo(Model model) { |
| 115 | BpmModelMetaInfoVO vo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class); | 127 | BpmModelMetaInfoVO vo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class); |
| 116 | if (vo == null) { | 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,6 +41,22 @@ public interface BpmModelService { | ||
| 41 | String createModel(@Valid BpmModelSaveReqVO modelVO); | 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 | * @param id 编号 | 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,6 +120,35 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | @Override | 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 | @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务 | 152 | @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务 |
| 124 | public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) { | 153 | public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) { |
| 125 | // 1. 校验流程模型存在 | 154 | // 1. 校验流程模型存在 |