0
我有一個基於TaskPlanning示例的簡單規則。它看起來像這樣:在Drools規則引擎中設置本地變量/事實
rule "It is better if user does not overexceeds its hours"
when
$emp : Employee()
$task : Task($taskType : taskType, employee == $emp)
accumulate(Task(employee == $emp);
$minutesOfEmplSpend : sum($taskType.getBaseDuration());
$emp.getMinutesAvailable() < $minutesOfEmplSpend
)
then
scoreHolder.addMediumConstraintMatch(kcontext,
$emp.getMinutesAvailable()-$minutesOfEmplSpend);
end
好的,它工作。但我也想在那裏添加額外的約束。 $任務變量有isSerious屬性,它保存布爾值。我希望在添加中等約束時也考慮到這一點。
我想實現這樣的事情:
scoreHolder.addMediumConstraintMatch(kcontext,
$emp.getMinutesAvailable()-$minutesOfEmplSpend - ($task.isSerious == true ? 100 : 10)));
但我得到規則的錯誤。我想我已經嘗試了一切 - 請至少讓我指出正確的方向。
這奏效了!我發誓我已經嘗試了這一百次! – Chlebik