👔 feat: 申请信用卡
This commit is contained in:
parent
3ce9c81757
commit
1e5d1274d7
|
@ -0,0 +1,49 @@
|
||||||
|
package cn.bunny.drools.bean.exercise;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CreditCardApply {
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package cn.bunny.drools.controller;
|
||||||
|
|
||||||
|
import cn.bunny.drools.bean.exercise.CreditCardApply;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.kie.api.KieBase;
|
||||||
|
import org.kie.api.KieServices;
|
||||||
|
import org.kie.api.runtime.KieContainer;
|
||||||
|
import org.kie.api.runtime.KieSession;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Tag(name = "申请信用卡")
|
||||||
|
@RequestMapping("/api/credit-card")
|
||||||
|
public class CreditCardApplyController {
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("")
|
||||||
|
@Operation(summary = "申请信用卡")
|
||||||
|
public CreditCardApply creditCardApply(@RequestBody CreditCardApply creditCardApply) {
|
||||||
|
KieServices kieServices = KieServices.Factory.get();
|
||||||
|
KieContainer kieContainer = kieServices.getKieClasspathContainer();
|
||||||
|
KieBase kieBase = kieContainer.getKieBase("CreditCardApply");
|
||||||
|
KieSession kieSession = kieBase.newKieSession();
|
||||||
|
|
||||||
|
kieSession.insert(creditCardApply);
|
||||||
|
kieSession.fireAllRules();
|
||||||
|
kieSession.dispose();
|
||||||
|
kieSession.close();
|
||||||
|
return creditCardApply;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,15 @@
|
||||||
<kmodule xmlns="http://www.drools.org/xsd/kmodule">
|
<kmodule xmlns="http://www.drools.org/xsd/kmodule">
|
||||||
|
|
||||||
<!-- 练习 -->
|
<!-- 练习 -->
|
||||||
<kbase name="Exercise" packages="rules.exercise" default="true">
|
<kbase name="Exercise" packages="rules.exercise.test" default="false">
|
||||||
</kbase>
|
</kbase>
|
||||||
|
|
||||||
<!-- 练习 -->
|
<!-- 计算税额 -->
|
||||||
<kbase name="ExerciseTax" packages="rules.exercise.tax" default="true">
|
<kbase name="ExerciseTax" packages="rules.exercise.tax" default="false">
|
||||||
|
</kbase>
|
||||||
|
|
||||||
|
<!-- 信用卡 -->
|
||||||
|
<kbase name="CreditCardApply" packages="rules.exercise.card" default="false">
|
||||||
</kbase>
|
</kbase>
|
||||||
|
|
||||||
<!-- demo 练习 -->
|
<!-- demo 练习 -->
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package rules.exercise.card;
|
||||||
|
import cn.bunny.drools.bean.exercise.CreditCardApply;
|
||||||
|
|
||||||
|
rule "检查学历与薪水1 如果申请人既没房也没车,同时学历为大专以下,并且月薪少于5000,那么不通过"
|
||||||
|
salience 10
|
||||||
|
no-loop true
|
||||||
|
|
||||||
|
// && 可以写成 ,
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(hasHouse == false, hasCar == false,
|
||||||
|
education == CreditCardApply.EDUCATION_1, monthlyIncome < 5000)
|
||||||
|
then
|
||||||
|
// 审核不通过直接结束
|
||||||
|
$creditCard.setCheckResult(false);
|
||||||
|
drools.halt();
|
||||||
|
end
|
||||||
|
|
||||||
|
rule "检查学历与薪水2 如果申请人既没房也没车,同时学历为大专或本科,并且月薪少于3000,那么不通过"
|
||||||
|
salience 10
|
||||||
|
no-loop true
|
||||||
|
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(hasCar == false, hasHouse==false,
|
||||||
|
(education == CreditCardApply.EDUCATION_2 || education == CreditCardApply.EDUCATION_3)
|
||||||
|
&&
|
||||||
|
monthlyIncome < 3000
|
||||||
|
)
|
||||||
|
then
|
||||||
|
$creditCard.setCheckResult(false);
|
||||||
|
drools.halt();
|
||||||
|
end
|
||||||
|
|
||||||
|
rule "检查学历与薪水3 如果申请人既没房也没车,同时学历为本科以上,并且月薪少于2000,同时之前没有信用卡的,那么不通过"
|
||||||
|
salience 10
|
||||||
|
no-loop true
|
||||||
|
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(hasCar == false, hasHouse==false,
|
||||||
|
education == CreditCardApply.EDUCATION_4 , monthlyIncome < 2000
|
||||||
|
, hasCreditCardCount == 0
|
||||||
|
)
|
||||||
|
then
|
||||||
|
$creditCard.setCheckResult(false);
|
||||||
|
drools.halt();
|
||||||
|
end
|
||||||
|
|
||||||
|
rule "检查申请人已有的信用卡数量 如果申请人现有的信用卡数量大于10,那么不通过"
|
||||||
|
salience 10
|
||||||
|
no-loop true
|
||||||
|
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(hasCreditCardCount > 20)
|
||||||
|
then
|
||||||
|
$creditCard.setCheckResult(false);
|
||||||
|
drools.halt();
|
||||||
|
end
|
|
@ -0,0 +1,79 @@
|
||||||
|
package rules.exercise.card;
|
||||||
|
import cn.bunny.drools.bean.exercise.CreditCardApply;
|
||||||
|
|
||||||
|
rule "如果申请人有房有车,或者月收入在20000以上,那么发放的信用卡额度为15000"
|
||||||
|
salience 1
|
||||||
|
no-loop true
|
||||||
|
activation-group "credit_card_apply_group"
|
||||||
|
|
||||||
|
// && 可以写成 ,
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(
|
||||||
|
checkResult == true
|
||||||
|
&&
|
||||||
|
(hasHouse == true && hasCar == true)
|
||||||
|
||
|
||||||
|
(monthlyIncome > 20000)
|
||||||
|
)
|
||||||
|
then
|
||||||
|
$creditCard.setQuota(15000);
|
||||||
|
end
|
||||||
|
|
||||||
|
rule "如果申请人没房没车,但月收入在10000~20000之间,那么发放的信用卡额度为6000"
|
||||||
|
salience 1
|
||||||
|
no-loop true
|
||||||
|
activation-group "credit_card_apply_group"
|
||||||
|
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(
|
||||||
|
checkResult == true && hasHouse == false && hasCar == false
|
||||||
|
&& monthlyIncome >= 10000 && monthlyIncome <= 20000
|
||||||
|
)
|
||||||
|
then
|
||||||
|
$creditCard.setQuota(6000);
|
||||||
|
end
|
||||||
|
|
||||||
|
rule "如果申请人没房没车,月收入在10000以下,那么发放的信用卡额度为3000"
|
||||||
|
salience 1
|
||||||
|
no-loop true
|
||||||
|
activation-group "credit_card_apply_group"
|
||||||
|
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(
|
||||||
|
checkResult == true && hasHouse == false && hasCar == false
|
||||||
|
&& monthlyIncome < 10000
|
||||||
|
)
|
||||||
|
then
|
||||||
|
$creditCard.setQuota(3000);
|
||||||
|
end
|
||||||
|
|
||||||
|
rule "如果申请人有房没车或者没房但有车,月收入在1000以下,那么发放的信用卡额度为5000"
|
||||||
|
salience 1
|
||||||
|
no-loop true
|
||||||
|
activation-group "credit_card_apply_group"
|
||||||
|
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(
|
||||||
|
checkResult == true && (hasHouse == true || hasCar == false)
|
||||||
|
&& monthlyIncome < 10000
|
||||||
|
)
|
||||||
|
then
|
||||||
|
$creditCard.setQuota(5000);
|
||||||
|
end
|
||||||
|
|
||||||
|
rule "如果申请人有房没车或者是没房但有车,月收入在10000~20000之间,那么发放的信用卡额度为8000"
|
||||||
|
salience 1
|
||||||
|
no-loop true
|
||||||
|
activation-group "credit_card_apply_group"
|
||||||
|
|
||||||
|
when
|
||||||
|
$creditCard:CreditCardApply(
|
||||||
|
checkResult == true
|
||||||
|
&&
|
||||||
|
((hasHouse == true && hasCar == false) || (hasHouse == false && hasCar == true))
|
||||||
|
&&
|
||||||
|
monthlyIncome >= 10000 && monthlyIncome <= 20000
|
||||||
|
)
|
||||||
|
then
|
||||||
|
$creditCard.setQuota(8000);
|
||||||
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
package rules.exercise;
|
package rules.exercise.test;
|
||||||
|
|
||||||
import cn.bunny.drools.bean.exercise.ComparisonOperation;
|
import cn.bunny.drools.bean.exercise.ComparisonOperation;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package rules.exercise;
|
package rules.exercise.test;
|
||||||
import cn.bunny.drools.bean.exercise.ComparisonOperation;
|
import cn.bunny.drools.bean.exercise.ComparisonOperation;
|
||||||
|
|
||||||
rule "exercise-02-contains"
|
rule "exercise-02-contains"
|
|
@ -1,4 +1,4 @@
|
||||||
package rules.exercise;
|
package rules.exercise.test;
|
||||||
import cn.bunny.drools.bean.exercise.ComparisonOperation;
|
import cn.bunny.drools.bean.exercise.ComparisonOperation;
|
||||||
|
|
||||||
rule "exercise-03-contains"
|
rule "exercise-03-contains"
|
|
@ -1,4 +1,4 @@
|
||||||
package rules.exercise;
|
package rules.exercise.test;
|
||||||
import cn.bunny.drools.bean.exercise.ComparisonOperation;
|
import cn.bunny.drools.bean.exercise.ComparisonOperation;
|
||||||
|
|
||||||
rule "exercise-04-contains"
|
rule "exercise-04-contains"
|
Loading…
Reference in New Issue