diff --git a/src/main/java/com/example/liteflow/mysql/LiteFlowCommand.java b/src/main/java/com/example/liteflow/mysql/LiteFlowCommand.java index cda97e2..c718560 100644 --- a/src/main/java/com/example/liteflow/mysql/LiteFlowCommand.java +++ b/src/main/java/com/example/liteflow/mysql/LiteFlowCommand.java @@ -1,12 +1,15 @@ package com.example.liteflow.mysql; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSON; import cn.hutool.json.JSONUtil; import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.CostCenter; import com.example.liteflow.mysql.model.CostCenterContext; import com.example.liteflow.mysql.model.ProfitCenter; +import com.googlecode.aviator.AviatorEvaluator; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import org.assertj.core.util.Lists; @@ -20,7 +23,9 @@ import java.util.ArrayList; import java.util.List; @Component -public class LiteFlowCommand { +public class LiteFlowCommand +// implements CommandLineRunner +{ private final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -31,9 +36,8 @@ public class LiteFlowCommand { private final List profitCenterList = Lists.newArrayList("profit01AndProfit02", "profit01", "profit02"); private final List costCenterList = Lists.newArrayList("cost01AndCost02", "cost01", "cost02"); - // @Override - public void run(String... args) throws Exception { + public void run1(String... args) throws Exception { // 事实对象 // CostCenter costCenter = new CostCenter(); // costCenter.setSectionClassification("成本科目1"); diff --git a/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorBean.java b/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorBean.java new file mode 100644 index 0000000..009190a --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/bean/AviatorEvaluatorBean.java @@ -0,0 +1,21 @@ +package com.example.liteflow.mysql.bean; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.googlecode.aviator.AviatorEvaluator; +import org.springframework.boot.CommandLineRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +/** + * @author: 陈韦龙 + * @date: 2022年12月09日 15:35 + */ +@Component +public class AviatorEvaluatorBean { + @Bean + public void aviatorEvaluatorInit() throws IllegalAccessException, NoSuchMethodException { + AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); + AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); + } +} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01Cmp.java b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01Cmp.java index 1c48dc0..ef53ea5 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01Cmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01Cmp.java @@ -34,7 +34,6 @@ public class CostCenter01Cmp extends NodeIfComponent { private BaseDataService baseDataService; @Resource private BaseRoleService baseRoleService; - private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}, {\"$contains\": [businessCategory, businessCategoryList]}]}]}]"; private static final String baseRoleName = "costCenter01Cmp"; @@ -44,36 +43,41 @@ public class CostCenter01Cmp extends NodeIfComponent { log.info("requestData = {}", JSONUtil.toJsonStr(requestData)); String droolStr = baseRoleService.getByName(baseRoleName); log.info("droolStr = {}", droolStr); - Field[] fields = ReflectUtil.getFields(BaseCenter.class); - for (Field field : fields) { - Object fieldValue = ReflectUtil.getFieldValue(requestData, field); - String name = field.getName(); - BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution()); - if (ObjectUtil.isNotNull(baseDataEntity)) { - String content = baseDataEntity.getContent(); - String contentName = baseDataEntity.getContentName(); - droolStr = StrUtil.replace(droolStr, contentName, content, false); + if (StrUtil.isNotBlank(droolStr)) { + Field[] fields = ReflectUtil.getFields(BaseCenter.class); + for (Field field : fields) { + Object fieldValue = ReflectUtil.getFieldValue(requestData, field); + String name = field.getName(); + BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution()); + if (ObjectUtil.isNotNull(baseDataEntity)) { + String content = baseDataEntity.getContent(); + String contentName = baseDataEntity.getContentName(); + droolStr = StrUtil.replace(droolStr, contentName, content, false); + } + String filedValueStr = ""; + if (ObjectUtil.isNotNull(fieldValue)) { + filedValueStr = fieldValue.toString(); + } + droolStr = StrUtil.replace(droolStr, name, filedValueStr, false); } - String filedValueStr = ""; - if (ObjectUtil.isNotNull(fieldValue)) { - filedValueStr = fieldValue.toString(); - } - droolStr = StrUtil.replace(droolStr, name, filedValueStr, false); + + log.info("after - droolStr = {}", droolStr); + JSONArray jsonArray = JSONUtil.parseArray(droolStr); + log.info("jsonArray = {}", jsonArray); + + String conditionResult = ConditionParser.parseCondition(jsonArray); + + log.info("condition template = {}", conditionResult); +// AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); +// AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); + Object executeB = AviatorEvaluator.execute(conditionResult); + log.info("CostCenter01Cmp-{} = {}", conditionResult, executeB); + boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); + log.info("CostCenter01Cmp-aBoolean = {}", aBoolean); + return aBoolean; + } else { + return false; } - log.info("after - droolStr = {}", droolStr); - JSONArray jsonArray = JSONUtil.parseArray(droolStr); - log.info("jsonArray = {}", jsonArray); - - String conditionResult = ConditionParser.parseCondition(jsonArray); - - log.info("condition template = {}", conditionResult); - AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); - AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); - Object executeB = AviatorEvaluator.execute(conditionResult); - log.info("CostCenter01Cmp-{} = {}", conditionResult, executeB); - boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); - log.info("CostCenter01Cmp-aBoolean = {}", aBoolean); - return aBoolean; } } diff --git a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01SoutCmp.java index 6ee9108..d505e75 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01SoutCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01SoutCmp.java @@ -1,11 +1,16 @@ package com.example.liteflow.mysql.cmp.costCenter; +import com.example.liteflow.mysql.entity.BaseDataEntity; +import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.CostCenter; +import com.example.liteflow.mysql.service.BaseDataService; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import lombok.extern.slf4j.Slf4j; +import javax.annotation.Resource; + /** * @author: 陈韦龙 * @date: 2022年12月05日 10:15 @@ -14,13 +19,18 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class CostCenter01SoutCmp extends NodeComponent { - private static final String costCenter01Code = "P350401028"; - private static final String costCenter01Name = "仓干配物流部利润中心"; - +// private static final String costCenter01Code = "P350401028"; +// private static final String costCenter01Name = "仓干配物流部利润中心"; + @Resource + private BaseDataService baseDataService; @Override public void process() { + BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.costCenter.getAttribution(), "costCenter01Code"); + BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.costCenter.getAttribution(), "costCenter01Name"); + String costCenter01Code = codeBaseData.getContent(); + String costCenter01Name = nameBaseData.getContent(); BaseCenter baseCenter = this.getRequestData(); baseCenter.setCostCenterCode(costCenter01Code); baseCenter.setCostCenterName(costCenter01Name); diff --git a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02Cmp.java b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02Cmp.java index 854394a..9438e57 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02Cmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02Cmp.java @@ -34,8 +34,6 @@ import java.util.Map; @Slf4j public class CostCenter02Cmp extends NodeIfComponent { - private static final String drool = "[{\"$or\": [{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"$contains\": [businessType, businessTypeList]}]}]}]"; - @Resource private BaseDataService baseDataService; @Resource @@ -45,38 +43,42 @@ public class CostCenter02Cmp extends NodeIfComponent { public boolean processIf() throws Exception { BaseCenter requestData = this.getRequestData(); String droolStr = baseRoleService.getByName(baseRoleName); - log.info("droolStr = {}", droolStr); log.info("CostCenter02Cmp-droolStr = {}", droolStr); - Field[] fields = ReflectUtil.getFields(BaseCenter.class); - for (Field field : fields) { - Object fieldValue = ReflectUtil.getFieldValue(requestData, field); - String name = field.getName(); - BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution()); - if (ObjectUtil.isNotNull(baseDataEntity)) { - String content = baseDataEntity.getContent(); - String contentName = baseDataEntity.getContentName(); - droolStr = StrUtil.replace(droolStr, contentName, content, false); + if (StrUtil.isNotBlank(droolStr)) { + Field[] fields = ReflectUtil.getFields(BaseCenter.class); + for (Field field : fields) { + Object fieldValue = ReflectUtil.getFieldValue(requestData, field); + String name = field.getName(); + BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.costCenter.getAttribution()); + if (ObjectUtil.isNotNull(baseDataEntity)) { + String content = baseDataEntity.getContent(); + String contentName = baseDataEntity.getContentName(); + droolStr = StrUtil.replace(droolStr, contentName, content, false); + } + String filedValueStr = ""; + if (ObjectUtil.isNotNull(fieldValue)) { + filedValueStr = fieldValue.toString(); + } + droolStr = StrUtil.replace(droolStr, name, filedValueStr, false); } - String filedValueStr = ""; - if (ObjectUtil.isNotNull(fieldValue)) { - filedValueStr = fieldValue.toString(); - } - droolStr = StrUtil.replace(droolStr, name, filedValueStr, false); + + log.info("after - replace4 = {}", droolStr); + JSONArray jsonArray = JSONUtil.parseArray(droolStr); + log.info("jsonArray = {}", jsonArray); + + String conditionResult = ConditionParser.parseCondition(jsonArray); + + log.info("condition template = {}", conditionResult); +// AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); +// AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); + Object executeB = AviatorEvaluator.execute(conditionResult); + log.info("CostCenter02Cmp-{} = {}", conditionResult, executeB); + boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); + log.info("CostCenter02Cmp-aBoolean = {}", aBoolean); + return aBoolean; + } else { + return false; } - log.info("after - replace4 = {}", droolStr); - JSONArray jsonArray = JSONUtil.parseArray(droolStr); - log.info("jsonArray = {}", jsonArray); - - String conditionResult = ConditionParser.parseCondition(jsonArray); - - log.info("condition template = {}", conditionResult); - AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); - AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); - Object executeB = AviatorEvaluator.execute(conditionResult); - log.info("CostCenter02Cmp-{} = {}", conditionResult, executeB); - boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); - log.info("CostCenter02Cmp-aBoolean = {}", aBoolean); - return aBoolean; } } diff --git a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02SoutCmp.java index 9fb65ec..5b94523 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02SoutCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02SoutCmp.java @@ -1,11 +1,16 @@ package com.example.liteflow.mysql.cmp.costCenter; +import com.example.liteflow.mysql.entity.BaseDataEntity; +import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.CostCenter; +import com.example.liteflow.mysql.service.BaseDataService; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import lombok.extern.slf4j.Slf4j; +import javax.annotation.Resource; + /** * @author: 陈韦龙 * @date: 2022年12月05日 10:15 @@ -14,14 +19,19 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class CostCenter02SoutCmp extends NodeComponent { - private static final String costCenter02Code = "P350401026"; - private static final String costCenter02Name = "商品车物流部利润中心"; - +// private static final String costCenter02Code = "P350401026"; +// private static final String costCenter02Name = "商品车物流部利润中心"; + @Resource + private BaseDataService baseDataService; @Override public void process() { + BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.costCenter.getAttribution(), "costCenter02Code"); + BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.costCenter.getAttribution(), "costCenter02Name"); BaseCenter baseCenter = this.getRequestData(); + String costCenter02Code = codeBaseData.getContent(); + String costCenter02Name = nameBaseData.getContent(); baseCenter.setCostCenterCode(costCenter02Code); baseCenter.setCostCenterName(costCenter02Name); baseCenter.setCostCenterGenerateCode(costCenter02Code + costCenter02Name); diff --git a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01Cmp.java b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01Cmp.java index 3f8349d..9089beb 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01Cmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01Cmp.java @@ -11,6 +11,7 @@ import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.service.BaseDataService; +import com.example.liteflow.mysql.service.BaseRoleService; import com.example.liteflow.mysql.util.ConditionParser; import com.googlecode.aviator.AviatorEvaluator; import com.yomahub.liteflow.annotation.LiteflowComponent; @@ -28,44 +29,51 @@ import java.lang.reflect.Field; @Slf4j public class ProfitCenter01Cmp extends NodeIfComponent { - private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}, {\"$contains\": [businessCategory, businessCategoryList]}]}]}, {\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}]}]}]"; - @Resource private BaseDataService baseDataService; + @Resource + private BaseRoleService baseRoleService; + private static final String baseRoleName = "profitCenter01Cmp"; @Override public boolean processIf() throws Exception { BaseCenter requestData = this.getRequestData(); - String droolStr = drool; - Field[] fields = ReflectUtil.getFields(BaseCenter.class); - for (Field field : fields) { - Object fieldValue = ReflectUtil.getFieldValue(requestData, field); - String name = field.getName(); - BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.profitCenter.getAttribution()); - if (ObjectUtil.isNotNull(baseDataEntity)) { - String content = baseDataEntity.getContent(); - String contentName = baseDataEntity.getContentName(); - droolStr = StrUtil.replace(droolStr, contentName, content, false); + String droolStr = baseRoleService.getByName(baseRoleName); + log.info("ProfitCenter01Cmp-droolStr = {}", droolStr); + if (StrUtil.isNotBlank(droolStr)) { + Field[] fields = ReflectUtil.getFields(BaseCenter.class); + for (Field field : fields) { + Object fieldValue = ReflectUtil.getFieldValue(requestData, field); + String name = field.getName(); + BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.profitCenter.getAttribution()); + if (ObjectUtil.isNotNull(baseDataEntity)) { + String content = baseDataEntity.getContent(); + String contentName = baseDataEntity.getContentName(); + droolStr = StrUtil.replace(droolStr, contentName, content, false); + } + String filedValueStr = ""; + if (ObjectUtil.isNotNull(fieldValue)) { + filedValueStr = fieldValue.toString(); + } + droolStr = StrUtil.replace(droolStr, name, filedValueStr, false); } - String filedValueStr = ""; - if (ObjectUtil.isNotNull(fieldValue)) { - filedValueStr = fieldValue.toString(); - } - droolStr = StrUtil.replace(droolStr, name, filedValueStr, false); + + log.info("after - droolStr = {}", droolStr); + JSONArray jsonArray = JSONUtil.parseArray(droolStr); + log.info("jsonArray = {}", jsonArray); + + String conditionResult = ConditionParser.parseCondition(jsonArray); + + log.info("condition template = {}", conditionResult); +// AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); +// AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); + Object executeB = AviatorEvaluator.execute(conditionResult); + log.info("ProfitCenter01Cmp-{} = {}", conditionResult, executeB); + boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); + log.info("ProfitCenter01Cmp-aBoolean = {}", aBoolean); + return aBoolean; + } else { + return false; } - log.info("after - droolStr = {}", droolStr); - JSONArray jsonArray = JSONUtil.parseArray(droolStr); - log.info("jsonArray = {}", jsonArray); - - String conditionResult = ConditionParser.parseCondition(jsonArray); - - log.info("condition template = {}", conditionResult); - AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); - AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); - Object executeB = AviatorEvaluator.execute(conditionResult); - log.info("ProfitCenter01Cmp-{} = {}", conditionResult, executeB); - boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); - log.info("ProfitCenter01Cmp-aBoolean = {}", aBoolean); - return aBoolean; } } diff --git a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01SoutCmp.java index 44db0ca..f0c0a2c 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01SoutCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01SoutCmp.java @@ -1,10 +1,15 @@ package com.example.liteflow.mysql.cmp.profitCenter; +import com.example.liteflow.mysql.entity.BaseDataEntity; +import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.model.BaseCenter; +import com.example.liteflow.mysql.service.BaseDataService; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import lombok.extern.slf4j.Slf4j; +import javax.annotation.Resource; + /** * @author: 陈韦龙 * @date: 2022年12月05日 10:15 @@ -13,13 +18,18 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class ProfitCenter01SoutCmp extends NodeComponent { - private static final String profitCenter01Code = "P350401029"; - private static final String profitCenter01Name = "仓干配物流部成本中心"; - +// private static final String profitCenter01Code = "P350401029"; +// private static final String profitCenter01Name = "仓干配物流部成本中心"; + @Resource + private BaseDataService baseDataService; @Override public void process() { + BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.profitCenter.getAttribution(), "profitCenter01Code"); + BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.profitCenter.getAttribution(), "profitCenter01Name"); BaseCenter baseCenter = this.getRequestData(); + String profitCenter01Code = codeBaseData.getContent(); + String profitCenter01Name = nameBaseData.getContent(); baseCenter.setProfitCenterCode(profitCenter01Code); baseCenter.setProfitCenterName(profitCenter01Name); baseCenter.setProfitCenterGenerateCode(profitCenter01Code + profitCenter01Name); diff --git a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02Cmp.java b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02Cmp.java index d7298f1..f47aa45 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02Cmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02Cmp.java @@ -10,21 +10,16 @@ import cn.hutool.json.JSONUtil; import com.example.liteflow.mysql.entity.BaseDataEntity; import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.model.BaseCenter; -import com.example.liteflow.mysql.model.CostCenter; -import com.example.liteflow.mysql.model.ProfitCenter; import com.example.liteflow.mysql.service.BaseDataService; +import com.example.liteflow.mysql.service.BaseRoleService; import com.example.liteflow.mysql.util.ConditionParser; import com.googlecode.aviator.AviatorEvaluator; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeIfComponent; import lombok.extern.slf4j.Slf4j; -import org.assertj.core.util.Lists; import javax.annotation.Resource; import java.lang.reflect.Field; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; /** * @author: 陈韦龙 @@ -34,44 +29,51 @@ import java.util.Map; @Slf4j public class ProfitCenter02Cmp extends NodeIfComponent { - private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"$and\": [{\"$contains\":[sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}]}]}]"; - @Resource private BaseDataService baseDataService; + @Resource + private BaseRoleService baseRoleService; + private static final String baseRoleName = "profitCenter02Cmp"; @Override public boolean processIf() throws Exception { BaseCenter requestData = this.getRequestData(); - String droolStr = drool; - Field[] fields = ReflectUtil.getFields(BaseCenter.class); - for (Field field : fields) { - Object fieldValue = ReflectUtil.getFieldValue(requestData, field); - String name = field.getName(); - BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.profitCenter.getAttribution()); - if (ObjectUtil.isNotNull(baseDataEntity)) { - String content = baseDataEntity.getContent(); - String contentName = baseDataEntity.getContentName(); - droolStr = StrUtil.replace(droolStr, contentName, content, false); + String droolStr = baseRoleService.getByName(baseRoleName); + log.info("ProfitCenter02Cmp-droolStr = {}", droolStr); + if (StrUtil.isNotBlank(droolStr)) { + Field[] fields = ReflectUtil.getFields(BaseCenter.class); + for (Field field : fields) { + Object fieldValue = ReflectUtil.getFieldValue(requestData, field); + String name = field.getName(); + BaseDataEntity baseDataEntity = baseDataService.getByType(name, BaseDataAttributionEnum.profitCenter.getAttribution()); + if (ObjectUtil.isNotNull(baseDataEntity)) { + String content = baseDataEntity.getContent(); + String contentName = baseDataEntity.getContentName(); + droolStr = StrUtil.replace(droolStr, contentName, content, false); + } + String filedValueStr = ""; + if (ObjectUtil.isNotNull(fieldValue)) { + filedValueStr = fieldValue.toString(); + } + droolStr = StrUtil.replace(droolStr, name, filedValueStr, false); } - String filedValueStr = ""; - if (ObjectUtil.isNotNull(fieldValue)) { - filedValueStr = fieldValue.toString(); - } - droolStr = StrUtil.replace(droolStr, name, filedValueStr, false); + + log.info("after - droolStr = {}", droolStr); + JSONArray jsonArray = JSONUtil.parseArray(droolStr); + log.info("jsonArray = {}", jsonArray); + + String conditionResult = ConditionParser.parseCondition(jsonArray); + + log.info("condition template = {}", conditionResult); +// AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); +// AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); + Object executeB = AviatorEvaluator.execute(conditionResult); + log.info("CostCenter02Cmp-{} = {}", conditionResult, executeB); + boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); + log.info("CostCenter02Cmp-aBoolean = {}", aBoolean); + return aBoolean; + } else { + return false; } - log.info("after - droolStr = {}", droolStr); - JSONArray jsonArray = JSONUtil.parseArray(droolStr); - log.info("jsonArray = {}", jsonArray); - - String conditionResult = ConditionParser.parseCondition(jsonArray); - - log.info("condition template = {}", conditionResult); - AviatorEvaluator.addStaticFunctions("CollUtil", CollUtil.class); - AviatorEvaluator.addStaticFunctions("StrUtil", StrUtil.class); - Object executeB = AviatorEvaluator.execute(conditionResult); - log.info("CostCenter02Cmp-{} = {}", conditionResult, executeB); - boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); - log.info("CostCenter02Cmp-aBoolean = {}", aBoolean); - return aBoolean; } } diff --git a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02SoutCmp.java index 86c2bdb..23de58e 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02SoutCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02SoutCmp.java @@ -1,10 +1,16 @@ package com.example.liteflow.mysql.cmp.profitCenter; +import cn.hutool.core.util.ObjectUtil; +import com.example.liteflow.mysql.entity.BaseDataEntity; +import com.example.liteflow.mysql.enums.BaseDataAttributionEnum; import com.example.liteflow.mysql.model.BaseCenter; +import com.example.liteflow.mysql.service.BaseDataService; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import lombok.extern.slf4j.Slf4j; +import javax.annotation.Resource; + /** * @author: 陈韦龙 * @date: 2022年12月05日 10:15 @@ -13,17 +19,24 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class ProfitCenter02SoutCmp extends NodeComponent { - private static final String profitCenter02Code = "P350401027"; - private static final String profitCenter02Name = "商品车物流部成本中心"; - +// private static final String profitCenter02Code = "P350401027"; +// private static final String profitCenter02Name = "商品车物流部成本中心"; +@Resource +private BaseDataService baseDataService; @Override public void process() { + BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.profitCenter.getAttribution(), "profitCenter02Code"); + BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("sout", BaseDataAttributionEnum.profitCenter.getAttribution(), "profitCenter02Name"); BaseCenter baseCenter = this.getRequestData(); - baseCenter.setProfitCenterCode(profitCenter02Code); - baseCenter.setProfitCenterName(profitCenter02Name); - baseCenter.setProfitCenterGenerateCode(profitCenter02Code + profitCenter02Name); - baseCenter.setGenerateCode(null); + if (ObjectUtil.isNotNull(codeBaseData) && ObjectUtil.isNotNull(nameBaseData)) { + String profitCenter02Code = codeBaseData.getContent(); + String profitCenter02Name = nameBaseData.getContent(); + baseCenter.setProfitCenterCode(profitCenter02Code); + baseCenter.setProfitCenterName(profitCenter02Name); + baseCenter.setProfitCenterGenerateCode(profitCenter02Code + profitCenter02Name); + baseCenter.setGenerateCode(null); + } } } diff --git a/src/main/java/com/example/liteflow/mysql/controller/BaseRoleController.java b/src/main/java/com/example/liteflow/mysql/controller/BaseRoleController.java index a611b80..27859aa 100644 --- a/src/main/java/com/example/liteflow/mysql/controller/BaseRoleController.java +++ b/src/main/java/com/example/liteflow/mysql/controller/BaseRoleController.java @@ -9,10 +9,7 @@ import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.enums.FlowParserTypeEnum; import com.yomahub.liteflow.flow.FlowBus; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @@ -30,8 +27,6 @@ public class BaseRoleController { @Resource private BaseRoleService baseRoleService; - @Resource - private FlowExecutor flowExecutor; @PostMapping("/createRole") public void createRole(@RequestBody RoleForm roleForm) { baseRoleService.createRole(roleForm); @@ -40,4 +35,9 @@ public class BaseRoleController { // System.out.println(JSONUtil.toJsonStr(collect)); // flowExecutor.reloadRule(); } + + @GetMapping("/testCreateRole") + public void testCreateRole() { + baseRoleService.testCreateRole(); + } } diff --git a/src/main/java/com/example/liteflow/mysql/controller/ChainController.java b/src/main/java/com/example/liteflow/mysql/controller/ChainController.java index 002b3b7..a228415 100644 --- a/src/main/java/com/example/liteflow/mysql/controller/ChainController.java +++ b/src/main/java/com/example/liteflow/mysql/controller/ChainController.java @@ -1,12 +1,14 @@ package com.example.liteflow.mysql.controller; import com.example.liteflow.mysql.entity.ChainEntity; +import com.example.liteflow.mysql.model.BaseCenter; import com.example.liteflow.mysql.model.role.RoleForm; import com.example.liteflow.mysql.service.ChainService; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.List; /** * @author: 陈韦龙 @@ -25,12 +27,17 @@ public class ChainController { } @GetMapping("/executeChain/{chainName}") - public void executeChain(@PathVariable("chainName") String chainName) { - chainService.executeChain(chainName); + public List executeChain(@PathVariable("chainName") String chainName) { + return chainService.executeChain(chainName); } @GetMapping("/getChainByName/{chainName}") public ChainEntity getChainByName(@PathVariable("chainName") String chainName) { return chainService.getChainName(chainName); } + + @DeleteMapping("/deleteChain/{id}") + public String deleteChain(@PathVariable("id") String id) { + return chainService.deleteChain(id); + } } 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 2efd355..e994343 100644 --- a/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java +++ b/src/main/java/com/example/liteflow/mysql/service/BaseDataService.java @@ -9,4 +9,6 @@ import com.example.liteflow.mysql.entity.BaseDataEntity; */ public interface BaseDataService extends IService { BaseDataEntity getByType(String type, String attribution); + BaseDataEntity getByTypeAndName(String type, String attribution, String contentName); + } diff --git a/src/main/java/com/example/liteflow/mysql/service/BaseRoleService.java b/src/main/java/com/example/liteflow/mysql/service/BaseRoleService.java index 4c92926..6f7539d 100644 --- a/src/main/java/com/example/liteflow/mysql/service/BaseRoleService.java +++ b/src/main/java/com/example/liteflow/mysql/service/BaseRoleService.java @@ -9,5 +9,7 @@ import com.example.liteflow.mysql.model.role.RoleForm; public interface BaseRoleService { void createRole(RoleForm roleForm); + void testCreateRole(); + String getByName(String roleName); } diff --git a/src/main/java/com/example/liteflow/mysql/service/ChainService.java b/src/main/java/com/example/liteflow/mysql/service/ChainService.java index 7e5635a..d662874 100644 --- a/src/main/java/com/example/liteflow/mysql/service/ChainService.java +++ b/src/main/java/com/example/liteflow/mysql/service/ChainService.java @@ -1,6 +1,9 @@ package com.example.liteflow.mysql.service; import com.example.liteflow.mysql.entity.ChainEntity; +import com.example.liteflow.mysql.model.BaseCenter; + +import java.util.List; /** * @author: 陈韦龙 @@ -9,7 +12,9 @@ import com.example.liteflow.mysql.entity.ChainEntity; public interface ChainService { void createChain(ChainEntity chainEntity); - void executeChain(String chainName); + List executeChain(String chainName); ChainEntity getChainName(String chainName); + + String deleteChain(String id); } 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 121dc5b..cfed4d8 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 @@ -17,10 +17,20 @@ import org.springframework.stereotype.Service; public class BaseDataServiceImpl extends ServiceImpl implements BaseDataService { @Override public BaseDataEntity getByType(String type, String attribution) { - log.info("type = {}, attribution = {}", type, attribution); +// log.info("type = {}, attribution = {}", type, attribution); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(BaseDataEntity::getType, type) .eq(BaseDataEntity::getAttribution, attribution); return this.getOne(queryWrapper); } + + @Override + public BaseDataEntity getByTypeAndName(String type, String attribution, String contentName) { +// log.info("type = {}, attribution = {}", type, attribution); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(BaseDataEntity::getType, type) + .eq(BaseDataEntity::getAttribution, attribution) + .eq(BaseDataEntity::getContentName, contentName); + return this.getOne(queryWrapper); + } } diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/BaseRoleServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/BaseRoleServiceImpl.java index f1df58e..12f7a86 100644 --- a/src/main/java/com/example/liteflow/mysql/service/impl/BaseRoleServiceImpl.java +++ b/src/main/java/com/example/liteflow/mysql/service/impl/BaseRoleServiceImpl.java @@ -7,14 +7,18 @@ import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.example.liteflow.mysql.entity.BaseRoleEntity; +import com.example.liteflow.mysql.enums.MathOperatorEnum; import com.example.liteflow.mysql.mapper.BaseRoleMapper; +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.example.liteflow.mysql.service.BaseRoleService; import com.example.liteflow.mysql.util.RoleUtil; import lombok.extern.slf4j.Slf4j; +import org.assertj.core.util.Lists; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -45,17 +49,261 @@ public class BaseRoleServiceImpl extends ServiceImpl roleForms = + Lists.newArrayList( + this.costCenter01Cmp(), + this.costCenter02Cmp(), + this.profitCenter01Cmp(), + this.profitCenter02Cmp() + ); + roleForms.forEach(roleForm -> { + List roles = roleForm.getRoles(); + String roleName = roleForm.getRoleName(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(BaseRoleEntity::getRoleName, roleName); + BaseRoleEntity baseRoleEntity = this.getOne(queryWrapper); + if(ObjectUtil.isNull(baseRoleEntity)) { + baseRoleEntity = new BaseRoleEntity(); + baseRoleEntity.setRoleStr(JSONUtil.toJsonStr(roles)); + baseRoleEntity.setRoleName(JSONUtil.toJsonStr(roleName)); + this.save(baseRoleEntity); + } else { + baseRoleEntity.setRoleStr(JSONUtil.toJsonStr(roles)); + this.updateById(baseRoleEntity); + } + }); + + } + @Override public String getByName(String roleName) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(BaseRoleEntity::getRoleName, roleName); BaseRoleEntity baseRoleEntity = this.getOne(queryWrapper); - String roleStr = baseRoleEntity.getRoleStr(); - log.info("roleStr = {}", roleStr); + if (ObjectUtil.isNotNull(baseRoleEntity)) { + String roleStr = baseRoleEntity.getRoleStr(); + log.info("roleStr = {}", roleStr); // JSONObject jsonObject = JSONUtil.parseObj(roleStr); - List roles = JSONUtil.toList(JSONUtil.parseArray(roleStr), Role.class); - List> collect = roles.stream().map(RoleUtil::parseRole).collect(Collectors.toList()); - return JSONUtil.toJsonStr(collect); + List roles = JSONUtil.toList(JSONUtil.parseArray(roleStr), Role.class); + List> collect = roles.stream().map(RoleUtil::parseRole).collect(Collectors.toList()); + return JSONUtil.toJsonStr(collect); + } else { + return ""; + } + + } + + public RoleForm costCenter01Cmp() { + Role role = new Role(); + role.setLogicOperators(MathOperatorEnum.or.getOperator()); + + Role child = new Role(); + child.setLogicOperators(MathOperatorEnum.and.getOperator()); + List matches = new ArrayList<>(); + Match match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("sectionClassification"); + match.setMatchingContent("sectionClassificationList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("businessType"); + match.setMatchingContent("businessTypeList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("salesman"); + match.setMatchingContent("salesmanList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("businessCategory"); + match.setMatchingContent("businessCategoryList"); + matches.add(match); + + child.setMatches(matches); + List children = Lists.newArrayList(child); + role.setChildren(children); + + List roles = Lists.newArrayList(role); + RoleForm roleForm = new RoleForm(); + roleForm.setRoles(roles); + roleForm.setRoleName("costCenter01Cmp"); + return roleForm; +// System.out.println(JSONUtil.toJsonStr(roles)); +// List> collect = roles.stream().map(this::parseRole).collect(Collectors.toList()); +// System.out.println(JSONUtil.toJsonStr(collect)); + } + + public RoleForm costCenter02Cmp() { + Role role = new Role(); + role.setLogicOperators(MathOperatorEnum.or.getOperator()); + + Role child = new Role(); + child.setLogicOperators(MathOperatorEnum.or.getOperator()); + + Role sun = new Role(); + sun.setLogicOperators(MathOperatorEnum.and.getOperator()); + List matches = new ArrayList<>(); + Match match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("sectionClassification"); + match.setMatchingContent("sectionClassificationList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("salesman"); + match.setMatchingContent("salesmanList"); + matches.add(match); + + sun.setMatches(matches); + List sunList = Lists.newArrayList(sun); + child.setChildren(sunList); + List children = Lists.newArrayList(child); + role.setChildren(children); + + + List matches2 = new ArrayList<>(); + Match match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("businessType"); + match2.setMatchingContent("businessTypeList"); + matches2.add(match2); + Role role2 = new Role(); + role2.setLogicOperators(MathOperatorEnum.or.getOperator()); + role2.setMatches(matches2); + + List roles = Lists.newArrayList(role, role2); + RoleForm roleForm = new RoleForm(); + roleForm.setRoles(roles); + roleForm.setRoleName("costCenter02Cmp"); + return roleForm; +// 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)); + } + + public RoleForm profitCenter01Cmp() { + Role role = new Role(); + role.setLogicOperators(MathOperatorEnum.or.getOperator()); + + Role child = new Role(); + child.setLogicOperators(MathOperatorEnum.and.getOperator()); + + List matches = new ArrayList<>(); + Match match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("businessType"); + match.setMatchingContent("businessTypeList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("salesman"); + match.setMatchingContent("salesmanList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("businessCategory"); + match.setMatchingContent("businessCategoryList"); + matches.add(match); + + child.setMatches(matches); + List children = Lists.newArrayList(child); + role.setChildren(children); + + Role role2 = new Role(); + role2.setLogicOperators(MathOperatorEnum.or.getOperator()); + Role child2 = new Role(); + child2.setLogicOperators(MathOperatorEnum.and.getOperator()); + List matches2 = new ArrayList<>(); + Match match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("sectionClassification"); + match2.setMatchingContent("sectionClassificationList"); + matches2.add(match2); + + match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("businessType"); + match2.setMatchingContent("businessTypeList"); + matches2.add(match2); + child2.setMatches(matches2); + List children2 = Lists.newArrayList(child2); + role2.setChildren(children2); + + List roles = Lists.newArrayList(role, role2); + RoleForm roleForm = new RoleForm(); + roleForm.setRoles(roles); + roleForm.setRoleName("profitCenter01Cmp"); + return roleForm; +// 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)); + } + + public RoleForm profitCenter02Cmp() { + Role role = new Role(); + role.setLogicOperators(MathOperatorEnum.or.getOperator()); + + Role child = new Role(); + child.setLogicOperators(MathOperatorEnum.and.getOperator()); + + List matches = new ArrayList<>(); + Match match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("businessType"); + match.setMatchingContent("businessTypeList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("salesman"); + match.setMatchingContent("salesmanList"); + matches.add(match); + + child.setMatches(matches); + List children = Lists.newArrayList(child); + role.setChildren(children); + + Role role2 = new Role(); + role2.setLogicOperators(MathOperatorEnum.or.getOperator()); + Role child2 = new Role(); + child2.setLogicOperators(MathOperatorEnum.and.getOperator()); + List matches2 = new ArrayList<>(); + Match match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("sectionClassification"); + match2.setMatchingContent("sectionClassificationList"); + matches2.add(match2); + + match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("businessType"); + match2.setMatchingContent("businessTypeList"); + matches2.add(match2); + child2.setMatches(matches2); + List children2 = Lists.newArrayList(child2); + role2.setChildren(children2); + + List roles = Lists.newArrayList(role, role2); + RoleForm roleForm = new RoleForm(); + roleForm.setRoles(roles); + roleForm.setRoleName("profitCenter02Cmp"); + return roleForm; +// 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)); } diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/ChainServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/ChainServiceImpl.java index 9c68183..9195c1c 100644 --- a/src/main/java/com/example/liteflow/mysql/service/impl/ChainServiceImpl.java +++ b/src/main/java/com/example/liteflow/mysql/service/impl/ChainServiceImpl.java @@ -44,7 +44,7 @@ public class ChainServiceImpl extends ServiceImpl imp } @Override - public void executeChain(String chainName) { + public List executeChain(String chainName) { List list = this.generateCostCenterTestData(); log.info("before-list = {}", JSONUtil.toJsonStr(list)); list.forEach(item -> { @@ -56,6 +56,7 @@ public class ChainServiceImpl extends ServiceImpl imp } }); log.info("after-list = {}", JSONUtil.toJsonStr(list)); + return list; } private List generateCostCenterTestData() { @@ -90,4 +91,15 @@ public class ChainServiceImpl extends ServiceImpl imp return list; } + + @Override + public String deleteChain(String id) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ChainEntity::getId, id); + if (this.remove(queryWrapper)) { + return "删除成功"; + } else { + return "删除失败"; + } + } } diff --git a/src/test/java/MyTest.java b/src/test/java/MyTest.java index 4d533e5..8ad79bf 100644 --- a/src/test/java/MyTest.java +++ b/src/test/java/MyTest.java @@ -1,4 +1,5 @@ import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.RandomUtil; import cn.hutool.json.JSONUtil; import com.example.liteflow.mysql.LiteflowMysqlApplication; import com.example.liteflow.mysql.enums.MathOperatorEnum; @@ -24,8 +25,8 @@ import java.util.stream.Collectors; * @author: 陈韦龙 * @date: 2022年12月07日 16:26 */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = LiteflowMysqlApplication.class) +//@RunWith(SpringRunner.class) +//@SpringBootTest(classes = LiteflowMysqlApplication.class) public class MyTest { @Resource @@ -295,7 +296,6 @@ public class MyTest { List matches2 = new ArrayList<>(); Match match2 = new Match(); - match2 = new Match(); match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); match2.setMatchingValue("businessType"); match2.setMatchingContent("businessTypeList"); @@ -313,6 +313,122 @@ public class MyTest { List> collect = roles.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()); + + Role child = new Role(); + child.setLogicOperators(MathOperatorEnum.and.getOperator()); + + List matches = new ArrayList<>(); + Match match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("businessType"); + match.setMatchingContent("businessTypeList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("salesman"); + match.setMatchingContent("salesmanList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("businessCategory"); + match.setMatchingContent("businessCategoryList"); + matches.add(match); + + child.setMatches(matches); + List children = Lists.newArrayList(child); + role.setChildren(children); + + Role role2 = new Role(); + role2.setLogicOperators(MathOperatorEnum.or.getOperator()); + Role child2 = new Role(); + child2.setLogicOperators(MathOperatorEnum.and.getOperator()); + List matches2 = new ArrayList<>(); + Match match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("sectionClassification"); + match2.setMatchingContent("sectionClassificationList"); + matches2.add(match2); + + match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("businessType"); + match2.setMatchingContent("businessTypeList"); + matches2.add(match2); + child2.setMatches(matches2); + List children2 = Lists.newArrayList(child2); + role2.setChildren(children2); + + List roles = Lists.newArrayList(role, role2); + RoleForm roleForm = new RoleForm(); + roleForm.setRoles(roles); + roleForm.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(collect)); + } + + @Test + public void test10() { + Role role = new Role(); + role.setLogicOperators(MathOperatorEnum.or.getOperator()); + + Role child = new Role(); + child.setLogicOperators(MathOperatorEnum.and.getOperator()); + + List matches = new ArrayList<>(); + Match match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("businessType"); + match.setMatchingContent("businessTypeList"); + matches.add(match); + + match = new Match(); + match.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match.setMatchingValue("salesman"); + match.setMatchingContent("salesmanList"); + matches.add(match); + + child.setMatches(matches); + List children = Lists.newArrayList(child); + role.setChildren(children); + + Role role2 = new Role(); + role2.setLogicOperators(MathOperatorEnum.or.getOperator()); + Role child2 = new Role(); + child2.setLogicOperators(MathOperatorEnum.and.getOperator()); + List matches2 = new ArrayList<>(); + Match match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("sectionClassification"); + match2.setMatchingContent("sectionClassificationList"); + matches2.add(match2); + + match2 = new Match(); + match2.setConditionalOperators(MathOperatorEnum.contains.getOperator()); + match2.setMatchingValue("businessType"); + match2.setMatchingContent("businessTypeList"); + matches2.add(match2); + child2.setMatches(matches2); + List children2 = Lists.newArrayList(child2); + role2.setChildren(children2); + + List roles = Lists.newArrayList(role, role2); + RoleForm roleForm = new RoleForm(); + roleForm.setRoles(roles); + roleForm.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(collect)); + } private Map parseRole(Role role) { List matchList = role.getMatches(); List roleChildren = role.getChildren(); @@ -372,4 +488,9 @@ public class MyTest { return map; } } + + @Test + public void generateId () { + System.out.println(RandomUtil.randomNumbers(16)); + } }