首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Drools4:对Shopping示范的分析

2012-10-25 
Drools4:对Shopping示例的分析??package?org.drools.examples ????#?定义Package中使用mvel,默认是使用jav

Drools4:对Shopping示例的分析

    ?
  1. ?
      1. package?org.drools.examples ??
      2. ??
      3. #?定义Package中使用mvel,默认是使用java ??
      4. dialect?"mvel"??
      5. ??
      6. #?列出客户购买商品的情况 ??
      7. rule?"Purchase?notification"??
      8. ????salience?10??
      9. ??
      10. ????when ??
      11. ????????$c?:?Customer() ??
      12. ????????$p?:?Purchase(?customer?==?$c)?????? ??
      13. ????then ??
      14. ????????System.out.println(?"Customer?"?+?$c.name?+?"?just?purchased?"?+?$p.product.name?); ??
      15. end?? ??
      16. ??
      17. #?当给与客户折扣时显示相关信息 ??
      18. rule?"Discount?awarded?notification"??
      19. ????when ??
      20. ????????$c?:?Customer() ??
      21. ????????$d?:?Discount(?customer?==?$c?) ??
      22. ????then ??
      23. ????????System.out.println(?"Customer?"?+?$c.name?+?"?now?has?a?discount?of?"?+?$d.amount?); ??
      24. end ??
      25. ??
      26. #?当折扣取消时显示相关信息 ??
      27. rule?"Discount?removed?notification"??
      28. ????when ??
      29. ????????$c?:?Customer() ??
      30. ????????not?Discount(?customer?==?$c?) ??
      31. ????then ??
      32. ????????$c.setDiscount(?0?); ??
      33. ????????System.out.println(?"Customers?"?+?$c.name?+?"?now?has?a?discount?of?"?+?$c.discount?); ??
      34. end ??
      35. ??
      36. #?如果客户购买的商品超过100元给与折扣 ??
      37. rule?"Apply?10%?discount?if?total?purcahses?is?over?100"???????????? ??
      38. ????no-loop?true???? ??
      39. ????dialect?"java"??
      40. ????when ??
      41. ????????$c?:?Customer() ??
      42. ????????$i?:?Double(doubleValue??>?100)?from?accumulate?(?Purchase(?customer?==?$c,?$price?:?product.price?),? ??
      43. ????????????????????????????????????????????????????????????????????sum(?$price?)?) ??
      44. ????then ??
      45. ????????$c.setDiscount(?10?); ??
      46. ????????insertLogical(?new?Discount($c,?10)?);?? ??
      47. ????????System.out.println(?"Customer?"?+?$c.getName()?+?"?now?has?a?shopping?total?of?"?+?$i?); ??
      48. end ??
      1 楼 john_summer 2008-05-08   发现一个问题,我分析了很久也没有结果,麻烦各位大虾帮想想
      如果把两个Product的价格都改为160,在retract之后,居然也激活了"Discount removed notification"了这个规则,但是此时"Apply 10% discount if total purcahses is over 100"的条件依然是满足的呀,insertLogical进去的Discout对象不应该被删除的呀,很是奇怪,麻烦各位帮解答一下,谢谢了

热点排行