房间金币大放送-新增在线时长统计

This commit is contained in:
tianfeng 2026-03-04 20:36:19 +08:00
parent c6f3545052
commit 2eee9254ba
2 changed files with 43 additions and 6 deletions

View File

@ -75,11 +75,14 @@ public class TeamMemberHeartbeatCmdExe {
.build());
}
boolean oneselfRoom = isOneselfRoom(cmd);
RoomProfile roomProfile = roomProfileManagerService.getProfileById(cmd.getRoomId());
ResponseAssert.notNull(RoomErrorCode.ROOM_NOT_EXISTS, roomProfile);
boolean oneselfRoom = Objects.equals(roomProfile.getUserId(), cmd.requiredReqUserId());
// 在他人房间上麦
if (!oneselfRoom) {
updateDailyTask(cmd, RoomDailyTaskCode.PERSONAL_MIC_IN_ROOM);
updateRoomMicUserDurationTask(cmd.requiredReqUserId(), roomProfile.getUserId(), cmd.getRoomId());
} else {
// 房主自己上麦
updateDailyTask(cmd, RoomDailyTaskCode.ROOM_OWNER_MIC_TIME);
@ -146,11 +149,41 @@ public class TeamMemberHeartbeatCmdExe {
System.out.println(ZonedDateTimeAsiaRiyadhUtils.nowDateToInt());
}
private boolean isOneselfRoom(AppRoomIdCmd cmd) {
RoomProfile roomProfile = roomProfileManagerService.getProfileById(cmd.getRoomId());
// 房间不存在
ResponseAssert.notNull(RoomErrorCode.ROOM_NOT_EXISTS, roomProfile);
return Objects.equals(roomProfile.getUserId(), cmd.requiredReqUserId());
/**
* 统计用户在房间的麦位时长到达30/60/120分钟时更新房主任务进度
*/
private void updateRoomMicUserDurationTask(Long userId, Long roomOwnerId, Long roomId) {
String redisKey = "room:daily:task:mic_duration:" + roomId + ":" + userId + ":" + ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate();
Long minutes = redisService.increment(redisKey, 1);
redisService.expire(redisKey, DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(), TimeUnit.SECONDS);
// 30分钟 Set 去重统计
updateMicUserCountTask(roomOwnerId, roomId, userId, minutes, 30, RoomDailyTaskCode.ROOM_MIC_USER_30MIN);
updateMicUserCountTask(roomOwnerId, roomId, userId, minutes, 60, RoomDailyTaskCode.ROOM_MIC_USER_60MIN);
updateMicUserCountTask(roomOwnerId, roomId, userId, minutes, 120, RoomDailyTaskCode.ROOM_MIC_USER_120MIN);
}
/**
* 达到指定时长閾値时将用户加入成功人数 Set更新房主进度
*/
private void updateMicUserCountTask(Long roomOwnerId, Long roomId, Long userId, Long minutes, int threshold, RoomDailyTaskCode taskCode) {
if (minutes < threshold) {
return;
}
String setKey = "room:daily:task:mic_users:" + taskCode.name() + ":" + roomId + ":" + ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate();
Long added = redisService.setAdd(setKey, userId);
redisService.expire(setKey, DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(), TimeUnit.SECONDS);
// 新增才更新进度避免重复刷入
if (!Long.valueOf(1L).equals(added)) {
return;
}
long uniqueCount = redisService.setSize(setKey);
roomDailyTaskProgressService.updateTaskProgress(
new RoomDailyTaskProgressUpdateCmd()
.setUserId(roomOwnerId)
.setTaskCode(taskCode.name())
.setProgressValue((int) uniqueCount)
);
}
}

View File

@ -171,6 +171,10 @@ public class TaskListener implements MessageListener {
try {
int micTime = Integer.parseInt(micTimeStr);
if (micTime > 90) {
return;
}
// 处理上麦30分钟任务
spinsUserTaskProgressService.updateTaskProgress(
new SpinsTaskProgressUpdateCmd()