我一直在尋找一段時間,但我無法在任何地方找到我的問題的確切答案,或者如果我找到類似的東西,它不起作用。如何在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))
函數是靜態的,返回一個布爾值。我已經在文件的開頭導入了類。
我在做什麼錯?
會發生什麼?不建立,不做你認爲應該的,或者是什麼? – gustafc 2013-02-21 12:39:42
你使用的是什麼版本的流口水? – radai 2013-02-21 12:43:28
我正在使用Drools 5.我收到一個奇怪的錯誤...我可以在我的程序中看到該規則不起作用。我的方法也有一個斷點,但我沒有達到它。我不知道我是否在調用像我應該......的功能? – hantonov 2013-02-21 12:57:42