1.提交成本中心测试用例
This commit is contained in:
parent
8d5a676693
commit
8774482141
|
@ -0,0 +1,27 @@
|
|||
package com.wezone.drools.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: 陈韦龙
|
||||
* @date: 2022年07月06日 12:08
|
||||
*/
|
||||
@Data
|
||||
public class CostCenter {
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
private String businessType;
|
||||
/**
|
||||
* 业务员
|
||||
*/
|
||||
private String salesman;
|
||||
/**
|
||||
* 业务类别
|
||||
*/
|
||||
private String businessCategory;
|
||||
/**
|
||||
* 科目分类
|
||||
*/
|
||||
private String sectionClassification;
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package rules;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import com.wezone.drools.model.*
|
||||
// 集合
|
||||
global java.util.List globalBusinessTypeList;
|
||||
global java.util.List globalSalesmanList;
|
||||
global java.util.List globalBusinessCategoryList;
|
||||
global java.util.List globalSectionClassificationList;
|
||||
// 对象
|
||||
global java.lang.String globalBusinessType;
|
||||
global java.lang.String globalSalesman;
|
||||
global java.lang.String globalBusinessCategory;
|
||||
global java.lang.String globalSectionClassification;
|
||||
// 输出代码和名称
|
||||
global java.lang.String costCenter01Code;
|
||||
global java.lang.String costCenter01Name;
|
||||
global java.lang.String costCenter02Code;
|
||||
global java.lang.String costCenter02Name;
|
||||
|
||||
/*
|
||||
(
|
||||
科目分类 IN (汇差;手续费;成本科目)
|
||||
AND 业务类型 IN (货代;报关;船代;散杂货 )
|
||||
AND 业务员 IN (仓干配物流部(物流))
|
||||
AND 业务类别(GHWL) IN (全货船业务;进出岛仓干配)
|
||||
)
|
||||
*/
|
||||
rule "costCenter01"
|
||||
activation-group "costCenter"
|
||||
when
|
||||
$map:Map(
|
||||
this['sectionClassification'] memberOf globalSectionClassificationList
|
||||
&& this['businessType'] memberOf globalBusinessTypeList
|
||||
&& this['salesman'] memberOf globalSalesmanList
|
||||
&& this['businessCategory'] memberOf globalBusinessCategoryList
|
||||
);
|
||||
then
|
||||
System.out.println("匹配成功-costCenter01");
|
||||
$map.put("code", costCenter01Code);
|
||||
$map.put("name", costCenter01Name);
|
||||
$map.put("generateCode", costCenter01Code + costCenter01Name);
|
||||
end
|
||||
/*
|
||||
(
|
||||
业务类型 IN (货代;船代;散杂货)
|
||||
AND 业务员 = 商品车物流部(物流)
|
||||
)
|
||||
OR (
|
||||
业务类型 IN (货代;船代;散杂货)
|
||||
AND 科目分类 IN (银行科目;预付科目;预收科目)
|
||||
)
|
||||
*/
|
||||
rule "costCenter02"
|
||||
activation-group "costCenter"
|
||||
when
|
||||
$map:Map(
|
||||
(
|
||||
this['businessType'] memberOf globalBusinessTypeList
|
||||
&& this['salesman'] == globalSalesman
|
||||
)
|
||||
||
|
||||
(
|
||||
this['businessType'] memberOf globalBusinessTypeList
|
||||
|
||||
)
|
||||
);
|
||||
then
|
||||
$map.put("code", costCenter02Code);
|
||||
$map.put("name", costCenter02Name);
|
||||
$map.put("generateCode", costCenter02Code + costCenter02Name);
|
||||
System.out.println("匹配成功-costCenter02");
|
||||
end
|
|
@ -0,0 +1,69 @@
|
|||
package com.wezone.drools.test;
|
||||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.wezone.drools.model.CostCenter;
|
||||
import com.wezone.drools.model.ProfitCenter;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.drools.core.base.RuleNameStartsWithAgendaFilter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.kie.api.KieServices;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CostCenterTest {
|
||||
@Test
|
||||
public void testCostCenter() {
|
||||
// 事实对象
|
||||
CostCenter costCenter = new CostCenter();
|
||||
costCenter.setSectionClassification("成本科目");
|
||||
costCenter.setBusinessType("货代");
|
||||
costCenter.setSalesman("仓干配物流部(物流)");
|
||||
costCenter.setBusinessCategory("全货船业务");
|
||||
|
||||
LinkedHashMap<String, String> 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.toJsonStr(map));
|
||||
List<String> sectionClassificationList = Lists.newArrayList("汇差", "手续费", "成本科目");
|
||||
List<String> businessTypeList = Lists.newArrayList("货代", "报关", "船代", "散杂货");
|
||||
List<String> salesmanList = Lists.newArrayList("仓干配物流部(物流)");
|
||||
List<String> businessCategoryList = Lists.newArrayList("全货船业务", "进出岛仓干配");
|
||||
//第一步:获取服务
|
||||
KieServices kieServices = KieServices.Factory.get();
|
||||
// 第二步:通过服务获取容器
|
||||
KieContainer container = kieServices.getKieClasspathContainer();
|
||||
// 第三步:通过容器获取KieSession,由KieSession去和规则引擎交互
|
||||
KieSession kieSession = container.newKieSession();
|
||||
|
||||
kieSession.setGlobal("globalBusinessTypeList", businessTypeList);
|
||||
kieSession.setGlobal("globalSalesmanList", salesmanList);
|
||||
kieSession.setGlobal("globalBusinessCategoryList", businessCategoryList);
|
||||
kieSession.setGlobal("globalSectionClassificationList", sectionClassificationList);
|
||||
kieSession.setGlobal("globalSalesman", "商品车物流部(物流)");
|
||||
kieSession.setGlobal("costCenter01Code", "P350401028");
|
||||
kieSession.setGlobal("costCenter01Name", "仓干配物流部利润中心");
|
||||
kieSession.setGlobal("costCenter02Code", "P350401026");
|
||||
kieSession.setGlobal("costCenter02Name", "商品车物流部利润中心");
|
||||
|
||||
kieSession.insert(map);
|
||||
|
||||
|
||||
// 第五步:执行规则引擎,触发规则
|
||||
// kieSession.fireAllRules();
|
||||
kieSession.fireAllRules(new RuleNameStartsWithAgendaFilter("costCenter"));
|
||||
// 第六步:关闭容器
|
||||
kieSession.dispose();
|
||||
System.out.println(JSONUtil.toJsonPrettyStr(map));
|
||||
}
|
||||
}
|
|
@ -11,9 +11,8 @@ import org.kie.api.runtime.KieContainer;
|
|||
import org.kie.api.runtime.KieSession;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProfitCenterTest {
|
||||
@Test
|
||||
|
@ -24,7 +23,7 @@ public class ProfitCenterTest {
|
|||
profitCenter.setSalesman("商品车物流部(物流)");
|
||||
// profitCenter.setBusinessCategory("运输业务");
|
||||
// profitCenter.setSectionClassification("银行科目");
|
||||
Map<String, String> map = new HashMap<>();
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
Field[] fields = ReflectUtil.getFields(ProfitCenter.class);
|
||||
for (Field field : fields) {
|
||||
Object fieldValue = ReflectUtil.getFieldValue(profitCenter, field);
|
||||
|
|
Loading…
Reference in New Issue