Authored by bblu

Merge branch 'test' of http://git.dev.yoho.cn/yoho30/yohobuy-activity into test

package com.yoho.queue.dal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.queue.dal.model.DrawlinePrizeSetting;
public interface IDrawlinePrizeSettingDAO {
... ... @@ -17,4 +21,6 @@ public interface IDrawlinePrizeSettingDAO {
int updateByPrimaryKeySelective(DrawlinePrizeSetting record);
int updateByPrimaryKey(DrawlinePrizeSetting record);
List<DrawlinePrizeSetting> selectByActivityIds(@Param("activityIds") String activityIds);
}
\ No newline at end of file
... ...
... ... @@ -36,7 +36,7 @@ public interface IDrawlineUserQueueDAO {
List<DrawlineUserQueue> selectByRand(@Param("activityId") int activityId, @Param("userType") byte userType, @Param("limit") int limit);
List<DrawlineUserQueue> selectByTypeAndActivityIds(@Param("activityIds") String activityIds);
List<DrawlineUserQueue> selectByTypeAndActivityIds(@Param("activityIds") String activityIds, @Param("userType") int userType);
List<Map<String, Object>> selectRealUserCountByActivityIds(@Param("activityIds") String activityIds);
}
\ No newline at end of file
... ...
... ... @@ -165,4 +165,7 @@
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByActivityIds" resultMap="BaseResultMap">
select * from drawline_prize_setting where activity_id in(${activityIds})
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -197,7 +197,7 @@
</select>
<select id="selectByTypeAndActivityIds" resultMap="BaseResultMap">
select * from drawline_user_queue where status=1 and user_type=2 and activity_id in (${activityIds})
select * from drawline_user_queue where status=1 and user_type=#{userType} and activity_id in (${activityIds})
</select>
<select id="selectRealUserCountByActivityIds" resultType="java.util.Map">
select activity_id, count(activity_id) nums from drawline_user_queue where status=1 and user_type=1
... ...
... ... @@ -23,9 +23,11 @@ import com.yoho.activity.common.utils.MapUtil;
import com.yoho.activity.common.utils.MapUtil.FunctionExPlus;
import com.yoho.activity.common.utils.PropertiesUtil;
import com.yoho.queue.dal.IDrawlineActivityDAO;
import com.yoho.queue.dal.IDrawlinePrizeSettingDAO;
import com.yoho.queue.dal.IDrawlineUserQueueDAO;
import com.yoho.queue.dal.IDrawlineVirtualUserDAO;
import com.yoho.queue.dal.model.DrawlineActivity;
import com.yoho.queue.dal.model.DrawlinePrizeSetting;
import com.yoho.queue.dal.model.DrawlineUserQueue;
import com.yoho.queue.dal.model.DrawlineVirtualUser;
... ... @@ -49,6 +51,8 @@ public class AddVirtualUserTimer {
IDrawlineActivityDAO drawlineActivityDAO;
@Resource
IDrawlineUserQueueDAO drawlineUserQueueDAO;
@Resource
IDrawlinePrizeSettingDAO drawlinePrizeSettingDAO;
//各个活动下,待进入排队的马甲
Map<Integer, List<DrawlineVirtualUser>> waitAddUserMap = new HashMap<Integer, List<DrawlineVirtualUser>>();
... ... @@ -83,7 +87,7 @@ public class AddVirtualUserTimer {
activityIdList.add(activity.getId());
}
//查询这些活动下,已经进入排队的马甲
List<DrawlineUserQueue> queueList = drawlineUserQueueDAO.selectByTypeAndActivityIds(StringUtils.join(activityIdList, ","));
List<DrawlineUserQueue> queueList = drawlineUserQueueDAO.selectByTypeAndActivityIds(StringUtils.join(activityIdList, ","), UserTypeEnum.VIRTUAL_USER.getValue());
//初始化所有的马甲用户
List<DrawlineVirtualUser> userList = drawlineVirtualUserDAO.selectWaitQueueVirtualUser();
... ... @@ -128,6 +132,10 @@ public class AddVirtualUserTimer {
log.info("activityList is empty over");
return;
}
//添加白名单
addWhiteUser();
//马甲全部排队完了,直接退出
if (!checkVirtual()) {
log.info("wait virtual is empty over");
... ... @@ -207,6 +215,87 @@ public class AddVirtualUserTimer {
}
/**
* 添加白名单
*/
private void addWhiteUser() {
// 查询所有的奖品设置
List<DrawlinePrizeSetting> prizeList = drawlinePrizeSettingDAO.selectByActivityIds(StringUtils.join(activityIdList, ","));
if (prizeList == null || prizeList.size() == 0) {
log.info("addWhiteUser prize is empty");
return;
}
// list 转 map
Map<Integer, String> whileMap = null;
if (prizeList != null) {
whileMap = MapUtil.transformListMap(prizeList, new FunctionExPlus<DrawlinePrizeSetting, Integer, String>() {
@Override
public Integer applyKey(DrawlinePrizeSetting input) {
return input.getActivityId();
}
@Override
public String applyValue(DrawlinePrizeSetting input) {
return input.getWhiteList();
}
});
}
// 查询所有排队的真实用户
List<DrawlineUserQueue> queueList = drawlineUserQueueDAO.selectByTypeAndActivityIds(StringUtils.join(activityIdList, ","), UserTypeEnum.REAL_USER.getValue());
String[] whileArr = null;
String whiteStr = "";
DrawlineUserQueue queueUser = null;
for (DrawlineActivity activity : activityList) {
whiteStr = whileMap.get(activity.getId());
if (StringUtils.isEmpty(whiteStr)) {
continue;
}
whileArr = whiteStr.split(",");
for (String white : whileArr) {
if (whiteIsExists(queueList, activity.getId().intValue(), Integer.parseInt(white))) {
log.debug("white user={} is queue in activityId={} exit", white, activity.getId());
continue;
}
//该白名单没有排队过,则进入排队
queueUser = new DrawlineUserQueue();
queueUser.setActivityId(activity.getId());
queueUser.setUid(Integer.parseInt(white));
queueUser.setUserType((byte) UserTypeEnum.REAL_USER.getValue());
queueUser.setStatus((byte) 1);
//插入排队表
drawlineUserQueueDAO.insertAutoSort(queueUser);
//一次只插入一条白名单
break;
}
}
}
/**
* 判断该白名单是否已经排队过
* @param queueList
* @param activityId
* @param whiteUid
* @return
*/
private boolean whiteIsExists(List<DrawlineUserQueue> queueList, int activityId, int whiteUid) {
if (queueList == null || queueList.size() == 0) {
return false;
}
for (DrawlineUserQueue queue : queueList) {
if (queue.getActivityId() == null || queue.getUid() == null) {
continue;
}
if (queue.getActivityId().intValue() == activityId && queue.getUid().intValue() == whiteUid) {
return true;
}
}
return false;
}
/**
* 检查是否还有剩余的马甲
* @return
*/
... ...