Drools4:对Shopping示范的分析
Drools4:对Shopping示例的分析??package?org.drools.examples ????#?定义Package中使用mvel,默认是使用jav
Drools4:对Shopping示例的分析
?
?
- package?org.drools.examples ??
- ??
- #?定义Package中使用mvel,默认是使用java ??
- dialect?"mvel"??
- ??
- #?列出客户购买商品的情况 ??
- rule?"Purchase?notification"??
- ????salience?10??
- ??
- ????when ??
- ????????$c?:?Customer() ??
- ????????$p?:?Purchase(?customer?==?$c)?????? ??
- ????then ??
- ????????System.out.println(?"Customer?"?+?$c.name?+?"?just?purchased?"?+?$p.product.name?); ??
- end?? ??
- ??
- #?当给与客户折扣时显示相关信息 ??
- rule?"Discount?awarded?notification"??
- ????when ??
- ????????$c?:?Customer() ??
- ????????$d?:?Discount(?customer?==?$c?) ??
- ????then ??
- ????????System.out.println(?"Customer?"?+?$c.name?+?"?now?has?a?discount?of?"?+?$d.amount?); ??
- end ??
- ??
- #?当折扣取消时显示相关信息 ??
- rule?"Discount?removed?notification"??
- ????when ??
- ????????$c?:?Customer() ??
- ????????not?Discount(?customer?==?$c?) ??
- ????then ??
- ????????$c.setDiscount(?0?); ??
- ????????System.out.println(?"Customers?"?+?$c.name?+?"?now?has?a?discount?of?"?+?$c.discount?); ??
- end ??
- ??
- #?如果客户购买的商品超过100元给与折扣 ??
- rule?"Apply?10%?discount?if?total?purcahses?is?over?100"???????????? ??
- ????no-loop?true???? ??
- ????dialect?"java"??
- ????when ??
- ????????$c?:?Customer() ??
- ????????$i?:?Double(doubleValue??>?100)?from?accumulate?(?Purchase(?customer?==?$c,?$price?:?product.price?),? ??
- ????????????????????????????????????????????????????????????????????sum(?$price?)?) ??
- ????then ??
- ????????$c.setDiscount(?10?); ??
- ????????insertLogical(?new?Discount($c,?10)?);?? ??
- ????????System.out.println(?"Customer?"?+?$c.getName()?+?"?now?has?a?shopping?total?of?"?+?$i?); ??
- end ??
1 楼 john_summer 2008-05-08 发现一个问题,我分析了很久也没有结果,麻烦各位大虾帮想想
如果把两个Product的价格都改为160,在retract之后,居然也激活了"Discount removed notification"了这个规则,但是此时"Apply 10% discount if total purcahses is over 100"的条件依然是满足的呀,insertLogical进去的Discout对象不应该被删除的呀,很是奇怪,麻烦各位帮解答一下,谢谢了