房间停留可获得礼物-用户背包伪造免费礼物坑位

This commit is contained in:
2022-12-14 09:42:40 +08:00
parent 0e29fa7206
commit e61159913e
8 changed files with 89 additions and 12 deletions

View File

@@ -3813,7 +3813,7 @@ public class Constant {
public static final byte RADISH_GIFT = 2;// 萝卜礼物
public static final byte FREE_GIFT = 3;// 免费礼物
public static final byte ROOM_FREE_GIFT = 3;// 免费礼物
}
public static class UserSignRoundPrizeStatus{

View File

@@ -112,7 +112,7 @@ public class GiftNotifyListener implements ApplicationListener<GiftMessageEvent>
logger.info("sendGiftNotify start,giftMessage={}",giftMessage.toString());
// 福袋开出的礼物不需要通知
if (giftMessage.getLuckyBagGift()
|| (null != giftMessage.getGiftConsumeType() && giftMessage.getGiftConsumeType() == Constant.GiftConsumeType.FREE_GIFT)
|| (null != giftMessage.getGiftConsumeType() && giftMessage.getGiftConsumeType() == Constant.GiftConsumeType.ROOM_FREE_GIFT)
|| (null != giftMessage.getGiftType() && giftMessage.getGiftType() == Constant.GiftType.LUCKY_BAG)) {
return;
}
@@ -166,7 +166,7 @@ public class GiftNotifyListener implements ApplicationListener<GiftMessageEvent>
Gift gift = giftService.getValidGiftById(giftId);
if (null == gift){
return;
} else if (gift.getConsumeType() == Constant.GiftConsumeType.FREE_GIFT){
} else if (gift.getConsumeType() == Constant.GiftConsumeType.ROOM_FREE_GIFT){
goldNum = gift.getGoldPrice();
}

View File

@@ -52,7 +52,7 @@ public class RankListener implements ApplicationListener<GiftMessageEvent> {
return;
}
boolean isFreeGift = Constant.GiftConsumeType.FREE_GIFT == gift.getConsumeType();
boolean isFreeGift = Constant.GiftConsumeType.ROOM_FREE_GIFT == gift.getConsumeType();
if (isFreeGift){
goldNum = gift.getGoldPrice();
}

View File

@@ -513,7 +513,7 @@ public class GiftSendService extends BaseService {
message.setGiftConsumeType(giftConsumeType);
message.setGiftType(giftType);
message.setGiftNum(giftNum);
message.setGoldNum(giftConsumeType != Constant.GiftConsumeType.FREE_GIFT? goldNum: 0L);//免费礼物
message.setGoldNum(giftConsumeType != Constant.GiftConsumeType.ROOM_FREE_GIFT? goldNum: 0L);//免费礼物
message.setRoomType(roomType);
message.setSendType(sendType);
message.setMessId(UUIDUitl.get());
@@ -688,7 +688,7 @@ public class GiftSendService extends BaseService {
case Constant.GiftConsumeType.RADISH_GIFT :
result = radishSendService.sendRadishGift(sendUid, receiveUids, roomUid, giftId, giftNum, msg, giftSource, sendType);
break;
case Constant.GiftConsumeType.FREE_GIFT:
case Constant.GiftConsumeType.ROOM_FREE_GIFT:
result = sendGiftV4(sendUid, receiveUids, roomUid, gift, giftNum, msg, giftSource, sendType);
break;
default: throw new ServiceException(BusiStatus.GIFTDOWNORNOTEXISTS);

View File

@@ -47,6 +47,11 @@ public class RoomFreeGiftService implements InitializingBean, ApplicationListene
private RMap<String, Long> userInfoMap;
public long getUserCurStage(Long uid){
String curStageKey = getCurStageKey(uid);
return userInfoMap.getOrDefault(curStageKey, 0L);
}
public RoomFreeGiftUserVo getVo(Long uid) {
RoomFreeGiftUserVo vo = new RoomFreeGiftUserVo();
@@ -161,7 +166,7 @@ public class RoomFreeGiftService implements InitializingBean, ApplicationListene
}
private RoomFreeGiftConfigDto getConfig(){
public RoomFreeGiftConfigDto getConfig(){
String configStr = sysConfService.getSysConfValueById(Constant.SysConfId.ROOM_FREE_GIFT_CONFIG);
if (StringUtils.isEmpty(configStr)){
return null;

View File

@@ -1,5 +1,6 @@
package com.accompany.business.service.user;
import com.accompany.business.dto.room.RoomFreeGiftConfigDto;
import com.accompany.business.model.Gift;
import com.accompany.business.model.UserBackpack;
import com.accompany.business.model.UserBackpackExample;
@@ -7,10 +8,12 @@ import com.accompany.business.mybatismapper.UserBackpackMapper;
import com.accompany.business.param.BatchGiftParam;
import com.accompany.business.param.UserBackpackParam;
import com.accompany.business.service.gift.GiftService;
import com.accompany.business.service.room.RoomFreeGiftService;
import com.accompany.business.util.ReplaceDomainUtil;
import com.accompany.business.vo.GiftVo;
import com.accompany.business.vo.UserBackpackVo;
import com.accompany.common.annotation.Frozen;
import com.accompany.common.constant.Constant;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.BlankUtil;
@@ -46,6 +49,8 @@ public class UserBackpackService extends BaseService {
private JedisLockService jedisLockService;
@Autowired
private GiftService giftService;
@Autowired
private RoomFreeGiftService roomFreeGiftService;
/**
* 根据用户ID查询用户的背包
*
@@ -83,7 +88,6 @@ public class UserBackpackService extends BaseService {
return userBackpackVos;
}
private UserBackpack getUserBackpackItem(Long uid, Integer giftId) {
UserBackpackExample userBackpackExample2 = new UserBackpackExample();
userBackpackExample2.createCriteria().andUidEqualTo(uid).andGiftIdEqualTo(giftId);
@@ -129,6 +133,33 @@ public class UserBackpackService extends BaseService {
return filterByConsumeType(userBackpackVos, consumeTypes);
}
/**
* 根据用户ID查询用户的背包包括缓存
*
* @param uid
* @return
*/
public List<UserBackpackVo> getUserBackpackListWithCacheV3(Long uid, Byte... consumeTypes) {
List<UserBackpackVo> userBackpackVos = this.getUserBackpackListByCache(uid);
// 当缓存不存在时
if (userBackpackVos == null) {
// 用户背包 加锁
String lockKey = getBackpackLock(uid);
String lockVal = jedisLockService.lock(lockKey, 10 * 1000);
try {
// 再次校验缓存是否存在信息
userBackpackVos = this.getUserBackpackListByCache(uid);
// 缓存依旧不存在信息,从数据库更新
if (userBackpackVos == null) {
userBackpackVos = this.getUserBackpackList(uid);
}
} finally {
jedisLockService.unlock(lockKey, lockVal);
}
}
return filterByConsumeTypeAndBuildRoomFreeGift(uid, userBackpackVos, consumeTypes);
}
/**
* 从缓存获取用户背包信息
* 无缓存返回 null
@@ -177,6 +208,36 @@ public class UserBackpackService extends BaseService {
return userBackpackVos;
}
private List<UserBackpackVo> filterByConsumeTypeAndBuildRoomFreeGift(Long uid, List<UserBackpackVo> list, Byte... consumeTypes) {
List<UserBackpackVo> userBackpackVos = Lists.newArrayList();
for (Byte consumeType : consumeTypes) {
List<UserBackpackVo> tempList = list.stream().filter(item ->
Objects.equals(item.getConsumeType(), consumeType)).collect(Collectors.toList());
if (consumeType.equals(Constant.GiftConsumeType.ROOM_FREE_GIFT)){
//理论上只有一个当用户未领完并且背包没有免费礼物时mock一个
RoomFreeGiftConfigDto config = roomFreeGiftService.getConfig();
if (null != config){
long curStage = roomFreeGiftService.getUserCurStage(uid);
if (curStage < config.getMaxStage() && CollectionUtils.isEmpty(tempList)){
//规定是一个
UserBackpack virtualFreeGift = new UserBackpack();
virtualFreeGift.setId(null);
virtualFreeGift.setUid(uid);
virtualFreeGift.setCount(0);
virtualFreeGift.setGiftSeq(0);
virtualFreeGift.setGiftType(Constant.GiftType.ROOM_FREE);
UserBackpackVo virtualVo = getUserBackpackVo(virtualFreeGift);
tempList.add(virtualVo);
}
}
}
Collections.sort(tempList, Comparator.comparing(UserBackpackVo::getSeqNo));
userBackpackVos.addAll(tempList);
}
ReplaceDomainUtil.handlerForList(userBackpackVos);
return userBackpackVos;
}
/**
* 获取背包的展示类
*

View File

@@ -54,4 +54,18 @@ public class UserBackpackController extends BaseController {
}
}
@RequestMapping(value = "/listUserBackpackV3",method = RequestMethod.GET)
public BusiResult<List<UserBackpackVo>> getUserBackpackListV3(long uid) {
try {
List<UserBackpackVo> userBackpackVos = userBackpackService.getUserBackpackListWithCacheV3(uid,
Constant.GiftConsumeType.ROOM_FREE_GIFT,
Constant.GiftConsumeType.RADISH_GIFT,
Constant.GiftConsumeType.GOLD_GIFT);
return new BusiResult(BusiStatus.SUCCESS, userBackpackVos);
} catch (Exception e) {
logger.error("listUserBackpackV3 error...uid=" + uid, e);
return new BusiResult(BusiStatus.BUSIERROR);
}
}
}

View File

@@ -33,7 +33,6 @@ import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.userdetails.UserDetails;
@@ -52,8 +51,6 @@ import java.util.Optional;
@Slf4j
public class MyUserDetailsServiceImpl implements MyUserDetailsService {
@Value("spring.profiles.active:dev")
private String activeProfile;
@Autowired
private JedisService jedisService;
@Autowired
@@ -112,7 +109,7 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
throws Exception {
Account account = null;
log.info("phone:{}, phoneAreaCode:{}, smsCode:{}, deviceInfo:{}, ipAddress:{}",phone,phoneAreaCode,smsCode,deviceInfo,ipAddress);
if (CommonUtil.checkPhoneFormat(phoneAreaCode,phone) || "dev".equals(activeProfile)) {
if (CommonUtil.checkPhoneFormat(phoneAreaCode,phone)) {
account = accountManageService.getOrGenAccountByPhone(phone,phoneAreaCode,smsCode,deviceInfo,ipAddress);
} else if (CommonUtil.checkNumberOnly(phone)) {
account = accountService.getAccountByErBanNo(Long.valueOf(phone));