VisualRulse规则引擎在KFC门店租金计算中的应用

VisualRulse规则引擎实现肯德基门店月租金计算的规则代码。这些规则将根据租金架构表中的 BILL_CODE 和 AND_OR 字段来确定租金类型,并根据规则包1.x的计算结果确定月租金类型。

// 规则1.0:租金类型为固定
rule "Rent Type Fixed Rule 1.0"
    salience 10
    when
        $rentStructure: RentStructure(billCode in ("RENP", "CREP"))
    then
        $rentStructure.setRentType("固定");
        update($rentStructure);
end

// 规则1.1:租金类型为抽成
rule "Rent Type Commission Rule 1.1"
    salience 9
    when
        $rentStructure: RentStructure(billCode in ("RENS", "REDS", "PAYA"))
    then
        $rentStructure.setRentType("抽成");
        update($rentStructure);
end

// 规则1.2:租金类型为固定+抽成(AND条件)
rule "Rent Type Fixed + Commission Rule 1.2"
    salience 8
    when
        $rentStructure: RentStructure(billCode in ("RENP", "CREP", "RENS", "REDS", "PAYA"), andOr == "AND")
    then
        $rentStructure.setRentType("固定+抽成");
        update($rentStructure);
end

// 规则1.3:租金类型为两者取高(OR条件)
rule "Rent Type Higher of Two Rule 1.3"
    salience 7
    when
        $rentStructure: RentStructure(billCode in ("RENP", "CREP", "RENS", "REDS", "PAYA"), andOr == "OR")
    then
        $rentStructure.setRentType("两者取高");
        update($rentStructure);
end

// 规则2.0:月租金类型维持不变
rule "Monthly Rent Type Consistent Rule 2.0"
    salience 6
    when
        $store: Store(storeId != null, month != null)
        $rentStructures: List() from collect(RentStructure(storeId == $store.storeId, month == $store.month))
        eval($rentStructures.stream().map(RentStructure::getRentType).distinct().count() == 1)
    then
        $store.setMonthlyRentType($rentStructures.get(0).getRentType());
        update($store);
end

// 规则2.1:月租金类型为固定+抽成
rule "Monthly Rent Type Fixed + Commission Rule 2.1"
    salience 5
    when
        $store: Store(storeId != null, month != null)
        $rentStructures: List() from collect(RentStructure(storeId == $store.storeId, month == $store.month))
        eval($rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "固定") &&
             $rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "抽成" || type == "固定+抽成"))
    then
        $store.setMonthlyRentType("固定+抽成");
        update($store);
end

// 规则2.2:月租金类型为两者取高
rule "Monthly Rent Type Higher of Two Rule 2.2"
    salience 4
    when
        $store: Store(storeId != null, month != null)
        $rentStructures: List() from collect(RentStructure(storeId == $store.storeId, month == $store.month))
        eval($rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "固定") &&
             $rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "两者取高"))
    then
        $store.setMonthlyRentType("两者取高");
        update($store);
end

// 规则2.3:月租金类型为固定+抽成
rule "Monthly Rent Type Fixed + Commission Rule 2.3"
    salience 3
    when
        $store: Store(storeId != null, month != null)
        $rentStructures: List() from collect(RentStructure(storeId == $store.storeId, month == $store.month))
        eval($rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "抽成") &&
             $rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "固定+抽成"))
    then
        $store.setMonthlyRentType("固定+抽成");
        update($store);
end

// 规则2.4:月租金类型为两者取高
rule "Monthly Rent Type Higher of Two Rule 2.4"
    salience 2
    when
        $store: Store(storeId != null, month != null)
        $rentStructures: List() from collect(RentStructure(storeId == $store.storeId, month == $store.month))
        eval($rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "抽成") &&
             $rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "两者取高"))
    then
        $store.setMonthlyRentType("两者取高");
        update($store);
end

// 规则2.5:月租金类型为两者取高
rule "Monthly Rent Type Higher of Two Rule 2.5"
    salience 1
    when
        $store: Store(storeId != null, month != null)
        $rentStructures: List() from collect(RentStructure(storeId == $store.storeId, month == $store.month))
        eval($rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "固定+抽成") &&
             $rentStructures.stream().map(RentStructure::getRentType).anyMatch(type -> type == "两者取高"))
    then
        $store.setMonthlyRentType("两者取高");
        update($store);
end

代码说明:

  1. 规则1.0到1.3:根据 BILL_CODE 和 AND_OR 字段的值确定租金类型。

  2. 规则2.0到2.5:根据规则包1.x的计算结果确定月租金类型。

注意事项:

  • 您需要根据实际的数据模型和业务逻辑调整代码中的类名和方法名。

  • 确保在规则引擎中正确加载和执行这些规则。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值