...
|
...
|
@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.yoho.activity.common.cache.RedisCache;
|
|
|
import com.yoho.activity.common.redis.CacheKeyEnum;
|
|
|
import com.yoho.activity.common.redis.RedisListCache;
|
|
|
import com.yoho.activity.queue.convert.DrawlineUserQueueConvert;
|
|
|
import com.yoho.activity.queue.service.IDrawlineList2MapService;
|
|
|
import com.yoho.activity.queue.service.IDrawlineUserQueueService;
|
...
|
...
|
@@ -38,6 +40,8 @@ public class DrawlineUserQueueServiceImpl implements IDrawlineUserQueueService { |
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
@Autowired
|
|
|
private RedisListCache redisListCache;
|
|
|
|
|
|
public int addDrawlineUserQueue(DrawlineUserQueueReqBO drawlineUserQueueReqBO) throws ServiceException {
|
|
|
logger.info("Enter addDrawlineUserQueue. param drawlineUserQueueReqBO is {}", drawlineUserQueueReqBO);
|
...
|
...
|
@@ -91,102 +95,10 @@ public class DrawlineUserQueueServiceImpl implements IDrawlineUserQueueService { |
|
|
throw new ServiceException(900001007, "参加活动排队失败");
|
|
|
}
|
|
|
|
|
|
// // (6)查询排队序号
|
|
|
// drawlineUserQueue =
|
|
|
// drawlineUserQueueDAO.selectByUidAndActivityIdAndUserType(uid,
|
|
|
// activityId, userType);
|
|
|
// logger.debug("addDrawlineUserQueue: drawlineUserQueueDAO.selectByUidAndActivityIdAndUserType. uid is {}, activityId is {}, userType is {}, drawlineUserQueue is {}",
|
|
|
// uid, activityId, userType,
|
|
|
// drawlineUserQueue);
|
|
|
//
|
|
|
// // (7)返回
|
|
|
// int sort = null == drawlineUserQueue.getSort() ? 0 :
|
|
|
// drawlineUserQueue.getSort().intValue();
|
|
|
logger.info("addDrawlineUserQueue: return. drawlineUserQueueReqBO is {}, sort is {}", drawlineUserQueueReqBO, sort);
|
|
|
return sort;
|
|
|
}
|
|
|
|
|
|
// public int addDrawlineUserQueue(DrawlineUserQueueReqBO
|
|
|
// drawlineUserQueueReqBO) throws ServiceException {
|
|
|
// logger.info("Enter addDrawlineUserQueue. param drawlineUserQueueReqBO is {}",
|
|
|
// drawlineUserQueueReqBO);
|
|
|
//
|
|
|
// // (1)获取参数
|
|
|
// int uid = 0, activityId = 0;
|
|
|
// byte userType = 1;
|
|
|
// if (null != drawlineUserQueueReqBO) {
|
|
|
// uid = null == drawlineUserQueueReqBO.getUid() ? 0 :
|
|
|
// drawlineUserQueueReqBO.getUid().intValue();
|
|
|
// activityId = null == drawlineUserQueueReqBO.getActivityId() ? 0 :
|
|
|
// drawlineUserQueueReqBO.getActivityId().intValue();
|
|
|
// userType = null == drawlineUserQueueReqBO.getUserType() ? 1 :
|
|
|
// drawlineUserQueueReqBO.getUserType().byteValue();
|
|
|
// }
|
|
|
//
|
|
|
// // (2)校验
|
|
|
// validAddDrawlineUserQueue(uid, activityId);
|
|
|
//
|
|
|
// // (3)判断活动是否存在,是否过期
|
|
|
// DrawlineActivity drawlineActivity =
|
|
|
// drawlineActivityDAO.selectByPrimaryKey(activityId);
|
|
|
// if (null == drawlineActivity) {
|
|
|
// logger.warn("addDrawlineUserQueue: drawlineActivity is not exists");
|
|
|
// throw new ServiceException(900001003, "活动已不存在");
|
|
|
// }
|
|
|
// int beginTime = null == drawlineActivity.getBeginTime() ? 0 :
|
|
|
// drawlineActivity.getBeginTime().intValue();
|
|
|
// int endTime = null == drawlineActivity.getEndTime() ? 0 :
|
|
|
// drawlineActivity.getEndTime().intValue();
|
|
|
// int currentTime = (int) (System.currentTimeMillis() / 1000);
|
|
|
// if (0 < beginTime && currentTime < beginTime) {
|
|
|
// logger.warn("addDrawlineUserQueue: drawlineActivity is not begin");
|
|
|
// throw new ServiceException(900001004, "活动尚未开始");
|
|
|
// }
|
|
|
// if (0 < endTime && currentTime > endTime) {
|
|
|
// logger.warn("addDrawlineUserQueue: drawlineActivity is already end");
|
|
|
// throw new ServiceException(900001005, "活动已结束");
|
|
|
// }
|
|
|
//
|
|
|
// // (4)判断是否已经参加排队
|
|
|
// DrawlineUserQueue drawlineUserQueue =
|
|
|
// drawlineUserQueueDAO.selectByUidAndActivityIdAndUserType(uid, activityId,
|
|
|
// userType);
|
|
|
// logger.debug("addDrawlineUserQueue: drawlineUserQueueDAO.selectByUidAndActivityIdAndUserType. uid is {}, activityId is {}, userType is {}, drawlineUserQueue is {}",
|
|
|
// uid, activityId, userType,
|
|
|
// drawlineUserQueue);
|
|
|
// if (null != drawlineUserQueue) {
|
|
|
// logger.warn("addDrawlineUserQueue: drawlineUserQueue is exists already");
|
|
|
// throw new ServiceException(900001006, "您已经参加过排队,无需再次排队");
|
|
|
// }
|
|
|
//
|
|
|
// // (5)组装数据,新增排队
|
|
|
// drawlineUserQueue = DrawlineUserQueueConvert.toDOBy(uid, activityId,
|
|
|
// userType);
|
|
|
// int rows = drawlineUserQueueDAO.insertAutoSort(drawlineUserQueue);
|
|
|
// logger.debug("addDrawlineUserQueue: drawlineUserQueueDAO.insertAutoSort. drawlineUserQueue is {}, rows is {}",
|
|
|
// drawlineUserQueue, rows);
|
|
|
// if (1 > rows) {
|
|
|
// logger.warn("addDrawlineUserQueue: fail to addDrawlineUserQueue. uid is {}, activityId is {}, userType is {}",
|
|
|
// uid, activityId, userType);
|
|
|
// throw new ServiceException(900001007, "参加活动排队失败");
|
|
|
// }
|
|
|
//
|
|
|
// // (6)查询排队序号
|
|
|
// drawlineUserQueue =
|
|
|
// drawlineUserQueueDAO.selectByUidAndActivityIdAndUserType(uid, activityId,
|
|
|
// userType);
|
|
|
// logger.debug("addDrawlineUserQueue: drawlineUserQueueDAO.selectByUidAndActivityIdAndUserType. uid is {}, activityId is {}, userType is {}, drawlineUserQueue is {}",
|
|
|
// uid, activityId, userType,
|
|
|
// drawlineUserQueue);
|
|
|
//
|
|
|
// // (7)返回
|
|
|
// int sort = null == drawlineUserQueue.getSort() ? 0 :
|
|
|
// drawlineUserQueue.getSort().intValue();
|
|
|
// logger.info("addDrawlineUserQueue: return. drawlineUserQueueReqBO is {}, sort is {}",
|
|
|
// drawlineUserQueueReqBO, sort);
|
|
|
// return sort;
|
|
|
// }
|
|
|
|
|
|
public List<DrawlineUserQueueRespBO> getDrawlineUserQueueList(DrawlineUserQueueReqBO drawlineUserQueueReqBO) throws ServiceException {
|
|
|
logger.info("Enter getDrawlineUserQueueList. param drawlineUserQueueReqBO is {}", drawlineUserQueueReqBO);
|
|
|
|
...
|
...
|
@@ -195,7 +107,7 @@ public class DrawlineUserQueueServiceImpl implements IDrawlineUserQueueService { |
|
|
if (null != drawlineUserQueueReqBO) {
|
|
|
activityId = null == drawlineUserQueueReqBO.getActivityId() ? 0 : drawlineUserQueueReqBO.getActivityId().intValue();
|
|
|
sort = null == drawlineUserQueueReqBO.getSort() ? 0 : drawlineUserQueueReqBO.getSort().intValue();
|
|
|
limit = drawlineUserQueueReqBO.getLimit();
|
|
|
limit = 1 > drawlineUserQueueReqBO.getLimit() ? 10 : drawlineUserQueueReqBO.getLimit();
|
|
|
}
|
|
|
|
|
|
// (2)校验
|
...
|
...
|
@@ -216,14 +128,22 @@ public class DrawlineUserQueueServiceImpl implements IDrawlineUserQueueService { |
|
|
return new ArrayList<DrawlineUserQueueRespBO>();
|
|
|
}
|
|
|
|
|
|
// (4)查询条件下,总记录数
|
|
|
int total = drawlineUserQueueDAO.selectCountBy(activityId, sort);
|
|
|
logger.debug("getDrawlineUserQueueList: drawlineUserQueueDAO.selectCountBy. activityId is {}, sort is {}, total is {}", activityId, sort, total);
|
|
|
// (4)重新计算sort,以补齐客户端记录数
|
|
|
if (0 < sort && sort < limit) {
|
|
|
sort = limit;
|
|
|
}
|
|
|
|
|
|
// (5)查询排队信息,如果条件记录总数小于分页数需补齐记录
|
|
|
if (0 < sort && total < limit) {
|
|
|
sort += limit - total;
|
|
|
// (5)redis 获取数据
|
|
|
if (0 < sort) { // sort为0时表示查询最新数据,不从redis中获取数据
|
|
|
String redisKeySuffix = activityId + ":" + sort + ":" + limit;
|
|
|
List<DrawlineUserQueueRespBO> drawlineUserQueueRespBOList = redisListCache.range(CacheKeyEnum.DRAWLINE_LIST, redisKeySuffix, DrawlineUserQueueRespBO.class, 0, -1);
|
|
|
if (null != drawlineUserQueueRespBOList) {
|
|
|
logger.info("getDrawlineUserQueueList: get result from redis. first result is {}", drawlineUserQueueRespBOList.get(0));
|
|
|
return drawlineUserQueueRespBOList;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// (6) 查询排队列表
|
|
|
List<DrawlineUserQueue> drawlineUserQueueList = drawlineUserQueueDAO.selectBy(activityId, sort, limit);
|
|
|
logger.debug("getDrawlineUserQueueList: drawlineUserQueueDAO.selectBy. activityId is {}, sort is {}, limit is {}, drawlineUserQueueList is {}", activityId, sort, limit, drawlineUserQueueList);
|
|
|
if (null == drawlineUserQueueList || 0 == drawlineUserQueueList.size()) {
|
...
|
...
|
@@ -231,23 +151,38 @@ public class DrawlineUserQueueServiceImpl implements IDrawlineUserQueueService { |
|
|
throw new ServiceException(900001008, "无人参与活动排队");
|
|
|
}
|
|
|
|
|
|
// (6)组装uids
|
|
|
// (7)组装uids
|
|
|
List<Integer> uidList = getUidList(drawlineUserQueueList);
|
|
|
|
|
|
// (7)调用查询用户信息服务
|
|
|
// (8)调用查询用户信息服务
|
|
|
AsyncFuture<UserBaseRspBO[]> userBaseRspBOArrAsync = drawlineList2MapService.postForUserBaseInfo(uidList);
|
|
|
|
|
|
// (8)查询用户中奖信息
|
|
|
// (9)查询用户中奖信息
|
|
|
Map<String, DrawlineLuckyUser> drawlineLuckyUserMap = drawlineList2MapService.getDrawlineLuckyUserMap(activityId, uidList);
|
|
|
|
|
|
// (9)查询马甲信息
|
|
|
// (10)查询马甲信息
|
|
|
Map<Integer, DrawlineVirtualUser> drawlineVirtualUserMap = drawlineList2MapService.getDrawlineVirtualUserMap(uidList);
|
|
|
|
|
|
// (10)获取用户信息
|
|
|
// (11)获取用户信息
|
|
|
Map<Integer, UserBaseRspBO> userBaseRspBOMap = drawlineList2MapService.getUserBaseRspBOMap(userBaseRspBOArrAsync);
|
|
|
|
|
|
// (11)组装返回
|
|
|
// (12)组装返回
|
|
|
List<DrawlineUserQueueRespBO> drawlineUserQueueRespBOList = DrawlineUserQueueConvert.toBOListByDOList(drawlineUserQueueList, drawlineLuckyUserMap, userBaseRspBOMap, drawlineVirtualUserMap);
|
|
|
|
|
|
// (13)数据保存至redis
|
|
|
for (DrawlineUserQueueRespBO drawlineUserQueueRespBO : drawlineUserQueueRespBOList) {
|
|
|
if (null == drawlineUserQueueRespBO || null == drawlineUserQueueRespBO.getSort()) {
|
|
|
continue;
|
|
|
}
|
|
|
sort = drawlineUserQueueRespBO.getSort().intValue();
|
|
|
break;
|
|
|
}
|
|
|
String redisKeySuffix = activityId + ":" + sort + ":" + limit;
|
|
|
if (redisListCache.hasKey(CacheKeyEnum.DRAWLINE_LIST, redisKeySuffix)) {
|
|
|
return drawlineUserQueueRespBOList;
|
|
|
}
|
|
|
redisListCache.rightPushAll(CacheKeyEnum.DRAWLINE_LIST, redisKeySuffix, drawlineUserQueueRespBOList);
|
|
|
|
|
|
return drawlineUserQueueRespBOList;
|
|
|
}
|
|
|
|
...
|
...
|
|