...
|
...
|
@@ -9,6 +9,9 @@ import javax.annotation.Resource; |
|
|
|
|
|
import com.netflix.config.DynamicLongProperty;
|
|
|
import com.netflix.config.DynamicPropertyFactory;
|
|
|
import com.yoho.activity.dal.ProductLimitUserHelpMapper;
|
|
|
import com.yoho.service.model.activity.drawline.response.LimitProductHelpUserRespBO;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -57,7 +60,8 @@ public class DrawlineUserQueueServiceImpl implements IDrawlineUserQueueService { |
|
|
private RedisCache redisCache;
|
|
|
@Autowired
|
|
|
private RedisValueCache redisValueCache;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductLimitUserHelpMapper productLimitUserHelpMapper;
|
|
|
@Resource
|
|
|
ServiceCaller serviceCaller;
|
|
|
|
...
|
...
|
@@ -243,10 +247,11 @@ public class DrawlineUserQueueServiceImpl implements IDrawlineUserQueueService { |
|
|
|
|
|
// (11)获取用户信息, 将用户的基础信息转换成MAP,
|
|
|
Map<Integer, UserBaseRspBO> userBaseRspBOMap = drawlineList2MapService.getUserBaseRspBOMap(userBaseRspBOArrAsync);
|
|
|
|
|
|
// (12)将查询排队列表用户的中奖信息, 基础信息,
|
|
|
List<DrawlineUserQueueRespBO> drawlineUserQueueRespBOList = DrawlineUserQueueConvert.toBOListByDOList(drawlineUserQueueList, drawlineLuckyUserMap, userBaseRspBOMap, drawlineVirtualUserMap);
|
|
|
|
|
|
// **补充助力排队用户信息 begin **
|
|
|
getHelpInfo(activityId, uidList, drawlineUserQueueRespBOList);
|
|
|
// **补充助力排队用户信息 end **
|
|
|
// (13)将查询的结果放入REDIS, yh:activity:活动ID:排队号:页数, 并且将查询的结果放入REDIS中
|
|
|
String value = JSONArray.toJSONString(drawlineUserQueueRespBOList);
|
|
|
DynamicLongProperty expire = DynamicPropertyFactory.getInstance().getLongProperty(CacheKeyEnum.DRAWLINE_QUEUELIST.getExpireKey(), 10);
|
...
|
...
|
@@ -255,6 +260,119 @@ public class DrawlineUserQueueServiceImpl implements IDrawlineUserQueueService { |
|
|
return drawlineUserQueueRespBOList.toArray(new DrawlineUserQueueRespBO[drawlineUserQueueRespBOList.size()]);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public DrawlineUserQueueRespBO[] getMyDrawlineUserQueueList(DrawlineUserQueueReqBO drawlineUserQueueReqBO) {
|
|
|
logger.info("Enter getMyDrawlineUserQueueList. param drawlineUserQueueReqBO is {}", drawlineUserQueueReqBO);
|
|
|
|
|
|
// (1)获取参数
|
|
|
int activityId = 0, sort = 0, limit = 10, uid = 0;
|
|
|
if (null != drawlineUserQueueReqBO) {
|
|
|
activityId = null == drawlineUserQueueReqBO.getActivityId() ? 0 : drawlineUserQueueReqBO.getActivityId().intValue();
|
|
|
sort = null == drawlineUserQueueReqBO.getSort() ? 0 : drawlineUserQueueReqBO.getSort().intValue();
|
|
|
limit = 1 > drawlineUserQueueReqBO.getLimit() ? 10 : drawlineUserQueueReqBO.getLimit();
|
|
|
uid = null == drawlineUserQueueReqBO.getUid() ? 0 : drawlineUserQueueReqBO.getUid();
|
|
|
}
|
|
|
|
|
|
// (2)校验
|
|
|
if (1 > activityId) {
|
|
|
logger.warn("getMyDrawlineUserQueueList: param activityId is null.");
|
|
|
throw new ServiceException(900001002, "请传参activityId");
|
|
|
}
|
|
|
// (2)校验
|
|
|
if (1 > uid) {
|
|
|
logger.warn("getMyDrawlineUserQueueList: param uid is null.");
|
|
|
throw new ServiceException(900001002, "请传参uid");
|
|
|
}
|
|
|
|
|
|
// (3)redis 取活动信息,如果不命中,从数据库中获取并保存至redis中
|
|
|
DrawlineActivity drawlineActivity = redisValueCache.get(CacheKeyEnum.DRAWLINE_ACTIVITY, activityId, DrawlineActivity.class);
|
|
|
|
|
|
if (null == drawlineActivity) {
|
|
|
drawlineActivity = drawlineActivityDAO.selectByPrimaryKey(activityId);
|
|
|
}
|
|
|
|
|
|
// (4)校验活动相关信息
|
|
|
if (null == drawlineActivity) {
|
|
|
logger.warn("getMyDrawlineUserQueueList: drawlineActivity is not exists");
|
|
|
throw new ServiceException(900001003, "活动已不存在");
|
|
|
}
|
|
|
int beginTime = null == drawlineActivity.getBeginTime() ? 0 : drawlineActivity.getBeginTime().intValue();
|
|
|
int currentTime = (int) (System.currentTimeMillis() / 1000);
|
|
|
if (0 < beginTime && currentTime < beginTime) {
|
|
|
return new DrawlineUserQueueRespBO[0];
|
|
|
}
|
|
|
|
|
|
// (5)保存活动信息至redis,并重新计算sort,以补齐客户端记录数
|
|
|
redisValueCache.setIfAbsent(CacheKeyEnum.DRAWLINE_ACTIVITY, activityId, drawlineActivity, TimeUnit.MINUTES);
|
|
|
if (0 < sort && sort < limit) {
|
|
|
sort = limit;
|
|
|
}
|
|
|
|
|
|
// (6)redis 获取排队数据
|
|
|
String redisKeySuffix = activityId + ":" + sort + ":" + limit;
|
|
|
DrawlineUserQueueRespBO[] arawlineUserQueueRespBOArr = redisValueCache.get(CacheKeyEnum.MY_DRAWLINE_QUEUELIST, redisKeySuffix, DrawlineUserQueueRespBO[].class);
|
|
|
if (null != arawlineUserQueueRespBOArr) {
|
|
|
logger.debug("getMyDrawlineUserQueueList: get result from redis. first result is {}", arawlineUserQueueRespBOArr[0]);
|
|
|
return arawlineUserQueueRespBOArr;
|
|
|
}
|
|
|
// (6) 查询排队列表
|
|
|
List<DrawlineUserQueue> drawlineUserQueueList = drawlineUserQueueDAO.selectMyQueueList(activityId, sort, limit,uid);
|
|
|
logger.debug("getMyDrawlineUserQueueList: drawlineUserQueueDAO.selectBy. activityId is {}, sort is {}, limit is {}, uid is{}, drawlineUserQueueList is {}", activityId, sort, limit,uid, drawlineUserQueueList);
|
|
|
if (null == drawlineUserQueueList || 0 == drawlineUserQueueList.size()) {
|
|
|
logger.warn("getMyDrawlineUserQueueList: drawlineUserQueueList is null.");
|
|
|
throw new ServiceException(900001008, "无人参与活动排队");
|
|
|
}
|
|
|
// (7)组装uids
|
|
|
List<Integer> uidList = getUidList(drawlineUserQueueList);
|
|
|
|
|
|
// (8)调用查询用户信息服务, 异步发送请求,在第11步取出数据
|
|
|
AsyncFuture<UserBaseRspBO[]> userBaseRspBOArrAsync = drawlineList2MapService.postForUserBaseInfo(uidList);
|
|
|
|
|
|
// (9)批量查询用户的中奖信息,并将用户的中奖信息转成MAP
|
|
|
Map<String, DrawlineLuckyUser> drawlineLuckyUserMap = drawlineList2MapService.getDrawlineLuckyUserMap(activityId, uidList);
|
|
|
// (10)查询马甲信息
|
|
|
Map<Integer, DrawlineVirtualUser> drawlineVirtualUserMap = drawlineList2MapService.getDrawlineVirtualUserMap(uidList);
|
|
|
|
|
|
// (11)获取用户信息, 将用户的基础信息转换成MAP,
|
|
|
Map<Integer, UserBaseRspBO> userBaseRspBOMap = drawlineList2MapService.getUserBaseRspBOMap(userBaseRspBOArrAsync);
|
|
|
// (12)将查询排队列表用户的中奖信息, 基础信息,
|
|
|
List<DrawlineUserQueueRespBO> drawlineUserQueueRespBOList = DrawlineUserQueueConvert.toBOListByDOList(drawlineUserQueueList, drawlineLuckyUserMap, userBaseRspBOMap, drawlineVirtualUserMap);
|
|
|
// **补充助力排队用户信息 begin **
|
|
|
getHelpInfo(activityId, uidList, drawlineUserQueueRespBOList);
|
|
|
// **补充助力排队用户信息 end **
|
|
|
// (13)将查询的结果放入REDIS, yh:activity:活动ID:排队号:页数, 并且将查询的结果放入REDIS中
|
|
|
String value = JSONArray.toJSONString(drawlineUserQueueRespBOList);
|
|
|
DynamicLongProperty expire = DynamicPropertyFactory.getInstance().getLongProperty(CacheKeyEnum.MY_DRAWLINE_QUEUELIST.getExpireKey(), 10);
|
|
|
redisValueCache.set(CacheKeyEnum.MY_DRAWLINE_QUEUELIST, redisKeySuffix, value, expire.get(), TimeUnit.SECONDS);
|
|
|
|
|
|
return drawlineUserQueueRespBOList.toArray(new DrawlineUserQueueRespBO[drawlineUserQueueRespBOList.size()]);
|
|
|
}
|
|
|
|
|
|
private void getHelpInfo(int activityId, List<Integer> uidList, List<DrawlineUserQueueRespBO> drawlineUserQueueRespBOList) {
|
|
|
String activityIdStr = String.valueOf(activityId);
|
|
|
LimitProductBo limitProductBo = serviceCaller.call("product.getLimitProductByActivityId", activityIdStr, LimitProductBo.class);
|
|
|
List<LimitProductHelpUserRespBO> limitProductHelpUserList = null;
|
|
|
if(limitProductBo!=null && !StringUtils.isEmpty(limitProductBo.getLimitProductCode())){
|
|
|
logger.info("getDrawlineUserQueueList limitProduct limitProductCode is {}",limitProductBo.getLimitProductCode());
|
|
|
String limitProductCode = limitProductBo.getLimitProductCode();
|
|
|
limitProductHelpUserList = productLimitUserHelpMapper.selectHelpInfoByUidAndCode(uidList,limitProductCode);
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(limitProductHelpUserList)){
|
|
|
for (DrawlineUserQueueRespBO drawlineUserQueueRespBO : drawlineUserQueueRespBOList){
|
|
|
for (LimitProductHelpUserRespBO limitProductHelpUserRespBO : limitProductHelpUserList){
|
|
|
if (StringUtils.isEmpty(drawlineUserQueueRespBO.getOpenId())){
|
|
|
break;
|
|
|
}
|
|
|
if (drawlineUserQueueRespBO.getOpenId().equals(limitProductHelpUserRespBO.getHelpUserId())){
|
|
|
drawlineUserQueueRespBO.setHelpName(limitProductHelpUserRespBO.getHelpUserName());
|
|
|
drawlineUserQueueRespBO.setHelpheadIco(limitProductHelpUserRespBO.getHelpUserImgUrl());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 通过排队信息列表拼装用户id列表,用以获取用户信息
|
|
|
private List<Integer> getUidList(List<DrawlineUserQueue> drawlineUserQueueList) {
|
|
|
List<Integer> uidList = new ArrayList<Integer>();
|
...
|
...
|
|