我正在尝试做下面的事情。 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
}
}
感谢
如果没有示例显示各种事实类的对象,这几乎是不可能的。另外,要达到最大值的措施是什么? – laune 2015-03-02 08:37:24
@laune请参阅编辑。 – Kumar 2015-03-02 08:45:42
没有办法,所有人的最大匹配是胜利者。 – Kumar 2015-03-02 08:46:21