如何在流口水中达到以下目标 [英] How to achieve below objective in drools

查看:101
本文介绍了如何在流口水中达到以下目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做以下事情。

I am trying to do below things. Plesse check.

rule "new rule"
        salience -101
        dialect "mvel"
when
$pricingLineItem : PricingLineItem( $ackId : ackId, $prefix : prefix  )
$baseUpChargeConfig : BaseUpChargeConfig( $baseOptionId : baseOptionId,
                                          prefix == $prefix )
$pricingOptionType : PricingOptionType( ackId == $ackId,
                 $optionId : optionId, $optionValue : optionValue )
$baseOptionConfig : BaseOptionConfig( bOptionValue == $optionValue,
                   bOptionCode == $optionId ,id == $baseOptionId )
then
  $pricingLineItem.increment($baseOptionId);
  System.out.println("excuted - "+ $baseOptionId +" "+$baseOptionConfig);   
end

一个PricngLineItem将有多个BaseUpChargeConfig对象匹配。在BaseUpChargeConfig对象中,我们将获取所有相关的BaseOptionConfig对象,然后尝试与PricingLineItem的PricingOptionType对象进行匹配。我需要采用与PricngLineItem的PricingOptionType对象最大匹配的最佳BaseUpChargeConfig对象。

There will multiple BaseUpChargeConfig object match for one PricngLineItem. In the BaseUpChargeConfig object, we are getting all related BaseOptionConfig object and then trying to matche with PricingOptionType object of PricingLineItem. I need to take the best BaseUpChargeConfig object having maximum match with the PricingOptionType object of PricngLineItem.

EDIT

说我有一个带有ackID(前缀值)的PricingLineItem对象。
现在,基于PricingLineItem的前缀值,我有多组BaseUpChargeConfig对象。

Say I have one PricingLineItem object with ackID, prefix value. Now, I have multiple set of BaseUpChargeConfig object based on prefix value of PricingLineItem.

现在ackId值,规则引擎中有一组PricingOptionType对象

Now on ackId value, I have certain set of PricingOptionType object in rule engine.

,而且在baseOptionId值上,我还有多个BaseOptionConfig对象。

and Also on baseOptionId value, I have multiple BaseOptionConfig object.

在PricingOptionType和BaseOptionConfig对象中,我需要比较optioncode和option值。

In PricingOptionType and BaseOptionConfig object, I need to compare the optioncode and option value.

如果两者都匹配,则需要收集所有Perticuler BaseUpChrageConfig的匹配定价选项类型。

If both are matching, I need to collect all matched pricing option type for a perticuler BaseUpChrageConfig.

在同样,这将检查所有其他BaseUpChrageConfig对象BaseOptionConfig是否匹配。

In the same way, this will check for all other BaseUpChrageConfig object BaseOptionConfig and match.

现在匹配度最高的BaseOptionConfig对象;我们将选择BaseUpChargeConfig作为我们的最佳对象。

Now the highest matched BaseOptionConfig object ; we will select that BaseUpChargeConfig as best object for our purpose.

我希望对您来说很清楚。

I hope it would be clear for you.

目前,我正在通过java方法来传递这三个方法并在java中进行计算。

Currently I am doing through java method by passing all three and calculating in java.

public void matchOptions(BaseUpChargeConfig config,ListpriceOptionList,$ price $ ListBaseOptionList){

public void matchOptions(BaseUpChargeConfig config, List pricingOptionList, List baseOptionList) {

if ((pricingOptionList != null && !pricingOptionList.isEmpty())
        && (baseOptionList != null && !baseOptionList.isEmpty())) {

    List<PricingOptionType> matchedOption = null;
    matchedOption = new ArrayList<PricingOptionType>();
    for (PricingOptionType pOption : pricingOptionList) {
        int matchCount = 0;

        for (BaseOptionConfig bConfig : baseOptionList) {
            boolean optioncodeMatch = pOption.getOptionCode() == bConfig.getBaseOptionCode();
            boolean optionValueMatch = pOption.getOptionValue() == bConfig.getBaseOptionValue();
            if (optioncodeMatch && optionValueMatch) {
                matchedOption.add(pOption);
                matchCount++;
            }
        }
        if (matchCount > 0) {
            if (bestBaseUpChargeConfig != null) {
                optionMatchCount = matchCount;
                bestBaseUpChargeConfig = config;
                matchedPrcOptionList = matchedOption;
            } else if (matchCount == optionMatchCount) {
                bestBaseUpChargeConfig = null;
                matchedOption = null;
                matchedPrcOptionList.clear();
            } else if (matchCount > optionMatchCount) {
                optionMatchCount = matchCount;
                bestBaseUpChargeConfig = config;
                matchedPrcOptionList = matchedOption;
            } else {
                // do nothing
            }
        }
    }

} else {
    // do nothing
}

}

谢谢

推荐答案

此版本可使用5.5编译,因此对于6.x也不应该是问题。

This compiles with 5.5, so it shouldn't be a problem with 6.x either.

除非您考虑涉及派生事实的更复杂的评估,否则积累的重复将无济于事。

The duplication of the accumulate can't be helped unless you consider a more complicated evaluation involving derived facts.

rule "find best BaseUpChargeConfig"
when
// pick up some PricingLineItem
$pli: PricingLineItem( $prefix: prefix, $ackId : ackId )
// it should have a BaseUpChargeConfig with a matching prefix
$bucc: BaseUpChargeConfig( prefix == $prefix,
                           $baseOptionId : baseOptionId )
// count BaseOptionConfigs (linked to BaseUpChargeConfig) matching
// PricingOptionTypes, by option id/code and option value
accumulate(
    BaseOptionConfig( id == $baseOptionId,
                      $ocod: bOptionCode, $oval: bOptionValue )
    and          
    PricingOptionType( ackId == $ackId,
                       optionId == $ocod, optionValue == $oval );
      $count: count(1) )

// The $count computed above is the maximum if we don't have another
// BaseUpChargeConfig (for that prefix) where the count of the
// subordinate BaseOptionConfigs is greater than $count
not(
    ( BaseUpChargeConfig( this != $bucc,
                          prefix == $prefix,
                          $baseOptionId2 : baseOptionId )
      and
      accumulate(
          BaseOptionConfig( id == $baseOptionId2,
                            $ocod2: bOptionCode, $oval2: bOptionValue )
          and            
          PricingOptionType( ackId == $ackId,
                             optionId == $ocod2, optionValue == $oval2);
      $count2: count(1);
      $count2 > $count ) ) )
then
    System.out.println( "best BaseUpChargeConfig: " + $baseOptionId );
end

这篇关于如何在流口水中达到以下目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