Commit 95bbf749a166f0900778750b29b0539b4ab4645b
1 parent
007639d6
【代码评审】BPM:review 快搭的实现
Showing
3 changed files
with
13 additions
and
117 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/BpmSimpleModelController.java
| ... | ... | @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*; |
| 14 | 14 | |
| 15 | 15 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 16 | 16 | |
| 17 | -// TODO @芋艿:后续考虑下,怎么放这个 Controller | |
| 17 | +// TODO @jason:融合到 BpmModelController 中,url 是 /bpm/model/simple/... 这样,通过一个子目录区分;目的是:逻辑更聚焦! | |
| 18 | 18 | @Tag(name = "管理后台 - BPM 仿钉钉流程设计器") |
| 19 | 19 | @RestController |
| 20 | 20 | @RequestMapping("/bpm/simple") | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelService.java
| ... | ... | @@ -46,7 +46,6 @@ public interface BpmModelService { |
| 46 | 46 | */ |
| 47 | 47 | byte[] getModelBpmnXML(String id); |
| 48 | 48 | |
| 49 | - | |
| 50 | 49 | /** |
| 51 | 50 | * 保存流程模型的 BPMN XML |
| 52 | 51 | * |
| ... | ... | @@ -107,4 +106,13 @@ public interface BpmModelService { |
| 107 | 106 | */ |
| 108 | 107 | BpmnModel getBpmnModelByDefinitionId(String processDefinitionId); |
| 109 | 108 | |
| 109 | + // ========== 仿钉钉/飞书的精简模型 ========= | |
| 110 | + | |
| 111 | + // TODO @jason:使用 ========== 仿钉钉/飞书的精简模型 ========= 分隔下;把相关的 controller、service 懂合并了;另外,vo 可以挪到 model/simple 这样的形式; | |
| 112 | + | |
| 113 | + // TODO @jason:BpmSimpleModelServiceImpl 迁移到这里,搞成 updateSimpleModel(BpmSimpleModelUpdateReqVO reqVO) | |
| 114 | + // TODO @jason:BpmSimpleModelServiceImpl 迁移到这里,搞成 getSimpleModel; | |
| 115 | + | |
| 116 | + // TODO @jason:另外个问题,因为是存储到 modelExtra 里,那需要 deploy 存储出快照。和 bpmn xml 一样。目前我想到的,就是存储到 BpmProcessDefinitionInfoDO 加一个 simple_model 字段,text 类型。可以看看还有啥方案? | |
| 117 | + | |
| 110 | 118 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmSimpleModelServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.service.definition; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.collection.CollUtil; | |
| 4 | -import cn.hutool.core.lang.Assert; | |
| 5 | -import cn.hutool.core.map.MapUtil; | |
| 6 | 3 | import cn.hutool.core.util.StrUtil; |
| 7 | 4 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 8 | 5 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelNodeVO; |
| 9 | 6 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.simple.BpmSimpleModelSaveReqVO; |
| 10 | -import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; | |
| 11 | -import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; | |
| 12 | 7 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; |
| 13 | 8 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils; |
| 14 | 9 | import jakarta.annotation.Resource; |
| 15 | -import org.flowable.bpmn.model.*; | |
| 10 | +import org.flowable.bpmn.model.BpmnModel; | |
| 16 | 11 | import org.flowable.engine.repository.Model; |
| 17 | 12 | import org.springframework.stereotype.Service; |
| 18 | 13 | import org.springframework.validation.annotation.Validated; |
| 19 | 14 | |
| 20 | -import java.util.List; | |
| 21 | -import java.util.Map; | |
| 22 | - | |
| 23 | 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 24 | -import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.CONVERT_TO_SIMPLE_MODEL_NOT_SUPPORT; | |
| 25 | 16 | import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.MODEL_NOT_EXISTS; |
| 26 | -import static cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType.START_EVENT; | |
| 27 | -import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.USER_TASK_CANDIDATE_PARAM; | |
| 28 | -import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY; | |
| 29 | 17 | |
| 30 | 18 | // TODO @jason:这块可以讨论下,是不是合并成一个 BpmnModelServiceImpl |
| 31 | 19 | /** |
| ... | ... | @@ -42,20 +30,12 @@ public class BpmSimpleModelServiceImpl implements BpmSimpleModelService { |
| 42 | 30 | |
| 43 | 31 | @Override |
| 44 | 32 | public Boolean saveSimpleModel(BpmSimpleModelSaveReqVO reqVO) { |
| 33 | + // 1.1 校验流程模型存在 | |
| 45 | 34 | Model model = bpmModelService.getModel(reqVO.getModelId()); |
| 46 | 35 | if (model == null) { |
| 47 | 36 | throw exception(MODEL_NOT_EXISTS); |
| 48 | 37 | } |
| 49 | -// byte[] bpmnBytes = bpmModelService.getModelBpmnXML(reqVO.getModelId()); | |
| 50 | -// if (ArrayUtil.isEmpty(bpmnBytes)) { | |
| 51 | -// // BPMN XML 不存在。新增 | |
| 52 | -// BpmnModel bpmnModel = BpmnModelUtils.convertSimpleModelToBpmnModel(model.getKey(), model.getName(), reqVO.getSimpleModelBody()); | |
| 53 | -// bpmModelService.saveModelBpmnXml(model.getId(), BpmnModelUtils.getBpmnXml(bpmnModel)); | |
| 54 | -// return Boolean.TRUE; | |
| 55 | -// } else { | |
| 56 | -// // TODO BPMN XML 已经存在。如何修改 ?? TODO add by 芋艿:感觉一个流程,只能二选一,要么 bpmn、要么 simple | |
| 57 | -// return Boolean.FALSE; | |
| 58 | -// } | |
| 38 | + | |
| 59 | 39 | // 1. JSON 转换成 bpmnModel |
| 60 | 40 | BpmnModel bpmnModel = SimpleModelUtils.convertSimpleModelToBpmnModel(model.getKey(), model.getName(), reqVO.getSimpleModelBody()); |
| 61 | 41 | // 2.1 保存 Bpmn XML |
| ... | ... | @@ -77,96 +57,4 @@ public class BpmSimpleModelServiceImpl implements BpmSimpleModelService { |
| 77 | 57 | return JsonUtils.parseObject(jsonBytes, BpmSimpleModelNodeVO.class); |
| 78 | 58 | } |
| 79 | 59 | |
| 80 | - // TODO @jason:一般要支持这个么?感觉 bpmn 转 json 支持会不会太复杂。可以优先级低一点,做下调研~ | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * Bpmn Model 转换成 仿钉钉流程设计模型数据结构(json) 待完善 | |
| 84 | - * | |
| 85 | - * @param bpmnModel Bpmn Model | |
| 86 | - * @return 仿钉钉流程设计模型数据结构 | |
| 87 | - */ | |
| 88 | - private BpmSimpleModelNodeVO convertBpmnModelToSimpleModel(BpmnModel bpmnModel) { | |
| 89 | - if (bpmnModel == null) { | |
| 90 | - return null; | |
| 91 | - } | |
| 92 | - StartEvent startEvent = BpmnModelUtils.getStartEvent(bpmnModel); | |
| 93 | - if (startEvent == null) { | |
| 94 | - return null; | |
| 95 | - } | |
| 96 | - BpmSimpleModelNodeVO rootNode = new BpmSimpleModelNodeVO(); | |
| 97 | - rootNode.setType(START_EVENT.getType()); | |
| 98 | - rootNode.setId(startEvent.getId()); | |
| 99 | - rootNode.setName(startEvent.getName()); | |
| 100 | - recursiveBuildSimpleModelNode(startEvent, rootNode); | |
| 101 | - return rootNode; | |
| 102 | - } | |
| 103 | - | |
| 104 | - private void recursiveBuildSimpleModelNode(FlowNode currentFlowNode, BpmSimpleModelNodeVO currentSimpleModeNode) { | |
| 105 | - BpmSimpleModelNodeType nodeType = BpmSimpleModelNodeType.valueOf(currentSimpleModeNode.getType()); | |
| 106 | - Assert.notNull(nodeType, "节点类型不支持"); | |
| 107 | - // 校验节点是否支持转仿钉钉的流程模型 | |
| 108 | - List<SequenceFlow> outgoingFlows = validateCanConvertSimpleNode(nodeType, currentFlowNode); | |
| 109 | - if (CollUtil.isEmpty(outgoingFlows) || CollUtil.getFirst(outgoingFlows).getTargetFlowElement() == null) { | |
| 110 | - return; | |
| 111 | - } | |
| 112 | - FlowElement targetElement = CollUtil.getFirst(outgoingFlows).getTargetFlowElement(); | |
| 113 | - // 如果是 EndEvent 直接退出 | |
| 114 | - if (targetElement instanceof EndEvent) { | |
| 115 | - return; | |
| 116 | - } | |
| 117 | - if (targetElement instanceof UserTask) { | |
| 118 | - BpmSimpleModelNodeVO childNode = convertUserTaskToSimpleModelNode((UserTask) targetElement); | |
| 119 | - currentSimpleModeNode.setChildNode(childNode); | |
| 120 | - recursiveBuildSimpleModelNode((FlowNode) targetElement, childNode); | |
| 121 | - } | |
| 122 | - // TODO 其它节点类型待实现 | |
| 123 | - } | |
| 124 | - | |
| 125 | - private BpmSimpleModelNodeVO convertUserTaskToSimpleModelNode(UserTask userTask) { | |
| 126 | - BpmSimpleModelNodeVO simpleModelNodeVO = new BpmSimpleModelNodeVO(); | |
| 127 | - simpleModelNodeVO.setType(BpmSimpleModelNodeType.USER_TASK.getType()); | |
| 128 | - simpleModelNodeVO.setName(userTask.getName()); | |
| 129 | - simpleModelNodeVO.setId(userTask.getId()); | |
| 130 | - Map<String, Object> attributes = MapUtil.newHashMap(); | |
| 131 | - // TODO 暂时是普通审批,需要加会签 | |
| 132 | - attributes.put("approveMethod", 1); | |
| 133 | - attributes.computeIfAbsent(USER_TASK_CANDIDATE_STRATEGY, (key) -> BpmnModelUtils.parseCandidateStrategy(userTask)); | |
| 134 | - attributes.computeIfAbsent(USER_TASK_CANDIDATE_PARAM, (key) -> BpmnModelUtils.parseCandidateParam(userTask)); | |
| 135 | - simpleModelNodeVO.setAttributes(attributes); | |
| 136 | - return simpleModelNodeVO; | |
| 137 | - } | |
| 138 | - | |
| 139 | - private List<SequenceFlow> validateCanConvertSimpleNode(BpmSimpleModelNodeType nodeType, FlowNode currentFlowNode) { | |
| 140 | - switch (nodeType) { | |
| 141 | - case START_EVENT: | |
| 142 | - case USER_TASK: { | |
| 143 | - List<SequenceFlow> outgoingFlows = currentFlowNode.getOutgoingFlows(); | |
| 144 | - if (CollUtil.isNotEmpty(outgoingFlows) && outgoingFlows.size() > 1) { | |
| 145 | - throw exception(CONVERT_TO_SIMPLE_MODEL_NOT_SUPPORT); | |
| 146 | - } | |
| 147 | - validIsSupportFlowNode(CollUtil.getFirst(outgoingFlows).getTargetFlowElement()); | |
| 148 | - return outgoingFlows; | |
| 149 | - } | |
| 150 | - default: { | |
| 151 | - // TODO 其它节点类型待实现 | |
| 152 | - throw exception(CONVERT_TO_SIMPLE_MODEL_NOT_SUPPORT); | |
| 153 | - } | |
| 154 | - } | |
| 155 | - } | |
| 156 | - | |
| 157 | - private void validIsSupportFlowNode(FlowElement targetElement) { | |
| 158 | - if (targetElement == null) { | |
| 159 | - return; | |
| 160 | - } | |
| 161 | - boolean isSupport = false; | |
| 162 | - for (Class<? extends FlowNode> item : BpmnModelConstants.SUPPORT_CONVERT_SIMPLE_FlOW_NODES) { | |
| 163 | - if (item.isInstance(targetElement)) { | |
| 164 | - isSupport = true; | |
| 165 | - break; | |
| 166 | - } | |
| 167 | - } | |
| 168 | - if (!isSupport) { | |
| 169 | - throw exception(CONVERT_TO_SIMPLE_MODEL_NOT_SUPPORT); | |
| 170 | - } | |
| 171 | - } | |
| 172 | 60 | } | ... | ... |