From c7a650ce7f85c22e8cf50c2b0268582ade4c5d6d Mon Sep 17 00:00:00 2001 From: ZuoZuo <68836346+Mrz-sakura@users.noreply.github.com> Date: Sat, 2 May 2026 02:23:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E4=BF=9D=E6=B4=BB=E5=92=8C?= =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmd/user/account/CreateAccountCmd.java | 45 +++++++------ .../domain/constant/ActiveSecondConstant.java | 21 +++--- .../live/domain/live/LiveMicrophone.java | 12 ++-- .../live/domain/online/LiveRoomUser.java | 12 ++-- .../impl/LiveMicUserCacheServiceImpl.java | 20 +++--- .../user/OnlineStatusUploadListener.java | 24 +++---- .../status/impl/OnlineUserServiceImpl.java | 66 +++++++++++-------- 7 files changed, 113 insertions(+), 87 deletions(-) diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/user/account/CreateAccountCmd.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/user/account/CreateAccountCmd.java index 146d1ef2..2445d64e 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/user/account/CreateAccountCmd.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/user/account/CreateAccountCmd.java @@ -1,12 +1,12 @@ package com.red.circle.other.inner.model.cmd.user.account; -import com.red.circle.common.business.dto.cmd.AppExtCommand; -import com.red.circle.framework.core.asserts.ResponseAssert; -import com.red.circle.framework.core.response.ResponseErrorCode; -import com.red.circle.tool.core.text.StringUtils; -import com.red.circle.other.inner.model.cmd.user.UserProfileCmd; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.framework.core.response.ResponseErrorCode; +import com.red.circle.other.inner.enums.user.AuthTypeEnum; +import com.red.circle.other.inner.model.cmd.user.UserProfileCmd; +import com.red.circle.tool.core.text.StringUtils; +import jakarta.validation.constraints.NotNull; import java.util.Objects; import lombok.Data; import lombok.EqualsAndHashCode; @@ -30,11 +30,10 @@ public class CreateAccountCmd extends AppExtCommand { */ private String invitationCode; - /** - * 注册类型:MOBILE、FACEBOOK、GOOGLE、APPLE、Snapchat. - */ - @NotBlank(message = "type required.") - private String type; + /** + * 注册类型:MOBILE、FACEBOOK、GOOGLE、APPLE、Snapchat. + */ + private String type = AuthTypeEnum.GOOGLE.name(); /** * 开放id. @@ -70,13 +69,21 @@ public class CreateAccountCmd extends AppExtCommand { return profile.getUserNickname(); } - public String profileAvatar() { - return profile.getUserAvatar(); - } - - public boolean checkTypeMobile() { - return Objects.equals(type, "MOBILE"); - } + public String profileAvatar() { + return profile.getUserAvatar(); + } + + public String getType() { + return StringUtils.isBlank(type) ? AuthTypeEnum.GOOGLE.name() : type; + } + + public void setType(String type) { + this.type = StringUtils.isBlank(type) ? AuthTypeEnum.GOOGLE.name() : type; + } + + public boolean checkTypeMobile() { + return Objects.equals(getType(), AuthTypeEnum.MOBILE.name()); + } public boolean checkChina() { if (Objects.equals(invitePeople, "CY1101")) { diff --git a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/constant/ActiveSecondConstant.java b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/constant/ActiveSecondConstant.java index 7e6f309c..8f550831 100644 --- a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/constant/ActiveSecondConstant.java +++ b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/constant/ActiveSecondConstant.java @@ -3,11 +3,16 @@ package com.red.circle.live.domain.constant; /** * @author pengliang on 2023/12/12 */ -public interface ActiveSecondConstant { - - /** - * 心跳60s一次, 预留30s异常等待. - */ - int EXPIRATION_SECOND = 120; - -} +public interface ActiveSecondConstant { + + /** + * 房间在线用户保活时间. + */ + int ROOM_USER_EXPIRATION_SECOND = 5 * 60; + + /** + * 麦位活跃保活时间. + */ + int MIC_EXPIRATION_SECOND = 120; + +} diff --git a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/LiveMicrophone.java b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/LiveMicrophone.java index 787a2799..70a1b080 100644 --- a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/LiveMicrophone.java +++ b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/live/LiveMicrophone.java @@ -49,9 +49,9 @@ public class LiveMicrophone implements Serializable { /** * 是否活跃. */ - public boolean checkInactiveExpire() { - long intervalTime = (System.currentTimeMillis() - this.refreshTime) / 1000; - return intervalTime >= ActiveSecondConstant.EXPIRATION_SECOND; - } - -} + public boolean checkInactiveExpire() { + long intervalTime = (System.currentTimeMillis() - this.refreshTime) / 1000; + return intervalTime >= ActiveSecondConstant.MIC_EXPIRATION_SECOND; + } + +} diff --git a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/online/LiveRoomUser.java b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/online/LiveRoomUser.java index 6f97b71b..91ddbf37 100644 --- a/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/online/LiveRoomUser.java +++ b/rc-service/rc-service-live/live-domain/src/main/java/com/red/circle/live/domain/online/LiveRoomUser.java @@ -48,9 +48,9 @@ public class LiveRoomUser implements Serializable { /** * 是否活跃. */ - public boolean checkInactiveExpire() { - long intervalTime = (System.currentTimeMillis() - this.refreshTime) / 1000; - return intervalTime > ActiveSecondConstant.EXPIRATION_SECOND; - } - -} + public boolean checkInactiveExpire() { + long intervalTime = (System.currentTimeMillis() - this.refreshTime) / 1000; + return intervalTime > ActiveSecondConstant.ROOM_USER_EXPIRATION_SECOND; + } + +} diff --git a/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/database/cache/service/impl/LiveMicUserCacheServiceImpl.java b/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/database/cache/service/impl/LiveMicUserCacheServiceImpl.java index a35e7e41..5bb15a01 100644 --- a/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/database/cache/service/impl/LiveMicUserCacheServiceImpl.java +++ b/rc-service/rc-service-live/live-infrastructure/src/main/java/com/red/circle/live/infra/database/cache/service/impl/LiveMicUserCacheServiceImpl.java @@ -1,8 +1,9 @@ package com.red.circle.live.infra.database.cache.service.impl; -import com.red.circle.component.redis.service.RedisService; -import com.red.circle.live.domain.online.LiveRoomUser; -import com.red.circle.live.domain.online.LiveRoomUserRefresh; +import com.red.circle.component.redis.service.RedisService; +import com.red.circle.live.domain.constant.ActiveSecondConstant; +import com.red.circle.live.domain.online.LiveRoomUser; +import com.red.circle.live.domain.online.LiveRoomUserRefresh; import com.red.circle.live.infra.database.cache.key.LiveMicUserKey; import com.red.circle.live.infra.database.cache.service.LiveMicUserCacheService; import com.red.circle.tool.core.collection.CollectionUtils; @@ -47,8 +48,8 @@ public class LiveMicUserCacheServiceImpl implements LiveMicUserCacheService { if (Objects.nonNull(user)) { redisService.hashPut(LiveMicUserKey.ROOM.getKey(roomId), Objects.toString(user.getUserId()), user); - //放入redis key IN_ROOM:userId v 是roomId 是 放1分钟30秒每次来了都刷新过期时间 - redisService.setString("IN_ROOM:" + user.getUserId(), roomId, 90, TimeUnit.SECONDS); + redisService.setString("IN_ROOM:" + user.getUserId(), roomId, + ActiveSecondConstant.ROOM_USER_EXPIRATION_SECOND, TimeUnit.SECONDS); } return new LiveRoomUserRefresh() @@ -95,7 +96,8 @@ public class LiveMicUserCacheServiceImpl implements LiveMicUserCacheService { } private void setExpire(Long roomId) { - redisService.expire(LiveMicUserKey.ROOM.getKey(roomId), 90, TimeUnit.SECONDS); - } - -} + redisService.expire(LiveMicUserKey.ROOM.getKey(roomId), + ActiveSecondConstant.ROOM_USER_EXPIRATION_SECOND, TimeUnit.SECONDS); + } + +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/OnlineStatusUploadListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/OnlineStatusUploadListener.java index 8f6c691c..f72cadc5 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/OnlineStatusUploadListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/OnlineStatusUploadListener.java @@ -40,9 +40,11 @@ import org.apache.commons.lang3.StringUtils; @Slf4j @RocketMqMessageListener(groupId = OnlineStatusUploadSink.INPUT, tag = OnlineStatusUploadSink.TAG) @RequiredArgsConstructor -public class OnlineStatusUploadListener implements MessageListener { - - private final ExpandService expandService; +public class OnlineStatusUploadListener implements MessageListener { + + private static final int ONLINE_EXPIRE_SECONDS = 5 * 60; + + private final ExpandService expandService; private final UserSVipGateway userSVipGateway; private final WalletGoldClient walletGoldClient; private final UserRegionGateway userRegionGateway; @@ -134,14 +136,14 @@ public class OnlineStatusUploadListener implements MessageListener { .setRegionCode(Optional.ofNullable( userRegionGateway.getUserRegion(userProfile.getId()) ).map(UserRegionDTO::getRegionCode).orElse("OTHER")) - .setStatus(StringUtils.isNotBlank(event.getStatus()) - ? UserOnlineStatusEnum.valueOf(event.getStatus()) - : UserOnlineStatusEnum.IDLE) - .setWeights(onlineStatusCommon.getWeights(userProfile.getId())) - .setExpiredTime(TimestampUtils.nowPlusSeconds(90)) - .setCreateTime(TimestampUtils.now()) - .setSessionId(DataTypeUtils.toLong(event.getSessionId())) - .setSvipLevel(userSVipGateway.checkSVipIdentity(userProfile.getId()))); + .setStatus(StringUtils.isNotBlank(event.getStatus()) + ? UserOnlineStatusEnum.valueOf(event.getStatus()) + : UserOnlineStatusEnum.IDLE) + .setWeights(onlineStatusCommon.getWeights(userProfile.getId())) + .setExpiredTime(TimestampUtils.nowPlusSeconds(ONLINE_EXPIRE_SECONDS)) + .setCreateTime(TimestampUtils.now()) + .setSessionId(DataTypeUtils.toLong(event.getSessionId())) + .setSvipLevel(userSVipGateway.checkSVipIdentity(userProfile.getId()))); } } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/status/impl/OnlineUserServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/status/impl/OnlineUserServiceImpl.java index 02b0e2f4..01703379 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/status/impl/OnlineUserServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/status/impl/OnlineUserServiceImpl.java @@ -39,18 +39,23 @@ public class OnlineUserServiceImpl implements OnlineUserService { private final MongoTemplate mongoTemplate; - @Override - public boolean exists(Long sessionId, Long userId) { - return mongoTemplate.exists(Query.query(Criteria.where("sessionId").is(sessionId) - .and("id").is(userId)), OnlineUser.class); - } - - @Override - public String getSessionId(Long userId) { - Criteria criteria = Criteria.where("id").is(userId); - return Optional.ofNullable(mongoTemplate.findOne(Query.query(criteria), OnlineUser.class)) - .map(OnlineUser::getSessionId) - .map(Objects::toString) + @Override + public boolean exists(Long sessionId, Long userId) { + return mongoTemplate.exists(Query.query(Criteria.where("sessionId").is(sessionId) + .and("id").is(userId) + .and("status").is(UserOnlineStatusEnum.LANGUAGE_HALL) + .and("expiredTime").gte(TimestampUtils.now())), OnlineUser.class); + } + + @Override + public String getSessionId(Long userId) { + Criteria criteria = Criteria.where("id").is(userId) + .and("status").is(UserOnlineStatusEnum.LANGUAGE_HALL) + .and("sessionId").gt(0) + .and("expiredTime").gte(TimestampUtils.now()); + return Optional.ofNullable(mongoTemplate.findOne(Query.query(criteria), OnlineUser.class)) + .map(OnlineUser::getSessionId) + .map(Objects::toString) .orElse(null); } @@ -202,10 +207,11 @@ public class OnlineUserServiceImpl implements OnlineUserService { // } @Override - public List flowSessionOnlineUser(String sessionId, UserOnlineStatusEnum status, - Long lastTimingId) { - Criteria criteria = Criteria.where("sessionId").is(Long.parseLong(sessionId)) - .and("status").is(status); + public List flowSessionOnlineUser(String sessionId, UserOnlineStatusEnum status, + Long lastTimingId) { + Criteria criteria = Criteria.where("sessionId").is(Long.parseLong(sessionId)) + .and("status").is(status) + .and("expiredTime").gte(TimestampUtils.now()); if (Objects.nonNull(lastTimingId)) { criteria.and("timingId").gt(lastTimingId); @@ -227,10 +233,12 @@ public class OnlineUserServiceImpl implements OnlineUserService { } @Override - public Long countSessionId(Long sessionId) { - return mongoTemplate.count(Query.query(Criteria.where("sessionId").is(sessionId)), - OnlineUser.class); - } + public Long countSessionId(Long sessionId) { + return mongoTemplate.count(Query.query(Criteria.where("sessionId").is(sessionId) + .and("status").is(UserOnlineStatusEnum.LANGUAGE_HALL) + .and("expiredTime").gte(TimestampUtils.now())), + OnlineUser.class); + } @Override public void removeByUserId(Long userId) { @@ -272,9 +280,10 @@ public class OnlineUserServiceImpl implements OnlineUserService { } @Override - public List flowLanguageHallTop200(Long roomId, Long lastTimingId) { - Criteria criteria = Criteria.where("sessionId").is(roomId) - .and("status").is(UserOnlineStatusEnum.LANGUAGE_HALL); + public List flowLanguageHallTop200(Long roomId, Long lastTimingId) { + Criteria criteria = Criteria.where("sessionId").is(roomId) + .and("status").is(UserOnlineStatusEnum.LANGUAGE_HALL) + .and("expiredTime").gte(TimestampUtils.now()); if (Objects.nonNull(lastTimingId)) { criteria.and("timingId").gt(lastTimingId); @@ -347,11 +356,12 @@ public class OnlineUserServiceImpl implements OnlineUserService { } @Override - public List flowLanguageHallByRoomId(Long roomId) { - Criteria criteria = Criteria.where("sessionId").is(roomId) - .and("status").is(UserOnlineStatusEnum.LANGUAGE_HALL); - return mongoTemplate.find(Query.query(criteria) - .with(Sort.by(Sort.Order.asc("timingId"))) + public List flowLanguageHallByRoomId(Long roomId) { + Criteria criteria = Criteria.where("sessionId").is(roomId) + .and("status").is(UserOnlineStatusEnum.LANGUAGE_HALL) + .and("expiredTime").gte(TimestampUtils.now()); + return mongoTemplate.find(Query.query(criteria) + .with(Sort.by(Sort.Order.asc("timingId"))) .limit(5), OnlineUser.class); }