修复了 other 区域房间列表显示的问题,以及游戏
This commit is contained in:
parent
13d5fbe41e
commit
19adf21dfd
@ -73,11 +73,12 @@ public class RoomVoiceDiscoverQryExe {
|
|||||||
private static final int DISCOVERY_LIMIT = 50;
|
private static final int DISCOVERY_LIMIT = 50;
|
||||||
|
|
||||||
public List<RoomVoiceProfileCO> execute(AppExtCommand cmd) {
|
public List<RoomVoiceProfileCO> execute(AppExtCommand cmd) {
|
||||||
|
boolean allRegionWhiteListUser = roomRegionFilterCommon.canViewAllRegions(cmd.requiredReqUserId());
|
||||||
RegionConfig currentRegion = roomRegionFilterCommon.requireRegionConfig(cmd.requiredReqUserId());
|
RegionConfig currentRegion = roomRegionFilterCommon.requireRegionConfig(cmd.requiredReqUserId());
|
||||||
String region = currentRegion.getRegionCode();
|
String region = currentRegion.getRegionCode();
|
||||||
UserProfile userProfile = userProfileGateway.getByUserId(cmd.requiredReqUserId());
|
UserProfile userProfile = userProfileGateway.getByUserId(cmd.requiredReqUserId());
|
||||||
|
|
||||||
String key = cmd.requireReqSysOrigin() + region;
|
String key = discoveryCacheKey(cmd.requireReqSysOrigin(), region, allRegionWhiteListUser);
|
||||||
String regionsRoom = regionRoomCacheService.getRegionsRoom(key);
|
String regionsRoom = regionRoomCacheService.getRegionsRoom(key);
|
||||||
if (Objects.nonNull(regionsRoom)) {
|
if (Objects.nonNull(regionsRoom)) {
|
||||||
List<RoomVoiceProfileCO> roomList = JSON.parseArray(regionsRoom, RoomVoiceProfileCO.class);
|
List<RoomVoiceProfileCO> roomList = JSON.parseArray(regionsRoom, RoomVoiceProfileCO.class);
|
||||||
@ -92,20 +93,32 @@ public class RoomVoiceDiscoverQryExe {
|
|||||||
return availableRooms;
|
return availableRooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ActiveVoiceRoom> activeVoiceRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion(
|
List<ActiveVoiceRoom> activeVoiceRooms = allRegionWhiteListUser
|
||||||
activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), region, DISCOVERY_LIMIT),
|
? activeVoiceRoomService.listDiscover(
|
||||||
region
|
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();
|
List<ActiveVoiceRoom> emptyRooms = getEmptyRoomsFromCache();
|
||||||
if (CollectionUtils.isNotEmpty(emptyRooms)) {
|
if (CollectionUtils.isNotEmpty(emptyRooms)) {
|
||||||
List<ActiveVoiceRoom> matchedEmptyRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion(
|
List<ActiveVoiceRoom> matchedEmptyRooms = allRegionWhiteListUser
|
||||||
emptyRooms.stream()
|
? emptyRooms.stream()
|
||||||
.filter(room -> Objects.equals(cmd.requireReqSysOrigin(), room.getSysOrigin()))
|
.filter(room -> Objects.equals(cmd.requireReqSysOrigin(), room.getSysOrigin()))
|
||||||
.toList(),
|
.toList()
|
||||||
region
|
: roomRegionFilterCommon.filterActiveVoiceRoomsByRegion(
|
||||||
);
|
emptyRooms.stream()
|
||||||
|
.filter(room -> Objects.equals(cmd.requireReqSysOrigin(), room.getSysOrigin()))
|
||||||
|
.toList(),
|
||||||
|
region
|
||||||
|
);
|
||||||
if (CollectionUtils.isNotEmpty(matchedEmptyRooms)) {
|
if (CollectionUtils.isNotEmpty(matchedEmptyRooms)) {
|
||||||
List<ActiveVoiceRoom> allRooms = new ArrayList<>(activeVoiceRooms);
|
List<ActiveVoiceRoom> allRooms = new ArrayList<>(activeVoiceRooms);
|
||||||
Set<Long> existingRoomIds = activeVoiceRooms.stream()
|
Set<Long> existingRoomIds = activeVoiceRooms.stream()
|
||||||
@ -119,15 +132,18 @@ public class RoomVoiceDiscoverQryExe {
|
|||||||
}
|
}
|
||||||
List<RoomVoiceProfileCO> roomList = roomVoiceProfileCommon.toListRoomVoiceProfileCO(activeVoiceRooms);
|
List<RoomVoiceProfileCO> roomList = roomVoiceProfileCommon.toListRoomVoiceProfileCO(activeVoiceRooms);
|
||||||
if (roomList.size() < DISCOVERY_LIMIT) {
|
if (roomList.size() < DISCOVERY_LIMIT) {
|
||||||
List<RoomProfileManager> fallbackRoomManagers = roomRegionFilterCommon.filterRoomProfileManagersByRegion(
|
List<RoomProfileManager> fallbackRoomManagersSource = roomProfileManagerService.listSelectiveLimitByCountryCodes(
|
||||||
roomProfileManagerService.listSelectiveLimitByCountryCodes(
|
cmd.requireReqSysOrigin(),
|
||||||
cmd.requireReqSysOrigin(),
|
allRegionWhiteListUser ? List.of() : roomRegionFilterCommon.listCountryCodes(currentRegion),
|
||||||
roomRegionFilterCommon.listCountryCodes(currentRegion),
|
roomList.stream().map(RoomVoiceProfileCO::getId).toList(),
|
||||||
roomList.stream().map(RoomVoiceProfileCO::getId).toList(),
|
DISCOVERY_LIMIT
|
||||||
DISCOVERY_LIMIT
|
|
||||||
),
|
|
||||||
region
|
|
||||||
);
|
);
|
||||||
|
List<RoomProfileManager> fallbackRoomManagers = allRegionWhiteListUser
|
||||||
|
? fallbackRoomManagersSource
|
||||||
|
: roomRegionFilterCommon.filterRoomProfileManagersByRegion(
|
||||||
|
fallbackRoomManagersSource,
|
||||||
|
region
|
||||||
|
);
|
||||||
roomList = mergeRoomList(roomList, roomVoiceProfileCommon.listRoomVoiceProfilesV2(fallbackRoomManagers),
|
roomList = mergeRoomList(roomList, roomVoiceProfileCommon.listRoomVoiceProfilesV2(fallbackRoomManagers),
|
||||||
DISCOVERY_LIMIT);
|
DISCOVERY_LIMIT);
|
||||||
}
|
}
|
||||||
@ -152,6 +168,10 @@ public class RoomVoiceDiscoverQryExe {
|
|||||||
return roomList;
|
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,
|
private List<RoomVoiceProfileCO> mergeRoomList(List<RoomVoiceProfileCO> currentRooms,
|
||||||
List<RoomVoiceProfileCO> fallbackRooms, int limit) {
|
List<RoomVoiceProfileCO> fallbackRooms, int limit) {
|
||||||
if (CollectionUtils.isEmpty(fallbackRooms)) {
|
if (CollectionUtils.isEmpty(fallbackRooms)) {
|
||||||
|
|||||||
@ -32,28 +32,35 @@ public class SearchRegionRoomQryExe {
|
|||||||
private final RoomProfileManagerService roomProfileManagerService;
|
private final RoomProfileManagerService roomProfileManagerService;
|
||||||
|
|
||||||
public List<RoomVoiceProfileCO> execute(RegionSearchRoomQryCmd cmd) {
|
public List<RoomVoiceProfileCO> execute(RegionSearchRoomQryCmd cmd) {
|
||||||
|
boolean allRegionWhiteListUser = roomRegionFilterCommon.canViewAllRegions(cmd.requiredReqUserId());
|
||||||
RegionConfig currentRegion = roomRegionFilterCommon.requireRegionConfig(cmd.requiredReqUserId());
|
RegionConfig currentRegion = roomRegionFilterCommon.requireRegionConfig(cmd.requiredReqUserId());
|
||||||
String currentRegionCode = currentRegion.getRegionCode();
|
String currentRegionCode = currentRegion.getRegionCode();
|
||||||
|
|
||||||
List<ActiveVoiceRoom> activeVoiceRooms = roomRegionFilterCommon.filterActiveVoiceRoomsByRegion(
|
List<ActiveVoiceRoom> activeVoiceRooms = allRegionWhiteListUser
|
||||||
activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), currentRegionCode,
|
? activeVoiceRoomService.listDiscover(cmd.requireReqSysOrigin(), true, currentRegionCode, null,
|
||||||
PageConstant.MAX_LIMIT_SIZE),
|
PageConstant.MAX_LIMIT_SIZE)
|
||||||
currentRegionCode
|
: roomRegionFilterCommon.filterActiveVoiceRoomsByRegion(
|
||||||
);
|
activeVoiceRoomService.listByRegion(cmd.requireReqSysOrigin(), currentRegionCode,
|
||||||
|
PageConstant.MAX_LIMIT_SIZE),
|
||||||
|
currentRegionCode
|
||||||
|
);
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(activeVoiceRooms) && activeVoiceRooms.size() >= 100) {
|
if (CollectionUtils.isNotEmpty(activeVoiceRooms) && activeVoiceRooms.size() >= 100) {
|
||||||
return assemblyRoomVoiceProfile(activeVoiceRooms);
|
return assemblyRoomVoiceProfile(activeVoiceRooms);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<RoomProfileManager> fallbackRoomManagers = roomRegionFilterCommon.filterRoomProfileManagersByRegion(
|
List<RoomProfileManager> fallbackRoomManagersSource = roomProfileManagerService.listSelectiveLimitByCountryCodes(
|
||||||
roomProfileManagerService.listSelectiveLimitByCountryCodes(
|
cmd.requireReqSysOrigin(),
|
||||||
cmd.requireReqSysOrigin(),
|
allRegionWhiteListUser ? List.of() : roomRegionFilterCommon.listCountryCodes(currentRegion),
|
||||||
roomRegionFilterCommon.listCountryCodes(currentRegion),
|
activeVoiceRooms.stream().map(ActiveVoiceRoom::getId).collect(Collectors.toList()),
|
||||||
activeVoiceRooms.stream().map(ActiveVoiceRoom::getId).collect(Collectors.toList()),
|
PageConstant.MAX_LIMIT_SIZE
|
||||||
PageConstant.MAX_LIMIT_SIZE
|
|
||||||
),
|
|
||||||
currentRegionCode
|
|
||||||
);
|
);
|
||||||
|
List<RoomProfileManager> fallbackRoomManagers = allRegionWhiteListUser
|
||||||
|
? fallbackRoomManagersSource
|
||||||
|
: roomRegionFilterCommon.filterRoomProfileManagersByRegion(
|
||||||
|
fallbackRoomManagersSource,
|
||||||
|
currentRegionCode
|
||||||
|
);
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(activeVoiceRooms)) {
|
if (CollectionUtils.isEmpty(activeVoiceRooms)) {
|
||||||
return roomVoiceProfileCommon.listRoomVoiceProfilesV2(fallbackRoomManagers);
|
return roomVoiceProfileCommon.listRoomVoiceProfilesV2(fallbackRoomManagers);
|
||||||
|
|||||||
@ -144,11 +144,13 @@ public class GameListConfigQryExe {
|
|||||||
return getGameListConfigs(cmd);
|
return getGameListConfigs(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<GameListConfigCO> getGameListConfigs(GameListQryCmd cmd) {
|
private List<GameListConfigCO> getGameListConfigs(GameListQryCmd cmd) {
|
||||||
|
|
||||||
String data = gameListCacheService.listCache(cmd.requireReqSysOrigin(),String.valueOf(cmd.getCategory()),
|
String activeBaishunProfile = gameListConfigService.getActiveBaishunProfile(cmd.requireReqSysOrigin());
|
||||||
sysOrigin -> JacksonUtils.toJson(sysConfigAppConvertor.toListGameListConfigCO(
|
String cacheCategory = String.valueOf(cmd.getCategory()) + ":BAISHUN:" + activeBaishunProfile;
|
||||||
gameListConfigService.listShowcaseConfig(cmd.requireReqSysOrigin(), cmd.getCategory(), cmd.getRoomSessionId()))), cmd.getReqAppIntel().getVersion());
|
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)) {
|
if (StringUtils.isBlank(data)) {
|
||||||
return Lists.newArrayList();
|
return Lists.newArrayList();
|
||||||
|
|||||||
@ -23,8 +23,15 @@ import org.springframework.stereotype.Service;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class RoomRegionFilterCommon {
|
public class RoomRegionFilterCommon {
|
||||||
|
|
||||||
|
// account 1001041
|
||||||
|
private static final Set<Long> ALL_REGION_ROOM_WHITELIST_USER_IDS = Set.of(2044700023064686594L);
|
||||||
|
|
||||||
private final UserRegionGateway userRegionGateway;
|
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) {
|
public RegionConfig requireRegionConfig(Long userId) {
|
||||||
RegionConfig regionConfig = userRegionGateway.getRegionConfigByUserId(userId);
|
RegionConfig regionConfig = userRegionGateway.getRegionConfigByUserId(userId);
|
||||||
if (Objects.nonNull(regionConfig) && StringUtils.isNotBlank(regionConfig.getRegionCode())) {
|
if (Objects.nonNull(regionConfig) && StringUtils.isNotBlank(regionConfig.getRegionCode())) {
|
||||||
|
|||||||
@ -37,6 +37,8 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|||||||
|
|
||||||
class RoomVoiceDiscoverQryExeTest {
|
class RoomVoiceDiscoverQryExeTest {
|
||||||
|
|
||||||
|
private static final long ALL_REGION_WHITE_USER_ID = 2044700023064686594L;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void execute_shouldIgnoreAllRegionAndOnlyReturnCurrentRegionRooms() {
|
void execute_shouldIgnoreAllRegionAndOnlyReturnCurrentRegionRooms() {
|
||||||
UserSVipGateway userSVipGateway = mock(UserSVipGateway.class);
|
UserSVipGateway userSVipGateway = mock(UserSVipGateway.class);
|
||||||
@ -119,4 +121,83 @@ class RoomVoiceDiscoverQryExeTest {
|
|||||||
verify(activeVoiceRoomService).listByRegion("YOLO", "AE", 50);
|
verify(activeVoiceRoomService).listByRegion("YOLO", "AE", 50);
|
||||||
verify(activeVoiceRoomService, never()).listDiscover("YOLO", true, "AE", null, 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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package com.red.circle.other.app.command.room.query;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.mock;
|
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 static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.red.circle.framework.core.dto.ReqSysOrigin;
|
import com.red.circle.framework.core.dto.ReqSysOrigin;
|
||||||
@ -20,6 +22,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
class SearchRegionRoomQryExeTest {
|
class SearchRegionRoomQryExeTest {
|
||||||
|
|
||||||
|
private static final long ALL_REGION_WHITE_USER_ID = 2044700023064686594L;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void execute_shouldUseCurrentUserRegionInsteadOfCountryCode() {
|
void execute_shouldUseCurrentUserRegionInsteadOfCountryCode() {
|
||||||
ActiveVoiceRoomService activeVoiceRoomService = mock(ActiveVoiceRoomService.class);
|
ActiveVoiceRoomService activeVoiceRoomService = mock(ActiveVoiceRoomService.class);
|
||||||
@ -71,4 +75,52 @@ class SearchRegionRoomQryExeTest {
|
|||||||
|
|
||||||
assertEquals(List.of(activeRoomCo, fallbackRoomCo), roomList);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,12 @@ public class BaishunProviderConfig extends TimestampBaseEntity {
|
|||||||
@TableField("sys_origin")
|
@TableField("sys_origin")
|
||||||
private String sysOrigin;
|
private String sysOrigin;
|
||||||
|
|
||||||
|
@TableField("profile")
|
||||||
|
private String profile;
|
||||||
|
|
||||||
|
@TableField("active")
|
||||||
|
private Boolean active;
|
||||||
|
|
||||||
@TableField("platform_base_url")
|
@TableField("platform_base_url")
|
||||||
private String platformBaseUrl;
|
private String platformBaseUrl;
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,8 @@ public class BaishunProviderConfigServiceImpl
|
|||||||
}
|
}
|
||||||
return query()
|
return query()
|
||||||
.eq(BaishunProviderConfig::getSysOrigin, sysOrigin)
|
.eq(BaishunProviderConfig::getSysOrigin, sysOrigin)
|
||||||
|
.eq(BaishunProviderConfig::getActive, true)
|
||||||
|
.orderByDesc(BaishunProviderConfig::getUpdateTime)
|
||||||
.last(PageConstant.LIMIT_ONE)
|
.last(PageConstant.LIMIT_ONE)
|
||||||
.getOne();
|
.getOne();
|
||||||
}
|
}
|
||||||
@ -36,6 +38,8 @@ public class BaishunProviderConfigServiceImpl
|
|||||||
}
|
}
|
||||||
return query()
|
return query()
|
||||||
.eq(BaishunProviderConfig::getAppId, appId)
|
.eq(BaishunProviderConfig::getAppId, appId)
|
||||||
|
.orderByDesc(BaishunProviderConfig::getActive)
|
||||||
|
.orderByDesc(BaishunProviderConfig::getUpdateTime)
|
||||||
.last(PageConstant.LIMIT_ONE)
|
.last(PageConstant.LIMIT_ONE)
|
||||||
.getOne();
|
.getOne();
|
||||||
}
|
}
|
||||||
@ -51,6 +55,8 @@ public class BaishunProviderConfigServiceImpl
|
|||||||
return query()
|
return query()
|
||||||
.eq(BaishunProviderConfig::getAppId, appId)
|
.eq(BaishunProviderConfig::getAppId, appId)
|
||||||
.eq(BaishunProviderConfig::getAppChannel, appChannel)
|
.eq(BaishunProviderConfig::getAppChannel, appChannel)
|
||||||
|
.orderByDesc(BaishunProviderConfig::getActive)
|
||||||
|
.orderByDesc(BaishunProviderConfig::getUpdateTime)
|
||||||
.last(PageConstant.LIMIT_ONE)
|
.last(PageConstant.LIMIT_ONE)
|
||||||
.getOne();
|
.getOne();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,10 +32,15 @@ public interface GameListConfigService extends BaseService<GameListConfig> {
|
|||||||
*/
|
*/
|
||||||
String getCoverByGameId(String gameId, String gameOrigin, String sysOrigin);
|
String getCoverByGameId(String gameId, String gameOrigin, String sysOrigin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表.
|
* 分页列表.
|
||||||
*/
|
*/
|
||||||
PageResult<GameListConfig> pageQuery(SysGameListQryCmd query);
|
PageResult<GameListConfig> pageQuery(SysGameListQryCmd query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取百顺当前启用的配置档案.
|
||||||
|
*/
|
||||||
|
String getActiveBaishunProfile(String sysOrigin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询游戏信息
|
* 查询游戏信息
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
package com.red.circle.other.infra.database.rds.service.sys.impl;
|
package com.red.circle.other.infra.database.rds.service.sys.impl;
|
||||||
|
|
||||||
import com.red.circle.framework.dto.PageResult;
|
import com.red.circle.framework.dto.PageResult;
|
||||||
import com.red.circle.framework.mybatis.constant.PageConstant;
|
import com.red.circle.framework.mybatis.constant.PageConstant;
|
||||||
import com.red.circle.framework.mybatis.entity.TimestampBaseEntity;
|
import com.red.circle.framework.mybatis.entity.TimestampBaseEntity;
|
||||||
import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl;
|
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.dao.sys.GameListConfigDAO;
|
||||||
import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig;
|
import com.red.circle.other.infra.database.rds.entity.game.BaishunProviderConfig;
|
||||||
import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService;
|
import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig;
|
||||||
import com.red.circle.other.inner.model.cmd.sys.SysGameListQryCmd;
|
import com.red.circle.other.infra.database.rds.service.game.BaishunProviderConfigService;
|
||||||
import com.red.circle.tool.core.collection.CollectionUtils;
|
import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService;
|
||||||
import com.red.circle.tool.core.text.StringUtils;
|
import com.red.circle.other.inner.model.cmd.sys.SysGameListQryCmd;
|
||||||
|
import com.red.circle.tool.core.collection.CollectionUtils;
|
||||||
import java.util.*;
|
import com.red.circle.tool.core.text.StringUtils;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -21,22 +23,57 @@ import org.springframework.stereotype.Service;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author pengshigang
|
* @author pengshigang
|
||||||
* @since 2022-06-10
|
* @since 2022-06-10
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class GameListConfigServiceImpl extends
|
public class GameListConfigServiceImpl extends
|
||||||
BaseServiceImpl<GameListConfigDAO, GameListConfig> implements GameListConfigService {
|
BaseServiceImpl<GameListConfigDAO, GameListConfig> implements GameListConfigService {
|
||||||
|
|
||||||
@Override
|
private static final String BAISHUN_GAME_ORIGIN = "BAISHUN";
|
||||||
public List<GameListConfig> listShowcaseConfig(String sysOrigin, String category, String roomId) {
|
private static final String BAISHUN_PROFILE_PROD = "PROD";
|
||||||
return query()
|
private static final String BAISHUN_ACTIVE_PROFILE_EXISTS_SQL = """
|
||||||
.eq(GameListConfig::getSysOrigin, sysOrigin)
|
EXISTS (
|
||||||
.eq(StringUtils.isNotBlank(category), GameListConfig::getCategory, category)
|
SELECT 1
|
||||||
.ne(StringUtils.isBlank(roomId), GameListConfig::getCategory, "HIDDEN")
|
FROM sys_game_list_vendor_ext ext
|
||||||
.eq(GameListConfig::getShowcase, Boolean.TRUE)
|
WHERE ext.game_list_config_id = sys_game_list_config.id
|
||||||
.orderByDesc(TimestampBaseEntity::getCreateTime, GameListConfig::getSort)
|
AND ext.sys_origin = sys_game_list_config.sys_origin
|
||||||
.list();
|
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
|
@Override
|
||||||
public String getCoverByGameCode(String gameCode) {
|
public String getCoverByGameCode(String gameCode) {
|
||||||
@ -50,13 +87,14 @@ public class GameListConfigServiceImpl extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCoverByGameId(String gameId, String gameOrigin, String sysOrigin) {
|
public String getCoverByGameId(String gameId, String gameOrigin, String sysOrigin) {
|
||||||
List<GameListConfig> gameListConfigs = query()
|
List<GameListConfig> gameListConfigs = query()
|
||||||
.select(GameListConfig::getGameCode, GameListConfig::getCover)
|
.select(GameListConfig::getGameCode, GameListConfig::getCover)
|
||||||
.eq(GameListConfig::getGameOrigin, gameOrigin)
|
.eq(GameListConfig::getGameOrigin, gameOrigin)
|
||||||
.eq(GameListConfig::getSysOrigin, sysOrigin)
|
.eq(GameListConfig::getSysOrigin, sysOrigin)
|
||||||
.eq(GameListConfig::getShowcase, Boolean.TRUE)
|
.eq(GameListConfig::getShowcase, Boolean.TRUE)
|
||||||
.list();
|
.apply(isBaishunGameOrigin(gameOrigin), BAISHUN_ACTIVE_PROFILE_EXISTS_SQL)
|
||||||
|
.list();
|
||||||
if (CollectionUtils.isEmpty(gameListConfigs)) {
|
if (CollectionUtils.isEmpty(gameListConfigs)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -93,41 +131,55 @@ public class GameListConfigServiceImpl extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<GameListConfig> pageQuery(SysGameListQryCmd query) {
|
public PageResult<GameListConfig> pageQuery(SysGameListQryCmd query) {
|
||||||
return query()
|
return query()
|
||||||
.eq(StringUtils.isNotBlank(query.getSysOrigin()), GameListConfig::getSysOrigin,
|
.eq(StringUtils.isNotBlank(query.getSysOrigin()), GameListConfig::getSysOrigin,
|
||||||
query.getSysOrigin())
|
query.getSysOrigin())
|
||||||
.eq(Objects.nonNull(query.getShowcase()), GameListConfig::getShowcase, query.getShowcase())
|
.eq(Objects.nonNull(query.getShowcase()), GameListConfig::getShowcase, query.getShowcase())
|
||||||
.eq(StringUtils.isNotBlank(query.getGameOrigin()), GameListConfig::getGameOrigin,
|
.eq(StringUtils.isNotBlank(query.getGameOrigin()), GameListConfig::getGameOrigin,
|
||||||
query.getGameOrigin())
|
query.getGameOrigin())
|
||||||
.like(StringUtils.isNotBlank(query.getRegion()), GameListConfig::getRegions,
|
.like(StringUtils.isNotBlank(query.getRegion()), GameListConfig::getRegions,
|
||||||
query.getRegion())
|
query.getRegion())
|
||||||
.orderByDesc(GameListConfig::getSort)
|
.apply(BAISHUN_ACTIVE_PROFILE_FILTER_SQL)
|
||||||
.page(query.getPageQuery());
|
.orderByDesc(GameListConfig::getSort)
|
||||||
}
|
.page(query.getPageQuery());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GameListConfig getByGameCode(String gameCode, String sysOrigin) {
|
public String getActiveBaishunProfile(String sysOrigin) {
|
||||||
return query()
|
if (StringUtils.isBlank(sysOrigin)) {
|
||||||
.eq(GameListConfig::getGameCode, gameCode)
|
return BAISHUN_PROFILE_PROD;
|
||||||
.eq(GameListConfig::getSysOrigin, sysOrigin)
|
}
|
||||||
.last(PageConstant.LIMIT_ONE)
|
BaishunProviderConfig config = baishunProviderConfigService.getBySysOrigin(sysOrigin);
|
||||||
.getOne();
|
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
|
* @param gameId 1345
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public GameListConfig getByGameId(String gameId, String gameOrigin, String sysOrigin) {
|
public GameListConfig getByGameId(String gameId, String gameOrigin, String sysOrigin) {
|
||||||
return query()
|
return query()
|
||||||
.eq(GameListConfig::getGameId, gameId)
|
.eq(GameListConfig::getGameId, gameId)
|
||||||
.eq(GameListConfig::getGameOrigin, gameOrigin)
|
.eq(GameListConfig::getGameOrigin, gameOrigin)
|
||||||
.eq(GameListConfig::getSysOrigin, sysOrigin)
|
.eq(GameListConfig::getSysOrigin, sysOrigin)
|
||||||
.last(PageConstant.LIMIT_ONE)
|
.apply(isBaishunGameOrigin(gameOrigin), BAISHUN_ACTIVE_PROFILE_EXISTS_SQL)
|
||||||
.getOne();
|
.last(PageConstant.LIMIT_ONE)
|
||||||
}
|
.getOne();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean checkGameUnshelve(Set<Long> gameIds) {
|
public Boolean checkGameUnshelve(Set<Long> gameIds) {
|
||||||
@ -136,6 +188,23 @@ public class GameListConfigServiceImpl extends
|
|||||||
.last(PageConstant.formatLimit(gameIds.size()))
|
.last(PageConstant.formatLimit(gameIds.size()))
|
||||||
.list())
|
.list())
|
||||||
.map(list -> list.stream().anyMatch(item -> item.getShowcase() == Boolean.FALSE))
|
.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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -131,8 +131,7 @@ public class UserRegionGatewayImpl implements UserRegionGateway {
|
|||||||
|
|
||||||
// 1. 主播代理团队区域
|
// 1. 主播代理团队区域
|
||||||
List<UserTeamRegionDTO> userTeamRegions = listUserTeamRegion(userIds);
|
List<UserTeamRegionDTO> userTeamRegions = listUserTeamRegion(userIds);
|
||||||
if (CollectionUtils.isNotEmpty(userTeamRegions)
|
if (CollectionUtils.isNotEmpty(userTeamRegions)) {
|
||||||
&& Objects.equals(userTeamRegions.size(), userIds.size())) {
|
|
||||||
|
|
||||||
Map<String, SysRegionConfig> regionConfigMap = sysRegionConfigService.mapAvailable(
|
Map<String, SysRegionConfig> regionConfigMap = sysRegionConfigService.mapAvailable(
|
||||||
userTeamRegions.stream().map(UserTeamRegionDTO::getRegionId).collect(Collectors.toSet())
|
userTeamRegions.stream().map(UserTeamRegionDTO::getRegionId).collect(Collectors.toSet())
|
||||||
|
|||||||
@ -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.convertor.user.UserRegionInfraConvertor;
|
||||||
import com.red.circle.other.infra.database.cache.service.user.SysRegionCacheService;
|
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.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.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.TeamMemberService;
|
||||||
import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService;
|
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.SysRegionAssistConfigService;
|
||||||
import com.red.circle.other.infra.database.mongo.service.user.region.SysRegionConfigService;
|
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.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -29,7 +32,11 @@ import org.junit.jupiter.api.Test;
|
|||||||
class UserRegionGatewayImplTest {
|
class UserRegionGatewayImplTest {
|
||||||
|
|
||||||
private static final long USER_ID = 2047206645188063233L;
|
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 SYS_ORIGIN = "LIKEI";
|
||||||
|
private static final String TEAM_REGION_ID = "middle-east-region";
|
||||||
|
private static final String TEAM_REGION_CODE = "中东区";
|
||||||
|
|
||||||
private TeamMemberService teamMemberService;
|
private TeamMemberService teamMemberService;
|
||||||
private TeamProfileService teamProfileService;
|
private TeamProfileService teamProfileService;
|
||||||
@ -37,6 +44,7 @@ class UserRegionGatewayImplTest {
|
|||||||
private SysRegionCacheService sysRegionCacheService;
|
private SysRegionCacheService sysRegionCacheService;
|
||||||
private SysRegionConfigService sysRegionConfigService;
|
private SysRegionConfigService sysRegionConfigService;
|
||||||
private UserRegionInfraConvertor userRegionInfraConvertor;
|
private UserRegionInfraConvertor userRegionInfraConvertor;
|
||||||
|
private CountryCodeAliasSupport countryCodeAliasSupport;
|
||||||
private UserRegionGatewayImpl userRegionGateway;
|
private UserRegionGatewayImpl userRegionGateway;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@ -49,7 +57,7 @@ class UserRegionGatewayImplTest {
|
|||||||
userRegionInfraConvertor = mock(UserRegionInfraConvertor.class);
|
userRegionInfraConvertor = mock(UserRegionInfraConvertor.class);
|
||||||
SysRegionAssistConfigService sysRegionAssistConfigService = mock(SysRegionAssistConfigService.class);
|
SysRegionAssistConfigService sysRegionAssistConfigService = mock(SysRegionAssistConfigService.class);
|
||||||
UserRegionCacheService userRegionCacheService = mock(UserRegionCacheService.class);
|
UserRegionCacheService userRegionCacheService = mock(UserRegionCacheService.class);
|
||||||
CountryCodeAliasSupport countryCodeAliasSupport = mock(CountryCodeAliasSupport.class);
|
countryCodeAliasSupport = mock(CountryCodeAliasSupport.class);
|
||||||
|
|
||||||
userRegionGateway = new UserRegionGatewayImpl(
|
userRegionGateway = new UserRegionGatewayImpl(
|
||||||
teamMemberService,
|
teamMemberService,
|
||||||
@ -100,6 +108,32 @@ class UserRegionGatewayImplTest {
|
|||||||
verify(userProfileGateway, never()).getLanguage(USER_ID);
|
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) {
|
private SysRegionConfig region(String regionCode, String countryCodes, String langeCodes) {
|
||||||
return new SysRegionConfig()
|
return new SysRegionConfig()
|
||||||
.setId(regionCode)
|
.setId(regionCode)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user