spring整合Drools规则引擎

           项目中有一个特殊需求,需要根据一定的规则监控可疑的开票,鉴于规则的复杂性以及多变性,放弃硬编码的想法,引入Drools规则引擎,以规则脚本的形式存放在文件中,使得规则的变更不需要修正代码重启机器就可以立即在线上环境生效。规则文件可以使用 .drl文件,也可以是xml文件,这里我们使用drl文件。接下来就直接上代码:

第一步:maven引入Drools依赖

第二步:在resources下面的META-INF中创建kmodule.xml

第三步:在resources/rules/suspicious目录下创建规则文件suspicious.drl,Drools语法可以自行百度。

package com.logic
import com.bosssoft.nontax.agency.invoice.domain.ComputerBill
import com.bosssoft.nontax.agency.invoice.domain.ComputerBillItem

global java.util.Map refuseData

rule "baseMessage"
   no-loop true
   lock-on-active true
   salience 1
   when
      ComputerBill(fpayerName contains "部队" || fpayerName contains "武警")
   then
      refuseData.put("filter",true);
end

rule "baseMessage1"
   no-loop true
   lock-on-active true
   salience 1
   when
      ComputerBill(fbillNature == "1" && ftotalAmt > 100000)
   then
      refuseData.put("filter",true);
end

rule "baseMessage2"
   no-loop true
   lock-on-active true
   salience 1
   when
       ComputerBill(fbillNature == "9" && fbillName contains "资金往来" && (ftotalAmt > 1000000 || fpayerName contains "公司" || fpayerName contains "企业"))
    then
       refuseData.put("filter",true);
end

rule "baseMessage3"
   no-loop true
   lock-on-active true
   salience 1
   when
       ComputerBill(fbillNature == "9" && fbillName contains "捐赠" && (ftotalAmt > 5000000 || fmemo contains "赞助"));
    then
       refuseData.put("filter",true);
end

rule "baseMessage4"
   no-loop true
   lock-on-active true
   salience 1
   when
       $computerBill : ComputerBill(fbillNature == "9" && fbillName contains "捐赠");
       ComputerBillItem(fitemName contains "捐赠") from $computerBill.computerBillItemList
    then
       refuseData.put("filter",true);
end

rule "baseMessage5"
   no-loop true
   lock-on-active true
   salience 1
   when
       ComputerBill(fbillNature == "9" && fbillName contains "团体" && ftotalAmt > 100000)
    then
       refuseData.put("filter",true);
end

第四步:系统调用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章