---
title: "基于jboss rule规则引擎的商务折扣例子"
author: "kebo"
date: "2006-06-13T01:19:00Z"
tags: []
slug: "jboss-rule"
draft: false
lastmod: "2006-06-13T01:19:00Z"
id: 255036
url: "https://kebo.iteye.com/blog/255036"
---

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-&gt;(c.getTotalPrice()&gt;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-&gt;(Helper.isContainType(c.getProducts(),Product.TV)))       
 then  
  p.setDiscout(0.95 * p.getDiscout());  
  modify(p);  
end

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

为什么blogjava没有code着色功能呢？代码贴上去一点都不好看，唉！![](/Emoticons/msn/sad_smile.gif)