原文地址:https://www.cnblogs.com/zhixiang-org-cn/p/10106551.html

 

1.引入项目依赖
<dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-core</artifactId>
    <version>7.14.0.Final</version>
</dependency>
<dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-spring</artifactId>
    <version>7.14.0.Final</version>
</dependency>

2.创建配置类

@Configuration
 
public class DroolsAutoConfiguration {
 
    private static final String RULES_PATH = "rules/";
    @Bean
    @ConditionalOnMissingBean(KieFileSystem.class)
    public KieFileSystem kieFileSystem() throws IOException {
        KieFileSystem kieFileSystem = getKieServices().newKieFileSystem();
        for (Resource file : getRuleFiles()) {
            kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + file.getFilename(), "UTF-8"));
        }
        return kieFileSystem;
    }
 
    private Resource[] getRuleFiles() throws IOException {
 
        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        return resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "**/*.*");
 
    }
    @Bean
    @ConditionalOnMissingBean(KieContainer.class)
    public KieContainer kieContainer() throws IOException {
 
        final KieRepository kieRepository = getKieServices().getRepository();
        kieRepository.addKieModule(new KieModule() {
            public ReleaseId getReleaseId() {
                return kieRepository.getDefaultReleaseId();
            }
        });
 
        KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem());
        kieBuilder.buildAll();
        return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
    }
 
    @Bean
    @ConditionalOnMissingBean(KieBase.class)
    public KieBase kieBase() throws IOException {
        return kieContainer().getKieBase();
    }
 
    @Bean
    @ConditionalOnMissingBean(KieSession.class)
    public KieSession kieSession() throws IOException {
 
        KieSession kieSession = kieContainer().newKieSession();
        return kieSession;
    }
    @Bean
    @ConditionalOnMissingBean(KModuleBeanFactoryPostProcessor.class)
 
    public KModuleBeanFactoryPostProcessor kiePostProcessor() {
        return new KModuleBeanFactoryPostProcessor();
    }
    public KieServices getKieServices() {
        System.setProperty("drools.dateformat","yyyy-MM-dd");
        return KieServices.Factory.get();
    }
 
}

不使用配置类的情况下,springboot引用drools可以直接在资源目录下配置META-INF/kmodule.xml

<?xml version="1.0" encoding="UTF-8"?>

<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
  <kbase name="FirstRules" packages="firstRules">
    <ksession name="ksession-firstRules"/>
  </kbase>
  <kbase name="FinalRules" packages="finalRules">
    <ksession name="ksession-finalRules"/>
  </kbase>
</kmodule>

 

3.创建规则文件.drt
Drools的规则文件是以*.drl结尾的文件,我们来看一个最简单的规则文件中都是包含什么。
通常来说,我们会把规则文件放在resources资源文件夹下,这里呢我们在resources文件夹下新建一个rules文件夹,然后再新建一个HelloWord.drl文件
package rules;
 
import cn.org.zhixiang.entity.User;
import java.lang.String;
import java.util.List;
 
rule "hello,word"
    when
        eval(true)
    then
        System.err.println("hello,word!");
end

 

4.项目调用
(1) 初次调用规则
@RunWith(SpringRunner.class)
@SpringBootTest
 
public class DroolsApplicationHelloWordTests {
 
    @Autowired
    KieSession kieSession;
}
上方注入的kieSession对象就是以后与Drools打交道最常用的一个对象了,通过它可以直接操作在配置类kieFileSystem方法中加载的所有的规则文件
@Test
public void testHelloWord() {
    kieSession.fireAllRules();
}
kieSession.fireAllRules方法是执行所有的规则,在运行了这个测试方法之后我们应该就可以看到控制台打印的一句hello,word!了
(2) 向规则文件中传参
public class User {
    private String name;
    private int age;
 
    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }
    //省略getter,setter
}
rule "user"
 
    when
      $u:User(name=="张三",age==18)
    then
        $u.setName("李四");
        System.err.println("hello,word:"+$u.getName());
end
$u:User(name==“张三”,age==18)的意思就是当存在一个user对象,并且它的name属性等于张三age等于18时就把这个对象赋值给$u。
在下方的then模块,如果上方的条件成立时就把$u的name属性更新一下,然后打印。
测试代码
@Test
    public void testOneRule() {
        User user=new User("张三",18);
        kieSession.insert(user);
        kieSession.fireAllRules(new RuleNameEndsWithAgendaFilter("user"));
    }
5.扩展知识
上方我们通过RuleNameEndsWithAgendaFilter对象成功指定了需要执行的规则文件,其实通过查看此对象的源码我们发现这个对象是AgendaFilter的一个实现类,决定执不执行一个规则的条件是accept方法返回的boolean值决定的。
所以说如果我们希望可以一次批量匹配多个规则的话可以通过继承AgendaFilter重写accept方法
A.连接符:逗号其实就是and,&& ||
B.<,>,==,!=,>=,<=使用eval函数进行判断,如eval(u.age>b.age)
contains not contains,
如:
rule "contains"
    when
      $s:String()
      $u:User(name contains $s)
    then
        System.err.println("用户张三存在");
