From 19adf21dfd03441130befd9ae85281cd727e4020 Mon Sep 17 00:00:00 2001 From: hy001 Date: Fri, 24 Apr 2026 12:39:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=20other=20=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=E6=88=BF=E9=97=B4=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98,=E4=BB=A5=E5=8F=8A=E6=B8=B8?= =?UTF-8?q?=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../room/query/RoomVoiceDiscoverQryExe.java | 56 +++-- .../room/query/SearchRegionRoomQryExe.java | 33 +-- .../sys/query/GameListConfigQryExe.java | 12 +- .../common/room/RoomRegionFilterCommon.java | 7 + .../query/RoomVoiceDiscoverQryExeTest.java | 81 +++++++ .../query/SearchRegionRoomQryExeTest.java | 52 +++++ .../entity/game/BaishunProviderConfig.java | 6 + .../BaishunProviderConfigServiceImpl.java | 6 + .../service/sys/GameListConfigService.java | 13 +- .../sys/impl/GameListConfigServiceImpl.java | 207 ++++++++++++------ .../gateway/user/UserRegionGatewayImpl.java | 3 +- .../user/UserRegionGatewayImplTest.java | 36 ++- 12 files changed, 400 insertions(+), 112 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 656375f7..781d2df0 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 @@ -73,11 +73,12 @@ public class RoomVoiceDiscoverQryExe { private static final int DISCOVERY_LIMIT = 50; public List execute(AppExtCommand cmd) { + boolean allRegionWhiteListUser = roomRegionFilterCommon.canViewAllRegions(cmd.requiredReqUserId()); RegionConfig currentRegion = roomRegionFilterCommon.requireRegionConfig(cmd.requiredReqUserId()); String region = currentRegion.getRegionCode(); UserProfile userProfile = userProfileGateway.getByUserId(cmd.requiredReqUserId()); - String key = cmd.requireReqSysOrigin() + region; + String key = discoveryCacheKey(cmd.requireReqSysOrigin(), region, allRegionWhiteListUser); String regionsRoom = regionRoomCacheService.getRegionsRoom(key); if (Objects.nonNull(regionsRoom)) { List roomList = JSON.parseArray(regionsRoom, RoomVoiceProfileCO.class); @@ -92,20 +93,32 @@ public class RoomVoiceDiscoverQryExe { return availableRooms; } - List activeVoiceRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion( - activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), region, DISCOVERY_LIMIT), - region - ); + List activeVoiceRooms = allRegionWhiteListUser + ? activeVoiceRoomService.listDiscover( + cmd.requireReqSysOrigin(), + true, + region, + Optional.ofNullable(userProfile).map(UserProfile::getCountryCode).orElse(null), + DISCOVERY_LIMIT + ) + : roomRegionFilterCommon.filterActiveVoiceRoomsByRegion( + activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), region, DISCOVERY_LIMIT), + region + ); // 查询没人的房间缓存,加入进去 List emptyRooms = getEmptyRoomsFromCache(); if (CollectionUtils.isNotEmpty(emptyRooms)) { - List matchedEmptyRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion( - emptyRooms.stream() + List matchedEmptyRooms = allRegionWhiteListUser + ? emptyRooms.stream() .filter(room -> Objects.equals(cmd.requireReqSysOrigin(), room.getSysOrigin())) - .toList(), - region - ); + .toList() + : roomRegionFilterCommon.filterActiveVoiceRoomsByRegion( + emptyRooms.stream() + .filter(room -> Objects.equals(cmd.requireReqSysOrigin(), room.getSysOrigin())) + .toList(), + region + ); if (CollectionUtils.isNotEmpty(matchedEmptyRooms)) { List allRooms = new ArrayList<>(activeVoiceRooms); Set existingRoomIds = activeVoiceRooms.stream() @@ -119,15 +132,18 @@ public class RoomVoiceDiscoverQryExe { } List roomList = roomVoiceProfileCommon.toListRoomVoiceProfileCO(activeVoiceRooms); if (roomList.size() < DISCOVERY_LIMIT) { - List fallbackRoomManagers = roomRegionFilterCommon.filterRoomProfileManagersByRegion( - roomProfileManagerService.listSelectiveLimitByCountryCodes( - cmd.requireReqSysOrigin(), - roomRegionFilterCommon.listCountryCodes(currentRegion), - roomList.stream().map(RoomVoiceProfileCO::getId).toList(), - DISCOVERY_LIMIT - ), - region + List fallbackRoomManagersSource = roomProfileManagerService.listSelectiveLimitByCountryCodes( + cmd.requireReqSysOrigin(), + allRegionWhiteListUser ? List.of() : roomRegionFilterCommon.listCountryCodes(currentRegion), + roomList.stream().map(RoomVoiceProfileCO::getId).toList(), + DISCOVERY_LIMIT ); + List fallbackRoomManagers = allRegionWhiteListUser + ? fallbackRoomManagersSource + : roomRegionFilterCommon.filterRoomProfileManagersByRegion( + fallbackRoomManagersSource, + region + ); roomList = mergeRoomList(roomList, roomVoiceProfileCommon.listRoomVoiceProfilesV2(fallbackRoomManagers), DISCOVERY_LIMIT); } @@ -152,6 +168,10 @@ public class RoomVoiceDiscoverQryExe { return roomList; } + private String discoveryCacheKey(String sysOrigin, String region, boolean allRegionWhiteListUser) { + return allRegionWhiteListUser ? sysOrigin + region + ":ALL_REGION" : sysOrigin + region; + } + private List mergeRoomList(List currentRooms, List fallbackRooms, int limit) { if (CollectionUtils.isEmpty(fallbackRooms)) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/SearchRegionRoomQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/SearchRegionRoomQryExe.java index 5d2fc29b..a19445d0 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/SearchRegionRoomQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/SearchRegionRoomQryExe.java @@ -32,28 +32,35 @@ public class SearchRegionRoomQryExe { private final RoomProfileManagerService roomProfileManagerService; public List execute(RegionSearchRoomQryCmd cmd) { + boolean allRegionWhiteListUser = roomRegionFilterCommon.canViewAllRegions(cmd.requiredReqUserId()); RegionConfig currentRegion = roomRegionFilterCommon.requireRegionConfig(cmd.requiredReqUserId()); String currentRegionCode = currentRegion.getRegionCode(); - List activeVoiceRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion( - activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), currentRegionCode, - PageConstant.MAX_LIMIT_SIZE), - currentRegionCode - ); + List activeVoiceRooms = allRegionWhiteListUser + ? activeVoiceRoomService.listDiscover(cmd.requireReqSysOrigin(), true, currentRegionCode, null, + PageConstant.MAX_LIMIT_SIZE) + : roomRegionFilterCommon.filterActiveVoiceRoomsByRegion( + activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), currentRegionCode, + PageConstant.MAX_LIMIT_SIZE), + currentRegionCode + ); if (CollectionUtils.isNotEmpty(activeVoiceRooms) && activeVoiceRooms.size() >= 100) { return assemblyRoomVoiceProfile(activeVoiceRooms); } - List fallbackRoomManagers = roomRegionFilterCommon.filterRoomProfileManagersByRegion( - roomProfileManagerService.listSelectiveLimitByCountryCodes( - cmd.requireReqSysOrigin(), - roomRegionFilterCommon.listCountryCodes(currentRegion), - activeVoiceRooms.stream().map(ActiveVoiceRoom::getId).collect(Collectors.toList()), - PageConstant.MAX_LIMIT_SIZE - ), - currentRegionCode + List fallbackRoomManagersSource = roomProfileManagerService.listSelectiveLimitByCountryCodes( + cmd.requireReqSysOrigin(), + allRegionWhiteListUser ? List.of() : roomRegionFilterCommon.listCountryCodes(currentRegion), + activeVoiceRooms.stream().map(ActiveVoiceRoom::getId).collect(Collectors.toList()), + PageConstant.MAX_LIMIT_SIZE ); + List fallbackRoomManagers = allRegionWhiteListUser + ? fallbackRoomManagersSource + : roomRegionFilterCommon.filterRoomProfileManagersByRegion( + fallbackRoomManagersSource, + currentRegionCode + ); if (CollectionUtils.isEmpty(activeVoiceRooms)) { return roomVoiceProfileCommon.listRoomVoiceProfilesV2(fallbackRoomManagers); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/sys/query/GameListConfigQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/sys/query/GameListConfigQryExe.java index 7957edca..9fefde0d 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/sys/query/GameListConfigQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/sys/query/GameListConfigQryExe.java @@ -144,11 +144,13 @@ public class GameListConfigQryExe { return getGameListConfigs(cmd); } - private List getGameListConfigs(GameListQryCmd cmd) { - - String data = gameListCacheService.listCache(cmd.requireReqSysOrigin(),String.valueOf(cmd.getCategory()), - sysOrigin -> JacksonUtils.toJson(sysConfigAppConvertor.toListGameListConfigCO( - gameListConfigService.listShowcaseConfig(cmd.requireReqSysOrigin(), cmd.getCategory(), cmd.getRoomSessionId()))), cmd.getReqAppIntel().getVersion()); + private List getGameListConfigs(GameListQryCmd cmd) { + + String activeBaishunProfile = gameListConfigService.getActiveBaishunProfile(cmd.requireReqSysOrigin()); + String cacheCategory = String.valueOf(cmd.getCategory()) + ":BAISHUN:" + activeBaishunProfile; + String data = gameListCacheService.listCache(cmd.requireReqSysOrigin(), cacheCategory, + sysOrigin -> JacksonUtils.toJson(sysConfigAppConvertor.toListGameListConfigCO( + gameListConfigService.listShowcaseConfig(cmd.requireReqSysOrigin(), cmd.getCategory(), cmd.getRoomSessionId()))), cmd.getReqAppIntel().getVersion()); if (StringUtils.isBlank(data)) { return Lists.newArrayList(); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/room/RoomRegionFilterCommon.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/room/RoomRegionFilterCommon.java index 32cda572..46715811 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/room/RoomRegionFilterCommon.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/room/RoomRegionFilterCommon.java @@ -23,8 +23,15 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class RoomRegionFilterCommon { + // account 1001041 + private static final Set ALL_REGION_ROOM_WHITELIST_USER_IDS = Set.of(2044700023064686594L); + private final UserRegionGateway userRegionGateway; + public boolean canViewAllRegions(Long userId) { + return Objects.nonNull(userId) && ALL_REGION_ROOM_WHITELIST_USER_IDS.contains(userId); + } + public RegionConfig requireRegionConfig(Long userId) { RegionConfig regionConfig = userRegionGateway.getRegionConfigByUserId(userId); if (Objects.nonNull(regionConfig) && StringUtils.isNotBlank(regionConfig.getRegionCode())) { diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExeTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExeTest.java index 2eaf4016..ac9a34d1 100644 --- a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExeTest.java +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExeTest.java @@ -37,6 +37,8 @@ import org.springframework.data.redis.core.RedisTemplate; class RoomVoiceDiscoverQryExeTest { + private static final long ALL_REGION_WHITE_USER_ID = 2044700023064686594L; + @Test void execute_shouldIgnoreAllRegionAndOnlyReturnCurrentRegionRooms() { UserSVipGateway userSVipGateway = mock(UserSVipGateway.class); @@ -119,4 +121,83 @@ class RoomVoiceDiscoverQryExeTest { verify(activeVoiceRoomService).listByRegion("YOLO", "AE", 50); verify(activeVoiceRoomService, never()).listDiscover("YOLO", true, "AE", null, 50); } + + @Test + void execute_shouldReturnAllRegionRoomsForWhiteListUser() { + UserSVipGateway userSVipGateway = mock(UserSVipGateway.class); + UserRegionGateway userRegionGateway = mock(UserRegionGateway.class); + RoomRegionFilterCommon roomRegionFilterCommon = mock(RoomRegionFilterCommon.class); + RoomVoiceProfileCommon roomVoiceProfileCommon = mock(RoomVoiceProfileCommon.class); + ActiveVoiceRoomService activeVoiceRoomService = mock(ActiveVoiceRoomService.class); + RoomUserBlacklistService roomUserBlacklistService = mock(RoomUserBlacklistService.class); + LatestMobileDeviceService latestMobileDeviceService = mock(LatestMobileDeviceService.class); + RoomProfileManagerService roomProfileManagerService = mock(RoomProfileManagerService.class); + RegionRoomCacheService regionRoomCacheService = mock(RegionRoomCacheService.class); + LiveMicClient liveMicClient = mock(LiveMicClient.class); + RedisTemplate redisTemplate = mock(RedisTemplate.class); + RocketStatusCacheService rocketStatusCacheService = mock(RocketStatusCacheService.class); + GameLudoService gameLudoService = mock(GameLudoService.class); + UserProfileGateway userProfileGateway = mock(UserProfileGateway.class); + CountryCodeAliasSupport countryCodeAliasSupport = mock(CountryCodeAliasSupport.class); + RoomVoiceDiscoverQryExe exe = new RoomVoiceDiscoverQryExe( + userSVipGateway, + userRegionGateway, + roomRegionFilterCommon, + roomVoiceProfileCommon, + activeVoiceRoomService, + roomUserBlacklistService, + latestMobileDeviceService, + roomProfileManagerService, + regionRoomCacheService, + liveMicClient, + redisTemplate, + rocketStatusCacheService, + gameLudoService, + userProfileGateway, + countryCodeAliasSupport + ); + + AppExtCommand cmd = new AppExtCommand(); + cmd.setReqUserId(ALL_REGION_WHITE_USER_ID); + cmd.setReqSysOrigin(ReqSysOrigin.of("YOLO", "YOLO")); + + RegionConfig currentRegion = new RegionConfig().setRegionCode("AE").setCountryCodes("AE,SA"); + UserProfile userProfile = new UserProfile().setCountryCode("AE"); + ActiveVoiceRoom activeVoiceRoom = new ActiveVoiceRoom().setId(101L).setUserId(201L); + RoomProfileManager fallbackRoomManager = new RoomProfileManager(); + fallbackRoomManager.setId(102L); + fallbackRoomManager.setUserId(202L); + + RoomVoiceProfileCO activeRoomCo = new RoomVoiceProfileCO().setId(101L).setUserId(201L); + RoomVoiceProfileCO fallbackRoomCo = new RoomVoiceProfileCO().setId(102L).setUserId(202L); + + when(roomRegionFilterCommon.canViewAllRegions(ALL_REGION_WHITE_USER_ID)).thenReturn(true); + when(roomRegionFilterCommon.requireRegionConfig(ALL_REGION_WHITE_USER_ID)).thenReturn(currentRegion); + when(userProfileGateway.getByUserId(ALL_REGION_WHITE_USER_ID)).thenReturn(userProfile); + when(regionRoomCacheService.getRegionsRoom("YOLOAE:ALL_REGION")).thenReturn(null); + when(activeVoiceRoomService.listDiscover("YOLO", true, "AE", "AE", 50)) + .thenReturn(List.of(activeVoiceRoom)); + when(redisTemplate.keys("empty_room_cache:*")).thenReturn(Set.of()); + when(roomVoiceProfileCommon.toListRoomVoiceProfileCO(List.of(activeVoiceRoom))).thenReturn( + List.of(activeRoomCo) + ); + when(roomProfileManagerService.listSelectiveLimitByCountryCodes( + "YOLO", List.of(), List.of(101L), 50 + )).thenReturn(List.of(fallbackRoomManager)); + when(roomVoiceProfileCommon.listRoomVoiceProfilesV2(List.of(fallbackRoomManager))).thenReturn( + List.of(fallbackRoomCo) + ); + when(userSVipGateway.checkSVipIdentity(anySet())).thenReturn( + Map.of(201L, SVIPLevelEnum.NONE, 202L, SVIPLevelEnum.NONE) + ); + when(rocketStatusCacheService.batchGetRocketStatus(List.of(101L, 102L))).thenReturn(Map.of()); + when(gameLudoService.listGameCoverByRoomIds(List.of(101L, 102L))).thenReturn(Map.of()); + + List roomList = exe.execute(cmd); + + assertEquals(List.of(activeRoomCo, fallbackRoomCo), roomList); + verify(activeVoiceRoomService, never()).listByRegion("YOLO", "AE", 50); + verify(roomRegionFilterCommon, never()).filterActiveVoiceRoomsByRegion(List.of(activeVoiceRoom), "AE"); + verify(roomRegionFilterCommon, never()).filterRoomProfileManagersByRegion(List.of(fallbackRoomManager), "AE"); + } } diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/room/query/SearchRegionRoomQryExeTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/room/query/SearchRegionRoomQryExeTest.java index 28fdc812..56b7e836 100644 --- a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/room/query/SearchRegionRoomQryExeTest.java +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/room/query/SearchRegionRoomQryExeTest.java @@ -2,6 +2,8 @@ package com.red.circle.other.app.command.room.query; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.red.circle.framework.core.dto.ReqSysOrigin; @@ -20,6 +22,8 @@ import org.junit.jupiter.api.Test; class SearchRegionRoomQryExeTest { + private static final long ALL_REGION_WHITE_USER_ID = 2044700023064686594L; + @Test void execute_shouldUseCurrentUserRegionInsteadOfCountryCode() { ActiveVoiceRoomService activeVoiceRoomService = mock(ActiveVoiceRoomService.class); @@ -71,4 +75,52 @@ class SearchRegionRoomQryExeTest { assertEquals(List.of(activeRoomCo, fallbackRoomCo), roomList); } + + @Test + void execute_shouldReturnAllRegionRoomsForWhiteListUser() { + ActiveVoiceRoomService activeVoiceRoomService = mock(ActiveVoiceRoomService.class); + RoomRegionFilterCommon roomRegionFilterCommon = mock(RoomRegionFilterCommon.class); + RoomVoiceProfileCommon roomVoiceProfileCommon = mock(RoomVoiceProfileCommon.class); + RoomProfileManagerService roomProfileManagerService = mock(RoomProfileManagerService.class); + SearchRegionRoomQryExe exe = new SearchRegionRoomQryExe( + activeVoiceRoomService, + roomRegionFilterCommon, + roomVoiceProfileCommon, + roomProfileManagerService + ); + + RegionSearchRoomQryCmd cmd = new RegionSearchRoomQryCmd(); + cmd.setReqUserId(ALL_REGION_WHITE_USER_ID); + cmd.setReqSysOrigin(ReqSysOrigin.of("YOLO", "YOLO")); + + RegionConfig currentRegion = new RegionConfig().setRegionCode("AE").setCountryCodes("AE,SA"); + ActiveVoiceRoom activeVoiceRoom = new ActiveVoiceRoom().setId(101L).setUserId(201L); + RoomProfileManager fallbackRoomManager = new RoomProfileManager(); + fallbackRoomManager.setId(102L); + fallbackRoomManager.setUserId(202L); + + RoomVoiceProfileCO activeRoomCo = new RoomVoiceProfileCO().setId(101L).setUserId(201L); + RoomVoiceProfileCO fallbackRoomCo = new RoomVoiceProfileCO().setId(102L).setUserId(202L); + + when(roomRegionFilterCommon.canViewAllRegions(ALL_REGION_WHITE_USER_ID)).thenReturn(true); + when(roomRegionFilterCommon.requireRegionConfig(ALL_REGION_WHITE_USER_ID)).thenReturn(currentRegion); + when(activeVoiceRoomService.listDiscover("YOLO", true, "AE", null, PageConstant.MAX_LIMIT_SIZE)) + .thenReturn(List.of(activeVoiceRoom)); + when(roomProfileManagerService.listSelectiveLimitByCountryCodes( + "YOLO", List.of(), List.of(101L), PageConstant.MAX_LIMIT_SIZE + )).thenReturn(List.of(fallbackRoomManager)); + when(roomVoiceProfileCommon.toListRoomVoiceProfileCO(List.of(activeVoiceRoom))).thenReturn( + List.of(activeRoomCo) + ); + when(roomVoiceProfileCommon.listRoomVoiceProfilesV2(List.of(fallbackRoomManager))).thenReturn( + List.of(fallbackRoomCo) + ); + + List roomList = exe.execute(cmd); + + assertEquals(List.of(activeRoomCo, fallbackRoomCo), roomList); + verify(activeVoiceRoomService, never()).listByRegion("YOLO", "AE", PageConstant.MAX_LIMIT_SIZE); + verify(roomRegionFilterCommon, never()).filterActiveVoiceRoomsByRegion(List.of(activeVoiceRoom), "AE"); + verify(roomRegionFilterCommon, never()).filterRoomProfileManagersByRegion(List.of(fallbackRoomManager), "AE"); + } } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/game/BaishunProviderConfig.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/game/BaishunProviderConfig.java index e88dd233..b4db4c44 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/game/BaishunProviderConfig.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/game/BaishunProviderConfig.java @@ -28,6 +28,12 @@ public class BaishunProviderConfig extends TimestampBaseEntity { @TableField("sys_origin") private String sysOrigin; + @TableField("profile") + private String profile; + + @TableField("active") + private Boolean active; + @TableField("platform_base_url") private String platformBaseUrl; diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/game/impl/BaishunProviderConfigServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/game/impl/BaishunProviderConfigServiceImpl.java index b3de5155..2d9fb6a7 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/game/impl/BaishunProviderConfigServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/game/impl/BaishunProviderConfigServiceImpl.java @@ -25,6 +25,8 @@ public class BaishunProviderConfigServiceImpl } return query() .eq(BaishunProviderConfig::getSysOrigin, sysOrigin) + .eq(BaishunProviderConfig::getActive, true) + .orderByDesc(BaishunProviderConfig::getUpdateTime) .last(PageConstant.LIMIT_ONE) .getOne(); } @@ -36,6 +38,8 @@ public class BaishunProviderConfigServiceImpl } return query() .eq(BaishunProviderConfig::getAppId, appId) + .orderByDesc(BaishunProviderConfig::getActive) + .orderByDesc(BaishunProviderConfig::getUpdateTime) .last(PageConstant.LIMIT_ONE) .getOne(); } @@ -51,6 +55,8 @@ public class BaishunProviderConfigServiceImpl return query() .eq(BaishunProviderConfig::getAppId, appId) .eq(BaishunProviderConfig::getAppChannel, appChannel) + .orderByDesc(BaishunProviderConfig::getActive) + .orderByDesc(BaishunProviderConfig::getUpdateTime) .last(PageConstant.LIMIT_ONE) .getOne(); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/GameListConfigService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/GameListConfigService.java index 7492debe..a8a7ef14 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/GameListConfigService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/GameListConfigService.java @@ -32,10 +32,15 @@ public interface GameListConfigService extends BaseService { */ String getCoverByGameId(String gameId, String gameOrigin, String sysOrigin); - /** - * 分页列表. - */ - PageResult pageQuery(SysGameListQryCmd query); + /** + * 分页列表. + */ + PageResult pageQuery(SysGameListQryCmd query); + + /** + * 获取百顺当前启用的配置档案. + */ + String getActiveBaishunProfile(String sysOrigin); /** * 查询游戏信息 diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/impl/GameListConfigServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/impl/GameListConfigServiceImpl.java index 02d579cd..3b04fd78 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/impl/GameListConfigServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/sys/impl/GameListConfigServiceImpl.java @@ -1,19 +1,21 @@ package com.red.circle.other.infra.database.rds.service.sys.impl; import com.red.circle.framework.dto.PageResult; -import com.red.circle.framework.mybatis.constant.PageConstant; -import com.red.circle.framework.mybatis.entity.TimestampBaseEntity; -import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl; -import com.red.circle.other.infra.database.rds.dao.sys.GameListConfigDAO; -import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig; -import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService; -import com.red.circle.other.inner.model.cmd.sys.SysGameListQryCmd; -import com.red.circle.tool.core.collection.CollectionUtils; -import com.red.circle.tool.core.text.StringUtils; - -import java.util.*; - -import org.springframework.stereotype.Service; +import com.red.circle.framework.mybatis.constant.PageConstant; +import com.red.circle.framework.mybatis.entity.TimestampBaseEntity; +import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl; +import com.red.circle.other.infra.database.rds.dao.sys.GameListConfigDAO; +import com.red.circle.other.infra.database.rds.entity.game.BaishunProviderConfig; +import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig; +import com.red.circle.other.infra.database.rds.service.game.BaishunProviderConfigService; +import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService; +import com.red.circle.other.inner.model.cmd.sys.SysGameListQryCmd; +import com.red.circle.tool.core.collection.CollectionUtils; +import com.red.circle.tool.core.text.StringUtils; + +import java.util.*; + +import org.springframework.stereotype.Service; /** *

