房间停留可获得礼物-新增协议用于更新礼物信息

This commit is contained in:
2022-12-15 19:08:45 +08:00
parent 002ecf79d4
commit acd1170d5b
4 changed files with 38 additions and 12 deletions

View File

@@ -303,7 +303,8 @@ public class Constant {
// --------------- 房间内免费礼物自定义消息类型 ---------------------
public static int roomFreeGift = 96;
public static int roomFreeGiftRest = 960;
public static int roomFreeGiftReset = 960;
public static int roomFreeGiftUpdate = 961;
// --------------- 房间内免费礼物自定义消息类型 ---------------------
}

View File

@@ -92,11 +92,6 @@ public class RoomFreeGiftService implements InitializingBean, ApplicationListene
return vo;
}
Date now = new Date();
CronSequenceGenerator resetCron = new CronSequenceGenerator(config.getResetTimeCron());
Date resetTime = resetCron.next(now);
vo.setUid(uid);
vo.setFirstSecond(config.getFirstStageSecond());
vo.setMaxStage(config.getMaxStage());
@@ -104,7 +99,6 @@ public class RoomFreeGiftService implements InitializingBean, ApplicationListene
vo.setGiftName(freeGift.getGiftName());
vo.setGiftUrl(freeGift.getPicUrl());
vo.setGoldPrice(freeGift.getGoldPrice());
vo.setResetTime(resetTime);
String curStageKey = getCurStageKey(uid);
long curStage = userInfoMap.getOrDefault(curStageKey, 0L);
@@ -114,6 +108,7 @@ public class RoomFreeGiftService implements InitializingBean, ApplicationListene
return vo;
}
Date now = new Date();
long nowTimestamp = now.getTime();
String finishTimestampKey = getFinishTimestampKey(uid);
String lastTimestampKey = getLastTimestampKey(uid);
@@ -295,7 +290,7 @@ public class RoomFreeGiftService implements InitializingBean, ApplicationListene
uidGiftIdSet = redissonClient.getSet(RedisKey.room_free_gift_user_uid_gift.getKey(), StringCodec.INSTANCE);
}
public void sendRefreshChatRoomMsg() {
public void sendResetChatRoomMsg() {
RoomFreeGiftConfigDto config = getConfig();
if (null == config || null == config.getGiftId()){
return;
@@ -303,11 +298,35 @@ public class RoomFreeGiftService implements InitializingBean, ApplicationListene
Attach attach = new Attach();
attach.setFirst(Constant.DefMsgType.roomFreeGift);
attach.setSecond(Constant.DefMsgType.roomFreeGiftRest);
attach.setSecond(Constant.DefMsgType.roomFreeGiftReset);
attach.setData(new RoomFreeGiftUserVo());
sendMessageToAllValidRooms(JSON.toJSONString(attach));
}
public void sendUpdateChatRoomMsg() {
RoomFreeGiftConfigDto config = getConfig();
if (null == config || null == config.getGiftId()){
return;
}
Gift freeGift = giftService.getValidGiftById(config.getGiftId());
if (null == freeGift){
return;
}
RoomFreeGiftUserVo vo = new RoomFreeGiftUserVo();
vo.setGiftId(freeGift.getGiftId());
vo.setGiftName(freeGift.getGiftName());
vo.setGiftUrl(freeGift.getPicUrl());
vo.setGoldPrice(freeGift.getGoldPrice());
Attach attach = new Attach();
attach.setFirst(Constant.DefMsgType.roomFreeGift);
attach.setSecond(Constant.DefMsgType.roomFreeGiftUpdate);
attach.setData(vo);
sendMessageToAllValidRooms(JSON.toJSONString(attach));
}
/**
* 发送所有有效房间消息
*

View File

@@ -36,7 +36,14 @@ public class RoomFreeGiftController extends BaseController {
@Profile({"native","dev"})
public BusiResult<Void> reset(){
roomFreeGiftService.resetFreeGift();
roomFreeGiftService.sendRefreshChatRoomMsg();
roomFreeGiftService.sendResetChatRoomMsg();
return new BusiResult<>(BusiStatus.SUCCESS);
}
@GetMapping("/update")
@Profile({"native","dev"})
public BusiResult<Void> update(){
roomFreeGiftService.sendUpdateChatRoomMsg();
return new BusiResult<>(BusiStatus.SUCCESS);
}

View File

@@ -47,8 +47,7 @@ public class RoomFreeGiftTask implements SchedulingConfigurer {
private Runnable doTask() {
return () -> {
roomFreeGiftService.resetFreeGift();
roomFreeGiftService.sendRefreshChatRoomMsg();
roomFreeGiftService.sendResetChatRoomMsg();
};
}
}