end
@Test
    public void testContains() {
       String name="张三";
        User user=new User("张三",18);
        kieSession.insert(name);
        kieSession.insert(user);
        kieSession.fireAllRules(new RuleNameEndsWithAgendaFilter("contains"));
    }
C.memberOf not memberOf:memberOf用于判断对象的某个字段是否存在一个集合中
 
rule "memberOf"
    when
      $list:List()
      $u:User(name memberOf $list)
    then
        System.err.println("用户李四存在");
end
@Test
    public void testMemberOf() {
        List list=new ArrayList();
        list.add("张三");
        list.add("李四");
        User user=new User("李四",18);
        kieSession.insert(list);
        kieSession.insert(user);
        kieSession.fireAllRules(new RuleNameEndsWithAgendaFilter("memberOf"));
    }

D.matches not matches:matches就是用于匹配正则表达式的了

rule "matches"
    when
      $u:User(name matches "张.*")
    then
        System.err.println("用户张xx存在");
end
@Test
   public void testMatches() {
       User user=new User("张三",18);
       kieSession.insert(user);
       kieSession.fireAllRules(new RuleNameEndsWithAgendaFilter("matches"));
   }

E.对象调用

.drt文件如下:

package com.hlt.claimaudit.firstAduit

import com.hlt.claimaudit.vo.*
import com.hlt.claimaudit.model.*
import com.hlt.claimaudit.util.*
import java.util.Date
import java.util.List
import java.util.Map
import com.hlt.claimaudit.constant.*
import java.util.ArrayList
import com.inslink.common.base.DateUtil
import com.hlt.claimaudit.constant.RuleLevelConst
dialect  "java"
//****************************************定义函数区*****************************************************************************
function  String comparedRate(String rate1,String rate2){
 if("000".equals(rate1)&&!"000".equals(rate2)){
            return rate2;
        }
        if("000".equals(rate2)&&!"000".equals(rate1)){
            return rate1;
        }
        if("000".equals(rate2)&&"000".equals(rate1)){
            return "0";
        }
        if(Double.valueOf(rate1)<Double.valueOf(rate2))
        {return rate1;}
        else
        {    return  rate2;    }
}
function String CalculationItemRate(String code,String rateeemployee,String ratecitizen){
        if(code.equals(MedicalInsuranceType.TOWN_EMPLOYEE)){
            return rateeemployee;
        }
        if(code.equals(MedicalInsuranceType.TOWN_RESIDENT)){
            return ratecitizen;
        }
        return"";
    }
 function String DoReplace(String source,String newstr){
 if(source.equals("000")){
 return newstr;
 }
 return source;
 }
// ***************************************发票层级相关规则=invoiceInfo**********************************************************
global java.util.Map secondmap;
global java.util.Map thirdmap;

rule "YXX_0002"
salience 99990
  // 获取理赔-[就诊日期]与保单-[保单生效日]比较,在之前的是无效账单
  // 获取[出险日期]/[入院日期]与[保单生效日]比较,在之前的是无效账单
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $policyInfo : PolicyInfo() from $claimSchema.policyInfos
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    $invoiceInfo : InvoiceInfo(invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN) from $medicalRecordInfo.invoiceInfos
    eval( DateUtil.toDate($invoiceInfo.treatmentDate).before(DateUtil.toDate($policyInfo.policyStartDate)) )
    //$secondmap:Map() from secondmap
  then
//    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
//    $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
//    $invoiceInfo.setInvoiceExcluded("1");//置为1标识需要除外
    secondmap.put($invoiceInfo.invoiceNo,secondmap.get($invoiceInfo.invoiceNo)==null?1:(Integer)secondmap.get($invoiceInfo.invoiceNo)+1);
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("就诊日期/入院日期在保单生效日期之前");
    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
    auditRuleInfo.setRuleResultDesc("账单["+$invoiceInfo.getInvoiceNo()+"]的就诊日期/入院日期在保单生效日期之前,账单相关费用不予赔付!");
    auditRuleInfo.setDisplayed("1");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("保单号",$policyInfo.policyNo));
    factorInfoList.add(new FactorInfo("就诊/入院日期",$invoiceInfo.treatmentDate));
    factorInfoList.add(new FactorInfo("保单生效日",$policyInfo.policyStartDate));
    factorInfoList.add(new FactorInfo("账单号",$invoiceInfo.invoiceNo));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("YXX_0002被触发");
end

rule "YXX_0003"
salience 99980
  // 获取理赔-[就诊日期]与保单-[保单终止日]比较,在之后的是无效账单
  // 获取[出险日期]/[入院日期]与[保单终止日]比较,在之后的是无效账单
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $policyInfo : PolicyInfo() from $claimSchema.policyInfos
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    $invoiceInfo : InvoiceInfo(invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN) from $medicalRecordInfo.invoiceInfos
    eval( DateUtil.toDate($policyInfo.policyEndDate).before(DateUtil.toDate($invoiceInfo.treatmentDate)) )
  then
