在流口水的子类上应用累积



我正在创建股票对象并插入股票值,如下所示

  1. 客户 1 有 2 只股票 股票4 和股票 5
  2. 客户 2 有 1 只股票阵列列表股票1

在这里,我试图使给定时段的所有股票的总和

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

如何计算客户 1 和客户 2 的 2 只股票的总和 我期待结果 12

谢谢

如果您只想计算所有客户的所有股票的总和,那么您可以尝试这样的事情:

rule "Stocks Sum"
when
$n: Number() from accumulate(
Customer($stk:stocks) and
Stocks($stockNumber: stockNumber) from $stk,
sum($stockNumber)
)
then
//...
end

希望对你有帮助

相关内容

  • 没有找到相关文章

最新更新