diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExe.java index aeb2aab3..3c444724 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/room/query/RoomVoiceDiscoverQryExe.java @@ -8,6 +8,7 @@ import com.red.circle.common.business.enums.SVIPLevelEnum; import com.red.circle.live.inner.endpoint.LiveMicClient; import com.red.circle.other.app.common.room.RoomVoiceProfileCommon; import com.red.circle.other.app.dto.clientobject.room.RoomVoiceProfileCO; +import com.red.circle.other.app.service.game.GameLudoService; import com.red.circle.other.app.service.room.RocketStatusCacheService; import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; import com.red.circle.other.domain.gateway.user.ability.UserSVipGateway; @@ -57,7 +58,8 @@ public class RoomVoiceDiscoverQryExe { private final RegionRoomCacheService regionRoomCacheService; private final LiveMicClient liveMicClient; private final RedisTemplate redisTemplate; - private final RocketStatusCacheService rocketStatusCacheService; + private final RocketStatusCacheService rocketStatusCacheService; + private final GameLudoService gameLudoService; private static final String EMPTY_ROOM_CACHE_KEY = "empty_room_cache:*"; @@ -115,10 +117,21 @@ public class RoomVoiceDiscoverQryExe { // 填充火箭状态 fillRocketStatus(roomList); + // 填充游戏图标 + fillGameIcon(roomList); return roomList; } + private void fillGameIcon(List roomList) { + if (CollectionUtils.isEmpty(roomList)) { + return; + } + List roomIds = roomList.stream().map(RoomVoiceProfileCO::getId).toList(); + Map coverMap = gameLudoService.listGameCoverByRoomIds(roomIds); + roomList.forEach(room -> room.setRoomGameIcon(coverMap.get(room.getId()))); + } + /** * 填充房间的火箭状态信息 * diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameLudoServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameLudoServiceImpl.java index 1bd4a77d..ccbb2be7 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameLudoServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/game/GameLudoServiceImpl.java @@ -11,6 +11,12 @@ import com.red.circle.other.app.command.game.ludo.GameLudoStartCmdExe; import com.red.circle.other.app.command.game.ludo.GameRoomExistsQueryExe; import com.red.circle.other.app.dto.clientobject.game.GameLudoRunCO; import com.red.circle.other.app.dto.cmd.game.GameLudoCreateCmd; +import com.red.circle.other.infra.database.mongo.entity.game.ludo.GameLudoRun; +import com.red.circle.other.infra.database.mongo.service.game.GameLudoRunService; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; import com.red.circle.other.app.dto.cmd.game.GameLudoEndCmd; import com.red.circle.other.app.dto.cmd.game.GameLudoJoinCmd; import com.red.circle.other.app.dto.cmd.game.GameLudoStartCmd; @@ -34,6 +40,7 @@ public class GameLudoServiceImpl implements GameLudoService { private final GameLudoRoomRunQueryExe gameLudoRoomRunQueryExe; private final GameLudoLatestEndCmdExe gameLudoLatestEndCmdExe; private final GameLudoLatestDisbandCmdExe gameLudoLatestDisbandCmdExe; + private final GameLudoRunService gameLudoRunService; @Override public GameLudoRunCO getRoomGame(AppRoomIdCmd cmd) { @@ -70,4 +77,11 @@ public class GameLudoServiceImpl implements GameLudoService { gameLudoLatestEndCmdExe.execute(cmd); } + @Override + public Map listGameCoverByRoomIds(List roomIds) { + return gameLudoRunService.listByRoomIds(roomIds).stream() + .filter(run -> Objects.nonNull(run.getGameInfo()) && Objects.nonNull(run.getGameInfo().getCover())) + .collect(Collectors.toMap(GameLudoRun::getRoomId, run -> run.getGameInfo().getCover(), (a, b) -> a)); + } + } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/game/GameLudoService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/game/GameLudoService.java index 75ee1151..936f45ab 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/game/GameLudoService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/game/GameLudoService.java @@ -3,6 +3,8 @@ package com.red.circle.other.app.service.game; import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd; import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd; import com.red.circle.other.app.dto.clientobject.game.GameLudoRunCO; +import java.util.List; +import java.util.Map; import com.red.circle.other.app.dto.cmd.game.GameLudoCreateCmd; import com.red.circle.other.app.dto.cmd.game.GameLudoEndCmd; import com.red.circle.other.app.dto.cmd.game.GameLudoJoinCmd; @@ -29,4 +31,9 @@ public interface GameLudoService { void end(GameLudoEndCmd cmd); + /** + * 批量获取房间正在进行的游戏封面,key=roomId,value=cover + */ + Map listGameCoverByRoomIds(List roomIds); + } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/GameLudoRunService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/GameLudoRunService.java index 7fe84e43..943517f2 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/GameLudoRunService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/GameLudoRunService.java @@ -47,4 +47,9 @@ public interface GameLudoRunService { * 移除房间游戏. */ void remove(Long id); + + /** + * 批量查询房间游戏. + */ + List listByRoomIds(List roomIds); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/impl/GameLudoRunServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/impl/GameLudoRunServiceImpl.java index 1b9675a7..e2f1cdd3 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/impl/GameLudoRunServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/game/impl/GameLudoRunServiceImpl.java @@ -82,6 +82,16 @@ public class GameLudoRunServiceImpl implements GameLudoRunService { GameLudoRun.class); } + @Override + public List listByRoomIds(List roomIds) { + if (roomIds == null || roomIds.isEmpty()) { + return List.of(); + } + return mongoTemplate.find( + Query.query(Criteria.where("id").in(roomIds)), + GameLudoRun.class); + } + @Override public void remove(Long id) { mongoTemplate.remove(Query.query(Criteria.where("id").is(id)), GameLudoRun.class);