Authored by zhaoqing

限定商品支持小程序

... ... @@ -15,6 +15,7 @@ public enum CacheKeyEnum {
DRAWLINE_ACTIVITY("yh:act_activity:", "drawline.activity.redisSwitch", "drawline.activity.redisExpire", "限购排队活动信息"),
DRAWLINE_ACTIVITYBO("yh:act_activitybo:", "drawline.activitybo.redisSwitch", "drawline.activitybo.redisExpire", "限购排队活动信息(BO)"),
DRAWLINE_QUEUELIST("yh:act_queuelist:", "drawline.queuelist.redisSwitch", "drawline.queuelist.redisExpire", "活动排队列表"),
MY_DRAWLINE_QUEUELIST("yh:act_my_queuelist:", "drawline.my.queuelist.redisSwitch", "drawline.my.queuelist.redisExpire", "我的排队列表"),
DRAWLINE_USERACTIVITY("yh:act_useractivity:", "drawline.useractivity.redisSwitch", "drawline.useractivity.redisExpire", "活动排队列表"),
DRAWLINE_LUCKYUSERLIST("yh:act_luckyuser:", "drawline.luckyuserlist.redisSwitch", "drawline.luckyuserlist.redisExpire", "中奖用户信息列表"),
USERDAY_DRAWPRIZENUM("yh:act_userday:drawPrizeNum", "userday.drawPrizeNum.redisSwitch", "userday.drawPrizeNum.redisExpire", "会员日虚拟参与抽奖人数"),
... ...
... ... @@ -13,4 +13,6 @@ public interface ProductLimitUserHelpMapper {
List<LimitProductHelpUserRespBO> selectHelpInfo(@Param("userId") Integer userId, @Param("limitProductCode") String limitProductCode);
void addhelpUserInfo(LimitProductHelpUser limitProductHelpUser);
List<LimitProductHelpUserRespBO> selectHelpInfoByUidAndCode(@Param("list") List<Integer> uidList, @Param("limitProductCode") String limitProductCode);
}
... ...
... ... @@ -29,4 +29,6 @@ public interface IDrawlineUserQueueDAO {
int selectMaxSortByActivityId(@Param("activityId") int activityId);
void insertBatch(List<DrawlineUserQueue> list);
List<DrawlineUserQueue> selectMyQueueList(@Param("activityId")int activityId, @Param("sort")int sort, @Param("limit")int limit, @Param("uid")int uid);
}
\ No newline at end of file
... ...
... ... @@ -108,6 +108,18 @@
</where>
order by sort desc limit 0, #{limit,jdbcType=INTEGER}
</select>
<select id="selectMyQueueList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from drawline_user_queue
<where>
activity_id = #{activityId,jdbcType=INTEGER} and status = 1 AND uid = #{uid,jdbcType=INTEGER}
<if test="sort > 0">
and sort &lt;= #{sort,jdbcType=INTEGER}
</if>
</where>
order by sort desc limit 0, #{limit,jdbcType=INTEGER}
</select>
<select id="selectRealUserQueueByActIdAndUids" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ...
... ... @@ -29,4 +29,14 @@
)
</insert>
<select id="selectHelpInfoByUidAndCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from limit_product_help_user
where user_id in
<foreach collection="list" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
and limit_product_code = #{limitProductCode,jdbcType=VARCHAR}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -73,6 +73,7 @@ public class DrawlineUserQueueConvert {
drawlineUserQueueRespBO.setUid(drawlineUserQueue.getUid());
drawlineUserQueueRespBO.setActivityId(drawlineUserQueue.getActivityId());
drawlineUserQueueRespBO.setSort(drawlineUserQueue.getSort());
drawlineUserQueueRespBO.setOpenId(drawlineUserQueue.getOpenId());
drawlineUserQueueRespBO.setQueueTime(currTime - drawlineUserQueue.getCreateTime());
drawlineUserQueueRespBO.setIsLucky(null == drawlineLuckyUser ? 0 : 1);
// drawlineUserQueueRespBO.setIsLucky(0); // 业务要求,取消是否中奖
... ...
... ... @@ -75,4 +75,30 @@ public class DrawlineUserQueueRest {
}
return new ApiResponse.ApiResponseBuilder().code(code).message(message).data(data).build();
}
/**
* 描述:获取我的限购码排队列表<br>
* 场景:<br>
* &nbsp;&nbsp;1.进入活动界面<br>
* &nbsp;&nbsp;2.列表上/下滑动<br>
* &nbsp;&nbsp;3.我的排队<br>
*
* @param drawlineUserQueueReqBO
* @return
*/
@RequestMapping(params = "method=app.drawline.getMyQueueList")
@ResponseBody
public ApiResponse getMyDrawlineUserQueueList(DrawlineUserQueueReqBO drawlineUserQueueReqBO) {
logger.info("Enter getMyDrawlineUserQueueList. param drawlineUserQueueReqBO is {}", drawlineUserQueueReqBO);
int code = 200;
String message = "";
DrawlineUserQueueRespBO[] data = new DrawlineUserQueueRespBO[0];
try {
data = drawlineUserQueueService.getMyDrawlineUserQueueList(drawlineUserQueueReqBO);
} catch (ServiceException e) {
code = e.getCode();
message = e.getErrorMessage();
}
return new ApiResponse.ApiResponseBuilder().code(code).message(message).data(data).build();
}
}
... ...
... ... @@ -51,4 +51,5 @@ public interface IDrawlineUserQueueService {
*/
DrawlineUserQueueRespBO[] getDrawlineUserQueueList(DrawlineUserQueueReqBO drawlineUserQueueReqBO) throws ServiceException;
DrawlineUserQueueRespBO[] getMyDrawlineUserQueueList(DrawlineUserQueueReqBO drawlineUserQueueReqBO);
}
... ...
... ... @@ -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>();
... ...