diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java index 3c6527b2..c082a30b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomEnterCmdExe.java @@ -92,10 +92,6 @@ public class RoomEnterCmdExe { private final TaskMqMessage taskMqMessage; private final AdministratorAuthService administratorAuthService; private final RocketRewardClaimCmdExe rocketRewardClaimCmdExe; - private final RoomDailyTaskProgressService roomDailyTaskProgressService; - private final RedisService redisService; - private final RedisTemplate redisTemplate; - private final RoomMemberService roomMemberService; public EntryRoomResponseCO execute(RoomEntryCmd cmd) { //checkEntryUserId(cmd); @@ -138,9 +134,6 @@ public class RoomEnterCmdExe { log.error("进房间添加足迹异常:{}", e.getMessage()); } - // 房间每日任务 - updateRoomDailyTask(cmd.getReqUserId(), manager.getUserId(), manager.getId()); - return new EntryRoomResponseCO() .setRoomProfile( new EntryRoomProfileCO() @@ -165,43 +158,6 @@ public class RoomEnterCmdExe { ); } - private void updateRoomDailyTask(Long enterUserId, Long roomOwnerId, Long roomId) { - // 只处理用户进入非自己房间的情况 - if (Objects.equals(enterUserId, roomOwnerId)) { - return; - } - RoomMember roomMember = roomMemberService.getRoomMember(roomId, enterUserId); - if (Objects.isNull(roomMember)) { - return; - } - String createDate = roomMember.getCreateTime().toLocalDateTime().toLocalDate().toString(); - String todayDate = ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate().toString(); - if (!createDate.equals(todayDate)) { - return; - } - - try { - // Redis 去重:同一用户当天进入同一房间只计一次 - String redisKey = "room:daily:task:new_member:" + roomOwnerId + ":" + ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate(); - Long added = redisTemplate.opsForSet().add(redisKey, enterUserId); - redisService.expire(redisKey, DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(), TimeUnit.SECONDS); - - if (!Long.valueOf(1L).equals(added)) { - return; - } - - long uniqueCount = redisService.setSize(redisKey); - roomDailyTaskProgressService.updateTaskProgress( - new RoomDailyTaskProgressUpdateCmd() - .setUserId(roomOwnerId) - .setTaskCode(RoomDailyTaskCode.ROOM_NEW_MEMBER.name()) - .setProgressValue((int) uniqueCount) - ); - } catch (Exception e) { - log.error("更新房间每日任务失败, roomOwnerId={}, enterUserId={}", roomOwnerId, enterUserId, e); - } - } - /** * 异步拿声网观众token,5分钟拿不到就返回默认一串字符串 * @param cmd diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomMemberChangeIdentityCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomMemberChangeIdentityCmdExe.java index 77ecfdef..470ce704 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomMemberChangeIdentityCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/RoomMemberChangeIdentityCmdExe.java @@ -9,6 +9,9 @@ import com.red.circle.mq.rocket.business.producer.UserMqMessageService; import com.red.circle.other.app.dto.clientobject.room.ChangeRoleSuccessCO; import com.red.circle.other.app.dto.cmd.room.RoomMemberIdentityCmd; import com.red.circle.other.app.dto.cmd.room.RoomMemberIdentityCmd.RoomChangeRolesReason; +import com.red.circle.other.app.dto.cmd.task.RoomDailyTaskProgressUpdateCmd; +import com.red.circle.other.app.service.task.RoomDailyTaskProgressService; +import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.infra.database.cache.service.other.RoomManagerCacheService; import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile; @@ -21,7 +24,9 @@ import com.red.circle.other.infra.database.rds.service.live.RoomMemberService; import com.red.circle.other.inner.asserts.RoomErrorCode; import com.red.circle.other.inner.enums.live.RoomUserRolesEnum; import com.red.circle.other.inner.enums.material.BadgeKeyEnum; +import com.red.circle.other.inner.enums.task.RoomDailyTaskCode; import com.red.circle.tool.core.date.DateUtils; +import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.json.JacksonUtils; import com.red.circle.tool.core.num.ArithmeticUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; @@ -33,9 +38,12 @@ import com.red.circle.wallet.inner.model.enums.GoldOrigin; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Objects; +import java.util.concurrent.TimeUnit; + import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DuplicateKeyException; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; /** @@ -57,6 +65,8 @@ public class RoomMemberChangeIdentityCmdExe { private final ApiOperationLogService apiOperationLogService; private final RoomManagerCacheService roomManagerCacheService; private final RoomProfileManagerService roomProfileManagerService; + private final RoomDailyTaskProgressService roomDailyTaskProgressService; + private final RedisTemplate redisTemplate; public ChangeRoleSuccessCO execute(RoomMemberIdentityCmd cmd) { apiOperationLogService.add( @@ -210,6 +220,48 @@ public class RoomMemberChangeIdentityCmdExe { } incrQuantity(cmd.getRoomId(), cmd.getRoles()); + + // 房间每日任务 + RoomProfileManager manager = roomProfileManagerService.getById(cmd.getRoomId()); + updateRoomDailyTask(cmd.getReqUserId(), manager.getUserId(), manager.getId()); + + } + + private void updateRoomDailyTask(Long enterUserId, Long roomOwnerId, Long roomId) { + // 只处理用户进入非自己房间的情况 + if (Objects.equals(enterUserId, roomOwnerId)) { + return; + } + RoomMember roomMember = roomMemberService.getRoomMember(roomId, enterUserId); + if (Objects.isNull(roomMember)) { + return; + } + String createDate = roomMember.getCreateTime().toLocalDateTime().toLocalDate().toString(); + String todayDate = ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate().toString(); + if (!createDate.equals(todayDate)) { + return; + } + + try { + // Redis 去重:同一用户当天进入同一房间只计一次 + String redisKey = "room:daily:task:new_member:" + roomOwnerId + ":" + ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate(); + Long added = redisTemplate.opsForSet().add(redisKey, enterUserId); + redisService.expire(redisKey, DateTimeAsiaRiyadhUtils.getSecondsUntilMidnight(), TimeUnit.SECONDS); + + if (!Long.valueOf(1L).equals(added)) { + return; + } + + long uniqueCount = redisService.setSize(redisKey); + roomDailyTaskProgressService.updateTaskProgress( + new RoomDailyTaskProgressUpdateCmd() + .setUserId(roomOwnerId) + .setTaskCode(RoomDailyTaskCode.ROOM_NEW_MEMBER.name()) + .setProgressValue((int) uniqueCount) + ); + } catch (Exception e) { + log.error("更新房间每日任务失败, roomOwnerId={}, enterUserId={}", roomOwnerId, enterUserId, e); + } } private void executeChangeTourist(RoomMember roomMember) {