房间停留可获得礼物-修改倒计时方法,兼容跨重置周期

This commit is contained in:
2022-12-15 03:20:43 +08:00
parent 4b3cad8613
commit 1d9eebc6ff
4 changed files with 173 additions and 92 deletions

View File

@@ -28,21 +28,12 @@ public class RoomFreeGiftTask implements InitializingBean {
@Autowired
private RoomFreeGiftService roomFreeGiftService;
@Autowired
private RoomQueryService roomQueryService;
@Autowired
private TaskExecutor bizExecutor;
@Autowired
private ErBanNetEaseService erBanNetEaseService;
@Scheduled(cron = "0 * * * * ?")
public void clanGoldSettlement() throws InterruptedException {
roomFreeGiftService.resetFreeGift();
Attach attach = new Attach();
attach.setFirst(Constant.DefMsgType.roomFreeGift);
attach.setSecond(Constant.DefMsgType.roomFreeGiftRest);
sendMessageToAllValidRooms(JSON.toJSONString(attach));
roomFreeGiftService.sendRefreshChatRoomMsg();
}
@@ -71,29 +62,5 @@ public class RoomFreeGiftTask implements InitializingBean {
return new CronSequenceGenerator(config.getResetTimeCron());
}
/**
* 发送所有有效房间消息
*
* @param msg
*/
public long sendMessageToAllValidRooms(final String msg) {
int BATCH_SIZE = 1000;
long count = this.roomQueryService.countValidRooms();
long times = count % BATCH_SIZE == 0 ? (count / BATCH_SIZE) : (count / BATCH_SIZE) + 1;
for (int i = 0; i < times; i++) {
Integer index = i * BATCH_SIZE;
List<Room> validRooms = this.roomQueryService.listValidRooms(index, BATCH_SIZE);
for (Room room : validRooms) {
bizExecutor.execute(() -> {
try {
this.erBanNetEaseService.sendChatRoomMsg(room.getRoomId(), UUIDUitl.get(), room.getUid().toString(), Constant.DefineProtocol.CUSTOM_MESS_DEFINE, msg, null);
} catch (Exception e) {
log.error("批量发送房间消息失败[room={}, message={}]", JSON.toJSONString(room), msg, e);
}
});
}
}
log.info("发送所有有效房间消息,房间数:{}", count);
return count;
}
}