From 3a3540079bf1a58b957ef7846c32ae5fcce9c597 Mon Sep 17 00:00:00 2001 From: 75349 <753495441@qq.com> Date: Fri, 16 Dec 2022 17:31:04 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A=202.?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=8B=BC=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql/bean/AviatorEvaluatorBean.java | 5 ++ .../liteflow/mysql/cmp/DefaultOutputCmp.java | 4 +- .../example/liteflow/mysql/cmp/OutputCmp.java | 3 + .../mysql/controller/BaseChainController.java | 16 +++++ .../mysql/controller/BaseDataController.java | 12 ++++ .../mysql/controller/BaseNodeController.java | 12 +++- .../controller/BaseTemplateController.java | 11 ++++ .../mysql/entity/BaseChainEntity.java | 2 +- .../liteflow/mysql/entity/BaseDataEntity.java | 1 + .../liteflow/mysql/entity/BaseNodeEntity.java | 2 +- .../mysql/entity/BaseTemplateEntity.java | 9 ++- .../mysql/enums/BaseDataContentTypeEnum.java | 1 + .../liteflow/mysql/enums/EnableMarkEnum.java | 1 + .../liteflow/mysql/enums/NodeEnum.java | 1 + .../mysql/handler/MybatisHandler.java | 2 + .../liteflow/mysql/model/BaseCenter.java | 1 + .../liteflow/mysql/model/OutputFrom.java | 1 + .../liteflow/mysql/model/rule/Match.java | 13 ++++- .../liteflow/mysql/model/rule/Rule.java | 23 ++++++-- .../liteflow/mysql/model/rule/RuleForm.java | 15 ----- .../mysql/runner/AviatorEvaluatorRunner.java | 4 ++ .../mysql/service/BaseChainService.java | 22 +++++++ .../mysql/service/BaseDataService.java | 22 ++++++- .../mysql/service/BaseNodeService.java | 26 +++++++-- .../mysql/service/BaseTemplateService.java | 19 +++++- .../service/impl/BaseChainServiceImpl.java | 58 +++++++++++++++---- .../service/impl/BaseDataServiceImpl.java | 19 ++++++ .../service/impl/BaseNodeServiceImpl.java | 13 ++++- .../service/impl/BaseTemplateServiceImpl.java | 26 +++++++-- .../example/liteflow/mysql/util/RoleUtil.java | 22 +++++-- src/test/java/MyTest.java | 17 ------ 31 files changed, 306 insertions(+), 77 deletions(-) delete mode 100644 src/main/java/com/example/liteflow/mysql/model/rule/RuleForm.java diff --git a/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorBean.java b/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorBean.java index 466162b..ad08ff6 100644 --- a/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorBean.java +++ b/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorBean.java @@ -12,6 +12,11 @@ import org.springframework.stereotype.Component; */ @Component public class AviatorEvaluatorBean { + /** + * 向google匹配方法中注入需要的工具类 + * @throws IllegalAccessException + * @throws NoSuchMethodException + */ @Bean public void aviatorEvaluatorInit() throws IllegalAccessException, NoSuchMethodException { AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); diff --git a/src/main/java/com/example/liteflow/mysql/cmp/DefaultOutputCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/DefaultOutputCmp.java index bce38f1..744864a 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/DefaultOutputCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/DefaultOutputCmp.java @@ -8,7 +8,9 @@ import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("defaultOutput") public class DefaultOutputCmp extends NodeComponent { - + /** + * 默认输出 + */ @Override public void process() { BaseCenter requestData = this.getRequestData(); diff --git a/src/main/java/com/example/liteflow/mysql/cmp/OutputCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/OutputCmp.java index ba9ac97..806e29a 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/OutputCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/OutputCmp.java @@ -28,6 +28,9 @@ public class OutputCmp extends NodeComponent { @Resource private BaseTemplateService baseTemplateService; + /** + * 输出节点 + */ @Override public void process() { BaseCenter requestData = this.getRequestData(); diff --git a/src/main/java/com/example/liteflow/mysql/controller/BaseChainController.java b/src/main/java/com/example/liteflow/mysql/controller/BaseChainController.java index b12a9ba..6e5323c 100644 --- a/src/main/java/com/example/liteflow/mysql/controller/BaseChainController.java +++ b/src/main/java/com/example/liteflow/mysql/controller/BaseChainController.java @@ -19,16 +19,32 @@ public class BaseChainController { @Resource private BaseChainService baseChainService; + /** + * 生成动态规则 + * + * @return CommonResult + */ @PostMapping("/generateDynamicChain") public CommonResult generateDynamicChain() { return baseChainService.generateDynamicChain(); } + /** + * 执行链路 + * + * @param chainName 链路名称 + * @return CommonResult + */ @GetMapping("/executeChain/{chainName}") public CommonResult executeChain(@PathVariable String chainName) { return baseChainService.executeChain(chainName); } + /** + * 获取所有已注入的动态链路 + * + * @return CommonResult + */ @GetMapping("/getChainList") public CommonResult getChainList() { return baseChainService.getChainList(); diff --git a/src/main/java/com/example/liteflow/mysql/controller/BaseDataController.java b/src/main/java/com/example/liteflow/mysql/controller/BaseDataController.java index 31894a5..cf40964 100644 --- a/src/main/java/com/example/liteflow/mysql/controller/BaseDataController.java +++ b/src/main/java/com/example/liteflow/mysql/controller/BaseDataController.java @@ -24,11 +24,23 @@ public class BaseDataController { @Resource private BaseDataService baseDataService; + /** + * 创建基础数据 + * + * @param createBaseDataFrom 创建参数 + * @return CommonResult + */ @PostMapping("/createBaseData") public CommonResult createBaseData(@RequestBody CreateBaseDataFrom createBaseDataFrom) { return baseDataService.createBaseData(createBaseDataFrom); } + /** + * 批量创建基础数据 + * + * @param createBaseDataFromList 创建参数集合 + * @return CommonResult + */ @PostMapping("/batchCreateBaseData") public CommonResult batchCreateBaseData(@RequestBody List createBaseDataFromList) { return baseDataService.batchCreateBaseData(createBaseDataFromList); diff --git a/src/main/java/com/example/liteflow/mysql/controller/BaseNodeController.java b/src/main/java/com/example/liteflow/mysql/controller/BaseNodeController.java index 088ce91..76df33d 100644 --- a/src/main/java/com/example/liteflow/mysql/controller/BaseNodeController.java +++ b/src/main/java/com/example/liteflow/mysql/controller/BaseNodeController.java @@ -20,12 +20,22 @@ public class BaseNodeController { @Resource private BaseNodeService baseNodeService; + /** + * 创建节点 + * + * @param createNodeFrom 创建参数 + * @return CommonResult + */ @PostMapping("/createNode") public CommonResult createNode(@RequestBody CreateNodeFrom createNodeFrom) { return baseNodeService.createNode(createNodeFrom); } - + /** + * 获取所有已注入节点 + * + * @return CommonResult + */ @GetMapping("/getNodeList") public CommonResult getNodeList() { return baseNodeService.getNodeList(); diff --git a/src/main/java/com/example/liteflow/mysql/controller/BaseTemplateController.java b/src/main/java/com/example/liteflow/mysql/controller/BaseTemplateController.java index 283f220..f510a19 100644 --- a/src/main/java/com/example/liteflow/mysql/controller/BaseTemplateController.java +++ b/src/main/java/com/example/liteflow/mysql/controller/BaseTemplateController.java @@ -20,11 +20,22 @@ public class BaseTemplateController { @Resource private BaseTemplateService baseTemplateService; + /** + * 创建爱你模板 + * + * @param createTemplateFrom 创建参数 + * @return CommonResult + */ @PostMapping("/createTemplate") public CommonResult createTemplate(@RequestBody CreateTemplateFrom createTemplateFrom) { return baseTemplateService.createTemplate(createTemplateFrom); } + /** + * 获取所有模板 + * + * @return CommonResult + */ @GetMapping("/getTemplateList") public CommonResult getTemplateList() { return baseTemplateService.getTemplateList(); diff --git a/src/main/java/com/example/liteflow/mysql/entity/BaseChainEntity.java b/src/main/java/com/example/liteflow/mysql/entity/BaseChainEntity.java index 5266205..d710efb 100644 --- a/src/main/java/com/example/liteflow/mysql/entity/BaseChainEntity.java +++ b/src/main/java/com/example/liteflow/mysql/entity/BaseChainEntity.java @@ -6,7 +6,7 @@ import lombok.Data; import java.time.LocalDateTime; /** - * + * 链路 * @TableName base_chain */ @TableName(value ="base_chain") diff --git a/src/main/java/com/example/liteflow/mysql/entity/BaseDataEntity.java b/src/main/java/com/example/liteflow/mysql/entity/BaseDataEntity.java index 528e73a..0a43b68 100644 --- a/src/main/java/com/example/liteflow/mysql/entity/BaseDataEntity.java +++ b/src/main/java/com/example/liteflow/mysql/entity/BaseDataEntity.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; /** + * 基础数据 * @author: 陈韦龙 * @date: 2022年12月06日 09:59 */ diff --git a/src/main/java/com/example/liteflow/mysql/entity/BaseNodeEntity.java b/src/main/java/com/example/liteflow/mysql/entity/BaseNodeEntity.java index 218b91f..7805cbc 100644 --- a/src/main/java/com/example/liteflow/mysql/entity/BaseNodeEntity.java +++ b/src/main/java/com/example/liteflow/mysql/entity/BaseNodeEntity.java @@ -6,7 +6,7 @@ import lombok.Data; import java.time.LocalDateTime; /** - * + * 节点 * @TableName base_node */ @TableName(value ="base_node") diff --git a/src/main/java/com/example/liteflow/mysql/entity/BaseTemplateEntity.java b/src/main/java/com/example/liteflow/mysql/entity/BaseTemplateEntity.java index 8782aaf..046e6f7 100644 --- a/src/main/java/com/example/liteflow/mysql/entity/BaseTemplateEntity.java +++ b/src/main/java/com/example/liteflow/mysql/entity/BaseTemplateEntity.java @@ -4,9 +4,10 @@ import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import java.time.LocalDateTime; +import java.util.List; /** - * + * 模板 * @TableName base_template */ @TableName(value ="base_template") @@ -42,4 +43,10 @@ public class BaseTemplateEntity { @TableField(value = "last_modify_time", fill = FieldFill.UPDATE) private LocalDateTime lastModifyTime; + /** + * 修改时间 + */ + @TableField(exist = false) + private List baseNodeEntityList; + } \ No newline at end of file diff --git a/src/main/java/com/example/liteflow/mysql/enums/BaseDataContentTypeEnum.java b/src/main/java/com/example/liteflow/mysql/enums/BaseDataContentTypeEnum.java index 0240735..f98a0a4 100644 --- a/src/main/java/com/example/liteflow/mysql/enums/BaseDataContentTypeEnum.java +++ b/src/main/java/com/example/liteflow/mysql/enums/BaseDataContentTypeEnum.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.ToString; /** + * 基础数据类型枚举 * @author: 陈韦龙 * @date: 2022年12月06日 10:17 */ diff --git a/src/main/java/com/example/liteflow/mysql/enums/EnableMarkEnum.java b/src/main/java/com/example/liteflow/mysql/enums/EnableMarkEnum.java index 6951821..f245b43 100644 --- a/src/main/java/com/example/liteflow/mysql/enums/EnableMarkEnum.java +++ b/src/main/java/com/example/liteflow/mysql/enums/EnableMarkEnum.java @@ -7,6 +7,7 @@ import lombok.Getter; import java.util.Objects; /** + * 有效状态枚举 * @author: 陈韦龙 * @date: 2022年12月14日 11:28 */ diff --git a/src/main/java/com/example/liteflow/mysql/enums/NodeEnum.java b/src/main/java/com/example/liteflow/mysql/enums/NodeEnum.java index a0882b2..1e02965 100644 --- a/src/main/java/com/example/liteflow/mysql/enums/NodeEnum.java +++ b/src/main/java/com/example/liteflow/mysql/enums/NodeEnum.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.ToString; /** + * 节点类型枚举 * @author: 陈韦龙 * @date: 2022年12月12日 17:24 */ diff --git a/src/main/java/com/example/liteflow/mysql/handler/MybatisHandler.java b/src/main/java/com/example/liteflow/mysql/handler/MybatisHandler.java index 3e571de..71120ad 100644 --- a/src/main/java/com/example/liteflow/mysql/handler/MybatisHandler.java +++ b/src/main/java/com/example/liteflow/mysql/handler/MybatisHandler.java @@ -7,6 +7,8 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; /** + * 自动插入创建时间和更新时间 + * * @author: 陈韦龙 * @date: 2022年12月14日 09:39 */ diff --git a/src/main/java/com/example/liteflow/mysql/model/BaseCenter.java b/src/main/java/com/example/liteflow/mysql/model/BaseCenter.java index 1a16155..227dcc2 100644 --- a/src/main/java/com/example/liteflow/mysql/model/BaseCenter.java +++ b/src/main/java/com/example/liteflow/mysql/model/BaseCenter.java @@ -4,6 +4,7 @@ import cn.hutool.json.JSONObject; import lombok.Data; /** + * 规则匹配数据类 * @author: 陈韦龙 * @date: 2022年12月05日 18:15 */ diff --git a/src/main/java/com/example/liteflow/mysql/model/OutputFrom.java b/src/main/java/com/example/liteflow/mysql/model/OutputFrom.java index c25a9d1..e83bc85 100644 --- a/src/main/java/com/example/liteflow/mysql/model/OutputFrom.java +++ b/src/main/java/com/example/liteflow/mysql/model/OutputFrom.java @@ -3,6 +3,7 @@ package com.example.liteflow.mysql.model; import lombok.Data; /** + * 输出数据类 * @author: 陈韦龙 * @date: 2022年12月12日 18:30 */ diff --git a/src/main/java/com/example/liteflow/mysql/model/rule/Match.java b/src/main/java/com/example/liteflow/mysql/model/rule/Match.java index a5bcce0..fb10185 100644 --- a/src/main/java/com/example/liteflow/mysql/model/rule/Match.java +++ b/src/main/java/com/example/liteflow/mysql/model/rule/Match.java @@ -3,15 +3,22 @@ package com.example.liteflow.mysql.model.rule; import lombok.Data; /** + * 匹配内容和运算符 * @author: 陈韦龙 * @date: 2022年12月07日 17:55 */ @Data public class Match { - // 条件运算符:"$eq" + /** + * 条件运算符:"$eq" + */ private String conditionalOperators; - // 匹配值 + /** + * 匹配值 + */ private String matchingValue; - // 匹配内容 + /** + * 匹配内容 + */ private String matchingContent; } diff --git a/src/main/java/com/example/liteflow/mysql/model/rule/Rule.java b/src/main/java/com/example/liteflow/mysql/model/rule/Rule.java index 69e2a2f..0919c9e 100644 --- a/src/main/java/com/example/liteflow/mysql/model/rule/Rule.java +++ b/src/main/java/com/example/liteflow/mysql/model/rule/Rule.java @@ -5,19 +5,34 @@ import lombok.Data; import java.util.List; /** + * 规则类 * @author: 陈韦龙 * @date: 2022年12月07日 16:04 */ @Data public class Rule { - // 逻辑运算符"$or" + /** + * 逻辑运算符"$or" + */ private String logicOperators; - // 条件运算符:"$eq" + /** + * 条件运算符:"$eq" + */ private String conditionalOperators; - // 匹配值 + /** + * 匹配值 + */ private String matchingValue; - // 匹配内容 + /** + * 匹配内容 + */ private String matchingContent; + /** + * 子规则 + */ private List children; + /** + * 自身下多条规则 + */ private List matches; } diff --git a/src/main/java/com/example/liteflow/mysql/model/rule/RuleForm.java b/src/main/java/com/example/liteflow/mysql/model/rule/RuleForm.java deleted file mode 100644 index 819b92b..0000000 --- a/src/main/java/com/example/liteflow/mysql/model/rule/RuleForm.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.example.liteflow.mysql.model.rule; - -import lombok.Data; - -import java.util.List; - -/** - * @author: 陈韦龙 - * @date: 2022年12月07日 10:41 - */ -@Data -public class RuleForm { - private String roleName; - private List rules; -} diff --git a/src/main/java/com/example/liteflow/mysql/runner/AviatorEvaluatorRunner.java b/src/main/java/com/example/liteflow/mysql/runner/AviatorEvaluatorRunner.java index 53e903e..a9a226e 100644 --- a/src/main/java/com/example/liteflow/mysql/runner/AviatorEvaluatorRunner.java +++ b/src/main/java/com/example/liteflow/mysql/runner/AviatorEvaluatorRunner.java @@ -17,6 +17,10 @@ public class AviatorEvaluatorRunner implements CommandLineRunner { @Resource private BaseChainService baseChainService; + /** + * 初始化链路和珠莲路 + * @param args + */ @Override public void run(String... args) { baseChainService.initDynamicChain(); diff --git a/src/main/java/com/example/liteflow/mysql/service/BaseChainService.java b/src/main/java/com/example/liteflow/mysql/service/BaseChainService.java index 1dc147b..42f048a 100644 --- a/src/main/java/com/example/liteflow/mysql/service/BaseChainService.java +++ b/src/main/java/com/example/liteflow/mysql/service/BaseChainService.java @@ -10,13 +10,35 @@ import com.example.liteflow.mysql.model.CommonResult; * @createDate 2022-12-14 15:25:39 */ public interface BaseChainService extends IService { + /** + * 生成动态规则 + * + * @return CommonResult + */ CommonResult generateDynamicChain(); + /** + * 初始化链路 + */ void initDynamicChain(); + /** + * 初始化主链路 + */ void initMainChain(); + /** + * 执行链路 + * + * @param chainName 链路名称 + * @return CommonResult + */ CommonResult executeChain(String chainName); + /** + * 获取所有已注入的动态链路 + * + * @return CommonResult + */ CommonResult getChainList(); } diff --git a/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java b/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java index 95ad7d0..4bb488e 100644 --- a/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java +++ b/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java @@ -12,8 +12,28 @@ import java.util.List; * @date: 2022年12月06日 09:58 */ public interface BaseDataService extends IService { - BaseDataEntity getByTypeAndTemplateId(String type, String attribution); + /** + * 根据类型和模板Id获取基础数据 + * + * @param type 类型 + * @param templateId 模板Id + * @return BaseDataEntity + */ + BaseDataEntity getByTypeAndTemplateId(String type, String templateId); + + /** + * 创建基础数据 + * + * @param createBaseDataFrom 创建参数 + * @return CommonResult + */ CommonResult createBaseData(CreateBaseDataFrom createBaseDataFrom); + /** + * 批量创建基础数据 + * + * @param createBaseDataFromList 创建参数集合 + * @return CommonResult + */ CommonResult batchCreateBaseData(List createBaseDataFromList); } diff --git a/src/main/java/com/example/liteflow/mysql/service/BaseNodeService.java b/src/main/java/com/example/liteflow/mysql/service/BaseNodeService.java index 8bd764d..04bfe5a 100644 --- a/src/main/java/com/example/liteflow/mysql/service/BaseNodeService.java +++ b/src/main/java/com/example/liteflow/mysql/service/BaseNodeService.java @@ -7,17 +7,33 @@ import com.example.liteflow.mysql.model.node.CreateNodeFrom; import com.example.liteflow.mysql.model.node.UpdateNodeFrom; /** -* @author 75349 -* @description 针对表【base_node】的数据库操作Service -* @createDate 2022-12-14 09:37:25 -*/ + * @author 75349 + * @description 针对表【base_node】的数据库操作Service + * @createDate 2022-12-14 09:37:25 + */ public interface BaseNodeService extends IService { - + /** + * 创建节点 + * + * @param createNodeFrom 创建参数 + * @return CommonResult + */ CommonResult createNode(CreateNodeFrom createNodeFrom); CommonResult updateNode(UpdateNodeFrom updateNodeFrom); + /** + * 根据动态节点中的Id获取节点 + * + * @param nodeId 动态节点中的Id获取节点 + * @return BaseNodeEntity + */ BaseNodeEntity getByNodeId(String nodeId); + /** + * 获取所有已注入节点 + * + * @return CommonResult + */ CommonResult getNodeList(); } diff --git a/src/main/java/com/example/liteflow/mysql/service/BaseTemplateService.java b/src/main/java/com/example/liteflow/mysql/service/BaseTemplateService.java index 46703f8..06224e8 100644 --- a/src/main/java/com/example/liteflow/mysql/service/BaseTemplateService.java +++ b/src/main/java/com/example/liteflow/mysql/service/BaseTemplateService.java @@ -14,12 +14,25 @@ import java.util.List; * @createDate 2022-12-14 09:37:25 */ public interface BaseTemplateService extends IService { - + /** + * 创建爱你模板 + * + * @param createTemplateFrom 创建参数 + * @return CommonResult + */ CommonResult createTemplate(CreateTemplateFrom createTemplateFrom); boolean updateTemplate(UpdateTemplateFrom updateTemplateFrom); - + /** + * 获取所有未生成链路的模板 + * + * @return List + */ List getNotExistsChain(); - + /** + * 获取所有模板 + * + * @return CommonResult + */ CommonResult getTemplateList(); } diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/BaseChainServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/BaseChainServiceImpl.java index 3e57de1..d3e77ab 100644 --- a/src/main/java/com/example/liteflow/mysql/service/impl/BaseChainServiceImpl.java +++ b/src/main/java/com/example/liteflow/mysql/service/impl/BaseChainServiceImpl.java @@ -49,6 +49,11 @@ public class BaseChainServiceImpl extends ServiceImpl templateQueryWrapper = new LambdaQueryWrapper<>(); @@ -56,27 +61,34 @@ public class BaseChainServiceImpl extends ServiceImpl templateList = baseTemplateService.list(templateQueryWrapper); log.info("templateList size = {}", templateList.size()); if (CollUtil.isNotEmpty(templateList)) { - Map> templateAndNodeMap = new HashMap<>(); templateList.forEach(template -> { String templateId = template.getId(); LambdaUpdateWrapper nodeQueryWrapper = new LambdaUpdateWrapper<>(); nodeQueryWrapper.eq(BaseNodeEntity::getTemplateId, templateId) .eq(BaseNodeEntity::getEnableMark, EnableMarkEnum.Enable.getValue()); List nodeList = baseNodeService.list(nodeQueryWrapper); - templateAndNodeMap.put(template, nodeList); + if (CollUtil.isNotEmpty(nodeList)) { + template.setBaseNodeEntityList(nodeList); + } }); - this.generateOrUpdateChain(templateAndNodeMap); + List collect = templateList.stream().filter(template -> CollUtil.isNotEmpty(template.getBaseNodeEntityList())).collect(Collectors.toList()); + log.info("collect size = {}", collect.size()); + this.generateOrUpdateChain(collect); } this.initMainChain(); return CommonResult.success("生成链路成功", this.list()); } - private void generateOrUpdateChain(Map> templateAndNodeMap) { - for (Map.Entry> entry : templateAndNodeMap.entrySet()) { - BaseTemplateEntity templateEntity = entry.getKey(); + /** + * 保存或更新链路 + * + * @param baseTemplateEntityList + */ + private void generateOrUpdateChain(List baseTemplateEntityList) { + baseTemplateEntityList.forEach(templateEntity -> { String templateName = templateEntity.getTemplateName(); String templateId = templateEntity.getId(); - List nodeList = entry.getValue(); + List nodeList = templateEntity.getBaseNodeEntityList(); // 将所有节点注入 nodeList.forEach(node -> { String nodeType = node.getNodeType(); @@ -151,9 +163,12 @@ public class BaseChainServiceImpl extends ServiceImpl templateList = baseTemplateService.list(templateQueryWrapper); log.info("templateList size = {}", templateList.size()); if (CollUtil.isNotEmpty(templateList)) { - Map> templateAndNodeMap = new HashMap<>(); templateList.forEach(template -> { String templateId = template.getId(); LambdaUpdateWrapper nodeQueryWrapper = new LambdaUpdateWrapper<>(); @@ -170,14 +184,18 @@ public class BaseChainServiceImpl extends ServiceImpl nodeList = baseNodeService.list(nodeQueryWrapper); if (CollUtil.isNotEmpty(nodeList)) { - templateAndNodeMap.put(template, nodeList); + template.setBaseNodeEntityList(nodeList); } }); - log.info("templateAndNodeMap size = {}", templateAndNodeMap.size()); - this.generateOrUpdateChain(templateAndNodeMap); + List collect = templateList.stream().filter(template -> CollUtil.isNotEmpty(template.getBaseNodeEntityList())).collect(Collectors.toList()); + log.info("collect size = {}", collect.size()); + this.generateOrUpdateChain(collect); } } + /** + * 初始化主链路 + */ @Override public void initMainChain() { log.info("进入【初始化主链路】方法"); @@ -212,6 +230,12 @@ public class BaseChainServiceImpl extends ServiceImpl list = this.generateCostCenterTestData(); @@ -228,6 +252,11 @@ public class BaseChainServiceImpl extends ServiceImpl + */ private List generateCostCenterTestData() { List list = new ArrayList<>(); BaseCenter costCenter = new BaseCenter(); @@ -265,6 +294,11 @@ public class BaseChainServiceImpl extends ServiceImpl chainNameList = FlowBus.getChainMap().values().stream() diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/BaseDataServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/BaseDataServiceImpl.java index 6e57606..2a64039 100644 --- a/src/main/java/com/example/liteflow/mysql/service/impl/BaseDataServiceImpl.java +++ b/src/main/java/com/example/liteflow/mysql/service/impl/BaseDataServiceImpl.java @@ -28,6 +28,13 @@ import java.util.stream.Collectors; @Slf4j @Service public class BaseDataServiceImpl extends ServiceImpl implements BaseDataService { + /** + * 根据类型和模板Id获取基础数据 + * + * @param type 类型 + * @param templateId 模板Id + * @return BaseDataEntity + */ @Override public BaseDataEntity getByTypeAndTemplateId(String type, String templateId) { log.info("type = {}, templateId = {}", type, templateId); @@ -37,6 +44,12 @@ public class BaseDataServiceImpl extends ServiceImpl createBaseDataFromList) { log.info("进入【批量创建基础数据】方法 = {}", JSONUtil.toJsonStr(createBaseDataFromList)); diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/BaseNodeServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/BaseNodeServiceImpl.java index 9ef1370..1e86154 100644 --- a/src/main/java/com/example/liteflow/mysql/service/impl/BaseNodeServiceImpl.java +++ b/src/main/java/com/example/liteflow/mysql/service/impl/BaseNodeServiceImpl.java @@ -42,7 +42,12 @@ public class BaseNodeServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/BaseTemplateServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/BaseTemplateServiceImpl.java index 1328595..03b8dde 100644 --- a/src/main/java/com/example/liteflow/mysql/service/impl/BaseTemplateServiceImpl.java +++ b/src/main/java/com/example/liteflow/mysql/service/impl/BaseTemplateServiceImpl.java @@ -18,14 +18,20 @@ import java.util.List; import java.util.stream.Collectors; /** -* @author 75349 -* @description 针对表【base_template】的数据库操作Service实现 -* @createDate 2022-12-14 09:37:25 -*/ + * @author 75349 + * @description 针对表【base_template】的数据库操作Service实现 + * @createDate 2022-12-14 09:37:25 + */ @Service @Slf4j public class BaseTemplateServiceImpl extends ServiceImpl - implements BaseTemplateService{ + implements BaseTemplateService { + /** + * 创建爱你模板 + * + * @param createTemplateFrom 创建参数 + * @return CommonResult + */ @Override public CommonResult createTemplate(CreateTemplateFrom createTemplateFrom) { log.info("进入【创建模板】方法 = {}", createTemplateFrom); @@ -49,11 +55,21 @@ public class BaseTemplateServiceImpl extends ServiceImpl + */ @Override public List getNotExistsChain() { return this.baseMapper.getNotExistsChain(); } + /** + * 获取所有模板 + * + * @return CommonResult + */ @Override public CommonResult getTemplateList() { List templateList = this.list(); diff --git a/src/main/java/com/example/liteflow/mysql/util/RoleUtil.java b/src/main/java/com/example/liteflow/mysql/util/RoleUtil.java index b7788fd..b5279bd 100644 --- a/src/main/java/com/example/liteflow/mysql/util/RoleUtil.java +++ b/src/main/java/com/example/liteflow/mysql/util/RoleUtil.java @@ -15,13 +15,21 @@ import java.util.stream.Collectors; * @date: 2022年12月08日 15:37 */ public class RoleUtil { + /** + * 规则解析 + * + * @param rule 规则 + * @return Map + */ public static Map parseRole(Rule rule) { List matchList = rule.getMatches(); List ruleChildren = rule.getChildren(); String logicOperators = rule.getLogicOperators(); if (CollUtil.isNotEmpty(ruleChildren)) { - List> collect = ruleChildren.stream().map(child -> { + // 存在子的情况 + List> collect = ruleChildren.stream().map(child -> { List sunList = child.getChildren(); + // 存在子嵌套子的情况 if (CollUtil.isNotEmpty(sunList)) { List> sunCollect = sunList.stream().map(RoleUtil::parseRole).collect(Collectors.toList()); String childLogicOperators = child.getLogicOperators(); @@ -48,11 +56,12 @@ public class RoleUtil { Map childMap = new HashMap<>(); childMap.put(logicOperators, collect); return childMap; - } else if (CollUtil.isNotEmpty(matchList)){ - List> list = matchList.stream().map(matche -> { - String conditionalOperators = matche.getConditionalOperators(); - String matchingValue = matche.getMatchingValue(); - String matchingContent = matche.getMatchingContent(); + } else if (CollUtil.isNotEmpty(matchList)) { + // 存在多条规则的情况 + List> list = matchList.stream().map(match -> { + String conditionalOperators = match.getConditionalOperators(); + String matchingValue = match.getMatchingValue(); + String matchingContent = match.getMatchingContent(); List itemList = Lists.newArrayList(matchingValue, matchingContent); Map itemMap = new HashMap<>(); itemMap.put(conditionalOperators, itemList); @@ -62,6 +71,7 @@ public class RoleUtil { childMap.put(logicOperators, list); return childMap; } else { + // 只有一条规则的情况 String matchingValue = rule.getMatchingValue(); String matchingContent = rule.getMatchingContent(); String conditionalOperators = rule.getConditionalOperators(); diff --git a/src/test/java/MyTest.java b/src/test/java/MyTest.java index c39bc82..cacfac8 100644 --- a/src/test/java/MyTest.java +++ b/src/test/java/MyTest.java @@ -6,7 +6,6 @@ import com.example.liteflow.mysql.enums.NodeEnum; import com.example.liteflow.mysql.model.node.CreateNodeFrom; import com.example.liteflow.mysql.model.rule.Match; import com.example.liteflow.mysql.model.rule.Rule; -import com.example.liteflow.mysql.model.rule.RuleForm; import org.assertj.core.util.Lists; import org.junit.Test; @@ -248,10 +247,6 @@ public class MyTest { rule.setChildren(children); List rules = Lists.newArrayList(rule); - RuleForm ruleForm = new RuleForm(); - ruleForm.setRules(rules); - ruleForm.setRoleName("costCenter01Cmp"); -// baseRoleService.createRole(roleForm); // System.out.println(JSONUtil.toJsonStr(roles)); // List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); // System.out.println(JSONUtil.toJsonStr(collect)); @@ -298,10 +293,6 @@ public class MyTest { rule2.setMatches(matches2); List rules = Lists.newArrayList(rule, rule2); - RuleForm ruleForm = new RuleForm(); - ruleForm.setRules(rules); - ruleForm.setRoleName("costCenter02Cmp"); -// baseRoleService.createRole(roleForm); System.out.println(JSONUtil.toJsonStr(rules)); List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); @@ -359,10 +350,6 @@ public class MyTest { rule2.setChildren(children2); List rules = Lists.newArrayList(rule, rule2); - RuleForm ruleForm = new RuleForm(); - ruleForm.setRules(rules); - ruleForm.setRoleName("profitCenter01Cmp"); -// baseRoleService.createRole(roleForm); System.out.println(JSONUtil.toJsonStr(rules)); List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); @@ -414,10 +401,6 @@ public class MyTest { rule2.setChildren(children2); List rules = Lists.newArrayList(rule, rule2); - RuleForm ruleForm = new RuleForm(); - ruleForm.setRules(rules); - ruleForm.setRoleName("profitCenter02Cmp"); -// baseRoleService.createRole(roleForm); System.out.println(JSONUtil.toJsonStr(rules)); List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect));