fix closed room visibility in lists

This commit is contained in:
hy001 2026-04-16 17:24:35 +08:00
parent d15ea98dc6
commit 258e56ea45
7 changed files with 207 additions and 141 deletions

View File

@ -24,6 +24,7 @@ import com.red.circle.other.infra.database.rds.service.family.FamilyLevelExpServ
import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService; import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService;
import com.red.circle.other.infra.enums.family.FamilyRoleEnum; import com.red.circle.other.infra.enums.family.FamilyRoleEnum;
import com.red.circle.other.infra.enums.family.FamilyStatusEnum; import com.red.circle.other.infra.enums.family.FamilyStatusEnum;
import com.red.circle.other.inner.enums.room.RoomEventEnum;
import com.red.circle.other.inner.model.dto.famliy.FamilyDetailsDTO; import com.red.circle.other.inner.model.dto.famliy.FamilyDetailsDTO;
import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.num.NumUtils; import com.red.circle.tool.core.num.NumUtils;
@ -220,7 +221,10 @@ public class FamilyHomeListExe {
return rooms.stream() return rooms.stream()
.map(room -> { .map(room -> {
UserProfile profile = profileMap.get(room.getUserId()); UserProfile profile = profileMap.get(room.getUserId());
RoomProfileManager roomProfileManager = roomProfileManagerMap.getOrDefault(room.getId(), new RoomProfileManager()); RoomProfileManager roomProfileManager = roomProfileManagerMap.get(room.getId());
if (!isAvailableRoom(roomProfileManager)) {
return null;
}
return new FamilyHomeRoomCO() return new FamilyHomeRoomCO()
.setRoomId(room.getId()) .setRoomId(room.getId())
@ -232,7 +236,15 @@ public class FamilyHomeListExe {
.setExistsPassword(StringUtils.isNotBlank(roomProfileManager.getSetting().getPassword())) .setExistsPassword(StringUtils.isNotBlank(roomProfileManager.getSetting().getPassword()))
.setOnlineQuantity(room.getOnlineQuantity()); .setOnlineQuantity(room.getOnlineQuantity());
}) })
.filter(Objects::nonNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private boolean isAvailableRoom(RoomProfileManager roomProfileManager) {
return Objects.nonNull(roomProfileManager)
&& !Objects.equals(roomProfileManager.getDel(), Boolean.TRUE)
&& !Objects.equals(roomProfileManager.getEvent(), RoomEventEnum.CLOSE.name())
&& Objects.nonNull(roomProfileManager.getSetting());
}
} }

View File

@ -3,6 +3,7 @@ package com.red.circle.other.app.command.party3rd.callback.trtc;
import com.red.circle.external.inner.model.callback.trtc.TrtcCallbackEvent; import com.red.circle.external.inner.model.callback.trtc.TrtcCallbackEvent;
import com.red.circle.other.infra.database.cache.service.other.RoomManagerCacheService; import com.red.circle.other.infra.database.cache.service.other.RoomManagerCacheService;
import com.red.circle.other.infra.database.mongo.service.live.ActiveVoiceRoomService; import com.red.circle.other.infra.database.mongo.service.live.ActiveVoiceRoomService;
import com.red.circle.tool.core.text.StringUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -22,9 +23,12 @@ public class DisbandRoomCallbackStrategy implements TrtcCallbackStrategy {
@Override @Override
public void doOperation(TrtcCallbackEvent event) { public void doOperation(TrtcCallbackEvent event) {
// log.warn("解散房间:{}", event); log.warn("解散房间:{}", event);
// activeVoiceRoomService.removeByRoomAccount(event.getRoomIdLongValve()); if (StringUtils.isBlank(event.getRoomId())) {
// roomManagerCacheService.removeNumberPeople(event.getRoomIdLongValve()); return;
}
activeVoiceRoomService.removeByRoomAccount(event.getRoomId());
roomManagerCacheService.removeNumberPeople(event.getRoomId());
} }
} }

View File

@ -80,7 +80,15 @@ public class RoomVoiceDiscoverQryExe {
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);
return roomList; if (CollectionUtils.isEmpty(roomList)) {
return CollectionUtils.newArrayList();
}
List<RoomVoiceProfileCO> availableRooms = roomVoiceProfileCommon
.filterAvailableRoomProfiles(roomList);
if (availableRooms.size() != roomList.size()) {
regionRoomCacheService.remove(key);
}
return availableRooms;
} }
String userCountryCode = userProfile != null ? userProfile.getCountryCode() : null; String userCountryCode = userProfile != null ? userProfile.getCountryCode() : null;

