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

This commit is contained in:
gnomeshgh
2026-07-03 22:38:11 +08:00
parent 7b35b16240
commit a3416fc449
3 changed files with 58 additions and 0 deletions
@@ -1,7 +1,9 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
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;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
@@ -27,7 +30,9 @@ import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -119,6 +124,28 @@ public class BpmModelController {
return success(modelService.createModel(createRetVO));
}
@PostMapping("/import")
@Operation(summary = "导入模型")
@Parameters({
@Parameter(name = "file", description = "流程模型 JSON 文件", required = true),
@Parameter(name = "key", description = "流程标识,替换导入文件中的标识", example = "process_yudao"),
@Parameter(name = "name", description = "流程名称,替换导入文件中的名称", example = "芋道")
})
@PreAuthorize("@ss.hasPermission('bpm:model:import')")
public CommonResult<String> importModel(@RequestParam("file") MultipartFile file,
@RequestParam(value = "key", required = false) String key,
@RequestParam(value = "name", required = false) String name) throws IOException
{
BpmModelSaveReqVO reqVO = JsonUtils.parseObject(file.getBytes(), BpmModelSaveReqVO.class);
if (StrUtil.isNotEmpty(key)) {
reqVO.setKey(key);
}
if (StrUtil.isNotEmpty(name)) {
reqVO.setName(name);
}
return success(modelService.importModel(reqVO));
}
@PutMapping("/update")
@Operation(summary = "修改模型")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
@@ -40,6 +40,14 @@ public interface BpmModelService {
*/
String createModel(@Valid BpmModelSaveReqVO modelVO);
/**
* 导入流程模型
*
* @param reqVO 导入信息
* @return 创建的流程模型的编号
*/
String importModel(@Valid BpmModelSaveReqVO reqVO);
/**
* 获得流程模块
*
@@ -119,6 +119,29 @@ public class BpmModelServiceImpl implements BpmModelService {
return model.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public String importModel(@Valid BpmModelSaveReqVO reqVO) {
if (!ValidationUtils.isXmlNCName(reqVO.getKey())) {
throw exception(MODEL_KEY_VALID);
}
// 1. 校验流程标识已经存在
Model keyModel = getModelByKey(reqVO.getKey());
if (keyModel != null) {
throw exception(MODEL_KEY_EXISTS, reqVO.getKey());
}
// 2. 创建 Model 对象
reqVO.setSort(System.currentTimeMillis());
Model model = repositoryService.newModel();
BpmModelConvert.INSTANCE.copyToModel(model, reqVO);
model.setTenantId(FlowableUtils.getTenantId());
// 3. 保存模型
saveModel(model, reqVO);
return model.getId();
}
@Override
@Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务
public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) {