1. #描述如何计算销售人员提成比例的规则
2. package org.gaofubing.commision
3.
4. import org.gaofubing.discount.CommisionComputer;
5.
6.
7. #折扣小于5折
8. rule "lessThanFive" 9.
10. when
11. computer:CommisionComputer(discount < 5)
12. then
13. computer.setDeduct(0.03);
14. end
15.
16. #折扣等于5折
17. rule "equalsFive" 18.
19. when
20. computer:CommisionComputer(discount == 5)
21. then
22. computer.setDeduct(0.1);
23. end
24.
25. #折扣大于5折小于等于6折
26. rule "betweenFiveAndSix" 27.
28. when
29. computer: CommisionComputer(discount:discount,discount > 5,discount <= 6)
30. then
31. computer.setDeduct(((discount.doubleValue() -5) * 0.5 + 6 * 0.1 ) / discount.doubleValue());
32. end
33.
34. #折扣大于6折小于等于7折
35. rule "betweenSixAndSeven" 36.
37. when
38. computer: CommisionComputer(discount:discount,discount > 6,discount <= 7)
39. then
40. computer.setDeduct(((discount.doubleValue() -6) * 0.6 + (6 - 5) * 0.5 + 5 * 0.1 ) / discount.doubleValue());
41. end
42.
43. #折扣大于7折小于等于8折
44. rule "betweenSevenAndEight" 45.
46. when
47. computer:CommisionComputer(discount:discount,discount > 7,discount <= 8)
48. then
49. computer.setDeduct(((discount.doubleValue() -7) * 0.65 + (7-6) * 0.6 + (6 - 5) * 0.5 + 5 * 0.1 ) / discount.doubleValue());
50. end
51.
52. #折扣大于8折小于等于9折
53. rule "betweenEightAndNine" 54.
55. when
56. computer:CommisionComputer(discount:discount,discount > 8,discount <= 9)
57. then
58. computer.setDeduct(((discount.doubleValue() -8) * 0.7 + (8-7) * 0.65 + (7-6) * 0.6 + (6 - 5) * 0.5 + 5 * 0.1 ) / discount.doubleValue());
59. end
60.
61. #折扣大于9折
62. rule "greaterThanNine" 63.
64. when
65. computer:CommisionComputer(discount:discount,discount > 9)
66. then
67. computer.setDeduct(((discount.doubleValue() -9) * 0.85 + (9-8) * 0.7 + (8-7) * 0.65 + (7-6) * 0.6 + (6 - 5) * 0.5 + 5 * 0.1 ) / discount.doubleValue());
68. end
在测试的时候发生过一些问题,如果要描述折扣大于8小于9的条件,使用如下代码就不行computer: CommisionComputer(discount:discount,discount > 6) && CommisionComputer(discount <= 7)
另外CommisionComputer的discount属性是double类型,Rules的then部分会将其自动封箱,但是不会自动拆箱,所以如果then部分使用discount就会报错,必须使用discount.doubleValue();