增加对比参数从数据库获取

This commit is contained in:
chenweilong 2022-12-06 15:55:22 +08:00
parent ad35e225a1
commit 51d3c5b57c
16 changed files with 267 additions and 95 deletions

35
pom.xml
View File

@ -3,7 +3,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/>
</parent>
<groupId>org.example</groupId> <groupId>org.example</groupId>
<artifactId>liteflow-demo</artifactId> <artifactId>liteflow-demo</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
@ -20,13 +25,23 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version> <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -35,12 +50,6 @@
<version>3.3.2</version> <version>3.3.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
@ -81,5 +90,11 @@
<artifactId>aviator</artifactId> <artifactId>aviator</artifactId>
<version>5.2.7</version> <version>5.2.7</version>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.22.0</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -2,22 +2,23 @@ package com.example.liteflow.mysql.cmp.costCenter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; 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.CostCenter; import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent; import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import javax.annotation.Resource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author: 陈韦龙 * @author: 陈韦龙
@ -26,33 +27,29 @@ import java.util.Map;
@LiteflowComponent("costCenter01Cmp") @LiteflowComponent("costCenter01Cmp")
@Slf4j @Slf4j
public class CostCenter01Cmp extends NodeIfComponent { public class CostCenter01Cmp extends NodeIfComponent {
@Resource
private BaseDataService baseDataService;
private static final String drool = "[{\"$or\": [{\"$and\": [{\"contains\": [sectionClassification, sectionClassificationList]}, {\"contains\": [businessType, businessTypeList]}, {\"contains\": [salesman, salesmanList]}, {\"contains\": [businessCategory, businessCategoryList]}]}]}]"; private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}, {\"$contains\": [businessCategory, businessCategoryList]}]}]}]";
private final LinkedHashMap<String, List<String>> map = new LinkedHashMap<String, List<String>>(){{
put("sectionClassificationList", Lists.newArrayList("汇差", "手续费", "成本科目"));
put("businessTypeList", Lists.newArrayList("货代", "报关", "船代", "散杂货"));
put("salesmanList", Lists.newArrayList("仓干配物流部(物流)"));
put("businessCategoryList", Lists.newArrayList("全货船业务", "进出岛仓干配"));
}};
@Override @Override
public boolean processIf() throws Exception { public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData(); CostCenter requestData = this.getRequestData();
String droolStr = drool; String droolStr = drool;
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
String key = entry.getKey();
List<String> list = entry.getValue();
droolStr = StrUtil.replace(droolStr, key, list.toString(), false);
}
log.info("before - droolStr = {}", droolStr);
Field[] fields = ReflectUtil.getFields(CostCenter.class); Field[] fields = ReflectUtil.getFields(CostCenter.class);
for (Field field : fields) { for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field); Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName(); 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);
}
droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false); droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false);
} }
log.info("after - replace4 = {}", droolStr); log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr); JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray); log.info("jsonArray = {}", jsonArray);

View File

@ -2,11 +2,15 @@ package com.example.liteflow.mysql.cmp.costCenter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; 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.CostCenter; import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowComponent;
@ -14,6 +18,7 @@ import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import javax.annotation.Resource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -27,27 +32,24 @@ import java.util.Map;
@Slf4j @Slf4j
public class CostCenter02Cmp extends NodeIfComponent { public class CostCenter02Cmp extends NodeIfComponent {
private static final String drool = "[{\"$or\": [{\"$or\": [{\"$and\": [{\"contains\": [sectionClassification, sectionClassificationList]}, {\"contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"contains\": [businessType, businessTypeList]}]}]}]"; private static final String drool = "[{\"$or\": [{\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"$contains\": [businessType, businessTypeList]}]}]}]";
private final LinkedHashMap<String, List<String>> map = new LinkedHashMap<String, List<String>>(){{ @Resource
put("sectionClassificationList", Lists.newArrayList("汇差", "手续费", "成本科目")); private BaseDataService baseDataService;
put("businessTypeList", Lists.newArrayList("货代", "报关", "船代", "散杂货"));
put("salesmanList", Lists.newArrayList("仓干配物流部(物流)"));
}};
@Override @Override
public boolean processIf() throws Exception { public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData(); CostCenter requestData = this.getRequestData();
String droolStr = drool; String droolStr = drool;
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
String key = entry.getKey();
List<String> list = entry.getValue();
droolStr = StrUtil.replace(droolStr, key, list.toString(), false);
}
log.info("before - droolStr = {}", droolStr);
Field[] fields = ReflectUtil.getFields(CostCenter.class); Field[] fields = ReflectUtil.getFields(CostCenter.class);
for (Field field : fields) { for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field); Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName(); 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);
}
droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false); droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false);
} }

