如何在流口水中达到以下目标

时间:2015-03-02 08:28:23

标签: java drools

我正在努力做下面的事情。 Plesse检查。

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对象。

修改

假设我有一个带有ackID,前缀值的PricingLineItem对象。 现在,我有一组基于PricingLineItem的前缀值的BaseUpChargeConfig对象。

现在在ackId值上,我在规则引擎中有一定数量的PricingOptionType对象。

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

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

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

以同样的方式,这将检查所有其他BaseUpChrageConfig对象BaseOptionConfig并匹配。

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

我希望你能清楚。

目前我通过传递所有三个并在java中计算来完成java方法。

public void matchOptions(BaseUpChargeConfig config,List pricingOptionList,         列出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
}

}

由于

1 个答案:

答案 0 :(得分:1)

这可以用5.5编译,所以它也不应该是6.x的问题。

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

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