diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/query/QueryRoomRedPacketListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/query/QueryRoomRedPacketListQryExe.java index b7b0aab1..54fc12e3 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/query/QueryRoomRedPacketListQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/redpacket/query/QueryRoomRedPacketListQryExe.java @@ -4,6 +4,8 @@ import com.red.circle.other.app.convertor.RoomRedPacketAppConvertor; import com.red.circle.other.app.dto.clientobject.RoomRedPacketCO; import com.red.circle.other.app.dto.cmd.QueryRoomRedPacketListCmd; import com.red.circle.other.domain.gateway.RoomRedPacketGateway; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.domain.redpacket.RoomRedPacket; import com.red.circle.other.infra.database.cache.service.other.RoomRedPacketCacheService; import lombok.RequiredArgsConstructor; @@ -11,6 +13,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; /** @@ -23,6 +27,7 @@ public class QueryRoomRedPacketListQryExe { private final RoomRedPacketGateway roomRedPacketGateway; private final RoomRedPacketCacheService roomRedPacketCacheService; + private final UserProfileGateway userProfileGateway; /** * 执行查询 @@ -33,9 +38,13 @@ public class QueryRoomRedPacketListQryExe { // 1. 查询房间红包列表(数据库) List redPackets = roomRedPacketGateway.findByRoomId( cmd.getRoomId(), - cmd.getLimit() + cmd.getCurrent().intValue(), + cmd.getSize().intValue() ); - + + Set userIds = redPackets.stream().map(RoomRedPacket::getUserId).collect(Collectors.toSet()); + Map profileMap = userProfileGateway.mapByUserIds(userIds); + // 2. 转换为CO List result = redPackets.stream() .map(redPacket -> { @@ -46,7 +55,14 @@ public class QueryRoomRedPacketListQryExe { redPacket.getPacketId(), userId ); co.setGrabbed(grabbed); - + + UserProfile userProfile = profileMap.get(redPacket.getUserId()); + if (userProfile != null) { + co.setUserAvatar(userProfile.getUserAvatar()); + co.setUserName(userProfile.getUserNickname()); + co.setUserId(userProfile.getId()); + } + return co; }) .collect(Collectors.toList()); diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/QueryRoomRedPacketListCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/QueryRoomRedPacketListCmd.java index ae7fdb26..205f92b0 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/QueryRoomRedPacketListCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/QueryRoomRedPacketListCmd.java @@ -1,5 +1,6 @@ package com.red.circle.other.app.dto.cmd; +import com.red.circle.common.business.dto.PageQueryCmd; import com.red.circle.common.business.dto.cmd.AppExtCommand; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -10,7 +11,7 @@ import lombok.EqualsAndHashCode; */ @EqualsAndHashCode(callSuper = true) @Data -public class QueryRoomRedPacketListCmd extends AppExtCommand { +public class QueryRoomRedPacketListCmd extends PageQueryCmd { /** * 房间ID @@ -18,8 +19,4 @@ public class QueryRoomRedPacketListCmd extends AppExtCommand { @NotNull(message = "Room ID cannot be empty") private Long roomId; - /** - * 查询数量限制(默认20) - */ - private Integer limit = 20; } diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/RoomRedPacketGateway.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/RoomRedPacketGateway.java index 9e84864a..7b5b9392 100644 --- a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/RoomRedPacketGateway.java +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/RoomRedPacketGateway.java @@ -44,5 +44,5 @@ public interface RoomRedPacketGateway { /** * 查询房间红包列表(分页) */ - List findByRoomId(Long roomId, Integer limit); + List findByRoomId(Long roomId, Integer current, Integer size); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/redpacket/RoomRedPacketDAO.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/redpacket/RoomRedPacketDAO.java index f7c2b0ce..62402a8f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/redpacket/RoomRedPacketDAO.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/redpacket/RoomRedPacketDAO.java @@ -44,5 +44,5 @@ public interface RoomRedPacketDAO { /** * 根据房间ID查询红包列表 */ - List selectByRoomId(@Param("roomId") Long roomId, @Param("limit") Integer limit); + List selectByRoomId(@Param("roomId") Long roomId, @Param("offset") Integer offset, @Param("size") Integer size); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/RoomRedPacketGatewayImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/RoomRedPacketGatewayImpl.java index 798dfa1c..717524b0 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/RoomRedPacketGatewayImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/RoomRedPacketGatewayImpl.java @@ -62,8 +62,9 @@ public class RoomRedPacketGatewayImpl implements RoomRedPacketGateway { } @Override - public List findByRoomId(Long roomId, Integer limit) { - List entities = roomRedPacketDAO.selectByRoomId(roomId, limit); + public List findByRoomId(Long roomId, Integer current, Integer size) { + int offset = (current - 1) * size; + List entities = roomRedPacketDAO.selectByRoomId(roomId, offset, size); return entities.stream() .map(RoomRedPacketConvertor::toDomain) .collect(Collectors.toList()); diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/redpacket/RoomRedPacketDAO.xml b/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/redpacket/RoomRedPacketDAO.xml index af5a8cd8..c25ac7ad 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/redpacket/RoomRedPacketDAO.xml +++ b/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/redpacket/RoomRedPacketDAO.xml @@ -90,9 +90,9 @@ SELECT FROM room_red_packet - WHERE room_id = #{roomId} + WHERE room_id = #{roomId} AND status != 3 ORDER BY create_time DESC - LIMIT #{limit} + LIMIT #{offset}, #{size}