規則引擎-例外城市規則 (第二階規則)

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

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; @Rule(name = "City Rule", description = "Products Recommendation by City") public class CityRule { private Properties actionResult = null; private int city = 0; public CityRule(Properties actionResult, int city) { super(); this.actionResult = actionResult; this.city = city; } @Condition public boolean doCheck() { boolean OK = false; switch (this.city) { case 0: // All break; case 1: // Taipei break; case 2: // Taoyuan OK = true; break; case 3: // Taichung break; case 4: // Tainan break; case 5: // Kaohsiung OK = true; break; case 6: // Hualian break; case 7: // Taidung break; } return (OK); } @Action public void doTask() throws Exception { synchronized (this.actionResult) { this.actionResult.put("CityRule", "2"); } } @Priority public int getPriority() { return 2; } public int getCity() { return this.city; } public void setCity(int city) { this.city = city; } }