refactor(crm): 优化订单明细查询逻辑,移除内存排序并迁移到SQL层
1. 新增联表分页查询方法,在数据库层完成排序和分页 2. 移除前端页面冗余的合同信息缓存和内存排序逻辑 3. 新增钢卷导入组件,支持调拨单钢批量化导入 4. 补充订单明细VO类的联表查询字段
This commit is contained in:
@@ -181,6 +181,59 @@ public class CrmOrderItemVo {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 删除标志
|
||||
*/
|
||||
private Long delFlag;
|
||||
|
||||
/**
|
||||
* 合同号(联表查询直接映射)
|
||||
*/
|
||||
@ExcelProperty(value = "合同号")
|
||||
private String contractCode;
|
||||
|
||||
/**
|
||||
* 供方(联表查询直接映射)
|
||||
*/
|
||||
@ExcelProperty(value = "供方")
|
||||
private String supplier;
|
||||
|
||||
/**
|
||||
* 需方(联表查询直接映射)
|
||||
*/
|
||||
@ExcelProperty(value = "需方")
|
||||
private String customer;
|
||||
|
||||
/**
|
||||
* 签订时间(联表查询直接映射)
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@ExcelProperty(value = "签订时间")
|
||||
private Date signTime;
|
||||
|
||||
/**
|
||||
* 交货日期(联表查询直接映射)
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@ExcelProperty(value = "交货日期")
|
||||
private Date deliveryDate;
|
||||
|
||||
/**
|
||||
* 订单信息
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.klp.crm.mapper;
|
||||
|
||||
import com.klp.crm.domain.CrmOrderItem;
|
||||
import com.klp.crm.domain.bo.CrmOrderItemBo;
|
||||
import com.klp.crm.domain.vo.CrmOrderItemVo;
|
||||
import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -22,4 +24,14 @@ public interface CrmOrderItemMapper extends BaseMapperPlus<CrmOrderItemMapper, C
|
||||
* @return 订单明细列表
|
||||
*/
|
||||
List<CrmOrderItem> selectOrderItemsByOrderIds(@Param("orderIds") List<Long> orderIds);
|
||||
|
||||
/**
|
||||
* 联表查询订单明细(支持排序和分页)
|
||||
* 排序规则:deliveryDate DESC -> orderId ASC -> createTime DESC
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param bo 查询条件
|
||||
* @return 分页结果
|
||||
*/
|
||||
Page<CrmOrderItemVo> selectVoListWithOrder(Page<CrmOrderItemVo> page, @Param("bo") CrmOrderItemBo bo);
|
||||
}
|
||||
|
||||
@@ -69,51 +69,19 @@ public class CrmOrderItemServiceImpl implements ICrmOrderItemService {
|
||||
|
||||
/**
|
||||
* 查询正式订单明细列表
|
||||
* 实现逻辑:查出全部匹配记录 → Java内存排序(交货日期倒序→订单ID升序→创建时间倒序)→ 手动分页
|
||||
* 排序跨页生效,同一合同明细连续排列
|
||||
* 实现逻辑:SQL联表查询 → 数据库层排序(交货日期倒序→订单ID升序→创建时间倒序)→ 物理分页
|
||||
* 排序跨页生效,同一合同明细连续排列,避免内存排序大数据量问题
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<CrmOrderItemVo> queryPageList(CrmOrderItemBo bo, PageQuery pageQuery) {
|
||||
List<Long> orderIdScope = resolveOrderIdScope(bo);
|
||||
if (orderIdScope != null && orderIdScope.isEmpty()) {
|
||||
Page<CrmOrderItemVo> emptyPage = new Page<>(ObjectUtil.defaultIfNull(pageQuery.getPageNum(), 1),
|
||||
ObjectUtil.defaultIfNull(pageQuery.getPageSize(), 10), 0);
|
||||
emptyPage.setRecords(Collections.emptyList());
|
||||
return TableDataInfo.build(emptyPage);
|
||||
}
|
||||
LambdaQueryWrapper<CrmOrderItem> lqw = buildQueryWrapper(bo);
|
||||
if (orderIdScope != null) {
|
||||
lqw.in(CrmOrderItem::getOrderId, orderIdScope);
|
||||
}
|
||||
// 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);
|
||||
// 使用MyBatis-Plus分页插件,SQL层完成联表查询、排序和分页
|
||||
Page<CrmOrderItemVo> page = new Page<>(
|
||||
ObjectUtil.defaultIfNull(pageQuery.getPageNum(), 1),
|
||||
ObjectUtil.defaultIfNull(pageQuery.getPageSize(), 10)
|
||||
);
|
||||
// 联表查询:在SQL层完成排序,避免内存排序
|
||||
Page<CrmOrderItemVo> resultPage = baseMapper.selectVoListWithOrder(page, bo);
|
||||
return TableDataInfo.build(resultPage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user