我正在创建股票对象并插入股票值,如下所示
- 客户 1 有 2 个股票 stock4 和 stock5
- customer2 有 1 个股票 arrayListStocks1
在这里,我试图计算给定会话的所有股票的总和
Stocks stocks1=new Stocks("stock1", 1, 1);
Stocks stocks2=new Stocks("stock2", 2, 2);
Stocks stocks4=new Stocks("stock4", 4, 4);
Stocks stocks5=new Stocks("stock5", 5, 5);
ArrayList<Stocks> arrayListStocks1=new ArrayList<Stocks>();
arrayListStocks1.add(stocks1);
arrayListStocks1.add(stocks2);
Customer customer1= new Customer();
customer1.setCustomerName("ACC");
customer1.setStocks(arrayListStocks1);
ArrayList<Stocks> arrayListStocks2=new ArrayList<Stocks>();
arrayListStocks2.add(stocks4);
arrayListStocks2.add(stocks5);
Customer customer2= new Customer();
customer2.setCustomerName("JINDAL");
customer2.setStocks(arrayListStocks2);
kSession.insert(customer1);
kSession.insert(customer2);
rule "Rule5"
// agenda-group "promotions2"
dialect "java"
no-loop
salience 80
when
$list: List() from collect($customer:Customer($customerName:customerName,$stk:stocks))
$customer:Customer($customerName:customerName,$stk:stocks)
$stocks:Stocks() from $stk
$listStocks: List() from collect(Stocks($stockNumber:stockNumber > 1) from $stk )
$sum:Number() from accumulate (Stocks($stockNumber: stockNumber) from $stk,sum($stockNumber))
then
// System.out.println("Rule5 Stock Number- " + $stocks.getStockNumber());
// System.out.println("Rule5 SIZE - " + $listStocks.size());
System.out.println("Number - " + $sum);
end
当我在规则之上运行时,我得到低于输出数字 - 9.0 数字 - 9.0 数字 - 3.0 数字 - 3.0
如何计算来自 customer1 和 customer2 的 2 只股票的总和我期待结果 12
谢谢,