2015-03-02 18 views
-1

我正在尝试做下面的事情。 Plesse检查。如何在drools中实现以下目标

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 

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

编辑

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

现在在ackId值上,我在规则引擎中有一些PricingOptionType对象。

还有关于baseOptionId值,我有多个BaseOptionConfig对象。

在PricingOptionType和BaseOptionConfig对象中,我需要比较选项代码和选项值。

如果两者都匹配,我需要收集所有匹配的定价选项类型,以便执行一个相关的BaseUpChrageConfig。

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

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

我希望这对你很清楚。

目前我通过java方法通过传递所有三个和计算在java中。

公共无效matchOptions(BaseUpChargeConfig配置,列表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 
} 

}

感谢

+0

如果没有示例显示各种事实类的对象,这几乎是不可能的。另外,要达到最大值的措施是什么? – laune 2015-03-02 08:37:24

+0

@laune请参阅编辑。 – Kumar 2015-03-02 08:45:42

+0

没有办法,所有人的最大匹配是胜利者。 – Kumar 2015-03-02 08:46:21

回答

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 
+0

感谢您的宝贵努力。然而,它只是通过我的头。 :)请你详细说明一下;只是一些不足点而已。非常感谢。 – Kumar 2015-03-02 10:30:10

+0

@Kumar增加了一些评论,HTH。 – laune 2015-03-02 11:16:22