以下是我的fireRules()方法,其中orderresponseVO對象將插入到會話中,以基於totalorderprice計算收益。將雙精度值設置爲0
private void fireRules(ProductResponseVO orderresponseVO,OrderDetailsVO orderdetailsVO{
orderresponseVO.setDiscounts(null);
FactHandle fact= vbDiscSession.insert(orderresponseVO);
vbDiscSession.fireAllRules();
calculateDiscounts(orderresponseVO);
orderdetailsVO.setEarnings(orderresponseVO.getEarnings());
orderdetailsVO.setInvoiceAmount(orderresponseVO.getInvoice());
vbDiscSession.retract(fact);
}
這裏是.drl文件 2規則寫入計算基礎上添加totalordervalue折扣和其解僱每次打印totalorderprice
//created on: Mar 21, 2014
package com.mit.rules.vb
import com.mit.vb.admin.order.bean.ProductResponseVO
import com.mit.vb.admin.order.bean.DiscountVO
import com.mit.vb.admin.order.bean.OrderResponseVO
//list any import classes here.
dialect "mvel"
//declare any global variables here
rule "Discount"
salience 100
no-loop true
when
$responseVO: ProductResponseVO(totalorderprice > 250)
//conditions
then
//actions
$responseVO.addDiscount(new DiscountVO("test",$responseVO.totalorderprice*0.35));
end
rule "Discount special"
salience 50
no-loop true
//include attributes such as "salience" here...
when
$responseVO: ProductResponseVO(totalorderprice >= 500)
//conditions
then
$responseVO.addDiscount(new DiscountVO(" You made it ",$responseVO.totalorderprice*0.10));
//actions
end
rule "Print before every rule" salience 150
when
$responseVO: ProductResponseVO()
then
// System.out.println(" -------------- " + $cpSellerDetails.cpInfoBean.name);
System.out.println(" -------------- " + $responseVO.totalorderprice);
end
基礎上totalordervalue新DiscountVO默認規則被添加。
這裏是addDiscount()方法
public void addDiscount(DiscountVO discount) {
if(this.discounts ==null)
this.discounts = new ArrayList<DiscountVO>();
discounts.add(discount);
}
和DiscountVO構造設置discountname和discountvalue是基於totalordervalue
public class DiscountVO implements Serializable {
/**
*
*/
private static final long serialVersionUID = 3440977389992293711L;
private int orderid;
private String discountName;
private Double discountValue;
private boolean isPercent=false;
private Double discountPercent;
public DiscountVO(String discountName,Double discountValue){
this.discountName= discountName;
this.discountValue=discountValue;
}
計算這裏的問題是每當使用添加DiscountVo drl文件中的addDiscount()DiscountVO中的構造函數將第二個參數設置爲0,即使實際計算不同。 我已經交叉檢查,以驗證discountValue.The計算甚至不爲零設置爲零
你如何得出結論:DiscoutVO中的構造函數會造成損害? Java方法或構造函數無法「將參數設置爲零」。如果DiscountVO對象中的discountValue爲零,則可能有其他原因,因爲調用構造函數看起來確定。 – laune
是laune.The問題不是在構造函數中,而是在.drl文件中的計算$ responseVO.totalorderprice * 0.35 --->這個計算結果爲0,而總的訂購價格是408,但這個乘法給出結果0 – sai