規則引擎-地區規則

主程式 年齡規則 性別規則 地區規則 例外城市規則 綜診規則

package com.emprogria; import java.util.Properties; import org.easyrules.annotation.Action; import org.easyrules.annotation.Condition; import org.easyrules.annotation.Priority; import org.easyrules.annotation.Rule; import org.easyrules.core.AnnotatedRulesEngine; @Rule(name = "Region Rule", description = "Products Recommendation by Region") public class RegionRule { private Properties actionResult = null; private int region = 0, city=0; public RegionRule(Properties actionResult, int region, int city) { super(); this.actionResult = actionResult; this.region = region; this.city = city; } @Condition public boolean doCheck() { boolean OK = false; if (this.region == 2) { // East OK = true; } else { AnnotatedRulesEngine rulesEngine = new AnnotatedRulesEngine(); CityRule cityRule = new CityRule(this.actionResult, this.city); rulesEngine.registerRule(cityRule); rulesEngine.fireRules(); } return (OK); } @Action public void doTask() throws Exception { synchronized (this.actionResult) { this.actionResult.put("RegionRule", "1"); } } @Priority public int getPriority() { return 1; } public int getRegion() { return this.region; } public void setRegion(int region) { this.region = region; } public int getCity() { return city; } public void setCity(int city) { this.city = city; } }