首页房间列表更改
This commit is contained in:
parent
46fe6c83a6
commit
0cf49ca884
@ -68,12 +68,6 @@ public class RoomVoiceDiscoverQryExe {
|
||||
private final MicUserCacheService micUserCacheService;
|
||||
|
||||
private static final String EMPTY_ROOM_CACHE_KEY = "empty_room_cache:*";
|
||||
|
||||
// 区域隔离常量 - 与ActiveVoiceRoomServiceImpl保持一致
|
||||
private static final Set<String> TR_REGIONS = Set.of("TR");
|
||||
private static final Set<String> SA_REGIONS = Set.of("BD","SA", "IN", "PK");
|
||||
private static final Set<String> AR_REGIONS = Set.of("AE", "AR", "BH", "DJ", "DZ", "EG", "EY", "ER", "IL", "IQ", "JO", "KM", "KW", "LB", "LY", "MA", "MR", "OM", "PS", "QA", "SD", "SO", "SS", "SY", "TD", "TN", "YE");
|
||||
private static final Set<String> OTHER_REGIONS = Set.of("OTHER", "PH", "ID", "GH", "IR", "AF", "NG", "DE", "MYS", "TM", "AZ", "NP");
|
||||
|
||||
public List<RoomVoiceProfileCO> execute(AppExtCommand cmd) {
|
||||
String region = cmd.isAllRegion() ? "ALL" : userRegionGateway.getRegionCode(cmd.requiredReqUserId());
|
||||
@ -86,13 +80,12 @@ public class RoomVoiceDiscoverQryExe {
|
||||
return roomList;
|
||||
}
|
||||
|
||||
String userCountryCode = userProfile != null ? userProfile.getCountryCode() : null;
|
||||
List<ActiveVoiceRoom> activeVoiceRooms = activeVoiceRoomService.listDiscover(cmd.requireReqSysOrigin(), cmd.isAllRegion(), region, userCountryCode, 50);
|
||||
List<ActiveVoiceRoom> activeVoiceRooms = activeVoiceRoomService.listDiscover(cmd.requireReqSysOrigin(), cmd.isAllRegion(), region, 50);
|
||||
|
||||
// 查询没人的房间缓存,加入进去
|
||||
List<ActiveVoiceRoom> emptyRooms = getEmptyRoomsFromCache();
|
||||
if (CollectionUtils.isNotEmpty(emptyRooms)) {
|
||||
List<ActiveVoiceRoom> matchedEmptyRooms = filterEmptyRoomsByRegion(emptyRooms, cmd.requireReqSysOrigin(), cmd.isAllRegion(), region, userCountryCode);
|
||||
List<ActiveVoiceRoom> matchedEmptyRooms = filterEmptyRoomsByRegion(emptyRooms, cmd.requireReqSysOrigin(), cmd.isAllRegion(), region);
|
||||
if (CollectionUtils.isNotEmpty(matchedEmptyRooms)) {
|
||||
List<ActiveVoiceRoom> allRooms = new ArrayList<>(activeVoiceRooms);
|
||||
Set<Long> existingRoomIds = activeVoiceRooms.stream()
|
||||
@ -287,95 +280,14 @@ public class RoomVoiceDiscoverQryExe {
|
||||
}
|
||||
}
|
||||
|
||||
private List<ActiveVoiceRoom> filterEmptyRoomsByRegion(List<ActiveVoiceRoom> emptyRooms, String sysOrigin, boolean isAllRegion, String region, String userCountryCode) {
|
||||
private List<ActiveVoiceRoom> filterEmptyRoomsByRegion(List<ActiveVoiceRoom> emptyRooms, String sysOrigin, boolean isAllRegion, String region) {
|
||||
return emptyRooms.stream()
|
||||
.filter(room -> Objects.equals(sysOrigin, room.getSysOrigin()) &&
|
||||
(isAllRegion || shouldShowRoom(region, room.getRegion())) &&
|
||||
(!SA_REGIONS.contains(region) || userCountryCode == null || userCountryCode.equals(room.getCountryCode())))
|
||||
.filter(room -> Objects.equals(sysOrigin, room.getSysOrigin()))
|
||||
.filter(room -> isAllRegion || Objects.equals(region, room.getRegion()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否应该显示该房间
|
||||
*/
|
||||
private boolean shouldShowRoom(String userRegion, String roomRegion) {
|
||||
// 获取用户所属区域组
|
||||
Set<String> userRegionGroup = getRegionGroup(userRegion);
|
||||
Set<String> roomRegionGroup = getRegionGroup(roomRegion);
|
||||
|
||||
// 如果用户在特殊区域组,只显示同组房间
|
||||
if (userRegionGroup != null) {
|
||||
return userRegionGroup.contains(roomRegion);
|
||||
}
|
||||
|
||||
// 如果用户不在特殊区域组,排除所有特殊区域组房间
|
||||
return roomRegionGroup == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取区域所属的特殊区域组(如果不属于任何特殊组则返回null)
|
||||
*/
|
||||
private Set<String> getRegionGroup(String region) {
|
||||
if (SA_REGIONS.contains(region)) {
|
||||
return SA_REGIONS;
|
||||
}
|
||||
if (AR_REGIONS.contains(region)) {
|
||||
return AR_REGIONS;
|
||||
}
|
||||
if (OTHER_REGIONS.contains(region)) {
|
||||
return OTHER_REGIONS;
|
||||
}
|
||||
if (TR_REGIONS.contains(region)) {
|
||||
return TR_REGIONS;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取需要排除的区域列表
|
||||
*/
|
||||
private List<String> getRegions(String region) {
|
||||
List<String> excludeRegions = new ArrayList<>();
|
||||
|
||||
if (SA_REGIONS.contains(region)) {
|
||||
excludeRegions.addAll(AR_REGIONS);
|
||||
excludeRegions.addAll(OTHER_REGIONS);
|
||||
} else if (AR_REGIONS.contains(region)) {
|
||||
excludeRegions.addAll(SA_REGIONS);
|
||||
excludeRegions.addAll(OTHER_REGIONS);
|
||||
} else if (OTHER_REGIONS.contains(region)) {
|
||||
excludeRegions.addAll(SA_REGIONS);
|
||||
excludeRegions.addAll(AR_REGIONS);
|
||||
} else {
|
||||
excludeRegions.addAll(SA_REGIONS);
|
||||
excludeRegions.addAll(AR_REGIONS);
|
||||
excludeRegions.addAll(OTHER_REGIONS);
|
||||
}
|
||||
|
||||
return excludeRegions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取特殊区域组列表
|
||||
*/
|
||||
private List<String> getSpecialRegions(String region) {
|
||||
if (SA_REGIONS.contains(region)) {
|
||||
return new ArrayList<>(SA_REGIONS);
|
||||
}
|
||||
|
||||
if (AR_REGIONS.contains(region)) {
|
||||
return new ArrayList<>(AR_REGIONS);
|
||||
}
|
||||
|
||||
if (OTHER_REGIONS.contains(region)) {
|
||||
return new ArrayList<>(OTHER_REGIONS);
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓存中获取没人的房间
|
||||
*
|
||||
|
||||
@ -37,7 +37,7 @@ public class EmptyRoomCleanTask {
|
||||
public void cleanEmptyRooms() {
|
||||
try {
|
||||
// 获取所有活跃房间
|
||||
List<ActiveVoiceRoom> allRooms = activeVoiceRoomService.listDiscover(SysOriginPlatformEnum.ATYOU.name(),true,"",null,200);
|
||||
List<ActiveVoiceRoom> allRooms = activeVoiceRoomService.listDiscover(SysOriginPlatformEnum.ATYOU.name(), true, "", 200);
|
||||
if (CollectionUtils.isEmpty(allRooms)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public interface ActiveVoiceRoomService {
|
||||
/**
|
||||
* 获取发现页数据.
|
||||
*/
|
||||
List<ActiveVoiceRoom> listDiscover(String sysOrigin, boolean isAllRegion, String region, String countryCode, Integer limit);
|
||||
List<ActiveVoiceRoom> listDiscover(String sysOrigin, boolean isAllRegion, String region, Integer limit);
|
||||
|
||||
/**
|
||||
* 获取区域房间.
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.red.circle.other.infra.database.mongo.service.live.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
||||
import com.red.circle.framework.mybatis.constant.PageConstant;
|
||||
import com.red.circle.other.infra.database.mongo.dto.query.live.ActiveVoiceRoomQuery;
|
||||
@ -19,8 +18,6 @@ import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
||||
import org.springframework.data.mongodb.core.aggregation.ConditionalOperators;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
@ -36,21 +33,6 @@ public class ActiveVoiceRoomServiceImpl implements ActiveVoiceRoomService {
|
||||
|
||||
private final MongoTemplate mongoTemplate;
|
||||
|
||||
private static final Set<String> TR_REGIONS = Set.of("TR");
|
||||
private static final Set<String> SA_REGIONS = Set.of("BD","SA", "IN", "PK");
|
||||
private static final Set<String> AR_REGIONS = Set.of("AE", "AR", "BH", "DJ", "DZ", "EG", "EY", "ER", "IL", "IQ", "JO", "KM", "KW", "LB", "LY", "MA", "MR", "OM", "PS", "QA", "SD", "SO", "SS", "SY", "TD", "TN", "YE");
|
||||
private static final Set<String> OTHER_REGIONS = Set.of("OTHER", "PH", "ID", "GH", "IR", "AF", "NG", "DE", "MYS", "TM", "AZ", "NP");
|
||||
private static final Set<String> ALL_SPECIAL_REGIONS;
|
||||
|
||||
static {
|
||||
Set<String> temp = new HashSet<>();
|
||||
temp.addAll(SA_REGIONS);
|
||||
temp.addAll(AR_REGIONS);
|
||||
temp.addAll(TR_REGIONS);
|
||||
temp.addAll(OTHER_REGIONS);
|
||||
ALL_SPECIAL_REGIONS = Collections.unmodifiableSet(temp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrUpdate(ActiveVoiceRoom param) {
|
||||
try {
|
||||
@ -133,103 +115,22 @@ public class ActiveVoiceRoomServiceImpl implements ActiveVoiceRoomService {
|
||||
|
||||
|
||||
@Override
|
||||
public List<ActiveVoiceRoom> listDiscover(String sysOrigin, boolean isAllRegion, String region, String countryCode, Integer limit) {
|
||||
// 区域隔离
|
||||
Set<String> userRegionGroup = getRegionGroup(region);
|
||||
Set<String> excludeRegions = userRegionGroup == null ? ALL_SPECIAL_REGIONS : getExcludeRegionsForGroup(userRegionGroup);
|
||||
|
||||
log.info("被隔离区域 regions:{}", JSON.toJSONString(excludeRegions));
|
||||
|
||||
// 构建聚合管道
|
||||
public List<ActiveVoiceRoom> listDiscover(String sysOrigin, boolean isAllRegion, String region, Integer limit) {
|
||||
Criteria criteria = Criteria.where("sysOrigin").is(sysOrigin);
|
||||
if (userRegionGroup != null && !isAllRegion) {
|
||||
criteria.and("region").in(userRegionGroup);
|
||||
// 非全部区域时,仅展示用户当前 region 的房间
|
||||
if (!isAllRegion && StringUtils.isNotBlank(region)) {
|
||||
criteria.and("region").is(region);
|
||||
}
|
||||
if (userRegionGroup == null && !isAllRegion) {
|
||||
criteria.and("region").nin(excludeRegions);
|
||||
}
|
||||
// SA_REGIONS 用户只能看到相同国家的房间
|
||||
if (SA_REGIONS.contains(region) && !isAllRegion && StringUtils.isNotBlank(countryCode)) {
|
||||
criteria.and("countryCode").is(countryCode);
|
||||
}
|
||||
Aggregation aggregation = Aggregation.newAggregation(
|
||||
// 1. 匹配国家(可选条件)
|
||||
Aggregation.match(criteria),
|
||||
|
||||
// 2. 计算匹配分数和动态调整 fixedWeights
|
||||
Aggregation.project("id", "timeId", "sysOrigin", "userId", "roomAccount", "familyProfile", "runGame", "superVipLevel", "hot", "fixedWeights", "region", "countryCode", "countryName", "onlineQuantity", "weights", "expiredTime", "createTime", "updateTime")
|
||||
.and(
|
||||
ConditionalOperators.when(Criteria.where("region").is(region))
|
||||
.then(1)
|
||||
.otherwise(0)
|
||||
).as("regionMatchScore")
|
||||
.and(
|
||||
ConditionalOperators.when(Criteria.where("region").is(region))
|
||||
.then("$fixedWeights")
|
||||
.otherwise(0)
|
||||
).as("fixedWeightsScore")
|
||||
.and("weights").as("weights"),
|
||||
|
||||
// 3. 排序逻辑
|
||||
Aggregation.sort(Sort.by(
|
||||
Sort.Order.desc("regionMatchScore"),
|
||||
Sort.Order.desc("fixedWeightsScore"), // 如果区域不匹配,fixedWeights 为 0,不影响排序
|
||||
Query query = Query.query(criteria)
|
||||
.with(Sort.by(
|
||||
Sort.Order.desc("fixedWeights"),
|
||||
Sort.Order.desc("weights"),
|
||||
Sort.Order.desc("onlineQuantity")
|
||||
)),
|
||||
))
|
||||
.limit(limit);
|
||||
|
||||
// 4. 分页
|
||||
Aggregation.skip(0),
|
||||
Aggregation.limit(limit)
|
||||
);
|
||||
|
||||
// 执行聚合操作并返回结果
|
||||
return mongoTemplate.aggregate(aggregation, ActiveVoiceRoom.class, ActiveVoiceRoom.class)
|
||||
.getMappedResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取区域所属的特殊区域组(如果不属于任何特殊组则返回null)
|
||||
*/
|
||||
private Set<String> getRegionGroup(String region) {
|
||||
if (SA_REGIONS.contains(region)) {
|
||||
return SA_REGIONS;
|
||||
}
|
||||
if (AR_REGIONS.contains(region)) {
|
||||
return AR_REGIONS;
|
||||
}
|
||||
if (OTHER_REGIONS.contains(region)) {
|
||||
return OTHER_REGIONS;
|
||||
}
|
||||
if (TR_REGIONS.contains(region)) {
|
||||
return TR_REGIONS;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定区域组需要排除的其他区域组
|
||||
*/
|
||||
private Set<String> getExcludeRegionsForGroup(Set<String> regionGroup) {
|
||||
Set<String> excludes = new HashSet<>();
|
||||
if (regionGroup == SA_REGIONS) {
|
||||
excludes.addAll(AR_REGIONS);
|
||||
excludes.addAll(OTHER_REGIONS);
|
||||
excludes.addAll(TR_REGIONS);
|
||||
} else if (regionGroup == AR_REGIONS) {
|
||||
excludes.addAll(SA_REGIONS);
|
||||
excludes.addAll(OTHER_REGIONS);
|
||||
excludes.addAll(TR_REGIONS);
|
||||
} else if (regionGroup == OTHER_REGIONS) {
|
||||
excludes.addAll(SA_REGIONS);
|
||||
excludes.addAll(AR_REGIONS);
|
||||
excludes.addAll(TR_REGIONS);
|
||||
} else if (regionGroup == TR_REGIONS) {
|
||||
excludes.addAll(SA_REGIONS);
|
||||
excludes.addAll(AR_REGIONS);
|
||||
excludes.addAll(OTHER_REGIONS);
|
||||
}
|
||||
return excludes;
|
||||
return mongoTemplate.find(query, ActiveVoiceRoom.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user