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>
2. 抽獎邏輯
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);
}