diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/TeamMemberHeartbeatCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/TeamMemberHeartbeatCmdExe.java index 54b8f24d..ce5d2761 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/TeamMemberHeartbeatCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/TeamMemberHeartbeatCmdExe.java @@ -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) + ); } } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java index c7237575..a3a9eb71 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/task/TaskListener.java @@ -171,6 +171,10 @@ public class TaskListener implements MessageListener { try { int micTime = Integer.parseInt(micTimeStr); + if (micTime > 90) { + return; + } + // 处理上麦30分钟任务 spinsUserTaskProgressService.updateTaskProgress( new SpinsTaskProgressUpdateCmd()