View File

@ -1,11 +1,15 @@
package com.example.liteflow.mysql.cmp.costCenter; package com.example.liteflow.mysql.cmp.costCenter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; 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.CostCenter; import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowComponent;
@ -13,6 +17,7 @@ import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import javax.annotation.Resource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.List; import java.util.List;
@ -24,31 +29,33 @@ import java.util.List;
@Slf4j @Slf4j
public class CostCenterCmp extends NodeIfComponent { public class CostCenterCmp extends NodeIfComponent {
private static final String droolStr = "[{\"$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]}]}]}]"; 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]}]}]}]";
private static final List<String> sectionClassificationList = Lists.newArrayList("汇差", "手续费", "成本科目"); private static final List<String> sectionClassificationList = Lists.newArrayList("汇差", "手续费", "成本科目");
private static final List<String> businessTypeList = Lists.newArrayList("货代", "报关", "船代", "散杂货"); private static final List<String> businessTypeList = Lists.newArrayList("货代", "报关", "船代", "散杂货");
private static final List<String> salesmanList = Lists.newArrayList("仓干配物流部(物流)"); private static final List<String> salesmanList = Lists.newArrayList("仓干配物流部(物流)");
private static final List<String> businessCategoryList = Lists.newArrayList("全货船业务", "进出岛仓干配"); private static final List<String> businessCategoryList = Lists.newArrayList("全货船业务", "进出岛仓干配");
@Resource
private BaseDataService baseDataService;
@Override @Override
public boolean processIf() throws Exception { public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData(); CostCenter requestData = this.getRequestData();
String replace = StrUtil.replace(droolStr, "sectionClassificationList", sectionClassificationList.toString(), false); String droolStr = drool;
String replace2 = StrUtil.replace(replace, "businessTypeList", businessTypeList.toString(), false);
String replace3 = StrUtil.replace(replace2, "salesmanList", salesmanList.toString(), false);
String replace4 = StrUtil.replace(replace3, "businessCategoryList", businessCategoryList.toString(), false);
log.info("before - replace4 = {}", replace4);
Field[] fields = ReflectUtil.getFields(CostCenter.class); Field[] fields = ReflectUtil.getFields(CostCenter.class);
for (Field field : fields) { for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field); Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName(); String name = field.getName();
replace4 = StrUtil.replace(replace4, name, "\"" + fieldValue + "\"", false); 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);
}
droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false);
} }
log.info("after - replace4 = {}", replace4); log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(replace4); JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray); log.info("jsonArray = {}", jsonArray);
String conditionResult = ConditionParser.parseCondition(jsonArray); String conditionResult = ConditionParser.parseCondition(jsonArray);

View File

