Authored by ping

自动添加马甲修改

... ... @@ -4,9 +4,11 @@
package com.yoho.activity.other.timer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Resource;
... ... @@ -68,7 +70,7 @@ public class AddVirtualUserTimer {
waitAddUserMap = new HashMap<Integer, List<DrawlineVirtualUser>>();
activityList = new ArrayList<DrawlineActivity>();
activityIdList = new ArrayList<Integer>();
first = new HashMap<Integer, Boolean>();
//first = new HashMap<Integer, Boolean>();
//初始化所有活动
activityList = drawlineActivityDAO.selectAllActivity();
... ... @@ -86,6 +88,11 @@ public class AddVirtualUserTimer {
//初始化所有的马甲用户
List<DrawlineVirtualUser> userList = drawlineVirtualUserDAO.selectWaitQueueVirtualUser();
if (userList != null) {
//打乱马甲顺序
Collections.shuffle(userList);
}
List<DrawlineVirtualUser> waitList = null;
for (DrawlineActivity activity : activityList) {
for (DrawlineVirtualUser user : userList) {
... ... @@ -121,13 +128,16 @@ public class AddVirtualUserTimer {
log.info("activityList is empty over");
return;
}
//马甲全部排队完了,直接退出
if (!checkVirtual()) {
log.info("wait virtual is empty over");
return;
}
//查询所有的活动,前一分钟内实际增加的真实用户数
List<Map<String, Object>> realUserCountList = drawlineUserQueueDAO.selectRealUserCountByActivityIds(StringUtils.join(activityIdList, ","));
//前一分钟没有真实用户参加
if (realUserCountList == null || realUserCountList.size() == 0) {
log.info("realUser add is empty");
return;
if (realUserCountList == null) {
realUserCountList = new ArrayList<Map<String,Object>>();
}
//list转map
Map<Integer, Integer> realUserCountMap = null;
... ... @@ -145,6 +155,9 @@ public class AddVirtualUserTimer {
}
});
}
if (realUserCountMap == null) {
realUserCountMap = new HashMap<Integer, Integer>();
}
//活动下,等待排队的马甲
List<DrawlineVirtualUser> waitList = null;
... ... @@ -153,10 +166,10 @@ public class AddVirtualUserTimer {
DrawlineUserQueue queueUser = null;
for (DrawlineActivity activity : activityList) {
n = 0;
if (realUserCountMap.get(activity.getId()) == null || realUserCountMap.get(activity.getId()) == 0) {
//该活动还没有一个用户参加,则不增加马甲
continue;
}
// if (realUserCountMap.get(activity.getId()) == null || realUserCountMap.get(activity.getId()) == 0) {
// //该活动还没有一个用户参加,则不增加马甲
// continue;
// }
waitList = waitAddUserMap.get(activity.getId());
if (waitList == null || waitList.size() == 0) {
log.info("wait queue user is empty with activityId is {}, activityName is {}", activity.getId(), activity.getActivityName());
... ... @@ -191,6 +204,24 @@ public class AddVirtualUserTimer {
}
/**
* 检查是否还有剩余的马甲
* @return
*/
private boolean checkVirtual() {
if (waitAddUserMap == null || waitAddUserMap.size() == 0) {
return false;
}
List<DrawlineVirtualUser> l = null;
for (Entry<Integer, List<DrawlineVirtualUser>> entry : waitAddUserMap.entrySet()) {
l = entry.getValue();
if (l != null && l.size() > 0) {
return true;
}
}
return false;
}
/**
* 查询该活动下,这个马甲有没有排队过
* @param activityId
* @param uid
... ...