当前位置:   article > 正文

Drools规则引擎drl文件语法_drl文件用什么打开

drl文件用什么打开

参考博客链接:https://www.cnblogs.com/atomicbomb/p/7251814.html

drl文件内包含:包路径,引用,规则体

package:包路径,改路径是逻辑路径(第一行)

import:导入外部变量,类(可以是类的静态方法)

globals:全局变量

functions:函数

queries:查询

rule:规则体,以rule开头,已end结尾,每个文件可以包含多个rule,规则体有三个部分:LHS,RHS,属性

    LHS:(Left Hand Side) 条件部分,在when和then中间的部分;可以包含0~n个条件;为空的话引擎会自动添加一个eval(true)的条件。

     RHS:(right hand side) 在then后的部分,满足LHS的条件,执行RHS;这部分可以直接编写java代码;可以对fact进行增删改的操作


 

 

  1. import com.sutpc.maas.orderbook.domain.Order;
  2. import com.sutpc.maas.orderbook.domain.StaffType;import com.sutpc.maas.orderbook.domain.OrderType;
  3. import com.sutpc.maas.orderbook.domain.ConnectionType;
  4. import com.sutpc.maas.orderbook.domain.Price;
  5. import com.sutpc.maas.orderbook.domain.DiscountType
  6. import java.math.BigDecimal;
  7. function Boolean containStr(String routeNo,String routeNos){
  8. Boolean isContain = routeNos.contains(routeNo);
  9. return isContain;
  10. }
  11. function Price queryPrice(Double routePrice){
  12. Price price = new Price();
  13. price.setPrice(routePrice);
  14. price.setActualPrice(routePrice);
  15. price.setDiscountType(DiscountType.NON);
  16. return price;
  17. }
  18. function Price calculatePrice(Double amount,Double discount){
  19. Price price = new Price();
  20. BigDecimal b = new BigDecimal(amount);
  21. amount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  22. price.setPrice(amount);
  23. Double actualPrice = amount*discount;
  24. actualPrice = new BigDecimal(actualPrice).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  25. price.setActualPrice(actualPrice);
  26. price.setDiscountType(DiscountType.DISCOUNT);
  27. return price;
  28. }
  29. rule "rule1"
  30. no-loop true
  31. when
  32. $order:Order(StaffType.INTERNAL==passenger.getType()&&orderType==OrderType.IMMED&&containStr(route.routeNo,"K4"))
  33. then
  34. System.out.println("进入rule1");
  35. Price price = new Price();
  36. price.setPrice($order.getRoute().getRoutePrice());
  37. price.setActualPrice(2.4);
  38. price.setDiscountType(DiscountType.FIX);
  39. $order.setPrice(price);
  40. update($order);
  41. end
  42. rule "rule2"
  43. no-loop true
  44. when
  45. $order:Order(StaffType.EXTERNAL==passenger.getType()&&orderType==OrderType.IMMED&&containStr(route.routeNo,"K4"))
  46. then
  47. System.out.println("进入rule2");
  48. Price price = queryPrice($order.getRoute().getRoutePrice());
  49. $order.setPrice(price);
  50. update($order);
  51. end
  52. rule "rule3"
  53. no-loop true
  54. when
  55. $order:Order(StaffType.EXTERNAL==passenger.getType()&&orderType==OrderType.IMMED&&containStr(route.routeNo,"K1,K2"))
  56. then
  57. System.out.println("进入rule3");
  58. Price price = queryPrice($order.getRoute().getRoutePrice());
  59. $order.setPrice(price);
  60. update($order);
  61. end
  62. rule "rule4"
  63. no-loop true
  64. when
  65. $order:Order(StaffType.INTERNAL==passenger.getType()&&orderType==OrderType.IMMED&&containStr(route.routeNo,"K1,K2"))
  66. then
  67. System.out.println("进入rule4");
  68. Price price = new Price();
  69. price.setPrice($order.getRoute().getRoutePrice());
  70. price.setActualPrice(0.0);
  71. price.setDiscountType(DiscountType.FIX);
  72. $order.setPrice(price);
  73. update($order);
  74. end
  75. rule "rule5"
  76. no-loop true
  77. when
  78. $order:Order(orderType==OrderType.IMMED&&containStr(route.routeNo,"C1-2")&&ConnectionType.UNITE==connectedTrip.connectionType&&numOfPeople==1)
  79. then
  80. System.out.println("进入rule5");
  81. Price price = queryPrice($order.getRoute().getRoutePrice());
  82. $order.setPrice(price);
  83. update($order);
  84. end
  85. rule "rule6"
  86. no-loop true
  87. when
  88. $order:Order(orderType==OrderType.IMMED&&containStr(route.routeNo,"C1-2")&&ConnectionType.UNITE==connectedTrip.connectionType&&numOfPeople==2)
  89. then
  90. System.out.println("进入rule6");
  91. Double amount = $order.getRoute().getRoutePrice()*$order.getNumOfPeople();
  92. Price price = calculatePrice(amount,0.8);
  93. $order.setPrice(price);
  94. update($order);
  95. end
  96. rule "rule7"
  97. no-loop true
  98. when
  99. $order:Order(orderType==OrderType.IMMED&&containStr(route.routeNo,"C1-2")&&ConnectionType.UNITE==connectedTrip.connectionType&&numOfPeople==3)
  100. then
  101. System.out.println("进入rule6");
  102. Double amount = $order.getRoute().getRoutePrice()*$order.getNumOfPeople();
  103. Price price = calculatePrice(amount,0.6);
  104. $order.setPrice(price);
  105. update($order);
  106. end
  107. rule "rule8"
  108. no-loop true
  109. when
  110. $order:Order(orderType==OrderType.IMMED&&containStr(route.routeNo,"C1-2")&&ConnectionType.UNITE==connectedTrip.connectionType&&numOfPeople>3)
  111. then
  112. System.out.println("进入rule6");
  113. Double amount = $order.getRoute().getRoutePrice()*$order.getNumOfPeople();
  114. Price price = calculatePrice(amount,0.5);
  115. $order.setPrice(price);
  116. update($order);
  117. end

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/798470
推荐阅读
相关标签
  

闽ICP备14008679号