Drools - 默认规则

发布于 2024-11-24 04:28:55 字数 615 浏览 3 评论 0原文

我正在尝试创建一个 Drools 模板来从电子表格生成规则。我们希望用户能够通过将字段留空来创建“默认规则”。举个简单的例子:我们想根据某个代码对商品的价格添加附加费。如果没有任何代码适用于此商品,则会收取默认附加费。比如:

Code  Surcharge
103   $50
297   $40
334   $30
      $20

所以基本上我想要这样的规则

when
  $u : Unit(code=103)
then
  $u.setSurcharge(50)

然后,如果没有任何附加费匹配,我想将附加费设置为 ​​20 美元。

如果我手写这些规则,我会给默认附加费一个较低的显着性,并将它们放入激活组或类似的组中,这样默认值就不会触发,除非没有任何显式值被触发。

但我正在尝试用模板生成它。我不知道如何让模板说“if @{code}=blank then salience=10 else salience=20”或类似的内容。没办法这么说。

(注意:我不能只是硬编码默认规则,因为实际上还有其他字段与可能为空的字段一起检查。也就是说,可能有许多具有空白代码的规则,根据与其他字段的匹配来应用。)

I am trying to create a Drools template to generate rules from a spreadsheet. We want the user to be able to create "default rules" by leaving a field blank. To make a simplified example: We want to add a surcharge to the price of an item based on a certain code. There is a default surcharge if none of the codes apply to this item. Like:

Code  Surcharge
103   $50
297   $40
334   $30
      $20

So basically I want rules that say

when
  $u : Unit(code=103)
then
  $u.setSurcharge(50)

etc.

Then if none of the surcharges match, I want to set the surcharge to $20.

If I was handwriting these rules, I'd give the default surcharge a lower salience and put them in an activation group or some such so the default wouldn't fire unless none of the explicit values fired.

But I'm trying to generate this with a template. I don't see how to how to make the template say "if @{code}=blank then salience=10 else salience=20" or some such. There's just no way to say that.

(Note: I can't just hardcode the default rule because really there are other fields examined in conjunction with the field that might be blank. That is, there can be many rules with blank code that apply depending on matching with other fields.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文