以下是我的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