//    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
//    $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
//    $invoiceInfo.setInvoiceExcluded("1");//置为1标识需要除外
    thirdmap.put($invoiceInfo.invoiceNo,thirdmap.get($invoiceInfo.invoiceNo)==null?1:(Integer)thirdmap.get($invoiceInfo.invoiceNo)+1);
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("就诊日期/入院日期在保单终止日之后");
    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
    auditRuleInfo.setRuleResultDesc("账单["+$invoiceInfo.getInvoiceNo()+"]的就诊日期/入院日期在保单终止日期之后,账单相关费用不予赔付!");
    auditRuleInfo.setDisplayed("1");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("保单号",$policyInfo.policyNo));
    factorInfoList.add(new FactorInfo("就诊/入院日期",$invoiceInfo.treatmentDate));
    factorInfoList.add(new FactorInfo("保单终止日",$policyInfo.policyEndDate));
    factorInfoList.add(new FactorInfo("账单号",$invoiceInfo.invoiceNo));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("YXX_0003被触发");
end

rule "HIDE_0008"
salience 99989
  // 获取理赔-[就诊日期]与保单-[保单终止日]比较,在之后的是无效账单
  // 获取[出险日期]/[入院日期]与[保单终止日]比较,在之后的是无效账单
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    $invoiceInfo : InvoiceInfo(invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN) from $medicalRecordInfo.invoiceInfos
    eval(secondmap.get($invoiceInfo.invoiceNo) != null)
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    $claimInfo.setFirstAuditResult((secondmap.get($invoiceInfo.invoiceNo)==null?0:(Integer)secondmap.get($invoiceInfo.invoiceNo))==$claimSchema.policyInfos.size()?"":RuleResultCode.ZHUANRENHE);
//     System.out.println($invoiceInfo.invoiceNo+"的数量"+secondmap.get($invoiceInfo.invoiceNo)+":"+$claimSchema.policyInfos.size());
//    System.out.println((secondmap.get($invoiceInfo.invoiceNo)==null?0:(Integer)secondmap.get($invoiceInfo.invoiceNo))==$claimSchema.policyInfos.size()?"1":"0");
    $invoiceInfo.setInvoiceExcluded((secondmap.get($invoiceInfo.invoiceNo)==null?0:(Integer)secondmap.get($invoiceInfo.invoiceNo))==$claimSchema.policyInfos.size()?"1":"0");//置为1标识需要除外
       AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
           auditRuleInfo.setRuleCode(drools.getRule().getName());
           auditRuleInfo.setRuleDesc("就诊日期/入院日期在保单生效日期之前隐藏规则");
           auditRuleInfo.setRuleResultCode(RuleResultCode.ZHUANRENHE);
           auditRuleInfo.setRuleResultDesc("账单["+$invoiceInfo.getInvoiceNo()+"]的就诊日期/入院日期在保单终止日期之前的隐藏规则");
           auditRuleInfo.setDisplayed("0");
           auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
           List<FactorInfo> factorInfoList = new ArrayList<>();
           factorInfoList.add(new FactorInfo("",""));
           auditRuleInfo.setFactorInfos(factorInfoList);
           $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
           //System.out.println("HIDE_0003被触发");
   //    auditRuleInfo.setRuleCode(drools.getRule().getName());
   //    auditRuleInfo.setRuleDesc("就诊日期/入院日期在保单终止日之后");
   //    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
   //    auditRuleInfo.setRuleResultDesc("账单["+$invoiceInfo.getInvoiceNo()+"]的就诊日期/入院日期在保单终止日期之后,账单相关费用不予赔付!");
   //    auditRuleInfo.setDisplayed("0");
   //    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
   //    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
     //  System.out.println("HIDE_YXX_0003被触发");
//    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
//    auditRuleInfo.setRuleCode(drools.getRule().getName());
//    auditRuleInfo.setRuleDesc("就诊日期/入院日期在保单终止日之后");
//    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
//    auditRuleInfo.setRuleResultDesc("账单["+$invoiceInfo.getInvoiceNo()+"]的就诊日期/入院日期在保单终止日期之后,账单相关费用不予赔付!");
//    auditRuleInfo.setDisplayed("0");
//    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
//    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("HIDE_0008被触发");
end



rule "HIDE_0009"
salience 99979
  // 获取理赔-[就诊日期]与保单-[保单终止日]比较,在之后的是无效账单
  // 获取[出险日期]/[入院日期]与[保单终止日]比较,在之后的是无效账单
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    $invoiceInfo : InvoiceInfo(invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN) from $medicalRecordInfo.invoiceInfos
    //eval( $claimSchema.policyInfos.size()== ((Integer)$thirdmap.get($invoiceInfo.invoiceNo)))
    eval(thirdmap.get($invoiceInfo.invoiceNo) != null)
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
     $claimInfo.setFirstAuditResult((thirdmap.get($invoiceInfo.invoiceNo)==null?0:(Integer)thirdmap.get($invoiceInfo.invoiceNo))==$claimSchema.policyInfos.size()?"":RuleResultCode.ZHUANRENHE);
