福袋上新-手气榜
This commit is contained in:
@@ -2273,6 +2273,8 @@ public enum RedisKey {
|
||||
|
||||
room_kick,//房间踢人
|
||||
|
||||
lucky_bag_rank, // 福袋轮播队列
|
||||
|
||||
;
|
||||
|
||||
public String getKey() {
|
||||
|
@@ -0,0 +1,131 @@
|
||||
package com.accompany.business.service.luckybag;
|
||||
|
||||
import com.accompany.business.model.Gift;
|
||||
import com.accompany.business.model.luckybag.LuckyBagRecord;
|
||||
import com.accompany.business.mybatismapper.luckybag.LuckyBagRecordMapper;
|
||||
import com.accompany.business.service.gift.GiftService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.luckybag.LuckyBagRecordRankItemVo;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.redisson.api.RMapCache;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class LuckyBagRankService implements InitializingBean {
|
||||
@Autowired
|
||||
private LuckyBagRecordMapper luckyBagRecordMapper;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private GiftService giftService;
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
|
||||
private RMapCache<Integer, List<LuckyBagRecordRankItemVo>> rankCacheMap;
|
||||
|
||||
public List<LuckyBagRecordRankItemVo> getRank(Integer giftId) {
|
||||
Gift luckyBag = giftService.getGiftById(giftId);
|
||||
if (null == luckyBag
|
||||
|| (Constant.GiftType.LUCKY_BAG != luckyBag.getGiftType() && Constant.GiftType.LUCKY_BAG_LINEAR != luckyBag.getGiftType())){
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
|
||||
List<LuckyBagRecordRankItemVo> cacheList = rankCacheMap.get(giftId);
|
||||
if (!CollectionUtils.isEmpty(cacheList)){
|
||||
return cacheList;
|
||||
}
|
||||
|
||||
QueryWrapper<LuckyBagRecord> queryWrapper = Wrappers.query();
|
||||
queryWrapper.lambda().eq(LuckyBagRecord::getLuckyBagId, giftId)
|
||||
.ge(LuckyBagRecord::getPrizeLevel, Constant.PrizePoolType.ORDINARY)
|
||||
.orderByDesc(LuckyBagRecord::getId);
|
||||
queryWrapper.last("limit 100");
|
||||
|
||||
List<LuckyBagRecord> list = luckyBagRecordMapper.selectList(queryWrapper);
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
cacheList = Collections.emptyList();
|
||||
rankCacheMap.fastPut(giftId, cacheList, 3, TimeUnit.SECONDS);
|
||||
return cacheList;
|
||||
}
|
||||
|
||||
list.sort(Comparator.comparing(LuckyBagRecord::getCreateTime).reversed()
|
||||
.thenComparing(LuckyBagRecord::getPlatformValue).reversed());
|
||||
|
||||
List<LuckyBagRecordRankItemVo> voList = new ArrayList<>();
|
||||
|
||||
List<Integer> giftIdList = new ArrayList<>();
|
||||
List<Long> uidList = new ArrayList<>();
|
||||
for (LuckyBagRecord record: list) {
|
||||
uidList.add(record.getUid());
|
||||
uidList.add(record.getReceiveUid());
|
||||
|
||||
giftIdList.add(record.getGiftId());
|
||||
}
|
||||
|
||||
Map<Integer, Gift> giftMap = giftService.getGiftByIdsFromDb(giftIdList.stream().distinct().collect(Collectors.toList()))
|
||||
.stream().collect(Collectors.toMap(Gift::getGiftId, g->g));
|
||||
|
||||
Map<Long, Users> usersMap = usersService.getUsersMapByUids(uidList.stream().distinct().collect(Collectors.toList()));
|
||||
|
||||
for (LuckyBagRecord record: list) {
|
||||
LuckyBagRecordRankItemVo vo = new LuckyBagRecordRankItemVo();
|
||||
vo.setSendUid(record.getUid());
|
||||
|
||||
Users sender = usersMap.get(record.getUid());
|
||||
if (null != sender){
|
||||
vo.setSendErbanNo(sender.getErbanNo());
|
||||
vo.setSendNick(sender.getNick());
|
||||
vo.setSendAvatar(sender.getAvatar());
|
||||
}
|
||||
|
||||
Users receiver = usersMap.get(record.getReceiveUid());
|
||||
if (null != receiver){
|
||||
vo.setReceiveErbanNo(receiver.getErbanNo());
|
||||
vo.setReceiveNick(receiver.getNick());
|
||||
vo.setReceiveAvatar(receiver.getAvatar());
|
||||
}
|
||||
|
||||
vo.setLuckyBagId(record.getLuckyBagId());
|
||||
vo.setLuckyBagName(luckyBag.getGiftName());
|
||||
vo.setLuckyBagNum(record.getLuckyBagNum());
|
||||
|
||||
vo.setGiftId(record.getGiftId());
|
||||
vo.setGiftNum(record.getGiftNum());
|
||||
vo.setGiftName(record.getGiftName());
|
||||
vo.setGoldPrice(record.getPlatformValue().longValue());
|
||||
|
||||
Gift gift = giftMap.get(record.getGiftId());
|
||||
if (null != gift){
|
||||
vo.setGiftUrl(gift.getPicUrl());
|
||||
}
|
||||
|
||||
vo.setCreateTime(record.getCreateTime());
|
||||
|
||||
voList.add(vo);
|
||||
}
|
||||
|
||||
rankCacheMap.fastPut(giftId, cacheList, 3, TimeUnit.SECONDS);
|
||||
|
||||
return voList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
rankCacheMap = redissonClient.getMapCache(RedisKey.lucky_bag_rank.getKey());
|
||||
}
|
||||
}
|
||||
|
@@ -4,30 +4,19 @@ import com.accompany.business.dto.lucky.LuckyBagRecordDto;
|
||||
import com.accompany.business.model.Gift;
|
||||
import com.accompany.business.model.luckybag.LuckyBagRecord;
|
||||
import com.accompany.business.mybatismapper.luckybag.LuckyBagRecordMapper;
|
||||
import com.accompany.business.service.gift.GiftService;
|
||||
import com.accompany.business.service.user.UsersService;
|
||||
import com.accompany.business.vo.luckybag.LuckyBagGiftIncomeVo;
|
||||
import com.accompany.business.vo.luckybag.LuckyBagRecordRankItemVo;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Room;
|
||||
import com.accompany.core.model.Users;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.redisson.api.RList;
|
||||
import org.redisson.api.RQueue;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class LuckyBagRecordService extends ServiceImpl<LuckyBagRecordMapper, LuckyBagRecord> implements InitializingBean {
|
||||
@@ -35,10 +24,6 @@ public class LuckyBagRecordService extends ServiceImpl<LuckyBagRecordMapper, Luc
|
||||
private LuckyBagRecordMapper luckyBagRecordMapper;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
@Autowired
|
||||
private GiftService giftService;
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
|
||||
private RList<LuckyBagRecordDto> bannerRecordQueue;
|
||||
|
||||
@@ -80,42 +65,6 @@ public class LuckyBagRecordService extends ServiceImpl<LuckyBagRecordMapper, Luc
|
||||
return bannerRecordQueue.range(10);
|
||||
}
|
||||
|
||||
public List<LuckyBagRecordRankItemVo> getRank(Integer giftId) {
|
||||
Gift gift = giftService.getGiftById(giftId);
|
||||
if (null == gift
|
||||
|| (Constant.GiftType.LUCKY_BAG != gift.getGiftType() && Constant.GiftType.LUCKY_BAG_LINEAR != gift.getGiftType())){
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
|
||||
QueryWrapper<LuckyBagRecord> queryWrapper = Wrappers.query();
|
||||
queryWrapper.lambda().eq(LuckyBagRecord::getLuckyBagId, giftId)
|
||||
.ge(LuckyBagRecord::getPrizeLevel, Constant.PrizePoolType.ORDINARY)
|
||||
.orderByDesc(LuckyBagRecord::getId, LuckyBagRecord::getPlatformValue);
|
||||
queryWrapper.last("limit 100");
|
||||
|
||||
List<LuckyBagRecord> list = list(queryWrapper);
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<LuckyBagRecordRankItemVo> voList = new ArrayList<>();
|
||||
|
||||
List<Long> uidList = new ArrayList<>();
|
||||
for (LuckyBagRecord record: list) {
|
||||
uidList.add(record.getUid());
|
||||
uidList.add(record.getReceiveUid());
|
||||
}
|
||||
|
||||
Map<Long, Users> usersMap = usersService.getUsersMapByUids(uidList.stream().distinct().collect(Collectors.toList()));
|
||||
|
||||
for (LuckyBagRecord record: list) {
|
||||
LuckyBagRecordRankItemVo vo = new LuckyBagRecordRankItemVo();
|
||||
|
||||
}
|
||||
|
||||
return voList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
bannerRecordQueue = redissonClient.getList(RedisKey.lucky_bag_banner_record.getKey());
|
||||
|
@@ -3,6 +3,7 @@ package com.accompany.business.controller.luckybag;
|
||||
import com.accompany.business.dto.lucky.LuckyBagRecordDto;
|
||||
import com.accompany.business.service.luckybag.LuckyBagLinearPoolService;
|
||||
import com.accompany.business.service.luckybag.LuckyBagPoolService;
|
||||
import com.accompany.business.service.luckybag.LuckyBagRankService;
|
||||
import com.accompany.business.service.luckybag.LuckyBagRecordService;
|
||||
import com.accompany.business.vo.luckybag.LuckyBagRecordRankItemVo;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
@@ -25,12 +26,12 @@ public class LuckyBagController {
|
||||
|
||||
@Autowired
|
||||
private LuckyBagPoolService luckyBagPoolService;
|
||||
|
||||
@Autowired
|
||||
private LuckyBagLinearPoolService luckyBagLinearPoolService;
|
||||
|
||||
@Autowired
|
||||
private LuckyBagRecordService luckyBagRecordService;
|
||||
@Autowired
|
||||
private LuckyBagRankService luckyBagRankService;
|
||||
|
||||
@ApiOperation("获取福袋礼物概率列表")
|
||||
@GetMapping(value = "/poolList")
|
||||
@@ -65,7 +66,7 @@ public class LuckyBagController {
|
||||
if (null == giftId) {
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
}
|
||||
List<LuckyBagRecordRankItemVo> rankVoList = luckyBagRecordService.getRank(giftId);
|
||||
List<LuckyBagRecordRankItemVo> rankVoList = luckyBagRankService.getRank(giftId);
|
||||
return new BusiResult<>(rankVoList);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user