@ -2,11 +2,16 @@ package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; 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.CostCenter;
import com.example.liteflow.mysql.model.ProfitCenter; import com.example.liteflow.mysql.model.ProfitCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowComponent;
@ -14,6 +19,7 @@ import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import javax.annotation.Resource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -27,28 +33,24 @@ import java.util.Map;
@Slf4j @Slf4j
public class ProfitCenter01Cmp extends NodeIfComponent { 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]}]}]}]"; private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}, {\"$contains\": [businessCategory, businessCategoryList]}]}]}, {\"$or\": [{\"$and\": [{\"$contains\": [sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}]}]}]";
private final LinkedHashMap<String, List<String>> map = new LinkedHashMap<String, List<String>>(){{ @Resource
put("sectionClassificationList", Lists.newArrayList("银行科目", "预付科目", "预收科目")); private BaseDataService baseDataService;
put("businessTypeList", Lists.newArrayList("货代", "船代", "散杂货"));
put("salesmanList", Lists.newArrayList("仓干配物流部(物流)"));
put("businessCategoryList", Lists.newArrayList("运输业务", "全货船业务", "进出岛仓干配"));
}};
@Override @Override
public boolean processIf() throws Exception { public boolean processIf() throws Exception {
ProfitCenter requestData = this.getRequestData(); ProfitCenter requestData = this.getRequestData();
String droolStr = drool; String droolStr = drool;
for (Map.Entry<String, List<String>> entry : map.entrySet()) { Field[] fields = ReflectUtil.getFields(CostCenter.class);
String key = entry.getKey();
List<String> list = entry.getValue();
droolStr = StrUtil.replace(droolStr, key, list.toString(), false);
}
log.info("before - droolStr = {}", droolStr);
Field[] fields = ReflectUtil.getFields(ProfitCenter.class);
for (Field field : fields) { for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field); Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName(); 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);
}
droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false); droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false);
} }

View File

@ -2,12 +2,16 @@ package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; 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.CostCenter; import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.model.ProfitCenter; import com.example.liteflow.mysql.model.ProfitCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowComponent;
@ -15,6 +19,7 @@ import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import javax.annotation.Resource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -28,31 +33,28 @@ import java.util.Map;
@Slf4j @Slf4j
public class ProfitCenter02Cmp extends NodeIfComponent { 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]}]}]}]"; private static final String drool = "[{\"$or\": [{\"$and\": [{\"$contains\": [businessType, businessTypeList]}, {\"$contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"$and\": [{\"$contains\":[sectionClassification, sectionClassificationList]}, {\"$contains\": [businessType, businessTypeList]}]}]}]";
private final LinkedHashMap<String, List<String>> map = new LinkedHashMap<String, List<String>>(){{ @Resource
put("sectionClassificationList", Lists.newArrayList("银行科目", "预付科目", "预收科目")); private BaseDataService baseDataService;
put("businessTypeList", Lists.newArrayList("货代", "船代", "散杂货"));
put("salesmanList", Lists.newArrayList("仓干配物流部(物流)"));
}};
@Override @Override
public boolean processIf() throws Exception { public boolean processIf() throws Exception {
ProfitCenter requestData = this.getRequestData(); ProfitCenter requestData = this.getRequestData();
String droolStr = drool; String droolStr = drool;
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
String key = entry.getKey();
List<String> list = entry.getValue();
droolStr = StrUtil.replace(droolStr, key, list.toString(), false);
}
log.info("before - droolStr = {}", droolStr);
Field[] fields = ReflectUtil.getFields(CostCenter.class); Field[] fields = ReflectUtil.getFields(CostCenter.class);
for (Field field : fields) { for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field); Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName(); 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);
}
droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false); droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false);
} }
log.info("after - replace4 = {}", droolStr); log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(droolStr); JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray); log.info("jsonArray = {}", jsonArray);

View File

