diff --git a/src/main/java/com/example/liteflow/mysql/cmp/BusinessCategoryCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/BusinessCategoryCmp.java deleted file mode 100644 index 9d19e18..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/BusinessCategoryCmp.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.example.liteflow.mysql.cmp; - -import com.example.liteflow.mysql.bean.BusinessCategoryBean; -import com.example.liteflow.mysql.model.CostCenter; -import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; - -import javax.annotation.Resource; -import java.util.List; - -@LiteflowComponent("businessCategory") -public class BusinessCategoryCmp extends NodeIfComponent { - - @Resource - private BusinessCategoryBean businessCategoryBean; - -// @Override -// public void process() { -// CostCenter requestData = this.getRequestData(); -// System.out.println("sectionClassificationCmp executed! ===>>>" + JsonUtil.toJsonString(requestData)); -// -// String sectionClassification = requestData.getSectionClassification(); -// List globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList(); -// if (globalSectionClassificationList.contains(sectionClassification)) { -// -// } -// } - - @Override - public boolean processIf() throws Exception { - CostCenter requestData = this.getRequestData(); - System.out.println("BusinessCategoryCmp executed!"); - - String businessCategory = requestData.getBusinessCategory(); - List globalBusinessCategoryList = businessCategoryBean.getGlobalBusinessCategoryList(); - return globalBusinessCategoryList.contains(businessCategory); - } -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/BusinessTypeCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/BusinessTypeCmp.java deleted file mode 100644 index 6422452..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/BusinessTypeCmp.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.example.liteflow.mysql.cmp; - -import com.example.liteflow.mysql.bean.BusinessTypeBean; -import com.example.liteflow.mysql.model.CostCenter; -import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; - -import javax.annotation.Resource; -import java.util.List; - -@LiteflowComponent("businessType") -public class BusinessTypeCmp extends NodeIfComponent { - - @Resource - private BusinessTypeBean businessTypeBean; - -// @Override -// public void process() { -// CostCenter requestData = this.getRequestData(); -// System.out.println("sectionClassificationCmp executed! ===>>>" + JsonUtil.toJsonString(requestData)); -// -// String sectionClassification = requestData.getSectionClassification(); -// List globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList(); -// if (globalSectionClassificationList.contains(sectionClassification)) { -// -// } -// } - - @Override - public boolean processIf() throws Exception { - CostCenter requestData = this.getRequestData(); - System.out.println("BusinessTypeCmp executed!"); - - String businessType = requestData.getBusinessType(); - List globalBusinessTypeList = businessTypeBean.getGlobalBusinessTypeList(); - return globalBusinessTypeList.contains(businessType); - } -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/SalesmanCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/SalesmanCmp.java deleted file mode 100644 index f194d1c..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/SalesmanCmp.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.example.liteflow.mysql.cmp; - -import com.example.liteflow.mysql.bean.SalesmanBean; -import com.example.liteflow.mysql.model.CostCenter; -import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; - -import javax.annotation.Resource; -import java.util.List; - -@LiteflowComponent("salesman") -public class SalesmanCmp extends NodeIfComponent { - - @Resource - private SalesmanBean salesmanBean; - -// @Override -// public void process() { -// CostCenter requestData = this.getRequestData(); -// System.out.println("sectionClassificationCmp executed! ===>>>" + JsonUtil.toJsonString(requestData)); -// -// String sectionClassification = requestData.getSectionClassification(); -// List globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList(); -// if (globalSectionClassificationList.contains(sectionClassification)) { -// -// } -// } - - @Override - public boolean processIf() throws Exception { - CostCenter requestData = this.getRequestData(); - System.out.println("SalesmanCmp executed!"); - String salesman = requestData.getSalesman(); - List globalSalesmanList = salesmanBean.getGlobalSalesmanList(); - return globalSalesmanList.contains(salesman); - } -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/SectionClassificationCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/SectionClassificationCmp.java deleted file mode 100644 index a17e824..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/SectionClassificationCmp.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - *

Title: liteflow

- *

Description: 轻量级的组件式流程框架

- * @author Bryan.Zhang - * @email weenyc31@163.com - * @Date 2020/4/1 - */ -package com.example.liteflow.mysql.cmp; - -import com.example.liteflow.mysql.bean.SectionClassificationBean; -import com.example.liteflow.mysql.model.CostCenter; -import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; - -import javax.annotation.Resource; -import java.util.List; - -@LiteflowComponent("sectionClassification") -public class SectionClassificationCmp extends NodeIfComponent { - - @Resource - private SectionClassificationBean sectionClassificationBean; - -// @Override -// public void process() { -// CostCenter requestData = this.getRequestData(); -// System.out.println("sectionClassificationCmp executed! ===>>>" + JsonUtil.toJsonString(requestData)); -// -// String sectionClassification = requestData.getSectionClassification(); -// List globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList(); -// if (globalSectionClassificationList.contains(sectionClassification)) { -// -// } -// } - - @Override - public boolean processIf() throws Exception { - CostCenter requestData = this.getRequestData(); - System.out.println("sectionClassificationCmp executed!"); - - String sectionClassification = requestData.getSectionClassification(); - List globalSectionClassificationList = sectionClassificationBean.getGlobalSectionClassificationList(); - return globalSectionClassificationList.contains(sectionClassification); - } -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java index f9519e6..c5ec0ea 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/SoutCmp.java @@ -12,14 +12,6 @@ public class SoutCmp extends NodeComponent { @Override public void process() { BaseCenter requestData = this.getRequestData(); -// LinkedHashMap map = new LinkedHashMap<>(); -// Field[] fields = ReflectUtil.getFields(CostCenter.class); -// for (Field field : fields) { -// Object fieldValue = ReflectUtil.getFieldValue(costCenter, field); -// String name = field.getName(); -// map.put(name, fieldValue == null ? null : String.valueOf(fieldValue)); -// } -// System.out.println(JsonUtil.toJsonString(map)); String costCenterGenerateCode = requestData.getCostCenterGenerateCode(); String profitCenterGenerateCode = requestData.getProfitCenterGenerateCode(); 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 deleted file mode 100644 index ef53ea5..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01Cmp.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.example.liteflow.mysql.cmp.costCenter; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSON; -import cn.hutool.json.JSONArray; -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.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 javax.annotation.Resource; -import java.lang.reflect.Field; - -/** - * @author: 陈韦龙 - * @date: 2022年12月05日 10:15 - */ -@LiteflowComponent("costCenter01Cmp") -@Slf4j -public class CostCenter01Cmp extends NodeIfComponent { - @Resource - private BaseDataService baseDataService; - @Resource - private BaseRoleService baseRoleService; - - private static final String baseRoleName = "costCenter01Cmp"; - - @Override - public boolean processIf() throws Exception { - BaseCenter requestData = this.getRequestData(); - log.info("requestData = {}", JSONUtil.toJsonStr(requestData)); - String droolStr = baseRoleService.getByName(baseRoleName); - log.info("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.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); - } - - 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; - } - - } -} 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 deleted file mode 100644 index d505e75..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter01SoutCmp.java +++ /dev/null @@ -1,41 +0,0 @@ -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 - */ -@LiteflowComponent("CostCenter01SoutCmp") -@Slf4j -public class CostCenter01SoutCmp extends NodeComponent { - -// 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); - baseCenter.setCostCenterGenerateCode(costCenter01Code + costCenter01Name); - baseCenter.setGenerateCode(null); - - } -} 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 deleted file mode 100644 index 9438e57..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02Cmp.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.example.liteflow.mysql.cmp.costCenter; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONArray; -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.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: 陈韦龙 - * @date: 2022年12月05日 10:15 - */ -@LiteflowComponent("costCenter02Cmp") -@Slf4j -public class CostCenter02Cmp extends NodeIfComponent { - - @Resource - private BaseDataService baseDataService; - @Resource - private BaseRoleService baseRoleService; - private static final String baseRoleName = "costCenter02Cmp"; - @Override - public boolean processIf() throws Exception { - BaseCenter requestData = this.getRequestData(); - String droolStr = baseRoleService.getByName(baseRoleName); - log.info("CostCenter02Cmp-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.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); - } - - 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; - } - - } -} diff --git a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterCmp.java index 733c5d4..227819a 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterCmp.java @@ -1,6 +1,6 @@ package com.example.liteflow.mysql.cmp.costCenter; -import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; @@ -9,14 +9,14 @@ 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.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 org.springframework.stereotype.Component; import javax.annotation.Resource; import java.lang.reflect.Field; @@ -26,7 +26,8 @@ import java.util.List; * @author: 陈韦龙 * @date: 2022年12月05日 10:15 */ -@LiteflowComponent("costCenterCmp") +//@LiteflowComponent("costCenterCmp") +@Component @Slf4j public class CostCenterCmp extends NodeIfComponent { @@ -38,38 +39,47 @@ public class CostCenterCmp extends NodeIfComponent { private static final List businessCategoryList = Lists.newArrayList("全货船业务", "进出岛仓干配"); @Resource private BaseDataService baseDataService; + @Resource + private BaseRoleService baseRoleService; @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.costCenter.getAttribution()); - if (ObjectUtil.isNotNull(baseDataEntity)) { - String content = baseDataEntity.getContent(); - String contentName = baseDataEntity.getContentName(); - droolStr = StrUtil.replace(droolStr, contentName, content, false); + String nodeId = this.getNodeId(); + String nodeName = this.getName(); + log.info("nodeId = {}, nodeName = {}", nodeId, nodeName); + String droolStr = baseRoleService.getByName(nodeName); + 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.getByTypeAndName(name, BaseDataAttributionEnum.costCenter.getAttribution(), name + "List"); + 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); + Object executeB = AviatorEvaluator.execute(conditionResult); + log.info("CostCenterCmp-{} = {}", conditionResult, executeB); + boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); + log.info("CostCenterCmp-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("{} = {}", conditionResult, executeB); - return Boolean.getBoolean(executeB.toString()); } } diff --git a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02SoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterSoutCmp.java similarity index 54% rename from src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02SoutCmp.java rename to src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterSoutCmp.java index 5b94523..d11f01b 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenter02SoutCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/costCenter/CostCenterSoutCmp.java @@ -3,11 +3,10 @@ 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 org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -15,9 +14,10 @@ import javax.annotation.Resource; * @author: 陈韦龙 * @date: 2022年12月05日 10:15 */ -@LiteflowComponent("CostCenter02SoutCmp") +//@LiteflowComponent("CostCenter02SoutCmp") +@Component @Slf4j -public class CostCenter02SoutCmp extends NodeComponent { +public class CostCenterSoutCmp extends NodeComponent { // private static final String costCenter02Code = "P350401026"; // private static final String costCenter02Name = "商品车物流部利润中心"; @@ -27,14 +27,17 @@ public class CostCenter02SoutCmp extends NodeComponent { @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); + String nodeId = this.getNodeId(); + String nodeName = this.getName(); + log.info("nodeId = {}, nodeName = {}", nodeId, nodeName); + BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("costCenterCode", BaseDataAttributionEnum.costCenter.getAttribution(), nodeName); + BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("costCenterName", BaseDataAttributionEnum.costCenter.getAttribution(), nodeName); + String costCenterCode = codeBaseData.getContent(); + String costCenterName = nameBaseData.getContent(); + baseCenter.setCostCenterCode(costCenterCode); + baseCenter.setCostCenterName(costCenterName); + baseCenter.setCostCenterGenerateCode(costCenterCode + costCenterName); baseCenter.setGenerateCode(null); } 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 deleted file mode 100644 index 9089beb..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01Cmp.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.example.liteflow.mysql.cmp.profitCenter; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONArray; -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.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 javax.annotation.Resource; -import java.lang.reflect.Field; - -/** - * @author: 陈韦龙 - * @date: 2022年12月05日 10:15 - */ -@LiteflowComponent("profitCenter01Cmp") -@Slf4j -public class ProfitCenter01Cmp extends NodeIfComponent { - - @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 = 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); - } - - 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; - } - - } -} 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 deleted file mode 100644 index f0c0a2c..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter01SoutCmp.java +++ /dev/null @@ -1,39 +0,0 @@ -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 - */ -@LiteflowComponent("ProfitCenter01SoutCmp") -@Slf4j -public class ProfitCenter01SoutCmp extends NodeComponent { - -// 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); - baseCenter.setGenerateCode(null); - - } -} 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 deleted file mode 100644 index f47aa45..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02Cmp.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.example.liteflow.mysql.cmp.profitCenter; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONArray; -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.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 javax.annotation.Resource; -import java.lang.reflect.Field; - -/** - * @author: 陈韦龙 - * @date: 2022年12月05日 10:15 - */ -@LiteflowComponent("profitCenter02Cmp") -@Slf4j -public class ProfitCenter02Cmp extends NodeIfComponent { - - @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 = 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); - } - - 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; - } - - } -} 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 deleted file mode 100644 index 23de58e..0000000 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenter02SoutCmp.java +++ /dev/null @@ -1,42 +0,0 @@ -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 - */ -@LiteflowComponent("ProfitCenter02SoutCmp") -@Slf4j -public class ProfitCenter02SoutCmp extends NodeComponent { - -// 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(); - 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/cmp/profitCenter/ProfitCenterCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterCmp.java index ee38f6c..6359557 100644 --- a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterCmp.java +++ b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterCmp.java @@ -1,6 +1,7 @@ package com.example.liteflow.mysql.cmp.profitCenter; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; @@ -10,11 +11,13 @@ 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; import com.yomahub.liteflow.core.NodeIfComponent; import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.lang.reflect.Field; @@ -23,46 +26,56 @@ import java.lang.reflect.Field; * @author: 陈韦龙 * @date: 2022年12月05日 10:15 */ -@LiteflowComponent("profitCenterCmp") +//@LiteflowComponent("profitCenterCmp") +@Component @Slf4j public class ProfitCenterCmp extends NodeIfComponent { private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}, {\"$contains\": [businessCategory, businessCategoryList]}]}]}, {\"$or\": [{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"$contains\": [businessType, businessTypeList]}]}]}]"; - @Resource private BaseDataService baseDataService; + @Resource + private BaseRoleService baseRoleService; + @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 nodeId = this.getNodeId(); + String nodeName = this.getName(); + log.info("nodeId = {}, nodeName = {}", nodeId, nodeName); + String droolStr = baseRoleService.getByName(nodeName); + 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.getByTypeAndName(name, BaseDataAttributionEnum.costCenter.getAttribution(), name + "List"); + 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); + Object executeB = AviatorEvaluator.execute(conditionResult); + log.info("ProfitCenterCmp-{} = {}", conditionResult, executeB); + boolean aBoolean = BooleanUtil.toBoolean(executeB.toString()); + log.info("ProfitCenterCmp-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("{} = {}", conditionResult, executeB); - return Boolean.getBoolean(executeB.toString()); } } diff --git a/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterSoutCmp.java b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterSoutCmp.java new file mode 100644 index 0000000..3d1437f --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/cmp/profitCenter/ProfitCenterSoutCmp.java @@ -0,0 +1,43 @@ +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.core.NodeComponent; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * @author: 陈韦龙 + * @date: 2022年12月05日 10:15 + */ +@Component +@Slf4j +public class ProfitCenterSoutCmp extends NodeComponent { + +// private static final String profitCenter02Code = "P350401026"; +// private static final String profitCenter02Name = "商品车物流部利润中心"; + + @Resource + private BaseDataService baseDataService; + + @Override + public void process() { + BaseCenter baseCenter = this.getRequestData(); + String nodeId = this.getNodeId(); + String nodeName = this.getName(); + log.info("nodeId = {}, nodeName = {}", nodeId, nodeName); + BaseDataEntity codeBaseData = baseDataService.getByTypeAndName("profitCenterCode", BaseDataAttributionEnum.profitCenter.getAttribution(), nodeName); + BaseDataEntity nameBaseData = baseDataService.getByTypeAndName("profitCenterName", BaseDataAttributionEnum.profitCenter.getAttribution(), nodeName); + String profitCenterCode = codeBaseData.getContent(); + String profitCenterName = nameBaseData.getContent(); + baseCenter.setProfitCenterCode(profitCenterCode); + baseCenter.setProfitCenterName(profitCenterName); + baseCenter.setProfitCenterGenerateCode(profitCenterCode + profitCenterName); + baseCenter.setGenerateCode(null); + + } +} 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 887e5bc..e03413f 100644 --- a/src/main/java/com/example/liteflow/mysql/controller/ChainController.java +++ b/src/main/java/com/example/liteflow/mysql/controller/ChainController.java @@ -26,6 +26,11 @@ public class ChainController { chainService.createChain(chainEntity); } + @PostMapping("/dynamicGenerateChain") + public void dynamicGenerateChain(@RequestBody ChainEntity chainEntity) { + chainService.dynamicGenerateChain(chainEntity); + } + @GetMapping("/executeChain/{chainName}") public List executeChain(@PathVariable("chainName") String chainName) { return chainService.executeChain(chainName); diff --git a/src/main/java/com/example/liteflow/mysql/controller/NodeController.java b/src/main/java/com/example/liteflow/mysql/controller/NodeController.java new file mode 100644 index 0000000..6f8997e --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/controller/NodeController.java @@ -0,0 +1,61 @@ +package com.example.liteflow.mysql.controller; + +import com.example.liteflow.mysql.model.node.CreateNodeFrom; +import com.example.liteflow.mysql.service.NodeService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author: 陈韦龙 + * @date: 2022年12月12日 09:29 + */ +@Slf4j +@RestController +@RequestMapping("/node") +public class NodeController { + @Resource + private NodeService nodeService; + + @PostMapping("/createCostCenterIfNode") + public void createCostCenterIfNode(@RequestBody CreateNodeFrom createNodeFrom) { + nodeService.createCostCenterIfNode(createNodeFrom); + } + + @PostMapping("/batchCreateCostCenterIfNode") + public void batchCreateCostCenterIfNode(@RequestBody List createNodeFroms) { + nodeService.batchCreateCostCenterIfNode(createNodeFroms); + } + + @PostMapping("/createCostCenterNode") + public void createCostCenterNode(@RequestBody CreateNodeFrom createNodeFrom) { + nodeService.createCostCenterNode(createNodeFrom); + } + + @PostMapping("/batchCreateCostCenterNode") + public void batchCreateCostCenterNode(@RequestBody List createNodeFroms) { + nodeService.batchCreateCostCenterNode(createNodeFroms); + } + + @PostMapping("/createProfitCenterIfNode") + public void createProfitCenterIfNode(@RequestBody CreateNodeFrom createNodeFrom) { + nodeService.createProfitCenterIfNode(createNodeFrom); + } + + @PostMapping("/batchCreateProfitCenterIfNode") + public void batchCreateProfitCenterIfNode(@RequestBody List createNodeFroms) { + nodeService.batchCreateProfitCenterIfNode(createNodeFroms); + } + + @PostMapping("/createProfitCenterNode") + public void createProfitCenterNode(@RequestBody CreateNodeFrom createNodeFrom) { + nodeService.createProfitCenterNode(createNodeFrom); + } + + @PostMapping("/batchCreateProfitCostCenterNode") + public void batchCreateProfitCostCenterNode(@RequestBody List createNodeFroms) { + nodeService.batchCreateProfitCostCenterNode(createNodeFroms); + } +} 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 new file mode 100644 index 0000000..492d795 --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/model/node/CreateNodeFrom.java @@ -0,0 +1,13 @@ +package com.example.liteflow.mysql.model.node; + +import lombok.Data; + +/** + * @author: 陈韦龙 + * @date: 2022年12月12日 09:38 + */ +@Data +public class CreateNodeFrom { + private String id; + private String name; +} 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 5277ff4..ac778ba 100644 --- a/src/main/java/com/example/liteflow/mysql/service/ChainService.java +++ b/src/main/java/com/example/liteflow/mysql/service/ChainService.java @@ -12,6 +12,8 @@ import java.util.List; public interface ChainService { void createChain(ChainEntity chainEntity); + void dynamicGenerateChain(ChainEntity chainEntity); + List executeChain(String chainName); ChainEntity getChainName(String chainName); diff --git a/src/main/java/com/example/liteflow/mysql/service/NodeService.java b/src/main/java/com/example/liteflow/mysql/service/NodeService.java new file mode 100644 index 0000000..2a22a5e --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/service/NodeService.java @@ -0,0 +1,27 @@ +package com.example.liteflow.mysql.service; + +import com.example.liteflow.mysql.model.node.CreateNodeFrom; + +import java.util.List; + +/** + * @author: 陈韦龙 + * @date: 2022年12月12日 09:30 + */ +public interface NodeService { + void createCostCenterIfNode(CreateNodeFrom createNodeFrom); + + void batchCreateCostCenterIfNode(List createNodeFroms); + + void createCostCenterNode(CreateNodeFrom createNodeFrom); + + void batchCreateCostCenterNode(List createNodeFroms); + + void createProfitCenterIfNode(CreateNodeFrom createNodeFrom); + + void batchCreateProfitCenterIfNode(List createNodeFroms); + + void createProfitCenterNode(CreateNodeFrom createNodeFrom); + + void batchCreateProfitCostCenterNode(List createNodeFroms); +} 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 cfed4d8..8708fb4 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,7 +17,7 @@ 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); 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 7b9a559..82aaad5 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 @@ -1,7 +1,5 @@ package com.example.liteflow.mysql.service.impl; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.RandomUtil; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -12,6 +10,7 @@ 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.ChainService; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import lombok.extern.slf4j.Slf4j; @@ -27,7 +26,7 @@ import java.util.List; */ @Service @Slf4j -public class ChainServiceImpl extends ServiceImpl implements ChainService { +public class ChainServiceImpl extends ServiceImpl implements ChainService { @Resource private FlowExecutor flowExecutor; @@ -35,6 +34,13 @@ public class ChainServiceImpl extends ServiceImpl imp @Override public void createChain(ChainEntity chainEntity) { this.save(chainEntity); + } + @Override + public void dynamicGenerateChain(ChainEntity chainEntity) { + LiteFlowChainELBuilder.createChain() + .setChainId(chainEntity.getChainName()) + .setEL(chainEntity.getElData()) + .build(); flowExecutor.reloadRule(); } @@ -105,6 +111,7 @@ public class ChainServiceImpl extends ServiceImpl imp return "删除失败"; } } + @Override public String updateChain(ChainEntity chainEntity) { String id = chainEntity.getId(); diff --git a/src/main/java/com/example/liteflow/mysql/service/impl/NodeServiceImpl.java b/src/main/java/com/example/liteflow/mysql/service/impl/NodeServiceImpl.java new file mode 100644 index 0000000..87b75fb --- /dev/null +++ b/src/main/java/com/example/liteflow/mysql/service/impl/NodeServiceImpl.java @@ -0,0 +1,94 @@ +package com.example.liteflow.mysql.service.impl; + +import com.example.liteflow.mysql.model.node.CreateNodeFrom; +import com.example.liteflow.mysql.service.NodeService; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author: 陈韦龙 + * @date: 2022年12月12日 09:30 + */ +@Service +@Slf4j +public class NodeServiceImpl implements NodeService { + + @Resource + private FlowExecutor flowExecutor; + + @Override + public void createCostCenterIfNode(CreateNodeFrom createNodeFrom) { + LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId()) + .setName(createNodeFrom.getName()) + .setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp") + .build(); +// flowExecutor.reloadRule(); + } + + @Override + public void batchCreateCostCenterIfNode(List createNodeFroms) { + createNodeFroms.forEach(createNodeFrom -> { + LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId()) + .setName(createNodeFrom.getName()) + .setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterCmp") + .build(); + }); + } + @Override + public void createCostCenterNode(CreateNodeFrom createNodeFrom) { + LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId()) + .setName(createNodeFrom.getName()) + .setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterSoutCmp") + .build(); +// flowExecutor.reloadRule(); + } + @Override + public void batchCreateCostCenterNode(List createNodeFroms) { + createNodeFroms.forEach(createNodeFrom -> { + LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId()) + .setName(createNodeFrom.getName()) + .setClazz("com.example.liteflow.mysql.cmp.costCenter.CostCenterSoutCmp") + .build(); + }); + } + @Override + public void createProfitCenterIfNode(CreateNodeFrom createNodeFrom) { + LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId()) + .setName(createNodeFrom.getName()) + .setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterCmp") + .build(); +// flowExecutor.reloadRule(); + } + @Override + public void batchCreateProfitCenterIfNode(List createNodeFroms) { + createNodeFroms.forEach(createNodeFrom -> { + LiteFlowNodeBuilder.createIfNode().setId(createNodeFrom.getId()) + .setName(createNodeFrom.getName()) + .setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterCmp") + .build(); + }); + } + + @Override + public void createProfitCenterNode(CreateNodeFrom createNodeFrom) { + LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId()) + .setName(createNodeFrom.getName()) + .setClazz("com.example.liteflow.mysql.cmp.profitCenter .ProfitCenterSoutCmp") + .build(); +// flowExecutor.reloadRule(); + } + @Override + public void batchCreateProfitCostCenterNode(List createNodeFroms) { + createNodeFroms.forEach(createNodeFrom -> { + LiteFlowNodeBuilder.createCommonNode().setId(createNodeFrom.getId()) + .setName(createNodeFrom.getName()) + .setClazz("com.example.liteflow.mysql.cmp.profitCenter.ProfitCenterSoutCmp") + .build(); + }); + } +} diff --git a/src/main/resources/db.sql b/src/main/resources/db.sql index de4794f..bc96707 100644 --- a/src/main/resources/db.sql +++ b/src/main/resources/db.sql @@ -59,13 +59,13 @@ INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('9047450688035130', 'businessType', 'costCenter', '[货代, 报关, 船代, 散杂货]', 'List', 'businessTypeList'); INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('2790513253702116', 'salesman', 'costCenter', '[仓干配物流部(物流)]', 'List', 'salesmanList'); -INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (3, 'demo', 'cost01AndCost02', '测试流程', 'IF(costCenter01Cmp, CostCenter01SoutCmp, IF(costCenter02Cmp, CostCenter02SoutCmp, sout));', '2022-12-06 16:03:34'); -INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (4, 'demo', 'cost01', '测试流程', 'IF(costCenter01Cmp, CostCenter01SoutCmp, sout);', '2022-12-06 16:03:34'); -INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (5, 'demo', 'cost02', '测试流程', 'IF(costCenter02Cmp, CostCenter02SoutCmp, sout);', '2022-12-06 16:03:34'); -INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (6, 'demo', 'profit01AndProfit02', '测试流程', 'IF(profitCenter01Cmp, ProfitCenter01SoutCmp, IF(profitCenter02Cmp, ProfitCenter02SoutCmp, sout));', '2022-12-06 16:03:34'); -INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (7, 'demo', 'profit01', '测试流程', 'IF(profitCenter01Cmp, ProfitCenter01SoutCmp, sout);', '2022-12-06 16:03:34'); -INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (8, 'demo', 'profit02', '测试流程', 'IF(profitCenter02Cmp, ProfitCenter02SoutCmp, sout);', '2022-12-06 16:03:34'); -INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (9, 'demo', 'costAndProfit', '测试流程', 'THEN(cost01AndCost02, profit01AndProfit02);', '2022-12-06 16:03:34'); +-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (3, 'demo', 'cost01AndCost02', '测试流程', 'IF(costCenter01Cmp, CostCenter01SoutCmp, IF(costCenter02Cmp, CostCenter02SoutCmp, sout));', '2022-12-06 16:03:34'); +-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (4, 'demo', 'cost01', '测试流程', 'IF(costCenter01Cmp, CostCenter01SoutCmp, sout);', '2022-12-06 16:03:34'); +-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (5, 'demo', 'cost02', '测试流程', 'IF(costCenter02Cmp, CostCenter02SoutCmp, sout);', '2022-12-06 16:03:34'); +-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (6, 'demo', 'profit01AndProfit02', '测试流程', 'IF(profitCenter01Cmp, ProfitCenter01SoutCmp, IF(profitCenter02Cmp, ProfitCenter02SoutCmp, sout));', '2022-12-06 16:03:34'); +-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (7, 'demo', 'profit01', '测试流程', 'IF(profitCenter01Cmp, ProfitCenter01SoutCmp, sout);', '2022-12-06 16:03:34'); +-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (8, 'demo', 'profit02', '测试流程', 'IF(profitCenter02Cmp, ProfitCenter02SoutCmp, sout);', '2022-12-06 16:03:34'); +-- INSERT INTO `chain`(`id`, `application_name`, `chain_name`, `chain_desc`, `el_data`, `create_time`) VALUES (9, 'demo', 'costAndProfit', '测试流程', 'THEN(cost01AndCost02, profit01AndProfit02);', '2022-12-06 16:03:34');