Commit 5b97d565cd6632ed340f6d8ae077e31cbd253e83

Authored by jason
1 parent 95bbf749

仿钉钉流程设计- code review 修改

Showing 9 changed files with 75 additions and 144 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmModelController.java
... ... @@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.common.util.io.IoUtils;
8 8 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
9 9 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
10 10 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*;
  11 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
  12 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
11 13 import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
12 14 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
13 15 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
... ... @@ -145,4 +147,21 @@ public class BpmModelController {
145 147 return success(true);
146 148 }
147 149  
  150 + // ========== 仿钉钉/飞书的精简模型 =========
  151 +
  152 + @GetMapping("/simple/get")
  153 + @Operation(summary = "获得仿钉钉流程设计模型")
  154 + @Parameter(name = "modelId", description = "流程模型编号", required = true, example = "a2c5eee0-eb6c-11ee-abf4-0c37967c420a")
  155 + public CommonResult<BpmSimpleModelNodeVO> getSimpleModel(@RequestParam("modelId") String modelId){
  156 + return success(modelService.getSimpleModel(modelId));
  157 + }
  158 +
  159 + @PostMapping("/simple/update")
  160 + @Operation(summary = "保存仿钉钉流程设计模型")
  161 + @PreAuthorize("@ss.hasPermission('bpm:model:update')")
  162 + public CommonResult<Boolean> updateSimpleModel(@Valid @RequestBody BpmSimpleModelUpdateReqVO reqVO) {
  163 + modelService.updateSimpleModel(reqVO);
  164 + return success(Boolean.TRUE);
  165 + }
  166 +
148 167 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmSimpleModelController.java deleted
1   -package cn.iocoder.yudao.module.bpm.controller.admin.definition;
2   -
3   -import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelNodeVO;
5   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelSaveReqVO;
6   -import cn.iocoder.yudao.module.bpm.service.definition.BpmSimpleModelService;
7   -import io.swagger.v3.oas.annotations.Operation;
8   -import io.swagger.v3.oas.annotations.Parameter;
9   -import io.swagger.v3.oas.annotations.tags.Tag;
10   -import jakarta.annotation.Resource;
11   -import jakarta.validation.Valid;
12   -import org.springframework.security.access.prepost.PreAuthorize;
13   -import org.springframework.web.bind.annotation.*;
14   -
15   -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
16   -
17   -// TODO @jason:融合到 BpmModelController 中,url 是 /bpm/model/simple/... 这样,通过一个子目录区分;目的是:逻辑更聚焦!
18   -@Tag(name = "管理后台 - BPM 仿钉钉流程设计器")
19   -@RestController
20   -@RequestMapping("/bpm/simple")
21   -public class BpmSimpleModelController {
22   - @Resource
23   - private BpmSimpleModelService bpmSimpleModelService;
24   -
25   - @PostMapping("/save")
26   - @Operation(summary = "保存仿钉钉流程设计模型")
27   - @PreAuthorize("@ss.hasPermission('bpm:model:update')")
28   - public CommonResult<Boolean> saveSimpleModel(@Valid @RequestBody BpmSimpleModelSaveReqVO reqVO) {
29   - return success(bpmSimpleModelService.saveSimpleModel(reqVO));
30   - }
31   -
32   - @GetMapping("/get")
33   - @Operation(summary = "获得仿钉钉流程设计模型")
34   - @Parameter(name = "modelId", description = "流程模型编号", required = true, example = "a2c5eee0-eb6c-11ee-abf4-0c37967c420a")
35   - public CommonResult<BpmSimpleModelNodeVO> getSimpleModel(@RequestParam("modelId") String modelId){
36   - return success(bpmSimpleModelService.getSimpleModel(modelId));
37   - }
38   -
39   -}
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/simple/BpmSimpleModelNodeVO.java renamed to yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
1   -package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple;
  1 +package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple;
2 2  
3 3 import cn.iocoder.yudao.framework.common.validation.InEnum;
4 4 import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType;
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/simple/BpmSimpleModelSaveReqVO.java renamed to yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelUpdateReqVO.java
1   -package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple;
  1 +package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import jakarta.validation.Valid;