@ -1,11 +1,15 @@
package com.example.liteflow.mysql.cmp.profitCenter; package com.example.liteflow.mysql.cmp.profitCenter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; 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.CostCenter; import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.service.BaseDataService;
import com.example.liteflow.mysql.util.ConditionParser; import com.example.liteflow.mysql.util.ConditionParser;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowComponent;
@ -13,6 +17,7 @@ import com.yomahub.liteflow.core.NodeIfComponent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
import javax.annotation.Resource;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.List; import java.util.List;
@ -24,31 +29,29 @@ import java.util.List;
@Slf4j @Slf4j
public class ProfitCenterCmp extends NodeIfComponent { public class ProfitCenterCmp extends NodeIfComponent {
private static final String droolStr = "[{\"$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]}]}]}]"; 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]}]}]}]";
private static final List<String> sectionClassificationList = Lists.newArrayList("汇差", "手续费", "成本科目"); @Resource
private static final List<String> businessTypeList = Lists.newArrayList("货代", "报关", "船代", "散杂货"); private BaseDataService baseDataService;
private static final List<String> salesmanList = Lists.newArrayList("仓干配物流部(物流)");
private static final List<String> businessCategoryList = Lists.newArrayList("全货船业务", "进出岛仓干配");
@Override @Override
public boolean processIf() throws Exception { public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData(); CostCenter requestData = this.getRequestData();
String replace = StrUtil.replace(droolStr, "sectionClassificationList", sectionClassificationList.toString(), false); String droolStr = drool;
String replace2 = StrUtil.replace(replace, "businessTypeList", businessTypeList.toString(), false);
String replace3 = StrUtil.replace(replace2, "salesmanList", salesmanList.toString(), false);
String replace4 = StrUtil.replace(replace3, "businessCategoryList", businessCategoryList.toString(), false);
log.info("before - replace4 = {}", replace4);
Field[] fields = ReflectUtil.getFields(CostCenter.class); Field[] fields = ReflectUtil.getFields(CostCenter.class);
for (Field field : fields) { for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field); Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName(); String name = field.getName();
replace4 = StrUtil.replace(replace4, name, "\"" + fieldValue + "\"", false); 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);
}
droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", false);
} }
log.info("after - replace4 = {}", replace4); log.info("after - droolStr = {}", droolStr);
JSONArray jsonArray = JSONUtil.parseArray(replace4); JSONArray jsonArray = JSONUtil.parseArray(droolStr);
log.info("jsonArray = {}", jsonArray); log.info("jsonArray = {}", jsonArray);
String conditionResult = ConditionParser.parseCondition(jsonArray); String conditionResult = ConditionParser.parseCondition(jsonArray);

View File

@ -0,0 +1,26 @@
package com.example.liteflow.mysql.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 09:59
*/
@Data
public class BaseDataEntity {
@TableId(value = "ID", type = IdType.ASSIGN_UUID)
private String id;
@TableField("type")
private String type;
@TableField("attribution")
private String attribution;
@TableField("content")
private String content;
@TableField("content_type")
private String contentType;
@TableField("content_name")
private String contentName;
}

View File

@ -0,0 +1,19 @@
package com.example.liteflow.mysql.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 14:43
*/
@Getter
@AllArgsConstructor
@ToString
public enum BaseDataAttributionEnum {
costCenter("costCenter"),
profitCenter("profitCenter"),
;
private final String attribution;
}

View File

@ -0,0 +1,20 @@
package com.example.liteflow.mysql.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 10:17
*/
@Getter
@AllArgsConstructor
@ToString
public enum BaseDataContentTypeEnum {
List("List"),
String("String")
;
private final String contentType;
}

View File

