任务 3:定义 pricing 规则任务
您将定义用于计算合格客户的租赁价格的任务,并且使用 RetePlus 算法运行规则。
关于此任务
过程
- 在规则流图中选择 pricing 规则任务。
- 在“属性”视图中,单击规则选择,然后单击编辑。
- 在“选择规则”对话框中,选择 pricing 规则包。使用箭头将其移至侧边面板,然后单击确定。
规则任务现在包含 pricing 规则包中的所有规则。
- 在“属性”视图中,单击规则任务,然后对于算法,选择 RetePlus。 RetePlus 方式更适合于定价规则,因为这些规则使用推论。这意味着工作内存中的对象由规则进行修改,而用于触发规则的条件应该予以重新求值。有关 RetePlus 方式的更多信息,请参阅引擎执行方式。
- 在“属性”视图中,单击规则选择,然后在选择运行时规则选择下选择静态 BAL。
- 输入以下代码:
the pickup date of 'the current rental agreement' is after or the same as the effective date of 'the rule', or by default the start date of the session and the pickup date of 'the current rental agreement' is before the expiration date of 'the rule', or by default the end date of the session通过此运行时规则选择语句,您指定只有截至提货日期仍然有效且未到期的 pricing 规则才能在运行时作为 pricing 规则任务的一部分进行评估。
- 在“属性”视图中,单击最终操作,选择 IRL,然后输入以下代码:
java.util.List offersList = new ArrayList(rental.offers); Collections.sort(offersList); Iterator it = offersList.iterator(); while (it.hasNext()) { Offer offer = (Offer) it.next(); session.displayMessage(" * Offer: " + offer); } session.displayMessage(" # Best Offer: " + rental.bestOffer);执行规则任务完成后,“控制台”输出显示一条消息,该消息列出所有可用报价的价格并说明对于客户最优惠的价格。
- 由于您将 IRL 用于最终操作,因此必须添加用于 BOM 类的导入:
- 单击规则流图的空白部分。
- 在规则流的“属性”视图中,单击导入。
- 输入以下导入:
import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Date; import carrental.Offer;use rental; use session;
- 保存工作。
结果
在下一个任务中,您将定义可将 eligibility 规则任务和 pricing 规则任务之间的转换作为规则流执行路径的一部分来执行的条件。