分区隔离-礼物面板

This commit is contained in:
khalil
2024-04-12 19:25:32 +08:00
parent b9f51ec420
commit d6e9db85cf
4 changed files with 40 additions and 113 deletions

View File

@@ -0,0 +1,19 @@
package com.accompany.core.util;
public class PartitionUtil {
public static boolean equalsPartition(Integer p1, Integer p2) {
if (null == p1 || null == p2) {
return false;
}
return p1.equals(p2);
}
public static boolean inPartition(Integer flag, Integer partitionId) {
if (null == flag || null == partitionId) {
return false;
}
return (flag & partitionId) != 0;
}
}

View File

@@ -8,7 +8,8 @@ import com.accompany.business.vo.luckybag.LuckyBagInfoVo;
import com.accompany.business.vo.luckybag.LuckyBagPlayInfoVo;
import com.accompany.business.vo.luckybag.LuckyBagPoolGiftInfoVo;
import com.accompany.common.constant.Constant;
import com.accompany.core.base.UidContextHolder;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.exception.ServiceException;
import com.accompany.core.model.Users;
import com.accompany.core.service.base.BaseService;
import com.accompany.core.service.user.UsersBaseService;
@@ -37,37 +38,23 @@ public class GiftListService extends BaseService {
@Autowired
private UsersBaseService usersBaseService;
private List<GiftVo> listGiftVoByRoomUid(Long roomUid) {
private List<GiftVo> listGiftVoByRoomUid(Long uid, Long roomUid) {
Users u = usersBaseService.getUsersByUid(uid);
if (null == u){
throw new ServiceException(BusiStatus.USERNOTEXISTS);
}
// 上架状态礼物
List<GiftVo> giftVoList = giftService.queryGiftListVo(Constant.GiftConsumeType.GOLD_GIFT);
List<GiftVo> giftVoList = giftService.queryGiftListVoByPartitionId(u.getPartitionId());
//查询属于该房间专属礼物
if (roomUid != null) {
List<Integer> giftIds = roomExclusiveGiftService.getGiftIdByRoomUid(roomUid);
return giftVoList.stream().filter(giftVo -> !giftVo.getRoomExclude()
|| giftIds.contains(giftVo.getGiftId())).collect(Collectors.toList());
}
return giftVoList.stream().filter(giftVo -> !giftVo.getRoomExclude()).collect(Collectors.toList());
}
private final List<String> tabV4List = Lists.newArrayList(
Constant.GiftPanelTab.NORMAL,
Constant.GiftPanelTab.LUCKY,
Constant.GiftPanelTab.LUCKY_POOL,
Constant.GiftPanelTab.VIP,
Constant.GiftPanelTab.SINGLE_POPULAR,
Constant.GiftPanelTab.WEEK_STAR,
Constant.GiftPanelTab.DRAW
);
/**
* 获取礼物列表 : 按照giftType进行分组每组内部进行排序
*
* @return
* @since v4.1.0
*/
public Map<String, List<GiftVo>> listGiftV4(Long roomUid) {
List<GiftVo> giftVoList = listGiftVoByRoomUid(roomUid);
return giftPanelService.buildPanel(null, giftVoList, tabV4List);
return giftVoList.stream()
.filter(giftVo -> !giftVo.getRoomExclude())
.collect(Collectors.toList());
}
/**
@@ -104,38 +91,7 @@ public class GiftListService extends BaseService {
);
public Map<String, List<GiftVo>> listGiftV5(Long uid, Long roomUid) {
List<GiftVo> giftVoList = listGiftVoByRoomUid(roomUid);
List<GiftVo> giftVoList = listGiftVoByRoomUid(uid, roomUid);
return giftPanelService.buildPanel(uid, giftVoList, tabV5List);
}
public boolean isBelongTo(Integer giftId) {
return isBelongTo(UidContextHolder.get(), giftId);
}
public boolean isBelongTo(Long uid, Integer giftId) {
Gift gift = giftService.getGiftById(giftId);
if (gift == null) {
return false;
}
return isBelongTo(uid, gift);
}
public boolean isBelongTo(Long uid, Gift gift) {
if (uid == null) {
return false;
}
Users users = usersBaseService.getUsersByUid(uid);
if (users == null) {
return false;
}
Integer partitionId = users.getPartitionId();
if (partitionId == null) {
return false;
}
Integer partitionFlag = gift.getPartitionFlag();
if (partitionFlag == null) {
return false;
}
return (partitionFlag & partitionId) != 0;
}
}

View File

@@ -11,13 +11,11 @@ import com.accompany.business.service.activity.WeekStarService;
import com.accompany.business.service.vip.VipAuthItemService;
import com.accompany.business.vo.GiftVo;
import com.accompany.common.constant.Constant;
import com.accompany.common.netease.neteaseacc.result.FileUploadRet;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.BlankUtil;
import com.accompany.core.service.base.BaseService;
import com.accompany.core.service.common.JedisService;
import com.accompany.core.util.PartitionUtil;
import com.accompany.core.vo.vip.VipBaseInfoVO;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
@@ -43,15 +41,7 @@ public class GiftService extends BaseService {
@Autowired
private GiftMapper giftMapper;
@Autowired
private RoomExclusiveGiftService roomExclusiveGiftService;
@Autowired
private VipAuthItemService vipAuthItemService;
@Autowired
private WeekStarConfigService weekStarConfigService;
@Autowired
private WeekStarService weekStarService;
@Autowired
private AppVersionService appVersionService;
public void refreshGiftCache() {
List<Gift> giftList = this.getAllValidGiftFromDB();
@@ -77,13 +67,6 @@ public class GiftService extends BaseService {
return giftMapper.selectByExample(giftExample);
}
public List<Gift> listGiftInType(List<Byte> types) {
GiftExample giftExample = new GiftExample();
giftExample.createCriteria().andGiftTypeIn(types);
giftExample.setOrderByClause(" seq_no asc");
return giftMapper.selectByExample(giftExample);
}
/**
* 查询福袋奖池礼物giftType为5
*
@@ -96,8 +79,8 @@ public class GiftService extends BaseService {
return giftVoList;
}
public List<GiftVo> queryGiftListVo(Byte consumeType) {
List<Gift> giftList = queryGiftList(consumeType);
public List<GiftVo> queryGiftListVoByPartitionId(Integer partitionId) {
List<Gift> giftList = queryGiftListByPartitionId(partitionId);
List<GiftVo> giftVoList = Lists.newArrayList();
for (Gift gift : giftList) {
GiftVo giftVo = new GiftVo();
@@ -159,15 +142,12 @@ public class GiftService extends BaseService {
giftVo.setGiftVipInfo(giftVipInfo);
}
public List<Gift> queryGiftList(Byte consumeType) {
public List<Gift> queryGiftListByPartitionId(Integer partitionId) {
Map<String, String> giftKeyMap = jedisService.hgetAllBykey(RedisKey.gift.getKey());
List<Gift> giftList = Lists.newArrayList();
if (giftKeyMap == null || giftKeyMap.size() == 0) {
GiftExample giftExample = new GiftExample();
giftExample.createCriteria().andGiftStatusEqualTo(Constant.status.valid);
if (consumeType != null) {
giftExample.createCriteria().andConsumeTypeEqualTo(consumeType);
}
giftExample.setOrderByClause(" seq_no asc");
giftList = giftMapper.selectByExample(giftExample);
batchSaveGiftCache(giftList);
@@ -181,18 +161,13 @@ public class GiftService extends BaseService {
if (!Constant.status.valid.equals(gift.getGiftStatus())) {
continue;
}
if (consumeType != null) {
if (consumeType.equals(gift.getConsumeType())) {
giftList.add(gift);
}
} else {
giftList.add(gift);
}
giftList.add(gift);
}
}
}
return giftList;
return giftList.stream()
.filter(g-> PartitionUtil.inPartition(g.getPartitionFlag(), partitionId))
.collect(Collectors.toList());
}
private void batchSaveGiftCache(List<Gift> giftList) {
@@ -245,23 +220,6 @@ public class GiftService extends BaseService {
return gift;
}
public BusiResult updateGift(FileUploadRet fileUploadRet, Integer giftId) {
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
GiftExample example = new GiftExample();
example.createCriteria().andGiftIdEqualTo(giftId);
List<Gift> gifts = giftMapper.selectByExample(example);
if (CollectionUtils.isEmpty(gifts)) {
return new BusiResult(BusiStatus.BUSIERROR);
}
Gift gift = gifts.get(0);
gift.setPicUrl(fileUploadRet.getUrl());
giftMapper.updateByPrimaryKey(gift);
jedisService.hdeleteKey(RedisKey.gift.getKey());
queryGiftList(null);
return busiResult;
}
/**
* 获取礼物的信息,礼物必须处在有效状态, CACHE -> DB -> CACHE
*

View File

@@ -170,12 +170,6 @@ public class GiftV2Controller extends BaseController {
}
}
@GetMapping("/listV4")
public BaseResponseVO<Map<String, List<GiftVo>>> listGiftV4(Long roomUid) {
Map<String, List<GiftVo>> giftMap = giftListService.listGiftV4(roomUid);
return new BaseResponseVO<>(BusiStatus.SUCCESS, giftMap);
}
@GetMapping("/listV5")
@Authorization
public BaseResponseVO<Map<String, List<GiftVo>>> listGiftV5(HttpServletRequest request,