基于jboss rule规则引擎的商务折扣例子

xxx购物超市折扣规则描述:
 1.任何顾客的购物总价大于1000元则享受9折优惠
 2.vip顾客的时候无论购物总价是多少享受7折优惠
 3.普通顾客没有特别政策,另有规定的除外
 4.白金顾客享受8.5优惠,无论购物总价多少。
 5.黄金顾客享受9折优惠无论购物总价多少。
 6.任何顾客所够商品中包含tv的时候,优惠后再优惠9.5折
这个user case 是自己想的,不是很复杂

对应的规则文件

#created on: 2006-6-10
#created by: kebo
package com.sample

import com.sample.Person;
import com.sample.ShopCat;
import com.sample.Product;
import com.sample.Helper;


rule "PRICE_DISCOUT"
 salience 2
 no-loop true
 when
  p:Person(c:cat->(c.getTotalPrice()>1000),discout==1)     
 then
  p.setDiscout(0.9);
  modify(p); 
end

rule "VIP"
 salience 3
 no-loop true
 when
  p:Person(type==Person.VIP,discout==1)     
 then
  p.setDiscout(0.7);
  modify(p); 
end

rule "COMMON"
 salience 3
 no-loop true
 when
  p:Person(type==Person.COMMON,discout==1)     
 then
  p.setDiscout(1);
  modify(p);
end

rule "PLATINA"
 salience 3
 no-loop true
 when
  p:Person(type==Person.PLATINA,discout==1)     
 then
  p.setDiscout(0.85); 
  modify(p);
end

rule "GOLD"
 salience 3
 no-loop true
 when
  p:Person(type==Person.GOLD,discout==1)     
 then  
  p.setDiscout(0.9); 
  modify(p);
end

rule "CONTAIN TV"
 salience 1
 no-loop true
 when
  p:Person(c:cat->(Helper.isContainType(c.getProducts(),Product.TV)))     
 then
  p.setDiscout(0.95 * p.getDiscout());
  modify(p);
end

解决rule的冲突还是比较麻烦的。

为什么blogjava没有code着色功能呢?代码贴上去一点都不好看,唉!

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值