赞
踩
参考博客链接: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进行增删改的操作
- import com.sutpc.maas.orderbook.domain.Order;
- import com.sutpc.maas.orderbook.domain.StaffType;import com.sutpc.maas.orderbook.domain.OrderType;
- import com.sutpc.maas.orderbook.domain.ConnectionType;
- import com.sutpc.maas.orderbook.domain.Price;
- import com.sutpc.maas.orderbook.domain.DiscountType
- import java.math.BigDecimal;
-
- function Boolean containStr(String routeNo,String routeNos){
- Boolean isContain = routeNos.contains(routeNo);
- return isContain;
- }
-
- function Price queryPrice(Double routePrice){
- Price price = new Price();
- price.setPrice(routePrice);
- price.setActualPrice(routePrice);
- price.setDiscountType(DiscountType.NON);
- return price;
- }
- function Price calculatePrice(Double amount,Double discount){
- Price price = new Price();
- BigDecimal b = new BigDecimal(amount);
- amount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
- price.setPrice(amount);
- Double actualPrice = amount*discount;
- actualPrice = new BigDecimal(actualPrice).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
- price.setActualPrice(actualPrice);
- price.setDiscountType(DiscountType.DISCOUNT);
- return price;
- }
- rule "rule1"
- no-loop true
- when
- $order:Order(StaffType.INTERNAL==passenger.getType()&&orderType==OrderType.IMMED&&containStr(route.routeNo,"K4"))
- then
- System.out.println("进入rule1");
- Price price = new Price();
- price.setPrice($order.getRoute().getRoutePrice());
- price.setActualPrice(2.4);
- price.setDiscountType(DiscountType.FIX);
- $order.setPrice(price);
- update($order);
- end
- rule "rule2"
- no-loop true
- when
- $order:Order(StaffType.EXTERNAL==passenger.getType()&&orderType==OrderType.IMMED&&containStr(route.routeNo,"K4"))
- then
- System.out.println("进入rule2");
- Price price = queryPrice($order.getRoute().getRoutePrice());
- $order.setPrice(price);
- update($order);
- end
- rule "rule3"
- no-loop true
- when
- $order:Order(StaffType.EXTERNAL==passenger.getType()&&orderType==OrderType.IMMED&&containStr(route.routeNo,"K1,K2"))
- then
- System.out.println("进入rule3");
- Price price = queryPrice($order.getRoute().getRoutePrice());
- $order.setPrice(price);
- update($order);
- end
- rule "rule4"
- no-loop true
- when
- $order:Order(StaffType.INTERNAL==passenger.getType()&&orderType==OrderType.IMMED&&containStr(route.routeNo,"K1,K2"))
- then
- System.out.println("进入rule4");
- Price price = new Price();
- price.setPrice($order.getRoute().getRoutePrice());
- price.setActualPrice(0.0);
- price.setDiscountType(DiscountType.FIX);
- $order.setPrice(price);
- update($order);
- end
- rule "rule5"
- no-loop true
- when
- $order:Order(orderType==OrderType.IMMED&&containStr(route.routeNo,"C1-2")&&ConnectionType.UNITE==connectedTrip.connectionType&&numOfPeople==1)
- then
- System.out.println("进入rule5");
- Price price = queryPrice($order.getRoute().getRoutePrice());
- $order.setPrice(price);
- update($order);
- end
- rule "rule6"
- no-loop true
- when
- $order:Order(orderType==OrderType.IMMED&&containStr(route.routeNo,"C1-2")&&ConnectionType.UNITE==connectedTrip.connectionType&&numOfPeople==2)
- then
- System.out.println("进入rule6");
- Double amount = $order.getRoute().getRoutePrice()*$order.getNumOfPeople();
- Price price = calculatePrice(amount,0.8);
- $order.setPrice(price);
- update($order);
- end
- rule "rule7"
- no-loop true
- when
- $order:Order(orderType==OrderType.IMMED&&containStr(route.routeNo,"C1-2")&&ConnectionType.UNITE==connectedTrip.connectionType&&numOfPeople==3)
- then
- System.out.println("进入rule6");
- Double amount = $order.getRoute().getRoutePrice()*$order.getNumOfPeople();
- Price price = calculatePrice(amount,0.6);
- $order.setPrice(price);
- update($order);
- end
- rule "rule8"
- no-loop true
- when
- $order:Order(orderType==OrderType.IMMED&&containStr(route.routeNo,"C1-2")&&ConnectionType.UNITE==connectedTrip.connectionType&&numOfPeople>3)
- then
- System.out.println("进入rule6");
- Double amount = $order.getRoute().getRoutePrice()*$order.getNumOfPeople();
- Price price = calculatePrice(amount,0.5);
- $order.setPrice(price);
- update($order);
- end
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。