红包列表接口更改
This commit is contained in:
parent
b2fb0fe217
commit
3b111efa04
@ -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.clientobject.RoomRedPacketCO;
|
||||||
import com.red.circle.other.app.dto.cmd.QueryRoomRedPacketListCmd;
|
import com.red.circle.other.app.dto.cmd.QueryRoomRedPacketListCmd;
|
||||||
import com.red.circle.other.domain.gateway.RoomRedPacketGateway;
|
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.domain.redpacket.RoomRedPacket;
|
||||||
import com.red.circle.other.infra.database.cache.service.other.RoomRedPacketCacheService;
|
import com.red.circle.other.infra.database.cache.service.other.RoomRedPacketCacheService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -11,6 +13,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,6 +27,7 @@ public class QueryRoomRedPacketListQryExe {
|
|||||||
|
|
||||||
private final RoomRedPacketGateway roomRedPacketGateway;
|
private final RoomRedPacketGateway roomRedPacketGateway;
|
||||||
private final RoomRedPacketCacheService roomRedPacketCacheService;
|
private final RoomRedPacketCacheService roomRedPacketCacheService;
|
||||||
|
private final UserProfileGateway userProfileGateway;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行查询
|
* 执行查询
|
||||||
@ -33,9 +38,13 @@ public class QueryRoomRedPacketListQryExe {
|
|||||||
// 1. 查询房间红包列表(数据库)
|
// 1. 查询房间红包列表(数据库)
|
||||||
List<RoomRedPacket> redPackets = roomRedPacketGateway.findByRoomId(
|
List<RoomRedPacket> redPackets = roomRedPacketGateway.findByRoomId(
|
||||||
cmd.getRoomId(),
|
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
|
// 2. 转换为CO
|
||||||
List<RoomRedPacketCO> result = redPackets.stream()
|
List<RoomRedPacketCO> result = redPackets.stream()
|
||||||
.map(redPacket -> {
|
.map(redPacket -> {
|
||||||
@ -46,7 +55,14 @@ public class QueryRoomRedPacketListQryExe {
|
|||||||
redPacket.getPacketId(), userId
|
redPacket.getPacketId(), userId
|
||||||
);
|
);
|
||||||
co.setGrabbed(grabbed);
|
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;
|
return co;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.red.circle.other.app.dto.cmd;
|
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 com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -10,7 +11,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class QueryRoomRedPacketListCmd extends AppExtCommand {
|
public class QueryRoomRedPacketListCmd extends PageQueryCmd {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 房间ID
|
* 房间ID
|
||||||
@ -18,8 +19,4 @@ public class QueryRoomRedPacketListCmd extends AppExtCommand {
|
|||||||
@NotNull(message = "Room ID cannot be empty")
|
@NotNull(message = "Room ID cannot be empty")
|
||||||
private Long roomId;
|
private Long roomId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询数量限制(默认20)
|
|
||||||
*/
|
|
||||||
private Integer limit = 20;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,5 +44,5 @@ public interface RoomRedPacketGateway {
|
|||||||
/**
|
/**
|
||||||
* 查询房间红包列表(分页)
|
* 查询房间红包列表(分页)
|
||||||
*/
|
*/
|
||||||
List<RoomRedPacket> findByRoomId(Long roomId, Integer limit);
|
List<RoomRedPacket> findByRoomId(Long roomId, Integer current, Integer size);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,5 +44,5 @@ public interface RoomRedPacketDAO {
|
|||||||
/**
|
/**
|
||||||
* 根据房间ID查询红包列表
|
* 根据房间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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,8 +62,9 @@ public class RoomRedPacketGatewayImpl implements RoomRedPacketGateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RoomRedPacket> findByRoomId(Long roomId, Integer limit) {
|
public List<RoomRedPacket> findByRoomId(Long roomId, Integer current, Integer size) {
|
||||||
List<RoomRedPacketEntity> entities = roomRedPacketDAO.selectByRoomId(roomId, limit);
|
int offset = (current - 1) * size;
|
||||||
|
List<RoomRedPacketEntity> entities = roomRedPacketDAO.selectByRoomId(roomId, offset, size);
|
||||||
return entities.stream()
|
return entities.stream()
|
||||||
.map(RoomRedPacketConvertor::toDomain)
|
.map(RoomRedPacketConvertor::toDomain)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@ -90,9 +90,9 @@
|
|||||||
SELECT
|
SELECT
|
||||||
<include refid="Base_Column_List"/>
|
<include refid="Base_Column_List"/>
|
||||||
FROM room_red_packet
|
FROM room_red_packet
|
||||||
WHERE room_id = #{roomId}
|
WHERE room_id = #{roomId} AND status != 3
|
||||||
ORDER BY create_time DESC
|
ORDER BY create_time DESC
|
||||||
LIMIT #{limit}
|
LIMIT #{offset}, #{size}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user