我将两个事实插入到我的drools会话中。我想查看以下内容:
(shipment1!= null&& shipment1.shipToCustomerNo == waypoint1.shipToNumber)|| shipment1 == null
如何在基于guvnor web的决策表中添加此条件?我尝试过使用谓词,而waypoint1和shipment1是成功插入会话的绑定变量。如果我使用谓词并添加上面的内容,我的测试用例工作正常,但是当我在我的Java应用程序中实际运行这些规则时,即使数据是等效的,条件也不会评估为真。我尝试了很多不同的方法来构建这个查询。以下是生成的来源:
//from row number: 1
rule "Row 1 Arrive Destination"
salience 3
activation-group "arrive-destination"
dialect "mvel"
when
waypoint1 : Waypoint( type == "Destination" )
clm1 : CarLocationMessage( sightCode == "Z" , loaded == true )
shipment1 : Shipment( eval( (shipment1 != null && shipment1.shipToCustomerNo == waypoint1.shipToNumber) || shipment1 == null ))
then
TripEventRuleResult tripEventRuleResult1 = new TripEventRuleResult();
tripEventRuleResult1.setEventType( "Arrive" );
insert( tripEventRuleResult1 );
end
答案 0 :(得分:1)
如果我正确理解了您的域名和问题描述,您应该可以像这样执行规则。
//from row number: 1
rule "Row 1 Arrive Destination"
salience 3
activation-group "arrive-destination"
dialect "mvel"
when
waypoint1 : Waypoint( type == "Destination" )
clm1 : CarLocationMessage( sightCode == "Z" , loaded == true )
Shipment( shipToCustomerNo == waypoint1.shipToNumber) or
not Shipment()
then
TripEventRuleResult tripEventRuleResult1 = new TripEventRuleResult();
tripEventRuleResult1.setEventType( "Arrive" );
insert( tripEventRuleResult1 );
end
简而言之,您不需要对Shipment对象进行空检查。它要么在工作记忆中,要么不在工作记忆中