
一:业务规则
合法性检查规则如下:
| 规则编号 | 名称 | 描述 |
|---|---|---|
| 1 | 检查学历与薪水1 | 如果申请人既没房也没车,同时学历为大专以下,并且月薪少于5000,那么不通过 |
| 2 | 检查学历与薪水2 | 如果申请人既没房也没车,同时学历为大专或本科,并且月薪少于3000,那么不通过 |
| 3 | 检查学历与薪水3 | 如果申请人既没房也没车,同时学历为本科以上,并且月薪少于2000,同时之前没有信用卡的,那么不通过 |
| 4 | 检查申请人已有的信用卡数量 | 如果申请人现有的信用卡数量大于10,那么不通过 |
信用卡额度确定规则:
| 规则编号 | 名称 | 描述 |
|---|---|---|
| 1 | 规则1 | 如果申请人有房有车,或者月收入在20000以上,那么发放的信用卡额度为15000 |
| 2 | 规则2 | 如果申请人没房没车,但月收入在10000~20000之间,那么发放的信用卡额度为6000 |
| 3 | 规则3 | 如果申请人没房没车,月收入在10000以下,那么发放的信用卡额度为3000 |
| 4 | 规则4 | 如果申请人有房没车或者没房但有车,月收入在10000以下,那么发放的信用卡额度为5000 |
| 5 | 规则5 | 如果申请人有房没车或者是没房但有车,月收入在10000~20000之间,那么发放的信用卡额度为8000 |
二:实体类
/**
* 信用卡申请信息
*/
public class CreditCardApplyInfo {
public static final String EDUCATION_1 = "专科以下";
public static final String EDUCATION_2 = "专科";
public static final String EDUCATION_3 = "本科";
public static final String EDUCATION_4 = "本科以上";
private String name;
private String sex;
private int age;
private String education;
private String telephone;
private double monthlyIncome = 0;//月收入
private String address;
private boolean hasHouse = false;//是否有房
private boolean hasCar = false;//是否有车
private int hasCreditCardCount = 0;//现持有信用卡数量
private boolean checkResult = true;//审核是否通过
private double quota = 0;//额度
}
三:规则文件
先进行合法性检查,如果检查不同过就没必要执行确定额度规则了drools.halt()。
package creditCardApply
import com.demo.drools.entity.CreditCardApplyInfo
//合法性检查
rule "如果申请人既没房也没车,同时学历为大专以下,并且月薪少于5000,那么不通过"
salience 10
no-loop true
when
$c:CreditCardApplyInfo(hasCar == false &&
hasHouse == false &&
education == CreditCardApplyInfo.EDUCATION_1 &&
monthlyIncome < 5000)
then
$c.setCheckResult(false);
drools.halt();
end
rule "如果申请人既没房也没车,同时学历为大专或本科,并且月薪少于3000,那么不通过"
salience 10
no-loop true
when
$c:CreditCardApplyInfo(hasCar == false &&
hasHouse == false &&
(education == CreditCardApplyInfo.EDUCATION_2 ||
education == CreditCardApplyInfo.EDUCATION_3) &&
monthlyIncome < 3000)
then
$c.setCheckResult(false);
drools.halt();
end
rule "如果申请人既没房也没车,同时学历为本科以上,并且月薪少于2000,同时之前没有信用卡的,那么不通过"
salience 10
no-loop true
when
$c:CreditCardApplyInfo(hasCar == false &&
hasHouse == false &&
education == CreditCardApplyInfo.EDUCATION_4 &&
monthlyIncome < 2000 &&
hasCreditCardCount == 0)
then
$c.setCheckResult(false);
drools.halt();
end
rule "如果申请人现有的信用卡数量大于10,那么不通过"
salience 10
no-loop true
when
$c:CreditCardApplyInfo(hasCreditCardCount > 10)
then
$c.setCheckResult(false);
drools.halt();
end
//--------------------------------------------------------------------------
//确定额度:activation-group 组内最多有一个能匹配条件成功
rule "如果申请人有房有车,或者月收入在20000以上,那么发放的信用卡额度为15000"
salience 1
no-loop true
activation-group "quota_group"
when
$c:CreditCardApplyInfo(checkResult == true &&
((hasHouse == true && hasCar == true) ||
(monthlyIncome > 20000)))
then
$c.setQuota(15000);
end
rule "如果申请人没房没车,但月收入在10000~20000之间,那么发放的信用卡额度为6000"
salience 1
no-loop true
activation-group "quota_group"
when
$c:CreditCardApplyInfo(checkResult == true &&
hasHouse == false &&
hasCar == false &&
monthlyIncome >= 10000 &&
monthlyIncome <= 20000)
then
$c.setQuota(6000);
end
rule "如果申请人没房没车,月收入在10000以下,那么发放的信用卡额度为3000"
salience 1
no-loop true
activation-group "quota_group"
when
$c:CreditCardApplyInfo(checkResult == true &&
hasHouse == false &&
hasCar == false &&
monthlyIncome < 10000)
then
$c.setQuota(3000);
end
rule "如果申请人有房没车或者没房但有车,月收入在10000以下,那么发放的信用卡额度为5000"
salience 1
no-loop true
activation-group "quota_group"
when
$c:CreditCardApplyInfo(checkResult == true &&
((hasHouse == true && hasCar == false) ||
(hasHouse == false && hasCar == true)) &&
monthlyIncome < 10000)
then
$c.setQuota(5000);
end
rule "如果申请人有房没车或者是没房但有车,月收入在10000~20000之间,那么发放的信用卡额度为8000"
salience 1
no-loop true
activation-group "quota_group"
when
$c:CreditCardApplyInfo(checkResult == true &&
((hasHouse == true && hasCar == false) ||
(hasHouse == false && hasCar == true)) &&
monthlyIncome >= 10000 &&
monthlyIncome <= 20000)
then
$c.setQuota(8000);
end
四:Service
@Service
public class RuleService {
@Autowired
private KieBase kieBase;
//调用Drools规则引擎实现信用卡申请
public CreditCardApplyInfo creditCardApply(CreditCardApplyInfo creditCardApplyInfo){
KieSession session = kieBase.newKieSession();
session.insert(creditCardApplyInfo);
session.fireAllRules();
session.dispose();
return creditCardApplyInfo;
}
}
五:Controller
@RestController
@RequestMapping("/rule")
public class RuleController {
@Autowired
private RuleService ruleService;
@RequestMapping("/creditCardApply")
public CreditCardApplyInfo creditCardApply(@RequestBody
CreditCardApplyInfo creditCardApplyInfo){
creditCardApplyInfo = ruleService.creditCardApply(creditCardApplyInfo);
return creditCardApplyInfo;
}
}
824

被折叠的 条评论
为什么被折叠?