View File

@ -10,6 +10,7 @@ import com.red.circle.other.infra.database.rds.service.live.RoomMemberService;
import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -37,6 +38,7 @@ public class UserJoinedRoomsQryExe {
return roomMembers.stream().map(roomMember -> new RoomBrowseRecordsV2CO() return roomMembers.stream().map(roomMember -> new RoomBrowseRecordsV2CO()
.setId(roomMember.getId()) .setId(roomMember.getId())
.setRoomProfile(roomProfileMap.get(roomMember.getRoomId()))) .setRoomProfile(roomProfileMap.get(roomMember.getRoomId())))
.filter(record -> Objects.nonNull(record.getRoomProfile()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -56,7 +56,8 @@ public class UserTraceRoomsQryExe {
.setId(roomTourist.getTimeId()) .setId(roomTourist.getTimeId())
.setRoomProfile(profileCO); .setRoomProfile(profileCO);
} }
).collect(Collectors.toList()); ).filter(record -> Objects.nonNull(record.getRoomProfile()))
.collect(Collectors.toList());
} }
} }

View File

@ -11,6 +11,7 @@ import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.infra.database.mongo.entity.live.ActiveVoiceRoom; import com.red.circle.other.infra.database.mongo.entity.live.ActiveVoiceRoom;
import com.red.circle.other.infra.database.mongo.entity.live.RoomProfileManager; import com.red.circle.other.infra.database.mongo.entity.live.RoomProfileManager;
import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService; import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService;
import com.red.circle.other.inner.enums.room.RoomEventEnum;
import com.red.circle.other.inner.model.dto.material.UseBadgeDTO; import com.red.circle.other.inner.model.dto.material.UseBadgeDTO;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.collection.CollectionUtils;
@ -49,14 +50,23 @@ public class RoomVoiceProfileCommon {
return Lists.newArrayList(); return Lists.newArrayList();
} }
List<RoomProfileManager> availableRooms = roomProfileManagers.stream()
.filter(this::isRoomAvailable)
.toList();
if (CollectionUtils.isEmpty(availableRooms)) {
return Lists.newArrayList();
}
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
userProfileGateway.mapByUserIds( userProfileGateway.mapByUserIds(
roomProfileManagers.stream().map(RoomProfileManager::getUserId) availableRooms.stream().map(RoomProfileManager::getUserId)
.collect(Collectors.toSet()))); .collect(Collectors.toSet())));
return roomProfileManagers.stream() return availableRooms.stream()
.map(roomManager -> mergeRoomVoiceProfile(userProfileMap.get(roomManager.getUserId()), .map(roomManager -> mergeRoomVoiceProfile(userProfileMap.get(roomManager.getUserId()),
roomManager)) roomManager))
.filter(Objects::nonNull)
.toList(); .toList();
} }
@ -79,10 +89,7 @@ public class RoomVoiceProfileCommon {
) )
.map(userProfile -> { .map(userProfile -> {
RoomProfileManager manager = roomProfileManagerService.getByUserId(userProfile.getId()); RoomProfileManager manager = roomProfileManagerService.getByUserId(userProfile.getId());
if (Objects.nonNull(manager)) { if (isRoomAvailable(manager)) {
if (Objects.equals(manager.getDel(), Boolean.TRUE)) {
return null;
}
return mergeRoomVoiceProfile(userProfile, manager); return mergeRoomVoiceProfile(userProfile, manager);
} }
@ -90,6 +97,20 @@ public class RoomVoiceProfileCommon {
}).orElse(null); }).orElse(null);
} }
public List<RoomVoiceProfileCO> filterAvailableRoomProfiles(
List<RoomVoiceProfileCO> roomVoiceProfiles) {
if (CollectionUtils.isEmpty(roomVoiceProfiles)) {
return Lists.newArrayList();
}
Map<Long, RoomProfileManager> roomProfileManagerMap = roomProfileManagerService.mapByRoomIds(
roomVoiceProfiles.stream().map(RoomVoiceProfileCO::getId).collect(Collectors.toSet()));
return roomVoiceProfiles.stream()
.filter(room -> isRoomAvailable(roomProfileManagerMap.get(room.getId())))
.toList();
}
public List<RoomVoiceProfileCO> toListRoomVoiceProfileCO(List<ActiveVoiceRoom> activeVoiceRooms) { public List<RoomVoiceProfileCO> toListRoomVoiceProfileCO(List<ActiveVoiceRoom> activeVoiceRooms) {
if (CollectionUtils.isEmpty(activeVoiceRooms)) { if (CollectionUtils.isEmpty(activeVoiceRooms)) {
return Lists.newArrayList(); return Lists.newArrayList();
@ -139,7 +160,7 @@ public class RoomVoiceProfileCommon {
private RoomVoiceProfileCO mergeRoomVoiceProfile(UserProfileDTO userProfile, private RoomVoiceProfileCO mergeRoomVoiceProfile(UserProfileDTO userProfile,
RoomProfileManager manager) { RoomProfileManager manager) {
if (Objects.isNull(manager)) { if (!isRoomAvailable(manager)) {
return null; return null;
} }
@ -158,5 +179,11 @@ public class RoomVoiceProfileCommon {
return roomVoiceProfile; return roomVoiceProfile;
} }
private boolean isRoomAvailable(RoomProfileManager manager) {
return Objects.nonNull(manager)
&& !Objects.equals(manager.getDel(), Boolean.TRUE)
&& !Objects.equals(manager.getEvent(), RoomEventEnum.CLOSE.name());
}
} }

View File

@ -6,12 +6,15 @@ import com.mongodb.BasicDBObject;
import com.red.circle.common.business.core.ReplaceString; import com.red.circle.common.business.core.ReplaceString;
import com.red.circle.common.business.core.SensitiveWordFilter; import com.red.circle.common.business.core.SensitiveWordFilter;
import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.other.infra.database.cache.service.other.RoomManagerCacheService;
import com.red.circle.other.infra.database.mongo.entity.live.RoomCounter; import com.red.circle.other.infra.database.mongo.entity.live.RoomCounter;
import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile; import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile;
import com.red.circle.other.infra.database.mongo.entity.live.RoomProfileManager; import com.red.circle.other.infra.database.mongo.entity.live.RoomProfileManager;
import com.red.circle.other.infra.database.mongo.entity.live.RoomSetting; import com.red.circle.other.infra.database.mongo.entity.live.RoomSetting;
import com.red.circle.other.infra.database.mongo.service.live.ActiveVoiceRoomService;
import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService; import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService;
import com.red.circle.other.inner.asserts.DynamicErrorCode; import com.red.circle.other.inner.asserts.DynamicErrorCode;
import com.red.circle.other.inner.enums.room.RoomEventEnum;
import com.red.circle.other.inner.model.cmd.room.RoomProfileOpsQryCmd; import com.red.circle.other.inner.model.cmd.room.RoomProfileOpsQryCmd;
import com.red.circle.other.inner.model.dto.material.UseBadgeDTO; import com.red.circle.other.inner.model.dto.material.UseBadgeDTO;
import com.red.circle.other.inner.model.dto.material.UsePropsDTO; import com.red.circle.other.inner.model.dto.material.UsePropsDTO;
@ -52,6 +55,8 @@ public class RoomProfileManagerServiceImpl implements RoomProfileManagerService
private final MongoTemplate mongoTemplate; private final MongoTemplate mongoTemplate;
private final RedisTemplate<String, String> redisTemplate; private final RedisTemplate<String, String> redisTemplate;
private final ActiveVoiceRoomService activeVoiceRoomService;
private final RoomManagerCacheService roomManagerCacheService;
/** /**
* Redis缓存Key前缀 * Redis缓存Key前缀
@ -447,6 +452,13 @@ public class RoomProfileManagerServiceImpl implements RoomProfileManagerService
mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(roomProfile.getId())), mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(roomProfile.getId())),
getUpdateSelectiveProfile(roomProfile), getUpdateSelectiveProfile(roomProfile),
RoomProfileManager.class); RoomProfileManager.class);
if (Objects.equals(roomProfile.getEvent(), RoomEventEnum.CLOSE.name())
|| Objects.equals(roomProfile.getDel(), Boolean.TRUE)) {
if (StringUtils.isNotBlank(profile.getRoomAccount())) {
activeVoiceRoomService.removeByRoomAccount(profile.getRoomAccount());
roomManagerCacheService.removeNumberPeople(profile.getRoomAccount());
}
}
return Boolean.TRUE; return Boolean.TRUE;
} }