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.0到1.3:根据
BILL_CODE和AND_OR字段的值确定租金类型。 -
规则2.0到2.5:根据规则包1.x的计算结果确定月租金类型。
注意事项:
-
您需要根据实际的数据模型和业务逻辑调整代码中的类名和方法名。
-
确保在规则引擎中正确加载和执行这些规则。

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



