新增多种判断结果

This commit is contained in:
chenweilong 2022-12-05 18:03:54 +08:00
parent 6915df728f
commit 433bc31eb5
7 changed files with 217 additions and 19 deletions

View File

@ -1,5 +1,6 @@
package com.example.liteflow.mysql;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.example.liteflow.mysql.model.CostCenter;
import com.example.liteflow.mysql.model.CostCenterContext;
@ -33,17 +34,17 @@ public class LiteFlowCommand implements CommandLineRunner {
// LiteflowResponse response = flowExecutor.execute2Resp("costCenter", costCenter, CostCenterContext.class);
// xml匹配
// LiteflowResponse response = flowExecutor.execute2Resp("mainChain", costCenter, CostCenterContext.class);
LiteflowResponse response = flowExecutor.execute2Resp("mainChain2", costCenter, CostCenterContext.class);
LiteflowResponse response = flowExecutor.execute2Resp("mainChain2", costCenter);
log.info("costCenter = {}", JSONUtil.toJsonStr(costCenter));
CostCenterContext costCenterContext = response.getFirstContextBean();
String code = costCenterContext.getCode();
String name = costCenterContext.getName();
String generateCode = costCenterContext.getGenerateCode();
costCenter.setCode(code);
costCenter.setName(name);
costCenter.setGenerateCode(generateCode);
log.info(JSONUtil.toJsonStr(costCenter));
// CostCenterContext costCenterContext = response.getFirstContextBean();
// String code = costCenterContext.getCode();
// String name = costCenterContext.getName();
// String generateCode = costCenterContext.getGenerateCode();
// costCenter.setCode(code);
// costCenter.setName(name);
// costCenter.setGenerateCode(generateCode);
// log.info(JSONUtil.toJsonStr(costCenter));
if (response.isSuccess()) {
log.info("执行成功");
} else {

View File

@ -0,0 +1,70 @@
package com.example.liteflow.mysql.cmp;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil;
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.model.CostCenter;
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 java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("costCenter01Cmp")
@Slf4j
public class CostCenter01Cmp extends NodeIfComponent {
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
public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData();
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);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", 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("CostCenter01Cmp-{} = {}", conditionResult, executeB);
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
log.info("CostCenter01Cmp-aBoolean = {}", aBoolean);
return aBoolean;
}
}

View File

@ -0,0 +1,29 @@
package com.example.liteflow.mysql.cmp;
import com.example.liteflow.mysql.model.CostCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
/**
* @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 = "仓干配物流部利润中心";
@Override
public void process() {
CostCenter costCenter = this.getRequestData();
costCenter.setCode(costCenter01Code);
costCenter.setName(costCenter01Name);
costCenter.setGenerateCode(costCenter01Code + costCenter01Name);
}
}

View File

@ -0,0 +1,69 @@
package com.example.liteflow.mysql.cmp;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil;
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.model.CostCenter;
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 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 {
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>>(){{
put("sectionClassificationList", Lists.newArrayList("汇差", "手续费", "成本科目"));
put("businessTypeList", Lists.newArrayList("货代", "报关", "船代", "散杂货"));
put("salesmanList", Lists.newArrayList("仓干配物流部(物流)"));
}};
@Override
public boolean processIf() throws Exception {
CostCenter requestData = this.getRequestData();
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);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
String name = field.getName();
droolStr = StrUtil.replace(droolStr, name, "\"" + fieldValue + "\"", 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("CostCenter01Cmp-aBoolean = {}", aBoolean);
return aBoolean;
}
}

View File

@ -0,0 +1,29 @@
package com.example.liteflow.mysql.cmp;
import com.example.liteflow.mysql.model.CostCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
/**
* @author: 陈韦龙
* @date: 2022年12月05日 10:15
*/
@LiteflowComponent("CostCenter02SoutCmp")
@Slf4j
public class CostCenter02SoutCmp extends NodeComponent {
private static final String costCenter02Code = "P350401026";
private static final String costCenter02Name = "商品车物流部利润中心";
@Override
public void process() {
CostCenter costCenter = this.getRequestData();
costCenter.setCode(costCenter02Code);
costCenter.setName(costCenter02Name);
costCenter.setGenerateCode(costCenter02Code + costCenter02Name);
}
}

View File

@ -1,6 +1,5 @@
package com.example.liteflow.mysql.cmp;
import cn.hutool.core.util.StrUtil;
import com.example.liteflow.mysql.model.CostCenter;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@ -20,13 +19,14 @@ public class SoutCmp extends NodeComponent {
// }
// System.out.println(JsonUtil.toJsonString(map));
String code = costCenter.getCode();
String name = costCenter.getName();
String generateCode = costCenter.getGenerateCode();
if (StrUtil.isBlank(code) && StrUtil.isBlank(name) && StrUtil.isBlank(generateCode)) {
costCenter.setGenerateCode("无匹配项");
}
// String code = costCenter.getCode();
// String name = costCenter.getName();
// String generateCode = costCenter.getGenerateCode();
//
// if (StrUtil.isBlank(code) && StrUtil.isBlank(name) && StrUtil.isBlank(generateCode)) {
// costCenter.setGenerateCode("无匹配项");
// }
costCenter.setGenerateCode("无匹配项");
}
}

View File

@ -29,7 +29,7 @@
</chain>
<chain name="mainChain2">
THEN(costCenterCmp);
IF(costCenter01Cmp, CostCenter01SoutCmp, IF(costCenter02Cmp, CostCenter02SoutCmp, sout));
</chain>
<nodes>