红包列表接口更改

This commit is contained in:
tianfeng 2025-11-26 12:17:40 +08:00
parent b2fb0fe217
commit 3b111efa04
6 changed files with 28 additions and 14 deletions

View File

@ -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<RoomRedPacket> redPackets = roomRedPacketGateway.findByRoomId(
cmd.getRoomId(),
cmd.getLimit()
cmd.getCurrent().intValue(),
cmd.getSize().intValue()
);
Set<Long> userIds = redPackets.stream().map(RoomRedPacket::getUserId).collect(Collectors.toSet());
Map<Long, UserProfile> profileMap = userProfileGateway.mapByUserIds(userIds);
// 2. 转换为CO
List<RoomRedPacketCO> 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());

View File

@ -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;
}

View File

@ -44,5 +44,5 @@ public interface RoomRedPacketGateway {
/**
* 查询房间红包列表分页
*/
List<RoomRedPacket> findByRoomId(Long roomId, Integer limit);
List<RoomRedPacket> findByRoomId(Long roomId, Integer current, Integer size);
}

View File

@ -44,5 +44,5 @@ public interface RoomRedPacketDAO {
/**
* 根据房间ID查询红包列表
*/
List<RoomRedPacketEntity> selectByRoomId(@Param("roomId") Long roomId, @Param("limit") Integer limit);
List<RoomRedPacketEntity> selectByRoomId(@Param("roomId") Long roomId, @Param("offset") Integer offset, @Param("size") Integer size);
}

View File

@ -62,8 +62,9 @@ public class RoomRedPacketGatewayImpl implements RoomRedPacketGateway {
}
@Override
public List<RoomRedPacket> findByRoomId(Long roomId, Integer limit) {
List<RoomRedPacketEntity> entities = roomRedPacketDAO.selectByRoomId(roomId, limit);
public List<RoomRedPacket> findByRoomId(Long roomId, Integer current, Integer size) {
int offset = (current - 1) * size;
List<RoomRedPacketEntity> entities = roomRedPacketDAO.selectByRoomId(roomId, offset, size);
return entities.stream()
.map(RoomRedPacketConvertor::toDomain)
.collect(Collectors.toList());

View File

@ -90,9 +90,9 @@
SELECT
<include refid="Base_Column_List"/>
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}
</select>
</mapper>