流口水在dinam上产生过滤器

发布于 2025-02-11 21:42:41 字数 1342 浏览 2 评论 0原文

新的JBoss流口水:)

我正在研究一个POC,其中有一个或多个过滤器存在的规则。我正在使用模板动态生成该规则。

template header

effectiveDate
expirationDate
rule
totalPriceValue

package test.template;
import  test.domain.ProductDiscountRequest;

template "value discount template"

rule "Value discount on customer_@{row.rowNumber}"
    date-effective "@{effectiveDate}"
    date-expires   "@{expirationDate}"
    when
        requestObject : ProductDiscountRequest(@{rule} && totalPrice > @{totalPriceValue});
    then
        requestObject.addDiscount(5.0d);
end

end template

该模板具有正确的输入,生成了一个规则,例如

package test.template;
import  test.domain.ProductDiscountRequest;

rule "Value discount on customer_0"
    date-effective "25-Jun-2022 16:00"
    date-expires   "26-Jun-2030 8:00"
    when
        requestObject : ProductDiscountRequest(customer == 'TestCustomer' && totalPrice > 30);
    then
        requestObject.addDiscount(5.0d);
end

有多个过滤器,也可以组合它们,因此 customer =='testCustomer'也可以是 customer =='testCustOustomer' && CustGroup ==“ TestGroup” 等。 我看到3个解决方案:

  1. 在代码中生成过滤零件,仅插入它
  2. 创建每个过滤器数量的不同规则(1个过滤器的1个规则,1个过滤器的1个规则等)
  3. 将过滤器发送到模板并将其直接生成

我尝试有些事情,但是我无法让#3上班。假设有一个过滤器列表,我该如何迭代它并将其连接到完整状态?

我对其他想法持开放态度,以使其变得更好。

New with JBoss Drools :)

I'm working on a PoC where there's a rule where one or multiple filters can exist. I'm using a template to generate that rule dynamically.

template header

effectiveDate
expirationDate
rule
totalPriceValue

package test.template;
import  test.domain.ProductDiscountRequest;

template "value discount template"

rule "Value discount on customer_@{row.rowNumber}"
    date-effective "@{effectiveDate}"
    date-expires   "@{expirationDate}"
    when
        requestObject : ProductDiscountRequest(@{rule} && totalPrice > @{totalPriceValue});
    then
        requestObject.addDiscount(5.0d);
end

end template

This template, with the correct input, generates a rule like

package test.template;
import  test.domain.ProductDiscountRequest;

rule "Value discount on customer_0"
    date-effective "25-Jun-2022 16:00"
    date-expires   "26-Jun-2030 8:00"
    when
        requestObject : ProductDiscountRequest(customer == 'TestCustomer' && totalPrice > 30);
    then
        requestObject.addDiscount(5.0d);
end

There are multiple filters available and they can also be combined, so customer == 'TestCustomer' can also be customer == 'TestCustomer' && custGroup == "TestGroup" and so forth.
I see 3 solutions:

  1. Generate the filtering part in the code and only insert it
  2. Create distinct rules per number of filters (1 rule for 1 filter, 1 rule for 2 filters etc)
  3. Send the filters to the template and generate it there directly

I tried some things but I couldn't get #3 to work. Supposing that there's a list of filters, how do I iterate over it and concatenate it to a full condition?

I'm open to other ideas to make this better.

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

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

发布评论

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