spring - Double value getting set to 0 -
here firerules() method within orderresponsevo object inserted in session calculate earnings based on totalorderprice.
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); }
here .drl file 2 rules written calculate add discounts based on totalordervalue , default rule fired everytime print 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 import classes here. dialect "mvel" //declare global variables here rule "discount" salience 100 no-loop true when $responsevo: productresponsevo(totalorderprice > 250) //conditions //actions $responsevo.adddiscount(new discountvo("test",$responsevo.totalorderprice*0.35)); end rule "discount special" salience 50 no-loop true //include attributes such "salience" here... when $responsevo: productresponsevo(totalorderprice >= 500) //conditions $responsevo.adddiscount(new discountvo(" made ",$responsevo.totalorderprice*0.10)); //actions end rule "print before every rule" salience 150 when $responsevo: productresponsevo() // system.out.println( " -------------- " + $cpsellerdetails.cpinfobean.name); system.out.println( " -------------- " + $responsevo.totalorderprice); end
based on totalordervalue new discountvo added.
here adddiscount() method
public void adddiscount(discountvo discount) { if(this.discounts ==null) this.discounts = new arraylist<discountvo>(); discounts.add(discount); }
and discountvo constructor set discountname , discountvalue calculated based on 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; }
the problem here whenever discountvo added using adddiscount() in drl file constructor in discountvo setting 2nd argument 0 though actual calculation differs. have cross checked verify discountvalue.the calculation not being 0 set zero
i reproduced issue reported. mvel bug caused multiplication of int double , i'll try fix asap. note indeed using java dialect works expected. conversely, if reason need use mvel dialect, quickest workaround can suggest putting double first: in case doing 0.35*$responsevo.totalorderprice works expected.
Comments
Post a Comment