我一直在寻找一段时间,但我无法在任何地方找到我的问题的确切答案,或者如果我发现类似的东西,它就行不通。
我想在规则的when部分调用一个简单的java方法。
我的代码如下所示:
rule "Ret Rule"
when
Map(this["LOYAL"] == "true")
Map(this["LOYALTYPROMORETENTION"] == "true")
PromotionValidityPeriod(promotionName == "VIVACLUB Loyalty Promo 2013 25 percent")
$customer: Customer( segment == "Residential" , $assets : assets )
$o: Order( ( (DPOrderType == 17 && retentionReason == "RET") || (DPOrderType == 2 && reason == "557") ) , $ct: contractTerms == 24, $olis: orderLineItems )
$tariff: OrderLI( part in ("DT2319", "DT2320"), actionCode not in ("Delete", "INVALID"), $parentId : parentId) from $olis
OrderLI( part == "DT2316", nodeId == $parentId, actionCode not in ("Delete", "INVALID"), $assetId : assetId ) from $olis
/*Asset( assetId == $assetId,
( (contractTerms != null && contractEndDate != null && eval(CalculationsHelper.getFullMonthDifference(new Date(), contractEndDate) < 3 ))
|| (contractTerms == null) ) ) from $assets*/
$li : OrderLI( $newTariff : part in ("DT2319", "DT2320"), parentId == $parentnodeid, actionCode == "Add") from $olis
$del : OrderLI( $oldTariff : part, parentId == $parentnodeid, actionCode == "Delete", productType == "Calling Plan") from $olis
eval(OrderDwrController.setTransitionCondition(fromTariff == $oldTariff, toTariff == $newTariff) == true
then
Offer of = new Offer("DT2331", $parentId, 7);
System.out.println($tariffOld);
of.getOrderLineItemAttributes().add(new OrderLIAttribute("DURATION", "" + $ct));
of.getOrderLineItemAttributes().add(new OrderLIAttribute("Discount of MRC", "25%"));
of.getOrderLineItemAttributes().add(new OrderLIAttribute("VIVACOM TV Package", $tariff.getProductNameENU()));
of.setProductNameENU("VIVACLUB Loyalty Promo 2013 25 percent");
$o.addOffer(of);
of.setLoyaltyPromo(true);
$o.addTextForOffer(of, new Integer[]{173});
end
我遇到问题的特定行是when
部分中的最后一行:
eval(OrderDwrController.setTransitionCondition(
fromTariff == $oldTariff, toTariff == $newTariff) == true
我只想调用一个简单的函数
(OrderDwrController.setTransitionCondition(
fromTariff == $oldTariff, toTariff == $newTariff))
像上面的那个
(eval(CalculationsHelper.getFullMonthDifference(
new Date(), contractEndDate) < 3 ))
该函数是静态的,返回一个布尔值。我已经在文件的开头导入了该类。
我做错了什么?
答案 0 :(得分:1)
首先你没有关闭eval()。
第二,如果你升级你的drools,你可以在then部分编写java表达式,它会比eval()更快
答案 1 :(得分:1)
很抱歉发布答案而不仅仅是回复你(还没有足够的声誉:))
无论你在eval中放置什么都必须求值为布尔值。我不确定你的是谁。这可能是问题所在。
希望有所帮助
干杯,
Avinash