@@ -21,22 +23,57 @@ import org.springframework.stereotype.Service; *

* * @author pengshigang - * @since 2022-06-10 - */ -@Service -public class GameListConfigServiceImpl extends - BaseServiceImpl implements GameListConfigService { - - @Override - public List listShowcaseConfig(String sysOrigin, String category, String roomId) { - return query() - .eq(GameListConfig::getSysOrigin, sysOrigin) - .eq(StringUtils.isNotBlank(category), GameListConfig::getCategory, category) - .ne(StringUtils.isBlank(roomId), GameListConfig::getCategory, "HIDDEN") - .eq(GameListConfig::getShowcase, Boolean.TRUE) - .orderByDesc(TimestampBaseEntity::getCreateTime, GameListConfig::getSort) - .list(); - } + * @since 2022-06-10 + */ +@Service +public class GameListConfigServiceImpl extends + BaseServiceImpl implements GameListConfigService { + + private static final String BAISHUN_GAME_ORIGIN = "BAISHUN"; + private static final String BAISHUN_PROFILE_PROD = "PROD"; + private static final String BAISHUN_ACTIVE_PROFILE_EXISTS_SQL = """ + EXISTS ( + SELECT 1 + FROM sys_game_list_vendor_ext ext + WHERE ext.game_list_config_id = sys_game_list_config.id + AND ext.sys_origin = sys_game_list_config.sys_origin + AND ext.vendor_type = 'BAISHUN' + AND ext.enabled = 1 + AND ext.profile = COALESCE(( + SELECT provider.profile + FROM baishun_provider_config provider + WHERE provider.sys_origin = sys_game_list_config.sys_origin + AND provider.active = 1 + ORDER BY provider.update_time DESC + LIMIT 1 + ), 'PROD') + ) + """; + private static final String BAISHUN_ACTIVE_PROFILE_FILTER_SQL = """ + ( + game_origin IS NULL + OR game_origin <> 'BAISHUN' + OR %s + ) + """.formatted(BAISHUN_ACTIVE_PROFILE_EXISTS_SQL); + + private final BaishunProviderConfigService baishunProviderConfigService; + + public GameListConfigServiceImpl(BaishunProviderConfigService baishunProviderConfigService) { + this.baishunProviderConfigService = baishunProviderConfigService; + } + + @Override + public List listShowcaseConfig(String sysOrigin, String category, String roomId) { + return query() + .eq(GameListConfig::getSysOrigin, sysOrigin) + .eq(StringUtils.isNotBlank(category), GameListConfig::getCategory, category) + .ne(StringUtils.isBlank(roomId), GameListConfig::getCategory, "HIDDEN") + .eq(GameListConfig::getShowcase, Boolean.TRUE) + .apply(BAISHUN_ACTIVE_PROFILE_FILTER_SQL) + .orderByDesc(TimestampBaseEntity::getCreateTime, GameListConfig::getSort) + .list(); + } @Override public String getCoverByGameCode(String gameCode) { @@ -50,13 +87,14 @@ public class GameListConfigServiceImpl extends } @Override - public String getCoverByGameId(String gameId, String gameOrigin, String sysOrigin) { - List gameListConfigs = query() - .select(GameListConfig::getGameCode, GameListConfig::getCover) - .eq(GameListConfig::getGameOrigin, gameOrigin) - .eq(GameListConfig::getSysOrigin, sysOrigin) - .eq(GameListConfig::getShowcase, Boolean.TRUE) - .list(); + public String getCoverByGameId(String gameId, String gameOrigin, String sysOrigin) { + List gameListConfigs = query() + .select(GameListConfig::getGameCode, GameListConfig::getCover) + .eq(GameListConfig::getGameOrigin, gameOrigin) + .eq(GameListConfig::getSysOrigin, sysOrigin) + .eq(GameListConfig::getShowcase, Boolean.TRUE) + .apply(isBaishunGameOrigin(gameOrigin), BAISHUN_ACTIVE_PROFILE_EXISTS_SQL) + .list(); if (CollectionUtils.isEmpty(gameListConfigs)) { return ""; } @@ -93,41 +131,55 @@ public class GameListConfigServiceImpl extends } @Override - public PageResult pageQuery(SysGameListQryCmd query) { - return query() - .eq(StringUtils.isNotBlank(query.getSysOrigin()), GameListConfig::getSysOrigin, - query.getSysOrigin()) - .eq(Objects.nonNull(query.getShowcase()), GameListConfig::getShowcase, query.getShowcase()) - .eq(StringUtils.isNotBlank(query.getGameOrigin()), GameListConfig::getGameOrigin, - query.getGameOrigin()) - .like(StringUtils.isNotBlank(query.getRegion()), GameListConfig::getRegions, - query.getRegion()) - .orderByDesc(GameListConfig::getSort) - .page(query.getPageQuery()); - } - - - @Override - public GameListConfig getByGameCode(String gameCode, String sysOrigin) { - return query() - .eq(GameListConfig::getGameCode, gameCode) - .eq(GameListConfig::getSysOrigin, sysOrigin) - .last(PageConstant.LIMIT_ONE) - .getOne(); - } + public PageResult pageQuery(SysGameListQryCmd query) { + return query() + .eq(StringUtils.isNotBlank(query.getSysOrigin()), GameListConfig::getSysOrigin, + query.getSysOrigin()) + .eq(Objects.nonNull(query.getShowcase()), GameListConfig::getShowcase, query.getShowcase()) + .eq(StringUtils.isNotBlank(query.getGameOrigin()), GameListConfig::getGameOrigin, + query.getGameOrigin()) + .like(StringUtils.isNotBlank(query.getRegion()), GameListConfig::getRegions, + query.getRegion()) + .apply(BAISHUN_ACTIVE_PROFILE_FILTER_SQL) + .orderByDesc(GameListConfig::getSort) + .page(query.getPageQuery()); + } + + @Override + public String getActiveBaishunProfile(String sysOrigin) { + if (StringUtils.isBlank(sysOrigin)) { + return BAISHUN_PROFILE_PROD; + } + BaishunProviderConfig config = baishunProviderConfigService.getBySysOrigin(sysOrigin); + if (Objects.isNull(config) || StringUtils.isBlank(config.getProfile())) { + return BAISHUN_PROFILE_PROD; + } + return normalizeBaishunProfile(config.getProfile()); + } + + @Override + public GameListConfig getByGameCode(String gameCode, String sysOrigin) { + return query() + .eq(GameListConfig::getGameCode, gameCode) + .eq(GameListConfig::getSysOrigin, sysOrigin) + .apply(BAISHUN_ACTIVE_PROFILE_FILTER_SQL) + .last(PageConstant.LIMIT_ONE) + .getOne(); + } /** * @param gameId 1345 */ @Override - public GameListConfig getByGameId(String gameId, String gameOrigin, String sysOrigin) { - return query() - .eq(GameListConfig::getGameId, gameId) - .eq(GameListConfig::getGameOrigin, gameOrigin) - .eq(GameListConfig::getSysOrigin, sysOrigin) - .last(PageConstant.LIMIT_ONE) - .getOne(); - } + public GameListConfig getByGameId(String gameId, String gameOrigin, String sysOrigin) { + return query() + .eq(GameListConfig::getGameId, gameId) + .eq(GameListConfig::getGameOrigin, gameOrigin) + .eq(GameListConfig::getSysOrigin, sysOrigin) + .apply(isBaishunGameOrigin(gameOrigin), BAISHUN_ACTIVE_PROFILE_EXISTS_SQL) + .last(PageConstant.LIMIT_ONE) + .getOne(); + } @Override public Boolean checkGameUnshelve(Set gameIds) { @@ -136,6 +188,23 @@ public class GameListConfigServiceImpl extends .last(PageConstant.formatLimit(gameIds.size())) .list()) .map(list -> list.stream().anyMatch(item -> item.getShowcase() == Boolean.FALSE)) - .orElse(Boolean.FALSE); - } -} + .orElse(Boolean.FALSE); + } + + private boolean isBaishunGameOrigin(String gameOrigin) { + return StringUtils.isNotBlank(gameOrigin) + && BAISHUN_GAME_ORIGIN.equalsIgnoreCase(gameOrigin.trim()); + } + + private String normalizeBaishunProfile(String profile) { + if (StringUtils.isBlank(profile)) { + return BAISHUN_PROFILE_PROD; + } + String value = profile.trim().toUpperCase(Locale.ROOT); + return switch (value) { + case "PRODUCT", "PRODUCTION", "ONLINE", "OFFICIAL", "FORMAL" -> BAISHUN_PROFILE_PROD; + case "TESTING", "SANDBOX", "DEV" -> "TEST"; + default -> value; + }; + } +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRegionGatewayImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRegionGatewayImpl.java index 9f8901a8..2d4a43b2 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRegionGatewayImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRegionGatewayImpl.java @@ -131,8 +131,7 @@ public class UserRegionGatewayImpl implements UserRegionGateway { // 1. 主播代理团队区域 List userTeamRegions = listUserTeamRegion(userIds); - if (CollectionUtils.isNotEmpty(userTeamRegions) - && Objects.equals(userTeamRegions.size(), userIds.size())) { + if (CollectionUtils.isNotEmpty(userTeamRegions)) { Map regionConfigMap = sysRegionConfigService.mapAvailable( userTeamRegions.stream().map(UserTeamRegionDTO::getRegionId).collect(Collectors.toSet()) diff --git a/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/gateway/user/UserRegionGatewayImplTest.java b/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/gateway/user/UserRegionGatewayImplTest.java index 17e30844..b2d20b15 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/gateway/user/UserRegionGatewayImplTest.java +++ b/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/gateway/user/UserRegionGatewayImplTest.java @@ -14,11 +14,14 @@ import com.red.circle.other.infra.common.sys.CountryCodeAliasSupport; import com.red.circle.other.infra.convertor.user.UserRegionInfraConvertor; import com.red.circle.other.infra.database.cache.service.user.SysRegionCacheService; import com.red.circle.other.infra.database.cache.service.user.UserRegionCacheService; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; +import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile; import com.red.circle.other.infra.database.mongo.entity.user.region.SysRegionConfig; import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService; import com.red.circle.other.infra.database.mongo.service.user.region.SysRegionAssistConfigService; import com.red.circle.other.infra.database.mongo.service.user.region.SysRegionConfigService; +import com.red.circle.other.inner.enums.team.TeamMemberRole; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -29,7 +32,11 @@ import org.junit.jupiter.api.Test; class UserRegionGatewayImplTest { private static final long USER_ID = 2047206645188063233L; + private static final long TEAM_USER_ID = 2045561213676482561L; + private static final long TEAM_ID = 2046067036517363714L; private static final String SYS_ORIGIN = "LIKEI"; + private static final String TEAM_REGION_ID = "middle-east-region"; + private static final String TEAM_REGION_CODE = "中东区"; private TeamMemberService teamMemberService; private TeamProfileService teamProfileService; @@ -37,6 +44,7 @@ class UserRegionGatewayImplTest { private SysRegionCacheService sysRegionCacheService; private SysRegionConfigService sysRegionConfigService; private UserRegionInfraConvertor userRegionInfraConvertor; + private CountryCodeAliasSupport countryCodeAliasSupport; private UserRegionGatewayImpl userRegionGateway; @BeforeEach @@ -49,7 +57,7 @@ class UserRegionGatewayImplTest { userRegionInfraConvertor = mock(UserRegionInfraConvertor.class); SysRegionAssistConfigService sysRegionAssistConfigService = mock(SysRegionAssistConfigService.class); UserRegionCacheService userRegionCacheService = mock(UserRegionCacheService.class); - CountryCodeAliasSupport countryCodeAliasSupport = mock(CountryCodeAliasSupport.class); + countryCodeAliasSupport = mock(CountryCodeAliasSupport.class); userRegionGateway = new UserRegionGatewayImpl( teamMemberService, @@ -100,6 +108,32 @@ class UserRegionGatewayImplTest { verify(userProfileGateway, never()).getLanguage(USER_ID); } + @Test + void mapRegionCode_shouldPreferTeamRegionForNonTouristUsersInMixedBatch() { + when(teamMemberService.listByMemberIds(Set.of(USER_ID, TEAM_USER_ID))).thenReturn(List.of( + new TeamMember() + .setMemberId(TEAM_USER_ID) + .setTeamId(TEAM_ID) + .setSysOrigin(SYS_ORIGIN) + .setRole(TeamMemberRole.OWN) + )); + when(teamProfileService.mapProfileByIds(Set.of(TEAM_ID))).thenReturn(Map.of( + TEAM_ID, + new TeamProfile().setId(TEAM_ID).setRegion(TEAM_REGION_ID) + )); + when(sysRegionConfigService.mapAvailable(Set.of(TEAM_REGION_ID))).thenReturn(Map.of( + TEAM_REGION_ID, + new SysRegionConfig().setId(TEAM_REGION_ID).setRegionCode(TEAM_REGION_CODE) + )); + + Map result = userRegionGateway.mapRegionCode(Set.of(USER_ID, TEAM_USER_ID)); + + assertEquals("OTHER", result.get(USER_ID)); + assertEquals(TEAM_REGION_CODE, result.get(TEAM_USER_ID)); + verify(userProfileGateway).listByUserIds(Set.of(USER_ID)); + verify(userProfileGateway, never()).getLanguage(TEAM_USER_ID); + } + private SysRegionConfig region(String regionCode, String countryCodes, String langeCodes) { return new SysRegionConfig() .setId(regionCode)