基于Drools 规则引擎的信用卡申请系统 之 Drools 实现业务规则

设计规则流如下:

先执行:check,然后执行payment

基于Drools 规则引擎的信用卡申请系统 之 Drools 实现业务规则_第1张图片

 

对应的规则流rmf文件如下: 【使用IDE生成,Drools4.0.7 的可读性,不如Drools 5】

 


 
   
      1
     
        1
        Start
       
       
         
            1
           
           
              check
              3
              check
             
               
             

             
               
                  1
                 
                 
                    payment
                    4
                    payment
                   
                     
                   

                   
                     
                        1
                       
                       
                          2
                          End
                         
                           
                         

                         
                       

                     

                   

                 

               

             

           

         

       

     

   

   
      2
     
   

   
      3
     
   

   
      4
     
   

 

 
  4
  myflow
  MyFlow
  1.0
  RuleFlow
  com.chen.drools

 

 

规则文件如下:

 

清单一:rules.drl


package com.chen.drools

#list any import classes here.
import com.chen.beans.User;


#declare any global variables here

 

#如果申请人既没房也没车,同时学历为大专及以下,并且月薪少于5000,那么不通过。
rule "No1"
 ruleflow-group "check"
 when
  #conditions
  $user: User(hasHouse =="无", hasCar =="无", degree =="大专以下", salary <5000)
 then
  #actions
  $user.setApprove(false);
end

#如果申请人既没房也没车,同时学历为大专或本科,并且月薪少于3000,那么不通过。

rule "No2"
 #include attributes such as "salience" here...
 ruleflow-group "check"
 when
  #conditions
  $user: User( hasHouse =="无", hasCar =="无", salary <3000,( degree =="大专" || degree =="本科"))
 then
  #actions
  $user.setApprove(false);
  
end

#如果申请人既没房也没车,同时学历为本科以上,并且月薪少于2000,同时之前没有信用卡的,那么不通过。

rule "No3"
    ruleflow-group "check"
 when
  $user:User( hasHouse =="无", hasCar =="无", degree =="本科以上", salary <2000)
 then
  $user.setApprove(false);
end

 

 

清单二: payment.drl
package com.chen.drools

#list any import classes here.
import com.chen.beans.CardInfo;
import com.chen.beans.User;
//如果申请人有房有车,或者月收入在20000以上,那么发放的信用卡信用额度为15000

rule "R1"
 ruleflow-group "payment"
 when
  $user: User( salary >20000 || (hasCar =="有" && hasHouse =="有") )
  $card: CardInfo(  )
 then
  
  $user.setCardInfo($card);
  $card.setValue(15000);
  $card.setBankName("中银广州");
  $card.setUser($user);
  #creatPayment(15000,$user);
  #输出测试
end

//如果申请人没房没车,但月收入在10000~20000之间,那么发放的信用卡信用额度为6000

rule "R2"
 #include attributes such as "salience" here...
 ruleflow-group"payment"
 when
  #conditions
  $user: User( hasHouse =="无" , hasCar =="无" , salary >10000 , salary <20000 )
  $card: CardInfo(  )
 then
  #actions
  $user.setCardInfo($card);
  $card.setValue(6000);
  $card.setBankName("中银广州2");
  $card.setUser($user);
  #creatPayment(6000,$user);
end

//如果申请人没房没车,月收入在10000以下,那么发放的信用额度为3000。

rule "R3"
    ruleflow-group"payment"
 when
  $user : User( hasHouse =="无", hasCar =="无" , salary <10000 )
  $card: CardInfo(  )
 then
     $user.setCardInfo($card);
  $card.setValue(3000);
  $card.setBankName("中银广州3");
  $card.setUser($user);
end

//如果申请人有房没车或者是没房但有车,月收入在10000以下,那么发放的信用额度为5000。

rule "R4"
    ruleflow-group"payment"
 when
    $user : User( ( hasHouse =="有" && hasCar =="无") || (hasHouse =="无" && hasCar =="有") && salary <10000 )
    $card: CardInfo(  )
 then
  $user.setCardInfo($card);
  $card.setValue(5000);
  $card.setBankName("中银广州4");
  $card.setUser($user);
end

// 如果申请人有房没车或者是没房但有车,月收入在10000~2000之间,那么发放的信用额度为8000。

rule "R5"
    ruleflow-group"payment"
 when
  $user: User( (hasHouse =="有" && hasCar =="无") || (hasHouse =="无" && hasCar =="有") && salary <= 20000 , salary >=10000 )
  $card: CardInfo(  )
 then
  $user.setCardInfo($card);
  $card.setValue(8000);
  $card.setBankName("中银广州5");
  $card.setUser($user);
end

 

 

你可能感兴趣的:(Drools)