@ -39,7 +39,7 @@ public enum MathOperatorEnum {
$match("$match", "match", "Logical", "匹配"), $match("$match", "match", "Logical", "匹配"),
// 特殊运算符 // 特殊运算符
contains("contains", "CollUtil.contains(StrUtil.split(\"{}\", \",\"), '{}')", "Special", "包含"), contains("$contains", "CollUtil.contains(StrUtil.split(\"{}\", \",\"), '{}')", "Special", "包含"),
; ;

View File

@ -0,0 +1,13 @@
package com.example.liteflow.mysql.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 10:08
*/
@Mapper
public interface BaseDataMapper extends BaseMapper<BaseDataEntity> {
}

View File

@ -0,0 +1,12 @@
package com.example.liteflow.mysql.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.liteflow.mysql.entity.BaseDataEntity;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 09:58
*/
public interface BaseDataService extends IService<BaseDataEntity> {
BaseDataEntity getByType(String type, String attribution);
}

View File

@ -0,0 +1,24 @@
package com.example.liteflow.mysql.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.liteflow.mysql.entity.BaseDataEntity;
import com.example.liteflow.mysql.mapper.BaseDataMapper;
import com.example.liteflow.mysql.service.BaseDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author: 陈韦龙
* @date: 2022年12月06日 09:59
*/
@Slf4j
@Service
public class BaseDataServiceImpl extends ServiceImpl<BaseDataMapper, BaseDataEntity> implements BaseDataService {
@Override
public BaseDataEntity getByType(String type, String attribution) {
return this.lambdaQuery()
.eq(BaseDataEntity::getType, type)
.eq(BaseDataEntity::getAttribution, attribution)
.getEntity();
}
}

View File

@ -1,6 +1,11 @@
spring: spring:
application: application:
name: liteflow-mysql name: liteflow-mysql
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test_db?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&serverTimezone=Asia/Shanghai
username: root
password: 123456
liteflow: liteflow:
rule-source: liteflow/*.el.xml rule-source: liteflow/*.el.xml
@ -21,4 +26,4 @@ liteflow:
# scriptIdField: script_id # scriptIdField: script_id
# scriptNameField: script_name # scriptNameField: script_name
# scriptDataField: script_data # scriptDataField: script_data
# scriptTypeField: script_type # scriptTypeField: script_type

View File

@ -34,4 +34,29 @@ INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `scri
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (8, 'demo', 's8', 'costCenter02', 'def costCenter02Code = \"P350401026\"\r\ncostCenterContext.setCode(costCenter02Code)\r\n\r\ndef costCenter02Name = \"商品车物流部利润中心\"\r\ncostCenterContext.setName(costCenter02Name)\r\n\r\ncostCenterContext.setGenerateCode(costCenter02Code + costCenter02Name)', 'script'); INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (8, 'demo', 's8', 'costCenter02', 'def costCenter02Code = \"P350401026\"\r\ncostCenterContext.setCode(costCenter02Code)\r\n\r\ndef costCenter02Name = \"商品车物流部利润中心\"\r\ncostCenterContext.setName(costCenter02Name)\r\n\r\ncostCenterContext.setGenerateCode(costCenter02Code + costCenter02Name)', 'script');
INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (9, 'demo', 's9', 'sout', 'def defaultName = \"无匹配项\"\r\ncostCenterContext.setGenerateCode(defaultName)', 'script'); INSERT INTO `script`(`id`, `application_name`, `script_id`, `script_name`, `script_data`, `script_type`) VALUES (9, 'demo', 's9', 'sout', 'def defaultName = \"无匹配项\"\r\ncostCenterContext.setGenerateCode(defaultName)', 'script');
CREATE TABLE `base_data` (
`id` varchar(255) NOT NULL,
`type` varchar(30) NULL,
`content` text NULL,
`content_type` varchar(30) NULL,
PRIMARY KEY (`id`)
);
ALTER TABLE `base_data`
ADD COLUMN `content_name` varchar(30) NULL AFTER `content_type`;
ALTER TABLE `base_data`
ADD COLUMN `attribution` varchar(30) NULL AFTER `type`;
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('0927941726325838', 'sectionClassification', 'costCenter', '[银行科目, 预付科目, 预收科目]', 'List', 'sectionClassificationList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('3927088550655742', 'businessCategory', 'costCenter', '[运输业务, 全货船业务, 进出岛仓干配]', 'List', 'businessCategoryList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('5363457043311084', 'businessType', 'costCenter', '[货代, 船代, 散杂货]', 'List', 'businessTypeList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('5587514507650183', 'salesman', 'costCenter', '[仓干配物流部(物流)]', 'List', 'salesmanList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('7203685907622705', 'sectionClassification', 'costCenter', '[汇差, 手续费, 成本科目]', 'List','sectionClassificationList');
INSERT INTO `base_data`(`id`, `type`, `attribution`, `content`, `content_type`, `content_name`) VALUES ('3843512879501886', 'businessCategory', 'costCenter', '[全货船业务, 进出岛仓干配]', 'List', 'businessCategoryList');
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');