//  System.out.println($invoiceInfo.invoiceNo+"的数量"+thirdmap.get($invoiceInfo.invoiceNo)+":"+$claimSchema.policyInfos.size());
//   System.out.println((thirdmap.get($invoiceInfo.invoiceNo)==null?0:(Integer)thirdmap.get($invoiceInfo.invoiceNo))==$claimSchema.policyInfos.size()?"1":"0");
     $invoiceInfo.setInvoiceExcluded((thirdmap.get($invoiceInfo.invoiceNo)==null?0:(Integer)thirdmap.get($invoiceInfo.invoiceNo))==$claimSchema.policyInfos.size()?"1":"0");//置为1标识需要除外
        AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
        auditRuleInfo.setRuleCode(drools.getRule().getName());
        auditRuleInfo.setRuleDesc("就诊日期/入院日期在保单终止日之后隐藏规则");
        auditRuleInfo.setRuleResultCode(RuleResultCode.ZHUANRENHE);
        auditRuleInfo.setRuleResultDesc("账单["+$invoiceInfo.getInvoiceNo()+"]的就诊日期/入院日期在保单终止日期之后隐藏规则");
        auditRuleInfo.setDisplayed("0");
        auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
        List<FactorInfo> factorInfoList = new ArrayList<>();
        factorInfoList.add(new FactorInfo("",""));
        auditRuleInfo.setFactorInfos(factorInfoList);
        $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
        //System.out.println("HIDE_0003被触发");
//    auditRuleInfo.setRuleCode(drools.getRule().getName());
//    auditRuleInfo.setRuleDesc("就诊日期/入院日期在保单终止日之后");
//    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
//    auditRuleInfo.setRuleResultDesc("账单["+$invoiceInfo.getInvoiceNo()+"]的就诊日期/入院日期在保单终止日期之后,账单相关费用不予赔付!");
//    auditRuleInfo.setDisplayed("0");
//    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
//    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("HIDE_0009被触发");
end





//rule "YXX_0004"
//salience 99970
//    // 获取[就诊日期]与[保单生效日]+[等待期]比较,在之前的是无效账单
//    // 获取[出险日期]/[入院日期]与[保单生效日]+[等待期]比较,在之前的是无效账单
//  when
//    $claimSchema:ClaimSchema()
//    // 出险原因=疾病
//    $claimInfo:ClaimInfo(accidentCause == "疾病") from $claimSchema.claimInfo
//    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
//    $invoiceInfo : InvoiceInfo(invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN) from $medicalRecordInfo.invoiceInfos
//    $policyInfo:PolicyInfo() from $claimSchema.policyInfos
//    $riskInfo:RiskInfo() from $policyInfo.insuredInfo.riskInfos
//    // 使用账单类型+出险原因+事故类型与保单责任上的这三个值进行匹配
//    $dutyInfo:DutyInfo() from $riskInfo.dutyInfos
//    $dutyInvoiceDefineInfo:DutyInvoiceDefineInfo(invoiceType == $invoiceInfo.invoiceType
//        ,accidentCause contains ($claimInfo.accidentCause)
//        ,accidentType contains ($claimInfo.accidentType)
//        ) from $dutyInfo.dutyInvoiceDefineInfos
//    eval
//    (
//      DateUtil.toDate($invoiceInfo.treatmentDate).before(DateUtil.changeDateByType(DateUtil.toDate($policyInfo.policyStartDate), "D", $dutyInfo.waitPeriod))
//    )
//  then
//    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
//    $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
//    $invoiceInfo.setInvoiceExcluded("1");//置为1标识需要除外
//    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
//    auditRuleInfo.setRuleCode(drools.getRule().getName());
//    auditRuleInfo.setRuleDesc("就诊日期/入院日期在保单等待期内");
//    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
//    auditRuleInfo.setRuleResultDesc("账单["+$invoiceInfo.getInvoiceNo()+"]的就诊日期/入院日期在保单责任的等待期内,账单相关费用不予赔付!");
//    auditRuleInfo.setDisplayed("1");
//    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
//    List<FactorInfo> factorInfoList = new ArrayList<>();
//    factorInfoList.add(new FactorInfo("保单号",$policyInfo.policyNo));
//    factorInfoList.add(new FactorInfo("就诊/入院日期",$invoiceInfo.treatmentDate));
//    factorInfoList.add(new FactorInfo("保单生效日",$policyInfo.policyStartDate));
//    factorInfoList.add(new FactorInfo("责任等待期",String.valueOf($dutyInfo.waitPeriod)));
//    factorInfoList.add(new FactorInfo("账单号",$invoiceInfo.invoiceNo));
//    auditRuleInfo.setFactorInfos(factorInfoList);
//    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
//    System.out.println("YXX_0004被触发");
//end

