我有一个客户事实,它有很多股票事实。
我希望在ist匹配后打破项循环。
List<Stocks> stocks = new ArrayList<Stocks>();
stocks.add(new Stocks("Apple", 10, 100));
stocks.add(new Stocks("Google", 35, 28));
Customer customer = new Customer();
customer.setStocks(stocks);
customer.setCustId("ABC123");
List<Stocks> stocks2 = new ArrayList<Stocks>();
stocks2.add(new Stocks("Apple", 10, 100));
stocks2.add(new Stocks("Google", 35, 28));
stocks2.add(new Stocks("salesforce", 160, 40));
Customer customer2 = new Customer();
customer2.setStocks(stocks2);
customer2.setCustId("ABC456");
ksession.insert(customer);
ksession.insert(customer2);
ksession.fireAllRules();
这是我的drl文件
rule "RS0Test"
when
$c : Customer()
$items : List( size > 1 ) from collect
(Stocks(quantity>1) from $c.stocks )
then
System.out.println("Customer : " + $c.getCustId() );
end
结果/输出:
Customer : ABC456
Customer : ABC123
请建议。
感谢您的帮助。
我正在考虑创建局部变量计数并通过递增值来修改子事实存量,或者在第一个实例中使用break逻辑。