新增方法
This commit is contained in:
parent
433bc31eb5
commit
ad35e225a1
|
@ -4,6 +4,7 @@ import cn.hutool.json.JSON;
|
|||
import cn.hutool.json.JSONUtil;
|
||||
import com.example.liteflow.mysql.model.CostCenter;
|
||||
import com.example.liteflow.mysql.model.CostCenterContext;
|
||||
import com.example.liteflow.mysql.model.ProfitCenter;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -25,17 +26,30 @@ public class LiteFlowCommand implements CommandLineRunner {
|
|||
public void run(String... args) throws Exception {
|
||||
// 事实对象
|
||||
CostCenter costCenter = new CostCenter();
|
||||
costCenter.setSectionClassification("成本科目");
|
||||
costCenter.setSectionClassification("成本科目1");
|
||||
costCenter.setBusinessType("货代");
|
||||
costCenter.setSalesman("仓干配物流部(物流)");
|
||||
costCenter.setBusinessCategory("全货船业务");
|
||||
|
||||
ProfitCenter profitCenter = new ProfitCenter();
|
||||
profitCenter.setBusinessType("货代");
|
||||
profitCenter.setSalesman("商品车物流部(物流)");
|
||||
profitCenter.setBusinessCategory("运输业务");
|
||||
profitCenter.setSectionClassification("银行科目");
|
||||
// 数据库匹配
|
||||
// LiteflowResponse response = flowExecutor.execute2Resp("costCenter", costCenter, CostCenterContext.class);
|
||||
// xml匹配
|
||||
// LiteflowResponse response = flowExecutor.execute2Resp("mainChain", costCenter, CostCenterContext.class);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("mainChain2", costCenter);
|
||||
// LiteflowResponse response = flowExecutor.execute2Resp("cost01AndCost02", costCenter);
|
||||
// LiteflowResponse response = flowExecutor.execute2Resp("cost01", costCenter);
|
||||
// LiteflowResponse response = flowExecutor.execute2Resp("cost02", costCenter);
|
||||
// LiteflowResponse response = flowExecutor.execute2Resp("profit01AndProfit02", profitCenter);
|
||||
// LiteflowResponse response = flowExecutor.execute2Resp("profit01", profitCenter);
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("profit02", profitCenter);
|
||||
|
||||
log.info("costCenter = {}", JSONUtil.toJsonStr(costCenter));
|
||||
log.info("profitCenter = {}", JSONUtil.toJsonStr(profitCenter));
|
||||
|
||||
|
||||
// CostCenterContext costCenterContext = response.getFirstContextBean();
|
||||
// String code = costCenterContext.getCode();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.example.liteflow.mysql.cmp;
|
||||
package com.example.liteflow.mysql.cmp.costCenter;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
|
@ -1,4 +1,4 @@
|
|||
package com.example.liteflow.mysql.cmp;
|
||||
package com.example.liteflow.mysql.cmp.costCenter;
|
||||
|
||||
import com.example.liteflow.mysql.model.CostCenter;
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
|
@ -1,4 +1,4 @@
|
|||
package com.example.liteflow.mysql.cmp;
|
||||
package com.example.liteflow.mysql.cmp.costCenter;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
|
@ -63,7 +63,7 @@ public class CostCenter02Cmp extends NodeIfComponent {
|
|||
Object executeB = AviatorEvaluator.execute(conditionResult);
|
||||
log.info("CostCenter02Cmp-{} = {}", conditionResult, executeB);
|
||||
boolean aBoolean = BooleanUtil.toBoolean(executeB.toString());
|
||||
log.info("CostCenter01Cmp-aBoolean = {}", aBoolean);
|
||||
log.info("CostCenter02Cmp-aBoolean = {}", aBoolean);
|
||||
return aBoolean;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.example.liteflow.mysql.cmp;
|
||||
package com.example.liteflow.mysql.cmp.costCenter;
|
||||
|
||||
import com.example.liteflow.mysql.model.CostCenter;
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
|
@ -1,4 +1,4 @@
|
|||
package com.example.liteflow.mysql.cmp;
|
||||
package com.example.liteflow.mysql.cmp.costCenter;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
|
@ -0,0 +1,70 @@
|
|||
package com.example.liteflow.mysql.cmp.profitCenter;
|
||||
|
||||
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.ProfitCenter;
|
||||
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("profitCenter01Cmp")
|
||||
@Slf4j
|
||||
public class ProfitCenter01Cmp extends NodeIfComponent {
|
||||
|
||||
private static final String drool = "[{\"$or\": [{\"$and\": [{\"contains\": [businessType, businessTypeList]}, {\"contains\": [salesman, salesmanList]}, {\"contains\": [businessCategory, businessCategoryList]}]}]}, {\"$or\": [{\"$and\": [{\"contains\": [sectionClassification, sectionClassificationList]}, {\"contains\": [businessType, businessTypeList]}]}]}]";
|
||||
|
||||
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 {
|
||||
ProfitCenter 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(ProfitCenter.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 - 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.example.liteflow.mysql.cmp.profitCenter;
|
||||
|
||||
import com.example.liteflow.mysql.model.CostCenter;
|
||||
import com.example.liteflow.mysql.model.ProfitCenter;
|
||||
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("ProfitCenter01SoutCmp")
|
||||
@Slf4j
|
||||
public class ProfitCenter01SoutCmp extends NodeComponent {
|
||||
|
||||
private static final String profitCenter01Code = "P350401028";
|
||||
private static final String profitCenter01Name = "仓干配物流部利润中心";
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
ProfitCenter profitCenter = this.getRequestData();
|
||||
profitCenter.setCode(profitCenter01Code);
|
||||
profitCenter.setName(profitCenter01Name);
|
||||
profitCenter.setGenerateCode(profitCenter01Code + profitCenter01Name);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.example.liteflow.mysql.cmp.profitCenter;
|
||||
|
||||
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.model.ProfitCenter;
|
||||
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("profitCenter02Cmp")
|
||||
@Slf4j
|
||||
public class ProfitCenter02Cmp extends NodeIfComponent {
|
||||
|
||||
private static final String drool = "[{\"$or\": [{\"$and\": [{\"contains\": [businessType, businessTypeList]}, {\"contains\": [salesman, salesmanList]}]}]}, {\"$or\": [{\"$and\": [{\"contains\":[sectionClassification, sectionClassificationList]}, {\"contains\": [businessType, businessTypeList]}]}]}]";
|
||||
|
||||
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 {
|
||||
ProfitCenter 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("CostCenter02Cmp-aBoolean = {}", aBoolean);
|
||||
return aBoolean;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.example.liteflow.mysql.cmp.profitCenter;
|
||||
|
||||
import com.example.liteflow.mysql.model.CostCenter;
|
||||
import com.example.liteflow.mysql.model.ProfitCenter;
|
||||
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("ProfitCenter02SoutCmp")
|
||||
@Slf4j
|
||||
public class ProfitCenter02SoutCmp extends NodeComponent {
|
||||
|
||||
private static final String profitCenter02Code = "P350401026";
|
||||
private static final String profitCenter02Name = "商品车物流部利润中心";
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
ProfitCenter profitCenter = this.getRequestData();
|
||||
profitCenter.setCode(profitCenter02Code);
|
||||
profitCenter.setName(profitCenter02Name);
|
||||
profitCenter.setGenerateCode(profitCenter02Code + profitCenter02Name);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.example.liteflow.mysql.cmp.profitCenter;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.List;
|
||||
|
||||
/**
|
||||
* @author: 陈韦龙
|
||||
* @date: 2022年12月05日 10:15
|
||||
*/
|
||||
@LiteflowComponent("profitCenterCmp")
|
||||
@Slf4j
|
||||
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 List<String> sectionClassificationList = Lists.newArrayList("汇差", "手续费", "成本科目");
|
||||
private static final List<String> businessTypeList = Lists.newArrayList("货代", "报关", "船代", "散杂货");
|
||||
private static final List<String> salesmanList = Lists.newArrayList("仓干配物流部(物流)");
|
||||
private static final List<String> businessCategoryList = Lists.newArrayList("全货船业务", "进出岛仓干配");
|
||||
@Override
|
||||
public boolean processIf() throws Exception {
|
||||
CostCenter requestData = this.getRequestData();
|
||||
String replace = StrUtil.replace(droolStr, "sectionClassificationList", sectionClassificationList.toString(), false);
|
||||
|
||||
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);
|
||||
for (Field field : fields) {
|
||||
Object fieldValue = ReflectUtil.getFieldValue(requestData, field);
|
||||
String name = field.getName();
|
||||
replace4 = StrUtil.replace(replace4, name, "\"" + fieldValue + "\"", false);
|
||||
}
|
||||
|
||||
log.info("after - replace4 = {}", replace4);
|
||||
JSONArray jsonArray = JSONUtil.parseArray(replace4);
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.example.liteflow.mysql.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: 陈韦龙
|
||||
* @date: 2022年12月05日 18:15
|
||||
*/
|
||||
@Data
|
||||
public class BaseCenter {
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
private String businessType;
|
||||
/**
|
||||
* 业务员
|
||||
*/
|
||||
private String salesman;
|
||||
/**
|
||||
* 业务类别
|
||||
*/
|
||||
private String businessCategory;
|
||||
/**
|
||||
* 科目分类
|
||||
*/
|
||||
private String sectionClassification;
|
||||
|
||||
private String code;
|
||||
private String name;
|
||||
private String generateCode;
|
||||
}
|
|
@ -7,26 +7,5 @@ import lombok.Data;
|
|||
* @date: 2022年07月06日 12:08
|
||||
*/
|
||||
@Data
|
||||
public class CostCenter {
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
private String businessType;
|
||||
/**
|
||||
* 业务员
|
||||
*/
|
||||
private String salesman;
|
||||
/**
|
||||
* 业务类别
|
||||
*/
|
||||
private String businessCategory;
|
||||
/**
|
||||
* 科目分类
|
||||
*/
|
||||
private String sectionClassification;
|
||||
|
||||
private String code;
|
||||
private String name;
|
||||
private String generateCode;
|
||||
|
||||
public class CostCenter extends BaseCenter {
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.example.liteflow.mysql.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 陈韦龙
|
||||
* @date 2022/07/01/ 15:41
|
||||
*/
|
||||
@Data
|
||||
public class ProfitCenter extends BaseCenter {
|
||||
}
|
|
@ -28,10 +28,30 @@
|
|||
);
|
||||
</chain>
|
||||
|
||||
<chain name="mainChain2">
|
||||
<chain name="cost01AndCost02">
|
||||
IF(costCenter01Cmp, CostCenter01SoutCmp, IF(costCenter02Cmp, CostCenter02SoutCmp, sout));
|
||||
</chain>
|
||||
|
||||
<chain name="cost01">
|
||||
IF(costCenter01Cmp, CostCenter01SoutCmp, sout);
|
||||
</chain>
|
||||
|
||||
<chain name="cost02">
|
||||
IF(costCenter02Cmp, CostCenter02SoutCmp, sout);
|
||||
</chain>
|
||||
|
||||
<chain name="profit01AndProfit02">
|
||||
IF(profitCenter01Cmp, ProfitCenter01SoutCmp, IF(profitCenter02Cmp, ProfitCenter02SoutCmp, sout));
|
||||
</chain>
|
||||
|
||||
<chain name="profit01">
|
||||
IF(profitCenter01Cmp, ProfitCenter01SoutCmp, sout);
|
||||
</chain>
|
||||
|
||||
<chain name="profit02">
|
||||
IF(profitCenter02Cmp, ProfitCenter02SoutCmp, sout);
|
||||
</chain>
|
||||
|
||||
<nodes>
|
||||
<node id="s3" name="sectionClassification" type="script">
|
||||
<![CDATA[
|
||||
|
|
Loading…
Reference in New Issue