From 2eee9254babc11b28d0faa3d3fbc300bd26ad805 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 4 Mar 2026 20:36:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E9=97=B4=E9=87=91=E5=B8=81=E5=A4=A7?= =?UTF-8?q?=E6=94=BE=E9=80=81-=E6=96=B0=E5=A2=9E=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E6=97=B6=E9=95=BF=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/TeamMemberHeartbeatCmdExe.java | 45 ++++++++++++++++--- .../other/app/listener/task/TaskListener.java | 4 ++ 2 files changed, 43 insertions(+), 6 deletions(-) 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()