diff --git a/src/main/java/com/example/liteflow/mysql/cmp/CenterCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/CenterCmp.java index e00db01..da37502 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/CenterCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/CenterCmp.java @@ -9,7 +9,7 @@ import cn.hutool.json.JSONUtil; import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.entity.BaseNodeEntity; import com.example.liteflow.mysql.model.BaseCenter; -import com.example.liteflow.mysql.model.role.Role; +import com.example.liteflow.mysql.model.rule.Rule; import com.example.liteflow.mysql.service.BaseDataService; import com.example.liteflow.mysql.service.BaseNodeService; import com.example.liteflow.mysql.util.ConditionParser; @@ -52,8 +52,8 @@ public class CenterCmp extends NodeIfComponent { String nodeRole = baseNodeEntity.getNodeRole(); String templateId = baseNodeEntity.getTemplateId(); log.info("nodeRole = {}", nodeRole); - List roles = JSONUtil.toList(JSONUtil.parseArray(nodeRole), Role.class); - List> collect = roles.stream().map(RoleUtil::parseRole).collect(Collectors.toList()); + List rules = JSONUtil.toList(JSONUtil.parseArray(nodeRole), Rule.class); + List> collect = rules.stream().map(RoleUtil::parseRole).collect(Collectors.toList()); String droolStr = JSONUtil.toJsonStr(collect); // 替换规则中的关键字 diff --git a/src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java b/src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java index 1f90cbd..39bff20 100644 --- a/src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java +++ b/src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java @@ -1,7 +1,7 @@ package com.example.liteflow.mysql.model.node; import com.example.liteflow.mysql.model.OutputFrom; -import com.example.liteflow.mysql.model.role.Role; +import com.example.liteflow.mysql.model.rule.Rule; import lombok.Data; import java.util.List; @@ -35,7 +35,7 @@ public class CreateNodeFrom { /** * 规则 */ - private List roles; + private List rules; /** * 节点对应输出节点id */ diff --git a/src/main/java/com/example/liteflow/mysql/model/node/UpdateNodeFrom.java b/src/main/java/com/example/liteflow/mysql/model/node/UpdateNodeFrom.java index aff3825..11ae130 100644 --- a/src/main/java/com/example/liteflow/mysql/model/node/UpdateNodeFrom.java +++ b/src/main/java/com/example/liteflow/mysql/model/node/UpdateNodeFrom.java @@ -1,7 +1,7 @@ package com.example.liteflow.mysql.model.node; import com.example.liteflow.mysql.model.OutputFrom; -import com.example.liteflow.mysql.model.role.Role; +import com.example.liteflow.mysql.model.rule.Rule; import lombok.Data; import java.util.List; @@ -20,7 +20,7 @@ public class UpdateNodeFrom { /** * 规则 */ - private List roles; + private List rules; /** * 内容 */ diff --git a/src/main/java/com/example/liteflow/mysql/model/role/Match.java b/src/main/java/com/example/liteflow/mysql/model/rule/Match.java similarity index 86% rename from src/main/java/com/example/liteflow/mysql/model/role/Match.java rename to src/main/java/com/example/liteflow/mysql/model/rule/Match.java index 9565d65..a5bcce0 100644 --- a/src/main/java/com/example/liteflow/mysql/model/role/Match.java +++ b/src/main/java/com/example/liteflow/mysql/model/rule/Match.java @@ -1,4 +1,4 @@ -package com.example.liteflow.mysql.model.role; +package com.example.liteflow.mysql.model.rule; import lombok.Data; diff --git a/src/main/java/com/example/liteflow/mysql/model/role/Role.java b/src/main/java/com/example/liteflow/mysql/model/rule/Rule.java similarity index 79% rename from src/main/java/com/example/liteflow/mysql/model/role/Role.java rename to src/main/java/com/example/liteflow/mysql/model/rule/Rule.java index 108a4b7..69e2a2f 100644 --- a/src/main/java/com/example/liteflow/mysql/model/role/Role.java +++ b/src/main/java/com/example/liteflow/mysql/model/rule/Rule.java @@ -1,4 +1,4 @@ -package com.example.liteflow.mysql.model.role; +package com.example.liteflow.mysql.model.rule; import lombok.Data; @@ -9,7 +9,7 @@ import java.util.List; * @date: 2022年12月07日 16:04 */ @Data -public class Role { +public class Rule { // 逻辑运算符"$or" private String logicOperators; // 条件运算符:"$eq" @@ -18,6 +18,6 @@ public class Role { private String matchingValue; // 匹配内容 private String matchingContent; - private List children; + private List children; private List matches; } diff --git a/src/main/java/com/example/liteflow/mysql/model/role/RoleForm.java b/src/main/java/com/example/liteflow/mysql/model/rule/RuleForm.java similarity index 59% rename from src/main/java/com/example/liteflow/mysql/model/role/RoleForm.java rename to src/main/java/com/example/liteflow/mysql/model/rule/RuleForm.java index 25a257c..819b92b 100644 --- a/src/main/java/com/example/liteflow/mysql/model/role/RoleForm.java +++ b/src/main/java/com/example/liteflow/mysql/model/rule/RuleForm.java @@ -1,4 +1,4 @@ -package com.example.liteflow.mysql.model.role; +package com.example.liteflow.mysql.model.rule; import lombok.Data; @@ -9,7 +9,7 @@ import java.util.List; * @date: 2022年12月07日 10:41 */ @Data -public class RoleForm { +public class RuleForm { private String roleName; - private List roles; + private List rules; } 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 8ddd373..9ef1370 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 @@ -18,7 +18,7 @@ import com.example.liteflow.mysql.model.OutputFrom; import com.example.liteflow.mysql.model.node.BaseNodeVO; import com.example.liteflow.mysql.model.node.CreateNodeFrom; import com.example.liteflow.mysql.model.node.UpdateNodeFrom; -import com.example.liteflow.mysql.model.role.Role; +import com.example.liteflow.mysql.model.rule.Rule; import com.example.liteflow.mysql.service.BaseNodeService; import com.example.liteflow.mysql.service.BaseTemplateService; import com.yomahub.liteflow.flow.FlowBus; @@ -58,10 +58,10 @@ public class BaseNodeServiceImpl extends ServiceImpl roles = createNodeFrom.getRoles(); + List rules = createNodeFrom.getRules(); OutputFrom content = createNodeFrom.getContent(); - if (CollUtil.isNotEmpty(roles) && NodeEnum.IfNode.getName().equals(nodeType)) { - baseNodeEntity.setNodeRole(JSONUtil.toJsonStr(roles)); + if (CollUtil.isNotEmpty(rules) && NodeEnum.IfNode.getName().equals(nodeType)) { + baseNodeEntity.setNodeRole(JSONUtil.toJsonStr(rules)); } else if (ObjectUtil.isNotNull(content) && NodeEnum.CommonNode.getName().equals(nodeType)) { baseNodeEntity.setNodeContent(JSONUtil.toJsonStr(content)); } else { @@ -77,8 +77,8 @@ public class BaseNodeServiceImpl extends ServiceImpl roles = updateNodeFrom.getRoles(); - String roleStr = ObjectUtil.isNotNull(roles) ? JSONUtil.toJsonStr(roles) : ""; + List rules = updateNodeFrom.getRules(); + String roleStr = ObjectUtil.isNotNull(rules) ? JSONUtil.toJsonStr(rules) : ""; OutputFrom content = updateNodeFrom.getContent(); String contentStr = ObjectUtil.isNotNull(content) ? JSONUtil.toJsonStr(content) : ""; LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); 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 420b5e0..b7788fd 100644 --- a/src/main/java/com/example/liteflow/mysql/util/RoleUtil.java +++ b/src/main/java/com/example/liteflow/mysql/util/RoleUtil.java @@ -1,8 +1,8 @@ package com.example.liteflow.mysql.util; import cn.hutool.core.collection.CollUtil; -import com.example.liteflow.mysql.model.role.Match; -import com.example.liteflow.mysql.model.role.Role; +import com.example.liteflow.mysql.model.rule.Match; +import com.example.liteflow.mysql.model.rule.Rule; import org.assertj.core.util.Lists; import java.util.HashMap; @@ -15,13 +15,13 @@ import java.util.stream.Collectors; * @date: 2022年12月08日 15:37 */ public class RoleUtil { - public static Map parseRole(Role role) { - List matchList = role.getMatches(); - List roleChildren = role.getChildren(); - String logicOperators = role.getLogicOperators(); - if (CollUtil.isNotEmpty(roleChildren)) { - List> collect = roleChildren.stream().map(child -> { - List sunList = child.getChildren(); + 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 sunList = child.getChildren(); if (CollUtil.isNotEmpty(sunList)) { List> sunCollect = sunList.stream().map(RoleUtil::parseRole).collect(Collectors.toList()); String childLogicOperators = child.getLogicOperators(); @@ -62,9 +62,9 @@ public class RoleUtil { childMap.put(logicOperators, list); return childMap; } else { - String matchingValue = role.getMatchingValue(); - String matchingContent = role.getMatchingContent(); - String conditionalOperators = role.getConditionalOperators(); + String matchingValue = rule.getMatchingValue(); + String matchingContent = rule.getMatchingContent(); + String conditionalOperators = rule.getConditionalOperators(); List itemList = Lists.newArrayList(matchingValue, matchingContent); Map itemMap = new HashMap<>(); itemMap.put(conditionalOperators, itemList); diff --git a/src/main/resources/测试参数.txt b/src/main/resources/测试参数.txt index 6c70e57..02d6db7 100644 --- a/src/main/resources/测试参数.txt +++ b/src/main/resources/测试参数.txt @@ -29,7 +29,7 @@ "nodeName": "costCenter01Cmp", "nodeType": "IfNode", "nodeContentId": "2480deadc736b40435a2b6930851aaa5", - "roles": [ + "rules": [ { "logicOperators": "$or", "children": [ @@ -70,7 +70,7 @@ "nodeName": "costCenter02Cmp", "nodeType": "IfNode", "nodeContentId": "0264efebbfb4c7cb5e4cb81092e1bce4", - "roles": [ + "rules": [ { "logicOperators": "$or", "children": [ @@ -140,7 +140,7 @@ "nodeName": "profitCenter01Cmp", "nodeType": "IfNode", "nodeContentId": "1a1df8cbdc9983fa03b3060049293b87", - "roles": [ + "rules": [ { "logicOperators": "$or", "children": [ @@ -196,7 +196,7 @@ "nodeName": "profitCenter02Cmp", "nodeType": "IfNode", "nodeContentId": "f050bd67f23cd0152f17d4f82d29b8a4", - "roles": [ + "rules": [ { "logicOperators": "$or", "children": [ diff --git a/src/test/java/MyTest.java b/src/test/java/MyTest.java index bf02348..c39bc82 100644 --- a/src/test/java/MyTest.java +++ b/src/test/java/MyTest.java @@ -4,16 +4,12 @@ import cn.hutool.json.JSONUtil; import com.example.liteflow.mysql.enums.MathOperatorEnum; import com.example.liteflow.mysql.enums.NodeEnum; import com.example.liteflow.mysql.model.node.CreateNodeFrom; -import com.example.liteflow.mysql.model.role.Match; -import com.example.liteflow.mysql.model.role.Role; -import com.example.liteflow.mysql.model.role.RoleForm; -import com.yomahub.liteflow.flow.FlowBus; -import com.yomahub.liteflow.flow.element.Node; +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; -import javax.annotation.Resource; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -30,13 +26,13 @@ public class MyTest { @Test public void test01() { - List roles = new ArrayList<>(); - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + List rules = new ArrayList<>(); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); - List children = new ArrayList<>(); - Role childRole = new Role(); - childRole.setLogicOperators(MathOperatorEnum.and.getOperator()); + List children = new ArrayList<>(); + Rule childRule = new Rule(); + childRule.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches = new ArrayList<>(); Match match = new Match(); @@ -50,31 +46,31 @@ public class MyTest { match.setMatchingContent("1"); matches.add(match); - childRole.setMatches(matches); - children.add(childRole); - role.setChildren(children); - roles.add(role); - System.out.println(JSONUtil.toJsonStr(roles)); + childRule.setMatches(matches); + children.add(childRule); + rule.setChildren(children); + rules.add(rule); + System.out.println(JSONUtil.toJsonStr(rules)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } @Test public void test02() { - List roles = new ArrayList<>(); - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + List rules = new ArrayList<>(); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child = new Role(); + Rule child = new Rule(); child.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role sun = new Role(); + Rule sun = new Rule(); sun.setLogicOperators(MathOperatorEnum.or.getOperator()); - List sunList = new ArrayList<>(); + List sunList = new ArrayList<>(); List matches = new ArrayList<>(); Match match = new Match(); @@ -92,12 +88,12 @@ public class MyTest { sunList.add(sun); child.setChildren(sunList); - List children = Lists.newArrayList(child); - role.setChildren(children); - roles.add(role); - System.out.println(JSONUtil.toJsonStr(roles)); + List children = Lists.newArrayList(child); + rule.setChildren(children); + rules.add(rule); + System.out.println(JSONUtil.toJsonStr(rules)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } @@ -105,8 +101,8 @@ public class MyTest { @Test public void test3() { - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); List matches = new ArrayList<>(); Match match = new Match(); @@ -115,17 +111,17 @@ public class MyTest { match.setMatchingContent("1"); matches.add(match); - role.setMatches(matches); - List roles = Lists.newArrayList(role); - System.out.println(JSONUtil.toJsonStr(roles)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + rule.setMatches(matches); + List rules = Lists.newArrayList(rule); + System.out.println(JSONUtil.toJsonStr(rules)); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } @Test public void test4() { - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); List matches = new ArrayList<>(); Match match = new Match(); @@ -140,34 +136,34 @@ public class MyTest { match.setMatchingContent("2"); matches.add(match); - role.setMatches(matches); - List roles = Lists.newArrayList(role); - System.out.println(JSONUtil.toJsonStr(roles)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + rule.setMatches(matches); + List rules = Lists.newArrayList(rule); + System.out.println(JSONUtil.toJsonStr(rules)); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } @Test public void test5() { - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); - role.setConditionalOperators(MathOperatorEnum.eq.getOperator()); - role.setMatchingValue("1"); - role.setMatchingContent("1"); + rule.setConditionalOperators(MathOperatorEnum.eq.getOperator()); + rule.setMatchingValue("1"); + rule.setMatchingContent("1"); - List roles = Lists.newArrayList(role); - System.out.println(JSONUtil.toJsonStr(roles)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + List rules = Lists.newArrayList(rule); + System.out.println(JSONUtil.toJsonStr(rules)); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } @Test public void test6() { - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child = new Role(); + Rule child = new Rule(); child.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches = new ArrayList<>(); Match match = new Match(); @@ -183,13 +179,13 @@ public class MyTest { matches.add(match); child.setMatches(matches); - List children = Lists.newArrayList(child); - role.setChildren(children); + List children = Lists.newArrayList(child); + rule.setChildren(children); - Role role2 = new Role(); - role2.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule2 = new Rule(); + rule2.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child2 = new Role(); + Rule child2 = new Rule(); child2.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches2 = new ArrayList<>(); Match match2 = new Match(); @@ -205,22 +201,22 @@ public class MyTest { matches2.add(match2); child2.setMatches(matches2); - List children2 = Lists.newArrayList(child2); - role2.setChildren(children2); + List children2 = Lists.newArrayList(child2); + rule2.setChildren(children2); - List roles = Lists.newArrayList(role, role2); - System.out.println(JSONUtil.toJsonStr(roles)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + List rules = Lists.newArrayList(rule, rule2); + System.out.println(JSONUtil.toJsonStr(rules)); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } @Test public void test7() { - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child = new Role(); + Rule child = new Rule(); child.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches = new ArrayList<>(); Match match = new Match(); @@ -248,13 +244,13 @@ public class MyTest { matches.add(match); child.setMatches(matches); - List children = Lists.newArrayList(child); - role.setChildren(children); + List children = Lists.newArrayList(child); + rule.setChildren(children); - List roles = Lists.newArrayList(role); - RoleForm roleForm = new RoleForm(); - roleForm.setRoles(roles); - roleForm.setRoleName("costCenter01Cmp"); + 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()); @@ -263,13 +259,13 @@ public class MyTest { @Test public void test8() { - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child = new Role(); + Rule child = new Rule(); child.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role sun = new Role(); + Rule sun = new Rule(); sun.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches = new ArrayList<>(); Match match = new Match(); @@ -285,10 +281,10 @@ public class MyTest { matches.add(match); sun.setMatches(matches); - List sunList = Lists.newArrayList(sun); + List sunList = Lists.newArrayList(sun); child.setChildren(sunList); - List children = Lists.newArrayList(child); - role.setChildren(children); + List children = Lists.newArrayList(child); + rule.setChildren(children); List matches2 = new ArrayList<>(); @@ -297,26 +293,26 @@ public class MyTest { match2.setMatchingValue("businessType"); match2.setMatchingContent("businessTypeList"); matches2.add(match2); - Role role2 = new Role(); - role2.setLogicOperators(MathOperatorEnum.or.getOperator()); - role2.setMatches(matches2); + Rule rule2 = new Rule(); + rule2.setLogicOperators(MathOperatorEnum.or.getOperator()); + rule2.setMatches(matches2); - List roles = Lists.newArrayList(role, role2); - RoleForm roleForm = new RoleForm(); - roleForm.setRoles(roles); - roleForm.setRoleName("costCenter02Cmp"); + List rules = Lists.newArrayList(rule, rule2); + RuleForm ruleForm = new RuleForm(); + ruleForm.setRules(rules); + ruleForm.setRoleName("costCenter02Cmp"); // baseRoleService.createRole(roleForm); - System.out.println(JSONUtil.toJsonStr(roles)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + System.out.println(JSONUtil.toJsonStr(rules)); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } @Test public void test09() { - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child = new Role(); + Rule child = new Rule(); child.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches = new ArrayList<>(); @@ -339,12 +335,12 @@ public class MyTest { matches.add(match); child.setMatches(matches); - List children = Lists.newArrayList(child); - role.setChildren(children); + List children = Lists.newArrayList(child); + rule.setChildren(children); - Role role2 = new Role(); - role2.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child2 = new Role(); + Rule rule2 = new Rule(); + rule2.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule child2 = new Rule(); child2.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches2 = new ArrayList<>(); Match match2 = new Match(); @@ -359,25 +355,25 @@ public class MyTest { match2.setMatchingContent("businessTypeList"); matches2.add(match2); child2.setMatches(matches2); - List children2 = Lists.newArrayList(child2); - role2.setChildren(children2); + List children2 = Lists.newArrayList(child2); + rule2.setChildren(children2); - List roles = Lists.newArrayList(role, role2); - RoleForm roleForm = new RoleForm(); - roleForm.setRoles(roles); - roleForm.setRoleName("profitCenter01Cmp"); + List rules = Lists.newArrayList(rule, rule2); + RuleForm ruleForm = new RuleForm(); + ruleForm.setRules(rules); + ruleForm.setRoleName("profitCenter01Cmp"); // baseRoleService.createRole(roleForm); - System.out.println(JSONUtil.toJsonStr(roles)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + System.out.println(JSONUtil.toJsonStr(rules)); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } @Test public void test10() { - Role role = new Role(); - role.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule rule = new Rule(); + rule.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child = new Role(); + Rule child = new Rule(); child.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches = new ArrayList<>(); @@ -394,12 +390,12 @@ public class MyTest { matches.add(match); child.setMatches(matches); - List children = Lists.newArrayList(child); - role.setChildren(children); + List children = Lists.newArrayList(child); + rule.setChildren(children); - Role role2 = new Role(); - role2.setLogicOperators(MathOperatorEnum.or.getOperator()); - Role child2 = new Role(); + Rule rule2 = new Rule(); + rule2.setLogicOperators(MathOperatorEnum.or.getOperator()); + Rule child2 = new Rule(); child2.setLogicOperators(MathOperatorEnum.and.getOperator()); List matches2 = new ArrayList<>(); Match match2 = new Match(); @@ -414,25 +410,25 @@ public class MyTest { match2.setMatchingContent("businessTypeList"); matches2.add(match2); child2.setMatches(matches2); - List children2 = Lists.newArrayList(child2); - role2.setChildren(children2); + List children2 = Lists.newArrayList(child2); + rule2.setChildren(children2); - List roles = Lists.newArrayList(role, role2); - RoleForm roleForm = new RoleForm(); - roleForm.setRoles(roles); - roleForm.setRoleName("profitCenter02Cmp"); + List rules = Lists.newArrayList(rule, rule2); + RuleForm ruleForm = new RuleForm(); + ruleForm.setRules(rules); + ruleForm.setRoleName("profitCenter02Cmp"); // baseRoleService.createRole(roleForm); - System.out.println(JSONUtil.toJsonStr(roles)); - List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); + System.out.println(JSONUtil.toJsonStr(rules)); + List> collect = rules.stream().map(this::parseRole).collect(Collectors.toList()); System.out.println(JSONUtil.toJsonStr(collect)); } - private Map parseRole(Role role) { - List matchList = role.getMatches(); - List roleChildren = role.getChildren(); - String logicOperators = role.getLogicOperators(); - if (CollUtil.isNotEmpty(roleChildren)) { - List> collect = roleChildren.stream().map(child -> { - List sunList = child.getChildren(); + private 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 sunList = child.getChildren(); if (CollUtil.isNotEmpty(sunList)) { List> sunCollect = sunList.stream().map(this::parseRole).collect(Collectors.toList()); String childLogicOperators = child.getLogicOperators(); @@ -473,9 +469,9 @@ public class MyTest { childMap.put(logicOperators, list); return childMap; } else { - String matchingValue = role.getMatchingValue(); - String matchingContent = role.getMatchingContent(); - String conditionalOperators = role.getConditionalOperators(); + String matchingValue = rule.getMatchingValue(); + String matchingContent = rule.getMatchingContent(); + String conditionalOperators = rule.getConditionalOperators(); List itemList = Lists.newArrayList(matchingValue, matchingContent); Map itemMap = new HashMap<>(); itemMap.put(conditionalOperators, itemList); @@ -503,5 +499,8 @@ public class MyTest { createNodeFrom.setNodeName("costCenter01Cmp"); createNodeFrom.setNodeType(NodeEnum.IfNode.getName()); System.out.println(JSONUtil.toJsonStr(createNodeFrom)); + + String str = "2"; + System.out.println(str.equals(null)); } }