Commit a3416fc4497d2e9e5da1a1aa54c1109b388172d8

Authored by gnomeshgh
1 parent 7b35b162

feat(bpm):新增导入模型接口

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;
... ... @@ -119,6 +124,28 @@ public class BpmModelController {
119 124 return success(modelService.createModel(createRetVO));
120 125 }
121 126  
  127 + @PostMapping("/import")
  128 + @Operation(summary = "导入模型")
  129 + @Parameters({
  130 + @Parameter(name = "file", description = "流程模型 JSON 文件", required = true),
  131 + @Parameter(name = "key", description = "流程标识,替换导入文件中的标识", example = "process_yudao"),
  132 + @Parameter(name = "name", description = "流程名称,替换导入文件中的名称", example = "芋道")
  133 + })
  134 + @PreAuthorize("@ss.hasPermission('bpm:model:import')")
  135 + public CommonResult<String> importModel(@RequestParam("file") MultipartFile file,
  136 + @RequestParam(value = "key", required = false) String key,
  137 + @RequestParam(value = "name", required = false) String name) throws IOException
  138 + {
  139 + BpmModelSaveReqVO reqVO = JsonUtils.parseObject(file.getBytes(), BpmModelSaveReqVO.class);
  140 + if (StrUtil.isNotEmpty(key)) {
  141 + reqVO.setKey(key);
  142 + }
  143 + if (StrUtil.isNotEmpty(name)) {
  144 + reqVO.setName(name);
  145 + }
  146 + return success(modelService.importModel(reqVO));
  147 + }
  148 +
122 149 @PutMapping("/update")
123 150 @Operation(summary = "修改模型")
124 151 @PreAuthorize("@ss.hasPermission('bpm:model:update')")
... ...
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelService.java
... ... @@ -41,6 +41,14 @@ 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 + /**
44 52 * 获得流程模块
45 53 *
46 54 * @param id 编号
... ...
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
... ... @@ -120,6 +120,29 @@ 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
123 146 @Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务
124 147 public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) {
125 148 // 1. 校验流程模型存在
... ...