public class DefaultAwardCommanderProcedure implements AwardCommanderProcdure { private List<Commander> commanderList; @Override public AwardResult execute(Context context) { if(getCommanderList() == null || getCommanderList().size() == 0) { return AwardResultUtils.buildErrorResult(DefaultResultCode.SYSTEM_ERROR); } for(Commander commander : getCommanderList()) { AwardResult result = commander.execute(context); if(!result.isSuccess()) { AwardLogUtils.getAwardLog().warn("DefaultAwardCommanderProcedure.execute() return false|context=" + context + "|awardResult=[" + result + "]"); return result; } } AwardLogUtils.getAwardLog().warn("DefaultAwardCommanderProcedure.execute() return success|context=[" + context + "]") return AwardResultUtils.buildSuccessResult(); } public List<Commander> getCommanderList() { return commanderList; } public void setCommanderList(List<Commander> commanderList) { this.commanderList = commanderList; }
<!-- 默认抽奖流程 --> <bean id="defaultAwardCommanderProcedure" class="com.taobao.wireless.award.biz.forward.biz.procedure.impl.DefaultAwardCommanderProcedure"> <property name="commanderList"> <list> <ref bean="permissionCommander" /> <!-- 抽奖逻辑 --> <ref bean="winCommander" /> <!-- 中奖逻辑 --> <ref bean="dispatchCommander" /> <!-- 发奖逻辑 --> </list> </property> </bean>
public class DefaultCommander implements Commander { private List<Processor> processorList; @Override public AwardResult execute(Context context) { if(getProcessorList() == null || getProcessorList().size() == 0) { return AwardResultUtils.buildErrorResult(DefaultResultCode.SYSTEM_ERROR); } for(Processor processor : getProcessorList()) { AwardResult result = processor.process(context); if(!result.isSuccess()) { return result; } } return AwardResultUtils.buildSuccessResult(); } public List<Processor> getProcessorList() { return processorList; } public void setProcessorList(List<Processor> processorList) { this.processorList = processorList; } }
<!-- 1、判断抽奖资格 --> <bean id="permissionCommander" class="com.taobao.wireless.award.biz.forward.biz.commander.impl.PermissionCommander"> <property name="processorList"> <list> <ref bean="checkUserGroupProcessor" /> <!-- 判断人群 --> <ref bean="awardCountingProcessor" /> <!-- 活动抽奖数计数 --> <ref bean="checkAndReducePermitPermissionProcessor" /> <!-- 判断是否有抽奖权限,有则减权限 --> <ref bean="checkBlacklistPermissionProcessor" /> <!-- 黑名单 --> <ref bean="checkWinCountPermissionProcessor" /> <!-- 判断中奖次数限制(如最多只能中3次) --> </list> </property> </bean>
public interface Processor { /** * 处理逻辑 * @param context * @return */ AwardResult process(Context context); }
原文:http://blog.csdn.net/itomge/article/details/20792567