From 6a1385fc99b43ef3384e45f6128a95414ffaebe3 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 20 Mar 2026 12:19:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=97=E4=BA=9A=E5=8C=BA=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../room/query/RoomVoiceDiscoverQryExe.java | 19 ++++++++++--------- .../app/scheduler/EmptyRoomCleanTask.java | 2 +- .../service/live/ActiveVoiceRoomService.java | 2 +- .../live/impl/ActiveVoiceRoomServiceImpl.java | 6 +++++- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExe.java index 3c444724..a0c05d32 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExe.java @@ -10,8 +10,10 @@ import com.red.circle.other.app.common.room.RoomVoiceProfileCommon; import com.red.circle.other.app.dto.clientobject.room.RoomVoiceProfileCO; import com.red.circle.other.app.service.game.GameLudoService; import com.red.circle.other.app.service.room.RocketStatusCacheService; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; import com.red.circle.other.domain.gateway.user.ability.UserSVipGateway; +import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.domain.rocket.RocketStatus; import com.red.circle.other.infra.database.cache.service.user.RegionRoomCacheService; import com.red.circle.other.infra.database.mongo.entity.live.ActiveVoiceRoom; @@ -60,6 +62,7 @@ public class RoomVoiceDiscoverQryExe { private final RedisTemplate redisTemplate; private final RocketStatusCacheService rocketStatusCacheService; private final GameLudoService gameLudoService; + private final UserProfileGateway userProfileGateway; private static final String EMPTY_ROOM_CACHE_KEY = "empty_room_cache:*"; @@ -71,6 +74,7 @@ public class RoomVoiceDiscoverQryExe { public List execute(AppExtCommand cmd) { String region = cmd.isAllRegion() ? "ALL" : userRegionGateway.getRegionCode(cmd.requiredReqUserId()); + UserProfile userProfile = userProfileGateway.getByUserId(cmd.requiredReqUserId()); String key = cmd.requireReqSysOrigin() + region; String regionsRoom = regionRoomCacheService.getRegionsRoom(key); @@ -79,28 +83,24 @@ public class RoomVoiceDiscoverQryExe { return roomList; } - List activeVoiceRooms = activeVoiceRoomService.listDiscover(cmd.requireReqSysOrigin(), cmd.isAllRegion(), region, 50); + String userCountryCode = userProfile != null ? userProfile.getCountryCode() : null; + List activeVoiceRooms = activeVoiceRoomService.listDiscover(cmd.requireReqSysOrigin(), cmd.isAllRegion(), region, userCountryCode, 50); // 查询没人的房间缓存,加入进去 List emptyRooms = getEmptyRoomsFromCache(); if (CollectionUtils.isNotEmpty(emptyRooms)) { - // 按照listDiscover的过滤规则过滤空房间 - List matchedEmptyRooms = filterEmptyRoomsByRegion(emptyRooms, cmd.requireReqSysOrigin(), cmd.isAllRegion(), region); + List matchedEmptyRooms = filterEmptyRoomsByRegion(emptyRooms, cmd.requireReqSysOrigin(), cmd.isAllRegion(), region, userCountryCode); if (CollectionUtils.isNotEmpty(matchedEmptyRooms)) { - // 创建新的可修改列表,合并活跃房间和空房间,并去重 List allRooms = new ArrayList<>(activeVoiceRooms); - // 获取已存在的房间ID Set existingRoomIds = activeVoiceRooms.stream() .map(ActiveVoiceRoom::getId) .collect(Collectors.toSet()); - // 只添加不存在的空房间 matchedEmptyRooms.stream() .filter(room -> !existingRoomIds.contains(room.getId())) .forEach(allRooms::add); activeVoiceRooms = allRooms; } } - log.info("activeVoiceRooms:{}", JSON.toJSONString(activeVoiceRooms)); List roomList = roomVoiceProfileCommon.toListRoomVoiceProfileCO(activeVoiceRooms); if (CollectionUtils.isEmpty(roomList)) { @@ -249,10 +249,11 @@ public class RoomVoiceDiscoverQryExe { } } - private List filterEmptyRoomsByRegion(List emptyRooms, String sysOrigin, boolean isAllRegion, String region) { + private List filterEmptyRoomsByRegion(List emptyRooms, String sysOrigin, boolean isAllRegion, String region, String userCountryCode) { return emptyRooms.stream() .filter(room -> Objects.equals(sysOrigin, room.getSysOrigin()) && - (isAllRegion || shouldShowRoom(region, room.getRegion()))) + (isAllRegion || shouldShowRoom(region, room.getRegion())) && + (!SA_REGIONS.contains(region) || userCountryCode == null || userCountryCode.equals(room.getCountryCode()))) .collect(Collectors.toList()); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/EmptyRoomCleanTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/EmptyRoomCleanTask.java index bdb8901a..55101958 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/EmptyRoomCleanTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/EmptyRoomCleanTask.java @@ -37,7 +37,7 @@ public class EmptyRoomCleanTask { public void cleanEmptyRooms() { try { // 获取所有活跃房间 - List allRooms = activeVoiceRoomService.listDiscover(SysOriginPlatformEnum.LIKEI.name(),true,"",200); + List allRooms = activeVoiceRoomService.listDiscover(SysOriginPlatformEnum.LIKEI.name(),true,"",null,200); if (CollectionUtils.isEmpty(allRooms)) { return; } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/live/ActiveVoiceRoomService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/live/ActiveVoiceRoomService.java index 02a2878c..5d5383d4 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/live/ActiveVoiceRoomService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/live/ActiveVoiceRoomService.java @@ -65,7 +65,7 @@ public interface ActiveVoiceRoomService { /** * 获取发现页数据. */ - List listDiscover(String sysOrigin, boolean isAllRegion, String region, Integer limit); + List listDiscover(String sysOrigin, boolean isAllRegion, String region, String countryCode, Integer limit); /** * 获取区域房间. diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/live/impl/ActiveVoiceRoomServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/live/impl/ActiveVoiceRoomServiceImpl.java index 0e4ce78b..b8a8d413 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/live/impl/ActiveVoiceRoomServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/live/impl/ActiveVoiceRoomServiceImpl.java @@ -133,7 +133,7 @@ public class ActiveVoiceRoomServiceImpl implements ActiveVoiceRoomService { @Override - public List listDiscover(String sysOrigin, boolean isAllRegion, String region, Integer limit) { + public List listDiscover(String sysOrigin, boolean isAllRegion, String region, String countryCode, Integer limit) { // 区域隔离 Set userRegionGroup = getRegionGroup(region); Set excludeRegions = userRegionGroup == null ? ALL_SPECIAL_REGIONS : getExcludeRegionsForGroup(userRegionGroup); @@ -148,6 +148,10 @@ public class ActiveVoiceRoomServiceImpl implements ActiveVoiceRoomService { if (userRegionGroup == null && !isAllRegion) { criteria.and("region").nin(excludeRegions); } + // SA_REGIONS 用户只能看到相同国家的房间 + if (SA_REGIONS.contains(region) && !isAllRegion && StringUtils.isNotBlank(countryCode)) { + criteria.and("countryCode").is(countryCode); + } Aggregation aggregation = Aggregation.newAggregation( // 1. 匹配国家(可选条件) Aggregation.match(criteria),