feat: 分页查询支持多字段排序

- 新增 SortDTO 排序参数DTO
- 扩展 PageQueryDTO 支持 sorts 排序列表
- 新增 SortUtils 排序工具类,支持驼峰/下划线路段名自动映射
- 订单列表接口支持自定义排序(字段:orderTime/createTime/receivedAmount/quantity)
- 前端订单列表页新增排序字段和排序方式选择器
- 订单列表下单时间和创建时间列支持点击排序
This commit is contained in:
小蟑螂
2026-03-27 08:59:01 +08:00
parent c94f60cfeb
commit 499593f0e6
6 changed files with 225 additions and 4 deletions
@@ -9,6 +9,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.dto.SortDTO;
import top.xyquan.ecomdmbbackend.common.utils.SortUtils;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.BatchImportOrderDTO;
@@ -312,9 +314,15 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
}
}
// 排序
wrapper.orderByDesc(OrderPO::getOrderTime)
.orderByDesc(OrderPO::getCreateTime);
// 排序(支持多字段自定义排序,默认按下单时间降序 + 创建时间降序)
List<SortDTO> sorts = pageQueryDTO.getSorts();
if (sorts == null || sorts.isEmpty()) {
// 默认排序:下单时间降序,创建时间降序
wrapper.orderByDesc(OrderPO::getOrderTime)
.orderByDesc(OrderPO::getCreateTime);
} else {
SortUtils.applySorts(wrapper, OrderPO.class, sorts);
}
// 执行分页查询
IPage<OrderPO> pageResult = this.page(page, wrapper);