2015-03-02 16 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