Authored by ping

update

1 package com.yoho.queue.dal; 1 package com.yoho.queue.dal;
2 2
  3 +import java.util.List;
  4 +
  5 +import org.apache.ibatis.annotations.Param;
  6 +
3 import com.yoho.queue.dal.model.DrawlinePrizeSetting; 7 import com.yoho.queue.dal.model.DrawlinePrizeSetting;
4 8
5 public interface IDrawlinePrizeSettingDAO { 9 public interface IDrawlinePrizeSettingDAO {
@@ -17,4 +21,6 @@ public interface IDrawlinePrizeSettingDAO { @@ -17,4 +21,6 @@ public interface IDrawlinePrizeSettingDAO {
17 int updateByPrimaryKeySelective(DrawlinePrizeSetting record); 21 int updateByPrimaryKeySelective(DrawlinePrizeSetting record);
18 22
19 int updateByPrimaryKey(DrawlinePrizeSetting record); 23 int updateByPrimaryKey(DrawlinePrizeSetting record);
  24 +
  25 + List<DrawlinePrizeSetting> selectByActivityIds(@Param("activityIds") String activityIds);
20 } 26 }
@@ -36,7 +36,7 @@ public interface IDrawlineUserQueueDAO { @@ -36,7 +36,7 @@ public interface IDrawlineUserQueueDAO {
36 36
37 List<DrawlineUserQueue> selectByRand(@Param("activityId") int activityId, @Param("userType") byte userType, @Param("limit") int limit); 37 List<DrawlineUserQueue> selectByRand(@Param("activityId") int activityId, @Param("userType") byte userType, @Param("limit") int limit);
38 38
39 - List<DrawlineUserQueue> selectByTypeAndActivityIds(@Param("activityIds") String activityIds); 39 + List<DrawlineUserQueue> selectByTypeAndActivityIds(@Param("activityIds") String activityIds, @Param("userType") int userType);
40 40
41 List<Map<String, Object>> selectRealUserCountByActivityIds(@Param("activityIds") String activityIds); 41 List<Map<String, Object>> selectRealUserCountByActivityIds(@Param("activityIds") String activityIds);
42 } 42 }
@@ -165,4 +165,7 @@ @@ -165,4 +165,7 @@
165 update_time = #{updateTime,jdbcType=INTEGER} 165 update_time = #{updateTime,jdbcType=INTEGER}
166 where id = #{id,jdbcType=INTEGER} 166 where id = #{id,jdbcType=INTEGER}
167 </update> 167 </update>
  168 + <select id="selectByActivityIds" resultMap="BaseResultMap">
  169 + select * from drawline_prize_setting where activity_id in(${activityIds})
  170 + </select>
168 </mapper> 171 </mapper>
@@ -197,7 +197,7 @@ @@ -197,7 +197,7 @@
197 </select> 197 </select>
198 198
199 <select id="selectByTypeAndActivityIds" resultMap="BaseResultMap"> 199 <select id="selectByTypeAndActivityIds" resultMap="BaseResultMap">
200 - select * from drawline_user_queue where status=1 and user_type=2 and activity_id in (${activityIds}) 200 + select * from drawline_user_queue where status=1 and user_type=#{userType} and activity_id in (${activityIds})
201 </select> 201 </select>
202 <select id="selectRealUserCountByActivityIds" resultType="java.util.Map"> 202 <select id="selectRealUserCountByActivityIds" resultType="java.util.Map">
203 select activity_id, count(activity_id) nums from drawline_user_queue where status=1 and user_type=1 203 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; @@ -23,9 +23,11 @@ import com.yoho.activity.common.utils.MapUtil;
23 import com.yoho.activity.common.utils.MapUtil.FunctionExPlus; 23 import com.yoho.activity.common.utils.MapUtil.FunctionExPlus;
24 import com.yoho.activity.common.utils.PropertiesUtil; 24 import com.yoho.activity.common.utils.PropertiesUtil;
25 import com.yoho.queue.dal.IDrawlineActivityDAO; 25 import com.yoho.queue.dal.IDrawlineActivityDAO;
  26 +import com.yoho.queue.dal.IDrawlinePrizeSettingDAO;
26 import com.yoho.queue.dal.IDrawlineUserQueueDAO; 27 import com.yoho.queue.dal.IDrawlineUserQueueDAO;
27 import com.yoho.queue.dal.IDrawlineVirtualUserDAO; 28 import com.yoho.queue.dal.IDrawlineVirtualUserDAO;
28 import com.yoho.queue.dal.model.DrawlineActivity; 29 import com.yoho.queue.dal.model.DrawlineActivity;
  30 +import com.yoho.queue.dal.model.DrawlinePrizeSetting;
29 import com.yoho.queue.dal.model.DrawlineUserQueue; 31 import com.yoho.queue.dal.model.DrawlineUserQueue;
30 import com.yoho.queue.dal.model.DrawlineVirtualUser; 32 import com.yoho.queue.dal.model.DrawlineVirtualUser;
31 33
@@ -49,6 +51,8 @@ public class AddVirtualUserTimer { @@ -49,6 +51,8 @@ public class AddVirtualUserTimer {
49 IDrawlineActivityDAO drawlineActivityDAO; 51 IDrawlineActivityDAO drawlineActivityDAO;
50 @Resource 52 @Resource
51 IDrawlineUserQueueDAO drawlineUserQueueDAO; 53 IDrawlineUserQueueDAO drawlineUserQueueDAO;
  54 + @Resource
  55 + IDrawlinePrizeSettingDAO drawlinePrizeSettingDAO;
52 56
53 //各个活动下,待进入排队的马甲 57 //各个活动下,待进入排队的马甲
54 Map<Integer, List<DrawlineVirtualUser>> waitAddUserMap = new HashMap<Integer, List<DrawlineVirtualUser>>(); 58 Map<Integer, List<DrawlineVirtualUser>> waitAddUserMap = new HashMap<Integer, List<DrawlineVirtualUser>>();
@@ -83,7 +87,7 @@ public class AddVirtualUserTimer { @@ -83,7 +87,7 @@ public class AddVirtualUserTimer {
83 activityIdList.add(activity.getId()); 87 activityIdList.add(activity.getId());
84 } 88 }
85 //查询这些活动下,已经进入排队的马甲 89 //查询这些活动下,已经进入排队的马甲
86 - List<DrawlineUserQueue> queueList = drawlineUserQueueDAO.selectByTypeAndActivityIds(StringUtils.join(activityIdList, ",")); 90 + List<DrawlineUserQueue> queueList = drawlineUserQueueDAO.selectByTypeAndActivityIds(StringUtils.join(activityIdList, ","), UserTypeEnum.VIRTUAL_USER.getValue());
87 91
88 //初始化所有的马甲用户 92 //初始化所有的马甲用户
89 List<DrawlineVirtualUser> userList = drawlineVirtualUserDAO.selectWaitQueueVirtualUser(); 93 List<DrawlineVirtualUser> userList = drawlineVirtualUserDAO.selectWaitQueueVirtualUser();
@@ -128,6 +132,10 @@ public class AddVirtualUserTimer { @@ -128,6 +132,10 @@ public class AddVirtualUserTimer {
128 log.info("activityList is empty over"); 132 log.info("activityList is empty over");
129 return; 133 return;
130 } 134 }
  135 +
  136 + //添加白名单
  137 + addWhiteUser();
  138 +
131 //马甲全部排队完了,直接退出 139 //马甲全部排队完了,直接退出
132 if (!checkVirtual()) { 140 if (!checkVirtual()) {
133 log.info("wait virtual is empty over"); 141 log.info("wait virtual is empty over");
@@ -204,6 +212,87 @@ public class AddVirtualUserTimer { @@ -204,6 +212,87 @@ public class AddVirtualUserTimer {
204 } 212 }
205 213
206 /** 214 /**
  215 + * 添加白名单
  216 + */
  217 + private void addWhiteUser() {
  218 + // 查询所有的奖品设置
  219 + List<DrawlinePrizeSetting> prizeList = drawlinePrizeSettingDAO.selectByActivityIds(StringUtils.join(activityIdList, ","));
  220 + if (prizeList == null || prizeList.size() == 0) {
  221 + log.info("addWhiteUser prize is empty");
  222 + return;
  223 + }
  224 +
  225 + // list 转 map
  226 + Map<Integer, String> whileMap = null;
  227 + if (prizeList != null) {
  228 + whileMap = MapUtil.transformListMap(prizeList, new FunctionExPlus<DrawlinePrizeSetting, Integer, String>() {
  229 +
  230 + @Override
  231 + public Integer applyKey(DrawlinePrizeSetting input) {
  232 + return input.getActivityId();
  233 + }
  234 +
  235 + @Override
  236 + public String applyValue(DrawlinePrizeSetting input) {
  237 + return input.getWhiteList();
  238 + }
  239 + });
  240 + }
  241 +
  242 + // 查询所有排队的真实用户
  243 + List<DrawlineUserQueue> queueList = drawlineUserQueueDAO.selectByTypeAndActivityIds(StringUtils.join(activityIdList, ","), UserTypeEnum.REAL_USER.getValue());
  244 +
  245 + String[] whileArr = null;
  246 + String whiteStr = "";
  247 + DrawlineUserQueue queueUser = null;
  248 + for (DrawlineActivity activity : activityList) {
  249 + whiteStr = whileMap.get(activity.getId());
  250 + if (StringUtils.isEmpty(whiteStr)) {
  251 + continue;
  252 + }
  253 + whileArr = whiteStr.split(",");
  254 + for (String white : whileArr) {
  255 + if (whiteIsExists(queueList, activity.getId().intValue(), Integer.parseInt(white))) {
  256 + log.debug("white user={} is queue in activityId={} exit", white, activity.getId());
  257 + continue;
  258 + }
  259 + //该白名单没有排队过,则进入排队
  260 + queueUser = new DrawlineUserQueue();
  261 + queueUser.setActivityId(activity.getId());
  262 + queueUser.setUid(Integer.parseInt(white));
  263 + queueUser.setUserType((byte) UserTypeEnum.REAL_USER.getValue());
  264 + queueUser.setStatus((byte) 1);
  265 + //插入排队表
  266 + drawlineUserQueueDAO.insertAutoSort(queueUser);
  267 + //一次只插入一条白名单
  268 + break;
  269 + }
  270 + }
  271 + }
  272 +
  273 + /**
  274 + * 判断该白名单是否已经排队过
  275 + * @param queueList
  276 + * @param activityId
  277 + * @param whiteUid
  278 + * @return
  279 + */
  280 + private boolean whiteIsExists(List<DrawlineUserQueue> queueList, int activityId, int whiteUid) {
  281 + if (queueList == null || queueList.size() == 0) {
  282 + return false;
  283 + }
  284 + for (DrawlineUserQueue queue : queueList) {
  285 + if (queue.getActivityId() == null || queue.getUid() == null) {
  286 + continue;
  287 + }
  288 + if (queue.getActivityId().intValue() == activityId && queue.getUid().intValue() == whiteUid) {
  289 + return true;
  290 + }
  291 + }
  292 + return false;
  293 + }
  294 +
  295 + /**
207 * 检查是否还有剩余的马甲 296 * 检查是否还有剩余的马甲
208 * @return 297 * @return
209 */ 298 */