修复了 other 区域房间列表显示的问题,以及游戏

This commit is contained in:
hy001 2026-04-24 12:39:15 +08:00
parent 13d5fbe41e
commit 19adf21dfd
12 changed files with 400 additions and 112 deletions

View File

@ -73,11 +73,12 @@ public class RoomVoiceDiscoverQryExe {
private static final int DISCOVERY_LIMIT = 50;
public List<RoomVoiceProfileCO> 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<RoomVoiceProfileCO> roomList = JSON.parseArray(regionsRoom, RoomVoiceProfileCO.class);
@ -92,20 +93,32 @@ public class RoomVoiceDiscoverQryExe {
return availableRooms;
}
List<ActiveVoiceRoom> activeVoiceRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion(
activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), region, DISCOVERY_LIMIT),
region
);
List<ActiveVoiceRoom> 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<ActiveVoiceRoom> emptyRooms = getEmptyRoomsFromCache();
if (CollectionUtils.isNotEmpty(emptyRooms)) {
List<ActiveVoiceRoom> matchedEmptyRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion(
emptyRooms.stream()
List<ActiveVoiceRoom> 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<ActiveVoiceRoom> allRooms = new ArrayList<>(activeVoiceRooms);
Set<Long> existingRoomIds = activeVoiceRooms.stream()
@ -119,15 +132,18 @@ public class RoomVoiceDiscoverQryExe {
}
List<RoomVoiceProfileCO> roomList = roomVoiceProfileCommon.toListRoomVoiceProfileCO(activeVoiceRooms);
if (roomList.size() < DISCOVERY_LIMIT) {
List<RoomProfileManager> fallbackRoomManagers = roomRegionFilterCommon.filterRoomProfileManagersByRegion(
roomProfileManagerService.listSelectiveLimitByCountryCodes(
cmd.requireReqSysOrigin(),
roomRegionFilterCommon.listCountryCodes(currentRegion),
roomList.stream().map(RoomVoiceProfileCO::getId).toList(),
DISCOVERY_LIMIT
),
region
List<RoomProfileManager> fallbackRoomManagersSource = roomProfileManagerService.listSelectiveLimitByCountryCodes(
cmd.requireReqSysOrigin(),
allRegionWhiteListUser ? List.of() : roomRegionFilterCommon.listCountryCodes(currentRegion),
roomList.stream().map(RoomVoiceProfileCO::getId).toList(),
DISCOVERY_LIMIT
);
List<RoomProfileManager> 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<RoomVoiceProfileCO> mergeRoomList(List<RoomVoiceProfileCO> currentRooms,
List<RoomVoiceProfileCO> fallbackRooms, int limit) {
if (CollectionUtils.isEmpty(fallbackRooms)) {

View File

@ -32,28 +32,35 @@ public class SearchRegionRoomQryExe {
private final RoomProfileManagerService roomProfileManagerService;
public List<RoomVoiceProfileCO> execute(RegionSearchRoomQryCmd cmd) {
boolean allRegionWhiteListUser = roomRegionFilterCommon.canViewAllRegions(cmd.requiredReqUserId());
RegionConfig currentRegion = roomRegionFilterCommon.requireRegionConfig(cmd.requiredReqUserId());
String currentRegionCode = currentRegion.getRegionCode();
List<ActiveVoiceRoom> activeVoiceRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion(
activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), currentRegionCode,
PageConstant.MAX_LIMIT_SIZE),
currentRegionCode
);
List<ActiveVoiceRoom> 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<RoomProfileManager> fallbackRoomManagers = roomRegionFilterCommon.filterRoomProfileManagersByRegion(
roomProfileManagerService.listSelectiveLimitByCountryCodes(
cmd.requireReqSysOrigin(),
roomRegionFilterCommon.listCountryCodes(currentRegion),
activeVoiceRooms.stream().map(ActiveVoiceRoom::getId).collect(Collectors.toList()),
PageConstant.MAX_LIMIT_SIZE
),
currentRegionCode
List<RoomProfileManager> fallbackRoomManagersSource = roomProfileManagerService.listSelectiveLimitByCountryCodes(
cmd.requireReqSysOrigin(),
allRegionWhiteListUser ? List.of() : roomRegionFilterCommon.listCountryCodes(currentRegion),
activeVoiceRooms.stream().map(ActiveVoiceRoom::getId).collect(Collectors.toList()),
PageConstant.MAX_LIMIT_SIZE
);
List<RoomProfileManager> fallbackRoomManagers = allRegionWhiteListUser
? fallbackRoomManagersSource
: roomRegionFilterCommon.filterRoomProfileManagersByRegion(
fallbackRoomManagersSource,
currentRegionCode
);
if (CollectionUtils.isEmpty(activeVoiceRooms)) {
return roomVoiceProfileCommon.listRoomVoiceProfilesV2(fallbackRoomManagers);

View File

@ -144,11 +144,13 @@ public class GameListConfigQryExe {
return getGameListConfigs(cmd);
}
private List<GameListConfigCO> 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<GameListConfigCO> 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();

View File

@ -23,8 +23,15 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class RoomRegionFilterCommon {
// account 1001041
private static final Set<Long> 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())) {

View File

@ -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<String, Object> 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<RoomVoiceProfileCO> 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");
}
}

View File

@ -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<RoomVoiceProfileCO> 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");
}
}

View File

@ -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;

View File

@ -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();
}

View File

@ -32,10 +32,15 @@ public interface GameListConfigService extends BaseService<GameListConfig> {
*/
String getCoverByGameId(String gameId, String gameOrigin, String sysOrigin);
/**
* 分页列表.
*/
PageResult<GameListConfig> pageQuery(SysGameListQryCmd query);
/**
* 分页列表.
*/
PageResult<GameListConfig> pageQuery(SysGameListQryCmd query);
/**
* 获取百顺当前启用的配置档案.
*/
String getActiveBaishunProfile(String sysOrigin);
/**
* 查询游戏信息

View File

@ -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;
/**
* <p>
@ -21,22 +23,57 @@ import org.springframework.stereotype.Service;
* </p>
*
* @author pengshigang
* @since 2022-06-10
*/
@Service
public class GameListConfigServiceImpl extends
BaseServiceImpl<GameListConfigDAO, GameListConfig> implements GameListConfigService {
@Override
public List<GameListConfig> 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<GameListConfigDAO, GameListConfig> 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<GameListConfig> 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<GameListConfig> 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<GameListConfig> 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<GameListConfig> 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<GameListConfig> 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<Long> 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;
};
}
}

View File

@ -131,8 +131,7 @@ public class UserRegionGatewayImpl implements UserRegionGateway {
// 1. 主播代理团队区域
List<UserTeamRegionDTO> userTeamRegions = listUserTeamRegion(userIds);
if (CollectionUtils.isNotEmpty(userTeamRegions)
&& Objects.equals(userTeamRegions.size(), userIds.size())) {
if (CollectionUtils.isNotEmpty(userTeamRegions)) {
Map<String, SysRegionConfig> regionConfigMap = sysRegionConfigService.mapAvailable(
userTeamRegions.stream().map(UserTeamRegionDTO::getRegionId).collect(Collectors.toSet())

View File

@ -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<Long, String> 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)