//rule "YXX_0001"
//  // 出险责任【出险原因、事故类型、账单类型】与投保的责任不匹配
//salience 99960
//  when
//    $claimSchema:ClaimSchema()
//    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
//    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
//    $invoiceInfo : InvoiceInfo(invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN) from $medicalRecordInfo.invoiceInfos
//    $policyInfo:PolicyInfo() from $claimSchema.policyInfos
//    $riskInfo:RiskInfo() from $policyInfo.insuredInfo.riskInfos
//    $dutyInfo:DutyInfo() from $riskInfo.dutyInfos
//    $dutyInvoiceDefineInfo:DutyInvoiceDefineInfo() from $dutyInfo.dutyInvoiceDefineInfos
//    eval(
//            !$dutyInvoiceDefineInfo.invoiceType.equals($invoiceInfo.invoiceType)
//            || !($dutyInvoiceDefineInfo.accidentCause.contains($claimInfo.accidentCause))
//            || !($dutyInvoiceDefineInfo.accidentType.contains($claimInfo.accidentType))
//        )
//  then
//    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
//    $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
//    $invoiceInfo.setInvoiceExcluded("1");//置为1标识需要除外
//    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
//    auditRuleInfo.setRuleCode(drools.getRule().getName());
//    auditRuleInfo.setRuleDesc("本次出险责任的出险原因、事故类型、账单类型与投保的责任可赔付的范围不一致");
//    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
//    auditRuleInfo.setRuleResultDesc("本次理赔的发票对应的出险原因["+DictData.accidentCauseMap.get($claimInfo.accidentCause)+"]/事故类型["+DictData.accidentTypeMap.get($claimInfo.accidentType)+"]/账单号["+$invoiceInfo.invoiceNo+"]的账单类型与保险责任包含的信息不符,不予赔付!");
//    auditRuleInfo.setDisplayed("1");
//    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
//    List<FactorInfo> factorInfoList = new ArrayList<>();
//    factorInfoList.add(new FactorInfo("保单号",$policyInfo.policyNo));
//    factorInfoList.add(new FactorInfo("理赔申请书号",$claimInfo.applicationNo));
//    factorInfoList.add(new FactorInfo("账单号",$invoiceInfo.invoiceNo));
//    factorInfoList.add(new FactorInfo("责任编码",$dutyInfo.dutyCode));
//    factorInfoList.add(new FactorInfo("可赔付的账单类型",DictData.invoiceTypeMap.get($dutyInvoiceDefineInfo.invoiceType)));
//    factorInfoList.add(new FactorInfo("账单类型",DictData.invoiceTypeMap.get($invoiceInfo.invoiceType)));
//    factorInfoList.add(new FactorInfo("可赔付的出险原因",DictData.accidentCauseMap.get($dutyInvoiceDefineInfo.accidentCause)));
//    factorInfoList.add(new FactorInfo("出险原因",DictData.accidentCauseMap.get($claimInfo.accidentCause)));
//    factorInfoList.add(new FactorInfo("可赔付的事故类型",DictData.accidentTypeMap.get($dutyInvoiceDefineInfo.accidentType)));
//    factorInfoList.add(new FactorInfo("事故类型",DictData.accidentTypeMap.get($claimInfo.accidentType)));
//    auditRuleInfo.setFactorInfos(factorInfoList);
//    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
//    System.out.println("YXX_0001被触发=1="+$dutyInvoiceDefineInfo.invoiceType.equals($invoiceInfo.invoiceType));
//    System.out.println("YXX_0001被触发=2="+($dutyInvoiceDefineInfo.accidentCause.contains($claimInfo.accidentCause)));
//    System.out.println("YXX_0001被触发=3="+($dutyInvoiceDefineInfo.accidentType.contains($claimInfo.accidentType)));
//end

rule "HLX_0003"
  // 被保人就诊的医院不在约定的医院范围
salience 99950
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    $invoiceInfo : InvoiceInfo(invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN) from $medicalRecordInfo.invoiceInfos
    eval
    (
      !"二级甲等".equals(DictDataUtil.claimHospitalMap.get($invoiceInfo.hospitalName)) &&
      !"二级乙等".equals(DictDataUtil.claimHospitalMap.get($invoiceInfo.hospitalName)) &&
      !"二级未定".equals(DictDataUtil.claimHospitalMap.get($invoiceInfo.hospitalName)) &&
      !"三级甲等".equals(DictDataUtil.claimHospitalMap.get($invoiceInfo.hospitalName)) &&
      !"三级乙等".equals(DictDataUtil.claimHospitalMap.get($invoiceInfo.hospitalName)) &&
      !"三级未定".equals(DictDataUtil.claimHospitalMap.get($invoiceInfo.hospitalName))
    )
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
    $invoiceInfo.setInvoiceExcluded("1");//置为1标识需要除外
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("被保人就诊的医院不在约定的医院范围");
    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
    auditRuleInfo.setRuleResultDesc("被保人账单["+$invoiceInfo.getInvoiceNo()+"]的就诊医院不属于约定的定点医院范围,相关金额不予赔付!");
    auditRuleInfo.setDisplayed("1");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("账单号",$invoiceInfo.invoiceNo));
    factorInfoList.add(new FactorInfo("医院名称",$invoiceInfo.hospitalName));
    factorInfoList.add(new FactorInfo("医院等级",DictDataUtil.claimHospitalMap.get($invoiceInfo.hospitalName)));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("HLX_0003被触发");
end

