`

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

    博客分类:
  • java
阅读更多

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着色功能呢?代码贴上去一点都不好看,唉!

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics