我一直在寻找一段时间,但我无法在任何地方找到我的问题的确切答案,或者如果我找到类似的东西,它不起作用。如何在drools规则的'when'部分中调用Java函数?
我想在部分规则中调用简单的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))
函数是静态的,返回一个布尔值。我已经在文件的开头导入了类。
我在做什么错?
2013-02-21
hantonov
+0
会发生什么?不建立,不做你认为应该的,或者是什么? –
2013-02-21 12:39:42
+0
你使用的是什么版本的流口水? –
2013-02-21 12:43:28
+0
我正在使用Drools 5.我收到一个奇怪的错误...我可以在我的程序中看到该规则不起作用。我的方法也有一个断点,但我没有达到它。我不知道我是否在调用像我应该......的功能? –
2013-02-21 12:57:42