//rule "HLX_0005"
//  // 更新项目等级和项目比例
//salience 99920
//  when
//    $claimSchema:ClaimSchema()
//    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
//    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
//    $invoiceInfo : InvoiceInfo(invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN) from $medicalRecordInfo.invoiceInfos
//    $invoiceDetailInfo : InvoiceDetailInfo() from $invoiceInfo.invoiceDetailInfos
//
//    $sanMu : SanMu() from DictDataUtil.sanMuMap.get(DictDataUtil.sanMuHospitalMap.get($invoiceInfo.hospitalName)+"_"+$invoiceDetailInfo.itemClass+"_"+$invoiceDetailInfo.itemCode)
//    eval( $sanMu != null )
//  then
//    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
//    $invoiceDetailInfo.setItemLevel($sanMu.getItemLevel());
//    $invoiceDetailInfo.setItemRateCitizen($sanMu.getItemRateCitizen());
//    $invoiceDetailInfo.setItemRateEmployee($sanMu.getItemRateEmployee());
//    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
//    auditRuleInfo.setRuleCode(drools.getRule().getName());
//    auditRuleInfo.setRuleDesc("项目明细层级的隐藏规则");
//    auditRuleInfo.setRuleResultCode("");
//    auditRuleInfo.setRuleResultDesc("更新项目等级和项目比例");
//    auditRuleInfo.setDisplayed("0");
//    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
//    List<FactorInfo> factorInfoList = new ArrayList<>();
//    factorInfoList.add(new FactorInfo("项目明细编码",$invoiceDetailInfo.itemCode));
//    factorInfoList.add(new FactorInfo("项目明细(三目)",$sanMu.toString()));
//    auditRuleInfo.setFactorInfos(factorInfoList);
//    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
////    System.out.println("HLX_0005=after="+SanMuUtil.sanMuMap.get("beijing_药品_x10%1"));
//    System.out.println("HLX_0005被触发");
//end

rule "HLX_0005"
  // 获取医保账单的项目等级和项目比例
salience 99990
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    $invoiceInfo : InvoiceInfo((invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN)&&(bmiIdentityCode==MedicalInsuranceType.TOWN_EMPLOYEE||bmiIdentityCode==MedicalInsuranceType.TOWN_RESIDENT)) from $medicalRecordInfo.invoiceInfos
    $invoiceDetailInfo : InvoiceDetailInfo() from $invoiceInfo.invoiceDetailInfos

    $sanMu : SanMu() from DictDataUtil.sanMuMap.get(DictDataUtil.sanMuHospitalMap.get($invoiceInfo.hospitalName)+"_"+$invoiceDetailInfo.itemClass+"_"+$invoiceDetailInfo.itemCode)
    eval( $sanMu != null && ($invoiceDetailInfo.itemLevel==""||$invoiceDetailInfo.itemRate==""))
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    $invoiceDetailInfo.setItemLevel($sanMu.getItemLevel());
    $invoiceDetailInfo.setItemRateCitizen(DoReplace($invoiceDetailInfo.itemRateCitizen,String.valueOf($sanMu.getItemRateCitizen())));
    $invoiceDetailInfo.setItemRateEmployee(DoReplace($invoiceDetailInfo.itemRateEmployee,String.valueOf($sanMu.getItemRateEmployee())));
     $invoiceDetailInfo.setItemRate(CalculationItemRate($invoiceInfo.getBmiIdentityCode(),String.valueOf($invoiceDetailInfo.itemRateEmployee),String.valueOf($invoiceDetailInfo.itemRateCitizen)));
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("获取医保账单的项目等级和项目比例");
    auditRuleInfo.setRuleResultCode("");
    auditRuleInfo.setRuleResultDesc("更新项目等级和项目比例");
    auditRuleInfo.setDisplayed("0");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("项目明细编码",$invoiceDetailInfo.itemCode));
    factorInfoList.add(new FactorInfo("项目明细(三目)",$sanMu.toString()));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
//    System.out.println("HLX_0005=after="+SanMuUtil.sanMuMap.get("beijing_药品_x10%1"));
    System.out.println("HLX_0005被触发");
end

rule "HLX_0007"
  // 获取自费账单的项目的项目等级和项目比例
salience 99970
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    $invoiceInfo : InvoiceInfo((invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN)&& bmiIdentityCode==MedicalInsuranceType.SALF_PAY) from $medicalRecordInfo.invoiceInfos
    $invoiceDetailInfo : InvoiceDetailInfo() from $invoiceInfo.invoiceDetailInfos
    $sanMu : SanMu() from DictDataUtil.sanMuMap.get(DictDataUtil.sanMuHospitalMap.get($invoiceInfo.hospitalName)+"_"+$invoiceDetailInfo.itemClass+"_"+$invoiceDetailInfo.itemCode)
    eval( $sanMu != null )
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    $invoiceDetailInfo.setItemLevel($sanMu.getItemLevel());
    $invoiceDetailInfo.setItemRateCitizen(DoReplace($invoiceDetailInfo.itemRateCitizen,String.valueOf($sanMu.getItemRateCitizen())));
    $invoiceDetailInfo.setItemRateEmployee(DoReplace($invoiceDetailInfo.itemRateEmployee,String.valueOf($sanMu.getItemRateEmployee())));
    $invoiceDetailInfo.setItemRate(comparedRate(String.valueOf($invoiceDetailInfo.itemRateEmployee),String.valueOf($invoiceDetailInfo.itemRateCitizen)));
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("获取自费账单的项目等级和项目比例");
    auditRuleInfo.setRuleResultCode("");
    auditRuleInfo.setRuleResultDesc("更新项目等级和项目比例");
    auditRuleInfo.setDisplayed("0");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("项目明细编码",$invoiceDetailInfo.itemCode));
    factorInfoList.add(new FactorInfo("项目明细(三目)",$sanMu.toString()));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
