feat(oms,wms):库存导出按到期日分组排序并合并同物料同到期日库存(仅wlExpiry查询生效)

需求:库存查询导出按商品到期日分组归类、相同到期日相邻显示,相同物料相同
到期日合并库存。仅在 queryRule=wlExpiry(物料+到期日汇总查询)导出时生效,
列表显示不变;同时回退 8fedb6d6 对列表默认排序的改动。

一、列表默认查询还原(回退 8fedb6d6):OMS queryList 恢复 order by a.update_time desc,
    Api 恢复 update_time 内存重排(空值最后),两侧列表排序与改动前一致。
二、导出排序(OMS/WMS queryListByWlExpiry):/list 新增可选参数 orderByExpiryDate,
    仅 queryRule=wlExpiry 时生效:
    1. wlExpiry + orderByExpiryDate=true(导出):到期日倒序(日期近的在前)、空值最后、
       0库存靠后、同到期日按更新时间倒序;排序在SQL层,跨页/全量导出分组不被打散;
       OMS Api 传参时跳过 update_time 内存重排,避免覆盖SQL排序
    2. 仅 wlExpiry 不带参数:排序保持原样(sort_order+更新时间倒序)
    3. 其他查询方式:不受影响,参数被忽略
三、合并:wlExpiry 查询 GROUP BY 物料+到期日+货主(货主隔离),相同物料相同到期日
    合并一行,库存/可用/冻结数量及净重/毛重/体积/面积 SUM 汇总(复用现成查询,未改)
四、前端导出:/list + queryRule=wlExpiry + orderByExpiryDate=true + 当前查询条件(不分页)
This commit is contained in:
rcx
2026-08-21 15:13:28 +08:00
parent 3aec384ba0
commit 22f2b66ffa
6 changed files with 52 additions and 12 deletions
@@ -255,4 +255,7 @@ public class ReservationMaterialInventoryDO extends MaterialBaseDO {
private String productionDateStr;
private String expiryDateStart;
private String expiryDateEnd;
@ApiModelProperty("导出按到期日分组排序标识:仅 queryRule=wlExpiry 时生效,true-到期日倒序(日期近的在前、空值最后、0库存靠后);不传-保持原有排序")
private Boolean orderByExpiryDate;
}
@@ -52,7 +52,8 @@ public class ReservationMaterialInventoryApi extends BaseController {
public TableDataInfo list(ReservationMaterialInventoryDTO materialInventoryDTO,
@RequestParam(value = "customerName", required = false) String customerName,
@RequestParam(value = "expiryDateStart", required = false) String expiryDateStart,
@RequestParam(value = "expiryDateEnd", required = false) String expiryDateEnd)
@RequestParam(value = "expiryDateEnd", required = false) String expiryDateEnd,
@RequestParam(value = "orderByExpiryDate", required = false) Boolean orderByExpiryDate)
{
// 出库分配前端传的是客户名称 customerName,这里通过名称查询货主ID,使用精确匹配(不模糊匹配)
String shipperName = null; // 保存查询到的货主名称
@@ -82,12 +83,24 @@ public class ReservationMaterialInventoryApi extends BaseController {
materialInventoryDO.setProductionDateStr(materialInventoryDTO.getProductionDate());
materialInventoryDO.setExpiryDateStart(expiryDateStart);
materialInventoryDO.setExpiryDateEnd(expiryDateEnd);
// 导出场景:queryRule=wlExpiry + orderByExpiryDate=true 时 SQL 按到期日倒序分组
// (日期近的在前、空值最后、0库存靠后、同到期日按更新时间倒序)
materialInventoryDO.setOrderByExpiryDate(orderByExpiryDate);
startPage();
// 使用带批次属性的查询方法,批次属性值从库存表中获取
// 排序由 SQL 统一处理:到期日倒序(日期近的在前、空值最后)、同到期日按更新时间倒序(空值最后),
// 查询列表与导出(同一接口)均按到期日分组,相同到期日的数据相邻显示;
// 不在内存重排,避免覆盖 SQL 排序导致跨页分组被打散
List<ReservationMaterialInventoryPO> list = materialInventoryApplicationService.queryListWithBatchAttributes(materialInventoryDO);
// 按更新时间倒序排序;update_time 为空的数据放最后
// (导出 orderByExpiryDate=true 时跳过该重排,避免覆盖 SQL 的到期日分组排序)
if (!Boolean.TRUE.equals(orderByExpiryDate)) {
list.sort((o1, o2) -> {
Date t1 = o1.getUpdateTime();
Date t2 = o2.getUpdateTime();
if (t1 == null && t2 == null) return 0;
if (t1 == null) return 1;
if (t2 == null) return -1;
return t2.compareTo(t1); // desc
});
}
TableDataInfo tableDataInfo = getDataTable(list);
return tableDataInfo;
}