refactor(crm order item): 移排序逻辑到后端并简化前端代码
1. 将原前端的分组排序逻辑迁移到后端service实现 2. 后端实现三级排序:交货日期倒序→订单ID升序→创建时间倒序,保证跨页排序一致性和合同组连续排列 3. 移除前端冗余的groupSort方法和排序状态变量,简化前端页面逻辑 4. 更新前端排序提示文案为固定描述
This commit is contained in:
@@ -69,6 +69,8 @@ public class CrmOrderItemServiceImpl implements ICrmOrderItemService {
|
||||
|
||||
/**
|
||||
* 查询正式订单明细列表
|
||||
* 实现逻辑:查出全部匹配记录 → Java内存排序(交货日期倒序→订单ID升序→创建时间倒序)→ 手动分页
|
||||
* 排序跨页生效,同一合同明细连续排列
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<CrmOrderItemVo> queryPageList(CrmOrderItemBo bo, PageQuery pageQuery) {
|
||||
@@ -83,9 +85,47 @@ public class CrmOrderItemServiceImpl implements ICrmOrderItemService {
|
||||
if (orderIdScope != null) {
|
||||
lqw.in(CrmOrderItem::getOrderId, orderIdScope);
|
||||
}
|
||||
Page<CrmOrderItemVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
fillOrderInfoOnItems(result.getRecords());
|
||||
return TableDataInfo.build(result);
|
||||
// 1. 查出全部匹配记录
|
||||
List<CrmOrderItemVo> allItems = baseMapper.selectVoList(lqw);
|
||||
// 2. 填充订单信息(含 deliveryDate)
|
||||
fillOrderInfoOnItems(allItems);
|
||||
// 3. 三级排序:deliveryDate DESC → orderId ASC → createTime DESC
|
||||
allItems.sort((a, b) -> {
|
||||
// 同一合同组内:按创建时间倒序
|
||||
if (Objects.equals(a.getOrderId(), b.getOrderId())) {
|
||||
return compareDate(a.getCreateTime(), b.getCreateTime(), true);
|
||||
}
|
||||
// 不同合同组:按交货日期倒序
|
||||
Date dateA = a.getOrderInfo() != null ? a.getOrderInfo().getDeliveryDate() : null;
|
||||
Date dateB = b.getOrderInfo() != null ? b.getOrderInfo().getDeliveryDate() : null;
|
||||
int cmp = compareDate(dateA, dateB, true);
|
||||
if (cmp != 0) return cmp;
|
||||
// 交货日期相同:按订单ID升序,保证同一合同组连续
|
||||
return Long.compare(a.getOrderId(), b.getOrderId());
|
||||
});
|
||||
// 4. 手动分页
|
||||
int total = allItems.size();
|
||||
int pageNum = ObjectUtil.defaultIfNull(pageQuery.getPageNum(), 1);
|
||||
int pageSize = ObjectUtil.defaultIfNull(pageQuery.getPageSize(), 10);
|
||||
int from = (pageNum - 1) * pageSize;
|
||||
int to = Math.min(from + pageSize, total);
|
||||
List<CrmOrderItemVo> pageItems = from >= total ? Collections.emptyList() : allItems.subList(from, to);
|
||||
|
||||
Page<CrmOrderItemVo> page = new Page<>(pageNum, pageSize, total);
|
||||
page.setRecords(pageItems);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较两个日期,null 值排在末尾
|
||||
* @param desc true=倒序,false=升序
|
||||
*/
|
||||
private int compareDate(Date a, Date b, boolean desc) {
|
||||
if (a == null && b == null) return 0;
|
||||
if (a == null) return 1; // null 排在后面
|
||||
if (b == null) return -1;
|
||||
int cmp = a.compareTo(b);
|
||||
return desc ? -cmp : cmp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user