//    System.out.println("HLX_0005=after="+SanMuUtil.sanMuMap.get("beijing_药品_x10%1"));
    System.out.println("HLX_0007被触发");
end

rule "HLX_0009"
  // 确定自费账单的项目的自付比例
salience 99950
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    $invoiceInfo : InvoiceInfo((invoiceType == InvoiceTypeConst.MEN_ZHEN || invoiceType == InvoiceTypeConst.ZHU_YUAN)&&(bmiIdentityCode!=MedicalInsuranceType.TOWN_EMPLOYEE&&bmiIdentityCode!=MedicalInsuranceType.TOWN_RESIDENT&&bmiIdentityCode!=MedicalInsuranceType.SALF_PAY)) from $medicalRecordInfo.invoiceInfos
    eval( $invoiceInfo != null )
 then
     $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
     $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
     AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
     auditRuleInfo.setRuleCode(drools.getRule().getName());
     auditRuleInfo.setRuleDesc("自费账单项目等级/自付比例获取不成功规则");
     auditRuleInfo.setRuleResultCode("");
     auditRuleInfo.setRuleResultDesc("更新项目等级和项目比例");
     auditRuleInfo.setDisplayed("0");
     auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
     List<FactorInfo> factorInfoList = new ArrayList<>();
     factorInfoList.add(new FactorInfo("发票账单号",$invoiceInfo.invoiceNo));
     auditRuleInfo.setFactorInfos(factorInfoList);
     $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
 // System.out.println("HLX_0005=after="+SanMuUtil.sanMuMap.get("beijing_药品_x10%1"));
     System.out.println("HLX_0009被触发");
end


rule "HIDE_0001"
salience 90990
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $auditRuleInfos:ArrayList(size > 0)
      from collect
        (
          AuditRuleInfo
          (
            displayed == "1" && ruleLevel == RuleLevelConst.FIRST_AUDIT
              && (ruleCode == "YXX_0002" || ruleCode == "YXX_0003" || ruleCode == "YXX_0004" || ruleCode == "YXX_0001" || ruleCode == "HLX_0003")
          )
          from $claimInfo.getAuditRuleInfos()
        )
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("账单层级的隐藏规则");
    auditRuleInfo.setRuleResultCode(RuleResultCode.ZHUANRENHE);
    auditRuleInfo.setRuleResultDesc("账单层级触发的规则条数大于0,则firstAuditResult为转人核");
    auditRuleInfo.setDisplayed("0");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("账单层级触发的规则条数",String.valueOf($auditRuleInfos.size())));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("HIDE_0001被触发");
end

// ***************************************医疗记录层级相关规则=MedicalRecordInfo**********************************************************
rule "HLX_0001"
    // 出险的诊断属于责任免除中的疾病
salience 89990
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    // 经20190226与@鲍强@姜晓莉沟通,此规则有修改,使用出现的诊断编码,从dutyExcludeICDMap中查询,查得即触发规则
    eval( DictDataUtil.claimDutyExcludeDiseaseMap.get($medicalRecordInfo.chiefDiagnosisCode) != null )
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
    $medicalRecordInfo.setChiefDiagnosisExcluded("1");//置为1标识需要除外
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("本次出险的如下诊断属于责任免除中的疾病");
    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
    auditRuleInfo.setRuleResultDesc("本次就诊的诊断["+$medicalRecordInfo.chiefDiagnosisName+"]是责任免除中的疾病,该诊断下的发票费用不予赔付!");
    auditRuleInfo.setDisplayed("1");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("诊断名称",$medicalRecordInfo.chiefDiagnosisName));
    factorInfoList.add(new FactorInfo("诊断编码",$medicalRecordInfo.chiefDiagnosisCode));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("HLX_0001被触发");
end

rule "HLX_0002"
salience 89980
  // 诊断所属的疾病/意外类型与出险原因不符
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $medicalRecordInfo : MedicalRecordInfo() from $claimSchema.medicalRecordInfos
    eval
    (
      DictDataUtil.claimDiagnosisTypeMap.get($medicalRecordInfo.chiefDiagnosisCode) != null &&
//      !DictDataUtil.claimDiagnosisTypeMap.get($medicalRecordInfo.chiefDiagnosisCode).equals()
      !($claimInfo.accidentCause.contains(DictDataUtil.claimDiagnosisTypeMap.get($medicalRecordInfo.chiefDiagnosisCode)))
    )

  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
    $medicalRecordInfo.setChiefDiagnosisExcluded("1");//置为1标识需要除外
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("本次就诊的诊断所属的疾病/意外类型与出险原因不符");
    auditRuleInfo.setRuleResultCode(RuleResultCode.JUPEI);
    auditRuleInfo.setRuleResultDesc("本次就诊的诊断["+$medicalRecordInfo.chiefDiagnosisName+"]与本次理赔申请的出险原因["+DictData.accidentCauseMap.get($claimInfo.accidentCause)+"]不一致,相关发票是否赔付请审核!");
    auditRuleInfo.setDisplayed("1");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("诊断编码",$medicalRecordInfo.chiefDiagnosisCode));
    factorInfoList.add(new FactorInfo("诊断名称",$medicalRecordInfo.chiefDiagnosisName));
    factorInfoList.add(new FactorInfo("出险原因",DictData.accidentCauseMap.get($claimInfo.accidentCause)));
    factorInfoList.add(new FactorInfo("诊断属性",DictData.accidentCauseMap.get(DictDataUtil.claimDiagnosisTypeMap.get($medicalRecordInfo.chiefDiagnosisCode))));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("HLX_0002被触发");