... ... @@ -6,10 +6,9 @@ import jakarta.validation.constraints.NotEmpty;
6 6 import jakarta.validation.constraints.NotNull;
7 7 import lombok.Data;
8 8  
9   -// TODO @芋艿:或许挪到 model 里的 simple 包
10 9 @Schema(description = "管理后台 - 仿钉钉流程设计模型的新增/修改 Request VO")
11 10 @Data
12   -public class BpmSimpleModelSaveReqVO {
  11 +public class BpmSimpleModelUpdateReqVO {
13 12  
14 13 @Schema(description = "流程模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
15 14 @NotEmpty(message = "流程模型编号不能为空")
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
... ... @@ -7,7 +7,7 @@ import cn.hutool.core.lang.TypeReference;
7 7 import cn.hutool.core.map.MapUtil;
8 8 import cn.hutool.core.util.*;
9 9 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
10   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelNodeVO;
  10 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
11 11 import cn.iocoder.yudao.module.bpm.enums.definition.BpmApproveMethodEnum;
12 12 import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModeConditionType;
13 13 import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType;
... ... @@ -59,11 +59,6 @@ public class SimpleModelUtils {
59 59 */
60 60 public static BpmnModel convertSimpleModelToBpmnModel(String processId, String processName, BpmSimpleModelNodeVO simpleModelNode) {
61 61 BpmnModel bpmnModel = new BpmnModel();
62   - // 不加这个 解析 Message 会报 NPE 异常
63   - bpmnModel.setTargetNamespace(BPMN2_NAMESPACE);
64   - Message rejectPostProcessMsg = new Message();
65   - rejectPostProcessMsg.setName(REJECT_POST_PROCESS_MESSAGE_NAME);
66   - bpmnModel.addMessage(rejectPostProcessMsg);
67 62  
68 63 Process mainProcess = new Process();
69 64 mainProcess.setId(processId);
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelService.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.*;
  4 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO;
  5 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
  6 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO;
  7 +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.BpmSimpleModelUpdateReqVO;
5 9 import jakarta.validation.Valid;
6 10 import org.flowable.bpmn.model.BpmnModel;
7 11 import org.flowable.engine.repository.Model;
... ... @@ -49,7 +53,7 @@ public interface BpmModelService {
49 53 /**
50 54 * 保存流程模型的 BPMN XML
51 55 *
52   - * @param id 编号
  56 + * @param id 编号
53 57 * @param xmlBytes BPMN XML bytes
54 58 */
55 59 // TODO @芋艿:感觉可以不修改这个方法,而是额外加一个方法;传入 id,bpmn,json;
... ... @@ -57,6 +61,7 @@ public interface BpmModelService {
57 61  
58 62 /**
59 63 * 获得仿钉钉快搭模型的 JSON 数据
  64 + *
60 65 * @param id 编号
61 66 * @return JSON bytes
62 67 */
... ... @@ -64,7 +69,8 @@ public interface BpmModelService {
64 69  
65 70 /**
66 71 * 保存仿钉钉快搭模型的 JSON 数据
67   - * @param id 编号
  72 + *
  73 + * @param id 编号
68 74 * @param jsonBytes JSON bytes
69 75 */
70 76 void saveModelSimpleJson(String id, byte[] jsonBytes);
... ... @@ -108,10 +114,20 @@ public interface BpmModelService {
108 114  
109 115 // ========== 仿钉钉/飞书的精简模型 =========
110 116  
111   - // TODO @jason:使用 ========== 仿钉钉/飞书的精简模型 ========= 分隔下;把相关的 controller、service 懂合并了;另外,vo 可以挪到 model/simple 这样的形式;
  117 + /**
  118 + * 获取仿钉钉流程设计模型结构
  119 + *
  120 + * @param modelId 流程模型编号
  121 + * @return 仿钉钉流程设计模型结构
  122 + */
  123 + BpmSimpleModelNodeVO getSimpleModel(String modelId);
112 124  
113   - // TODO @jason:BpmSimpleModelServiceImpl 迁移到这里,搞成 updateSimpleModel(BpmSimpleModelUpdateReqVO reqVO)
114   - // TODO @jason:BpmSimpleModelServiceImpl 迁移到这里,搞成 getSimpleModel;
  125 + /**
  126 + * 更新仿钉钉流程设计模型
  127 + *
  128 + * @param reqVO 请求信息
  129 + */
  130 + void updateSimpleModel(@Valid BpmSimpleModelUpdateReqVO reqVO);
115 131  
116 132 // TODO @jason:另外个问题,因为是存储到 modelExtra 里,那需要 deploy 存储出快照。和 bpmn xml 一样。目前我想到的,就是存储到 BpmProcessDefinitionInfoDO 加一个 simple_model 字段,text 类型。可以看看还有啥方案?
117 133  
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
... ... @@ -9,12 +9,15 @@ import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
9 9 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO;
10 10 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
11 11 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO;
  12 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
  13 +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
12 14 import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
13 15 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
14 16 import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
15 17 import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
16 18 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
17 19 import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
  20 +import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils;
18 21 import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
19 22 import jakarta.annotation.Resource;
20 23 import jakarta.validation.Valid;
... ... @@ -209,6 +212,33 @@ public class BpmModelServiceImpl implements BpmModelService {
209 212 return repositoryService.getBpmnModel(processDefinitionId);
210 213 }
211 214  
  215 + @Override
  216 + public BpmSimpleModelNodeVO getSimpleModel(String modelId) {
  217 + Model model = getModel(modelId);
  218 + if (model == null) {
  219 + throw exception(MODEL_NOT_EXISTS);
  220 + }
  221 + // 通过 ACT_RE_MODEL 表 EDITOR_SOURCE_EXTRA_VALUE_ID_ 获取 仿钉钉快搭模型的JSON 数据
  222 + byte[] jsonBytes = getModelSimpleJson(model.getId());
  223 + return JsonUtils.parseObject(jsonBytes, BpmSimpleModelNodeVO.class);
  224 + }
  225 +
  226 + @Override
  227 + public void updateSimpleModel(BpmSimpleModelUpdateReqVO reqVO) {
  228 + // 1.1 校验流程模型存在
  229 + Model model = getModel(reqVO.getModelId());
  230 + if (model == null) {
  231 + throw exception(MODEL_NOT_EXISTS);
  232 + }
  233 + // 1.2 JSON 转换成 bpmnModel
  234 + BpmnModel bpmnModel = SimpleModelUtils.convertSimpleModelToBpmnModel(model.getKey(), model.getName(), reqVO.getSimpleModelBody());
  235 + // 2.1 保存 Bpmn XML
  236 + saveModelBpmnXml(model.getId(), StrUtil.utf8Bytes(BpmnModelUtils.getBpmnXml(bpmnModel)));
  237 + // 2.2 保存 JSON 数据
  238 + saveModelSimpleJson(model.getId(), JsonUtils.toJsonByte(reqVO.getSimpleModelBody()));
  239 + }
  240 +
  241 +
212 242 /**
213 243 * 校验流程表单已配置
214 244 *
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmSimpleModelService.java deleted
1   -package cn.iocoder.yudao.module.bpm.service.definition;
2   -
3   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelNodeVO;
4   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelSaveReqVO;
5   -import jakarta.validation.Valid;
6   -
7   -/**
8   - * 仿钉钉流程设计 Service 接口
9   - *
10   - * @author jason
11   - */
12   -public interface BpmSimpleModelService {
13   -
14   - /**
15   - * 保存仿钉钉流程设计模型
16   - *
17   - * @param reqVO 请求信息
18   - */
19   - Boolean saveSimpleModel(@Valid BpmSimpleModelSaveReqVO reqVO);
20   -
21   - /**
22   - * 获取仿钉钉流程设计模型结构
23   - *
24   - * @param modelId 流程模型编号
25   - * @return 仿钉钉流程设计模型结构
26   - */
27   - BpmSimpleModelNodeVO getSimpleModel(String modelId);
28   -
29   -}
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmSimpleModelServiceImpl.java deleted
1   -package cn.iocoder.yudao.module.bpm.service.definition;
2   -
3   -import cn.hutool.core.util.StrUtil;
4   -import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
5   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelNodeVO;
6   -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelSaveReqVO;
7   -import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
8   -import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils;
9   -import jakarta.annotation.Resource;
10   -import org.flowable.bpmn.model.BpmnModel;
11   -import org.flowable.engine.repository.Model;
12   -import org.springframework.stereotype.Service;
13   -import org.springframework.validation.annotation.Validated;
14   -
15   -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
16   -import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.MODEL_NOT_EXISTS;
17   -
18   -// TODO @jason:这块可以讨论下,是不是合并成一个 BpmnModelServiceImpl
19   -/**
20   - * 仿钉钉流程设计 Service 实现类
21   - *
22   - * @author jason
23   - */
24   -@Service
25   -@Validated
26   -public class BpmSimpleModelServiceImpl implements BpmSimpleModelService {
27   -
28   - @Resource
29   - private BpmModelService bpmModelService;
30   -
31   - @Override
32   - public Boolean saveSimpleModel(BpmSimpleModelSaveReqVO reqVO) {
33   - // 1.1 校验流程模型存在
34   - Model model = bpmModelService.getModel(reqVO.getModelId());
35   - if (model == null) {
36   - throw exception(MODEL_NOT_EXISTS);
37   - }
38   -
39   - // 1. JSON 转换成 bpmnModel
40   - BpmnModel bpmnModel = SimpleModelUtils.convertSimpleModelToBpmnModel(model.getKey(), model.getName(), reqVO.getSimpleModelBody());
41   - // 2.1 保存 Bpmn XML
42   - bpmModelService.saveModelBpmnXml(model.getId(), StrUtil.utf8Bytes(BpmnModelUtils.getBpmnXml(bpmnModel)));
43   - // 2.2 保存 JSON 数据
44   - bpmModelService.saveModelSimpleJson(model.getId(), JsonUtils.toJsonByte(reqVO.getSimpleModelBody()));
45   - return Boolean.TRUE;
46   - }
47   -
48   - @Override
49   - public BpmSimpleModelNodeVO getSimpleModel(String modelId) {
50   - Model model = bpmModelService.getModel(modelId);
51   - if (model == null) {
52   - throw exception(MODEL_NOT_EXISTS);
53   - }
54   - // 暂时不用 bpmn 转 json, 有点复杂,
55   - // 通过 ACT_RE_MODEL 表 EDITOR_SOURCE_EXTRA_VALUE_ID_ 获取 仿钉钉快搭模型的JSON 数据
56   - byte[] jsonBytes = bpmModelService.getModelSimpleJson(model.getId());
57   - return JsonUtils.parseObject(jsonBytes, BpmSimpleModelNodeVO.class);
58   - }
59   -
60   -}