新增多种判断结果
This commit is contained in:
parent
6915df728f
commit
433bc31eb5
|
@ -1,5 +1,6 @@
|
||||||
package com.example.liteflow.mysql;
|
package com.example.liteflow.mysql;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSON;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.example.liteflow.mysql.model.CostCenter;
|
import com.example.liteflow.mysql.model.CostCenter;
|
||||||
import com.example.liteflow.mysql.model.CostCenterContext;
|
import com.example.liteflow.mysql.model.CostCenterContext;
|
||||||
|
@ -33,17 +34,17 @@ public class LiteFlowCommand implements CommandLineRunner {
|
||||||
// LiteflowResponse response = flowExecutor.execute2Resp("costCenter", costCenter, CostCenterContext.class);
|
// LiteflowResponse response = flowExecutor.execute2Resp("costCenter", costCenter, CostCenterContext.class);
|
||||||
// xml匹配
|
// xml匹配
|
||||||
// LiteflowResponse response = flowExecutor.execute2Resp("mainChain", costCenter, CostCenterContext.class);
|
// 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();
|
||||||
CostCenterContext costCenterContext = response.getFirstContextBean();
|
// String code = costCenterContext.getCode();
|
||||||
String code = costCenterContext.getCode();
|
// String name = costCenterContext.getName();
|
||||||
String name = costCenterContext.getName();
|
// String generateCode = costCenterContext.getGenerateCode();
|
||||||
String generateCode = costCenterContext.getGenerateCode();
|
// costCenter.setCode(code);
|
||||||
costCenter.setCode(code);
|
// costCenter.setName(name);
|
||||||
costCenter.setName(name);
|
// costCenter.setGenerateCode(generateCode);
|
||||||
costCenter.setGenerateCode(generateCode);
|
// log.info(JSONUtil.toJsonStr(costCenter));
|
||||||
log.info(JSONUtil.toJsonStr(costCenter));
|
|
||||||
if (response.isSuccess()) {
|
if (response.isSuccess()) {
|
||||||
log.info("执行成功");
|
log.info("执行成功");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package com.example.liteflow.mysql.cmp;
|
package com.example.liteflow.mysql.cmp;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.example.liteflow.mysql.model.CostCenter;
|
import com.example.liteflow.mysql.model.CostCenter;
|
||||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||||
import com.yomahub.liteflow.core.NodeComponent;
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
@ -20,13 +19,14 @@ public class SoutCmp extends NodeComponent {
|
||||||
// }
|
// }
|
||||||
// System.out.println(JsonUtil.toJsonString(map));
|
// System.out.println(JsonUtil.toJsonString(map));
|
||||||
|
|
||||||
String code = costCenter.getCode();
|
// String code = costCenter.getCode();
|
||||||
String name = costCenter.getName();
|
// String name = costCenter.getName();
|
||||||
String generateCode = costCenter.getGenerateCode();
|
// String generateCode = costCenter.getGenerateCode();
|
||||||
|
//
|
||||||
if (StrUtil.isBlank(code) && StrUtil.isBlank(name) && StrUtil.isBlank(generateCode)) {
|
// if (StrUtil.isBlank(code) && StrUtil.isBlank(name) && StrUtil.isBlank(generateCode)) {
|
||||||
|
// costCenter.setGenerateCode("无匹配项");
|
||||||
|
// }
|
||||||
costCenter.setGenerateCode("无匹配项");
|
costCenter.setGenerateCode("无匹配项");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
</chain>
|
</chain>
|
||||||
|
|
||||||
<chain name="mainChain2">
|
<chain name="mainChain2">
|
||||||
THEN(costCenterCmp);
|
IF(costCenter01Cmp, CostCenter01SoutCmp, IF(costCenter02Cmp, CostCenter02SoutCmp, sout));
|
||||||
</chain>
|
</chain>
|
||||||
|
|
||||||
<nodes>
|
<nodes>
|
||||||
|
|
Loading…
Reference in New Issue