end

rule "HIDE_0002"
salience 80990
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $auditRuleInfos:ArrayList(size > 0)
      from collect
        (
          AuditRuleInfo
          (
            displayed == "1" && ruleLevel == RuleLevelConst.FIRST_AUDIT
              && (ruleCode == "HLX_0002" || ruleCode == "HLX_0001")
          )
          from $claimInfo.getAuditRuleInfos()
        )
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("病历层级的隐藏规则");
    auditRuleInfo.setRuleResultCode(RuleResultCode.ZHUANRENHE);
    auditRuleInfo.setRuleResultDesc("病历层级触发的规则条数大于0,则firstAuditResult为转人核");
    auditRuleInfo.setDisplayed("0");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("病历层级触发的规则条数",String.valueOf($auditRuleInfos.size())));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("HIDE_0002被触发");
end

// ***************************************赔案层级相关规则=ClaimInfo**********************************************************
rule "WTJ_0001"
  // 患者姓名、性别与保单被保险人基本信息不符
salience 69990
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $policyInfo:PolicyInfo() from $claimSchema.policyInfos
    eval( !($claimInfo.name.equals($policyInfo.insuredInfo.insuredName) && $claimInfo.gender.equals($policyInfo.insuredInfo.insuredGender)) )
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    $claimInfo.setFirstAuditResult(RuleResultCode.ZHUANRENHE);
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("出险人姓名、性别与保单被保险人姓名、性别不符");
    auditRuleInfo.setRuleResultCode(RuleResultCode.ZHUANRENHE);
    auditRuleInfo.setRuleResultDesc("出险人信息与被保人信息不一致,请转人工确认!");
    auditRuleInfo.setDisplayed("1");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("理赔申请书号",$claimInfo.applicationNo));
    factorInfoList.add(new FactorInfo("保单号",$policyInfo.policyNo));
    factorInfoList.add(new FactorInfo("出险人姓名",$claimInfo.name));
    factorInfoList.add(new FactorInfo("被保人姓名",$policyInfo.insuredInfo.insuredName));
    factorInfoList.add(new FactorInfo("出险人性别",DictData.genderMap.get($claimInfo.gender)));
    factorInfoList.add(new FactorInfo("被保人性别",DictData.genderMap.get($policyInfo.insuredInfo.insuredGender)));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("WTJ_0001被触发");
end

rule "HIDE_0003"
salience 60990
  when
    $claimSchema:ClaimSchema()
    $claimInfo:ClaimInfo() from $claimSchema.claimInfo
    $auditRuleInfos:ArrayList(size > 0)
      from collect
        (
          AuditRuleInfo
          (
            displayed == "1" && ruleLevel == RuleLevelConst.FIRST_AUDIT
              && ruleCode == "WTJ_0001"
          )
          from $claimInfo.getAuditRuleInfos()
        )
  then
    $claimInfo.setClaimAudit(RuleLevelConst.FIRST_AUDIT);
    AuditRuleInfo auditRuleInfo = new AuditRuleInfo();
    auditRuleInfo.setRuleCode(drools.getRule().getName());
    auditRuleInfo.setRuleDesc("赔案层级的隐藏规则");
    auditRuleInfo.setRuleResultCode(RuleResultCode.ZHUANRENHE);
    auditRuleInfo.setRuleResultDesc("赔案层级触发的规则条数大于0,则firstAuditResult为转人核");
    auditRuleInfo.setDisplayed("0");
    auditRuleInfo.setRuleLevel(RuleLevelConst.FIRST_AUDIT);
    List<FactorInfo> factorInfoList = new ArrayList<>();
    factorInfoList.add(new FactorInfo("赔案层级触发的规则条数",String.valueOf($auditRuleInfos.size())));
    auditRuleInfo.setFactorInfos(factorInfoList);
    $claimSchema.getClaimInfo().getAuditRuleInfos().add(auditRuleInfo);
    System.out.println("HIDE_0003被触发");
end

claimSchema对象:

@Data
public class ClaimSchema {
  //  public Header header;
  //  public Body body;
  public ClaimInfo claimInfo;
  public List<PolicyInfo> policyInfos;
  public List<MedicalRecordInfo> medicalRecordInfos;
}

 

 

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
posted on 2019-11-27 15:47  梓木的稻稻  阅读(749)  评论(0编辑  收藏  举报