feat(oms,wms):库存查询导出新增isExport标识与融合排序 /list 新增可选参数 isExport 标识导出请求(导出显示商品饮用有效期/物料分类/进货日期由查询结果直接返回);isExport=true 时所有查询维度(OMS 6条/WMS 8条)统一启用导出融合排序:到期日倒序空值最后(保留原 orderByExpiryDate 第一优先级,融合不取代)→同到期日内按物料编码升序→0库存靠后→更新时间倒序→MAX(库存ID)兜底保证分页稳定;各语句挂载公共片段 exportOrderByMaterialCode,不传 isExport 保持原有排序;OMS Controller 在 isExport=true 时跳过 Java 按更新时间重排避免覆盖 SQL 导出排序

This commit is contained in:
rcx
2026-09-01 16:29:41 +08:00
parent bb3ca932d2
commit a4f27ab643
6 changed files with 143 additions and 29 deletions
@@ -270,4 +270,7 @@ public class ReservationMaterialInventoryDO extends MaterialBaseDO {
@ApiModelProperty("导出排除库存为0标识:true-排除库存数量汇总为0的数据(所有查询维度 queryRule 均生效);不传-不过滤")
private Boolean excludeZeroInventoryQuantity;
@ApiModelProperty("导出标识:导出与查询共用 /list,true-本次为导出请求,启用导出融合排序(到期日倒序优先→同到期日按物料编码升序→0库存靠后→更新时间倒序);不传-保持原有排序")
private Boolean isExport;
}
@@ -47,7 +47,7 @@ public class ReservationMaterialInventoryApi extends BaseController {
/**
* 分页查询物料库存列表
*/
@ApiOperation(value = "查询物料库存列表", notes = "导出复用本接口,任意查询维度(queryRule)下:前端\"库存为0是否导出\"\"\"时传 excludeZeroInventoryQuantity=true 排除库存为0的数据,不传或 false 导出全部(含库存为0)orderByExpiryDate=true 按到期日分组排序")
@ApiOperation(value = "查询物料库存列表", notes = "导出复用本接口:传 isExport=true 标识导出请求(导出显示:商品饮用有效期expiryDate/物料分类materialClassifyName/进货日期purchaseDate,所有查询维度均返回);excludeZeroInventoryQuantity=true 排除库存为0的数据(所有维度生效)orderByExpiryDate=true 按到期日分组排序")
@GetMapping("/list")
public TableDataInfo list(ReservationMaterialInventoryDTO materialInventoryDTO,
@RequestParam(value = "customerName", required = false) String customerName,
@@ -56,7 +56,9 @@ public class ReservationMaterialInventoryApi extends BaseController {
@RequestParam(value = "purchaseDateStart", required = false) String purchaseDateStart,
@RequestParam(value = "purchaseDateEnd", required = false) String purchaseDateEnd,
@RequestParam(value = "excludeZeroInventoryQuantity", required = false) Boolean excludeZeroInventoryQuantity,
@RequestParam(value = "orderByExpiryDate", required = false) Boolean orderByExpiryDate)
@RequestParam(value = "orderByExpiryDate", required = false) Boolean orderByExpiryDate,
// 导出标识:导出与查询共用本接口,isExport=true 表示本次请求为导出(导出专属排序等逻辑以此开关)
@RequestParam(value = "isExport", required = false) Boolean isExport)
{
// 出库分配前端传的是客户名称 customerName,这里通过名称查询货主ID,使用精确匹配(不模糊匹配)
String shipperName = null; // 保存查询到的货主名称
@@ -95,12 +97,14 @@ public class ReservationMaterialInventoryApi extends BaseController {
// 导出场景:前端"库存为0是否导出"选"是"时传 excludeZeroInventoryQuantity=true
// SQL 用 HAVING 排除汇总库存为0的数据(与 WMS 同名参数语义一致)
materialInventoryDO.setExcludeZeroInventoryQuantity(excludeZeroInventoryQuantity);
// 导出标识:isExport=true 启用导出融合排序(到期日倒序优先 → 同到期日按物料编码升序,所有维度生效)
materialInventoryDO.setIsExport(isExport);
startPage();
// 使用带批次属性的查询方法,批次属性值从库存表中获取
List<ReservationMaterialInventoryPO> list = materialInventoryApplicationService.queryListWithBatchAttributes(materialInventoryDO);
// 按更新时间倒序排序;update_time 为空的数据放最后
// (导出 orderByExpiryDate=true 时跳过该重排,避免覆盖 SQL 的到期日分组排序)
if (!Boolean.TRUE.equals(orderByExpiryDate)) {
// (导出 orderByExpiryDate=true 或 isExport=true 时跳过该重排,避免覆盖 SQL 的导出排序)
if (!Boolean.TRUE.equals(orderByExpiryDate) && !Boolean.TRUE.equals(isExport)) {
list.sort((o1, o2) -> {
Date t1 = o1.getUpdateTime();
Date t2 = o2.getUpdateTime();
@@ -305,6 +305,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</sql>
<!-- 导出融合排序(isExport=true):保留"到期日优先"第一优先级(到期日倒序、空值最后),
融合新增"同到期日内按物料编码升序",再保留 0库存靠后、更新时间倒序 兜底,
末位以 MAX(物料库存ID) 保证分页序稳定;不传 isExport 各语句保持原有排序 -->
<sql id="exportOrderByMaterialCode">
order by CASE WHEN MAX(a.expiry_date) IS NULL THEN 1 ELSE 0 END ASC, MAX(a.expiry_date) DESC,
MAX(b.material_code) ASC,
CASE WHEN IFNULL(SUM(a.inventory_quantity), 0) = 0 THEN 1 ELSE 0 END ASC,
MAX(a.update_time) DESC,
MAX(a.material_inventory_id) DESC
</sql>
<select id="queryList" parameterType="com.mhd.oms.domain.reservationMaterialInventory.repository.todo.ReservationMaterialInventoryDO" resultMap="MaterialInventoryResult">
select
<include refid="selectMaterialInventoryPo"/>
@@ -315,7 +326,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectMaterialInventoryPo1"/>
<include refid="JoinMaterialBaseInfoPoWhere"/>
</where>
group by a.MATERIAL_INVENTORY_ID <include refid="excludeZeroInventoryHaving"/> order by a.update_time desc
group by a.MATERIAL_INVENTORY_ID <include refid="excludeZeroInventoryHaving"/>
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise> order by a.update_time desc </otherwise>
</choose>
</select>
<select id="queryListByWlKw" parameterType="com.mhd.oms.domain.reservationMaterialInventory.repository.todo.ReservationMaterialInventoryDO" resultMap="MaterialInventoryResult">
@@ -330,6 +347,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
GROUP BY a.MATERIAL_BASE_INFO_ID,a.WAREHOUSE_ID,a.STORAGE_SECTION_ID,a.STORAGE_LOCATION_ID
<include refid="excludeZeroInventoryHaving"/>
<if test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</if>
</select>
<select id="queryListByKw" parameterType="com.mhd.oms.domain.reservationMaterialInventory.repository.todo.ReservationMaterialInventoryDO" resultMap="MaterialInventoryResult">
@@ -344,6 +364,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
GROUP BY a.WAREHOUSE_ID,a.STORAGE_SECTION_ID,a.STORAGE_LOCATION_ID
<include refid="excludeZeroInventoryHaving"/>
<if test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</if>
</select>
<select id="queryListByWl" parameterType="com.mhd.oms.domain.reservationMaterialInventory.repository.todo.ReservationMaterialInventoryDO" resultMap="MaterialInventoryResult">
@@ -358,6 +381,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
GROUP BY a.MATERIAL_BASE_INFO_ID
<include refid="excludeZeroInventoryHaving"/>
<if test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</if>
</select>
<!-- 按物料+过期日期汇总 -->
@@ -401,6 +427,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
a.organization_id, a.organization_name, a.top_organization_id,
b.material_code, b.material_name
<include refid="excludeZeroInventoryHaving"/>
<!-- 导出排序两级开关:isExport=true 用融合排序(到期日优先→同到期日按物料编码升序,与 orderByExpiryDate 融合不取代)
否则保持原有 orderByExpiryDate 分支排序 -->
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise>
<!-- 导出(queryRule=wlExpiry + orderByExpiryDate=true)按到期日分组归类:到期日倒序(日期近的在前)、
空值放最后、0库存靠后、同到期日按更新时间倒序;相同物料+相同到期日合并为一行,数量类字段SUM汇总。
不传 orderByExpiryDate 保持原有排序 -->
@@ -413,6 +446,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by sort_order, MAX(a.update_time) desc
</otherwise>
</choose>
</otherwise>
</choose>
</select>
<select id="queryListByHz" parameterType="com.mhd.oms.domain.reservationMaterialInventory.repository.todo.ReservationMaterialInventoryDO" resultMap="MaterialInventoryResult">
@@ -427,6 +462,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
GROUP BY a.SHIPPER_ID
<include refid="excludeZeroInventoryHaving"/>
<if test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</if>
</select>
<resultMap type="com.mhd.oms.domain.reservationMaterialInventory.repository.po.ReservationMaterialInventoryQueryListPO" id="MaterialQueryListResult">
@@ -285,4 +285,7 @@ public class MaterialInventoryDO extends MaterialBaseDO {
@ApiModelProperty("库存分配匹配:Batch Ref NO's token 列表(默认不启用,仅显式赋值时参与匹配)")
private List<String> batchRefNoList;
@ApiModelProperty("导出标识:导出与查询共用 /list,true-本次为导出请求,启用导出融合排序(到期日倒序优先→同到期日按物料编码升序→0库存靠后→更新时间倒序);不传-保持原有排序")
private Boolean isExport;
}
@@ -53,7 +53,7 @@ public class MaterialInventoryApi extends BaseController {
/**
* 分页查询物料库存列表
*/
@ApiOperation(value = "查询物料库存列表", notes = "库存查询页不传 excludeZeroInventoryQuantity 可查出数量为0;出库分配页传 excludeZeroInventoryQuantity=true 排除库存数量为0")
@ApiOperation(value = "查询物料库存列表", notes = "库存查询页不传 excludeZeroInventoryQuantity 可查出数量为0;出库分配页传 excludeZeroInventoryQuantity=true 排除库存数量为0;导出复用本接口:传 isExport=true 标识导出请求(导出显示:商品饮用有效期expiryDate/物料分类materialClassifyName/进货日期purchaseDate,所有查询维度均返回)")
@GetMapping("/list")
public TableDataInfo list(MaterialInventoryDTO materialInventoryDTO,
@RequestParam(value = "customerName", required = false) String customerName,
@@ -62,7 +62,9 @@ public class MaterialInventoryApi extends BaseController {
@RequestParam(value = "expiryDateEnd", required = false) String expiryDateEnd,
@RequestParam(value = "purchaseDateStart", required = false) String purchaseDateStart,
@RequestParam(value = "purchaseDateEnd", required = false) String purchaseDateEnd,
@RequestParam(value = "orderByExpiryDate", required = false) Boolean orderByExpiryDate)
@RequestParam(value = "orderByExpiryDate", required = false) Boolean orderByExpiryDate,
// 导出标识:导出与查询共用本接口,isExport=true 表示本次请求为导出(导出专属排序等逻辑以此开关)
@RequestParam(value = "isExport", required = false) Boolean isExport)
{
if (Boolean.TRUE.equals(excludeZeroInventoryQuantity)) {
materialInventoryDTO.setExcludeZeroInventoryQuantity(true);
@@ -100,6 +102,8 @@ public class MaterialInventoryApi extends BaseController {
materialInventoryDO.setPurchaseDateEnd(purchaseDateEnd);
// 导出场景:queryRule=wlExpiry + orderByExpiryDate=true 时 SQL 按到期日倒序分组(与 OMS 库存查询导出一致)
materialInventoryDO.setOrderByExpiryDate(orderByExpiryDate);
// 导出标识:isExport=true 启用导出融合排序(到期日倒序优先 → 同到期日按物料编码升序,所有维度生效)
materialInventoryDO.setIsExport(isExport);
Date updateTime = materialInventoryDTO.getUpdateTime();
if (updateTime != null) {
LocalDateTime localDateTime = updateTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
@@ -172,7 +176,8 @@ public class MaterialInventoryApi extends BaseController {
// materialDetailId 是新接口专用参数(出库单明细ID),库存 DTO 的同名字段语义是「上架单明细ID」,
// 泄入原查询会生成错误的 a.material_detail_id 条件导致查空,进原查询前显式清除
materialInventoryDTO.setMaterialDetailId(null);
return list(materialInventoryDTO, customerName, excludeZeroInventoryQuantity, expiryDateStart, expiryDateEnd, null, null, orderByExpiryDate);
// assignableList 非导出场景,isExport 传 null
return list(materialInventoryDTO, customerName, excludeZeroInventoryQuantity, expiryDateStart, expiryDateEnd, null, null, orderByExpiryDate, null);
}
@ApiOperation("查询物料库存列表不分页;queryRule=hz 时按货主+物料分组(同一物料在不同货主各占一行)")
@@ -403,6 +403,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</sql>
<!-- 导出融合排序(isExport=true):保留"到期日优先"第一优先级(到期日倒序、空值最后),
融合新增"同到期日内按物料编码升序",再保留 0库存靠后、更新时间倒序 兜底,
末位以 MAX(物料库存ID) 保证分页序稳定;不传 isExport 各语句保持原有排序 -->
<sql id="exportOrderByMaterialCode">
order by CASE WHEN MAX(a.expiry_date) IS NULL THEN 1 ELSE 0 END ASC, MAX(a.expiry_date) DESC,
MAX(b.material_code) ASC,
CASE WHEN IFNULL(SUM(a.inventory_quantity), 0) = 0 THEN 1 ELSE 0 END ASC,
MAX(a.update_time) DESC,
MAX(a.material_inventory_id) DESC
</sql>
<select id="queryList" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">
select
<include refid="selectMaterialInventoryPo"/>
@@ -413,7 +424,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectMaterialInventoryPo1"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPoWhere"/>
</where>
group by a.MATERIAL_INVENTORY_ID order by sort_order, a.update_time desc
group by a.MATERIAL_INVENTORY_ID
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise> order by sort_order, a.update_time desc </otherwise>
</choose>
</select>
<!-- 库存数量合计:与 queryList 相同筛选条件,对全部命中明细行 SUM(库存数量);
@@ -496,7 +513,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectMaterialInventoryPo1"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPoWhere"/>
</where>
GROUP BY a.SHIPPER_ID,a.MATERIAL_BASE_INFO_ID,a.WAREHOUSE_ID,a.STORAGE_SECTION_ID,a.STORAGE_LOCATION_ID order by sort_order, a.update_time desc
GROUP BY a.SHIPPER_ID,a.MATERIAL_BASE_INFO_ID,a.WAREHOUSE_ID,a.STORAGE_SECTION_ID,a.STORAGE_LOCATION_ID
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise> order by sort_order, a.update_time desc </otherwise>
</choose>
</select>
<select id="queryListByKw" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">
@@ -509,7 +532,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectMaterialInventoryPo1"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPoWhere"/>
</where>
GROUP BY a.WAREHOUSE_ID,a.STORAGE_SECTION_ID,a.STORAGE_LOCATION_ID order by sort_order, a.update_time desc
GROUP BY a.WAREHOUSE_ID,a.STORAGE_SECTION_ID,a.STORAGE_LOCATION_ID
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise> order by sort_order, a.update_time desc </otherwise>
</choose>
</select>
<select id="queryListByWl" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">
@@ -542,7 +571,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
GROUP BY a.MATERIAL_BASE_INFO_ID, a.WAREHOUSE_ID,
loc.warehouse_id, loc.warehouse_code, loc.warehouse_name,
loc.storage_section_id, loc.storage_code, loc.storage_name,
loc.storage_location_id, loc.storage_location_code, loc.storage_location_name order by sort_order, a.update_time desc
loc.storage_location_id, loc.storage_location_code, loc.storage_location_name
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise> order by sort_order, a.update_time desc </otherwise>
</choose>
</select>
<!-- 按物料+过期日期汇总:相同物料+相同过期日期合并,不同过期日期分开 -->
@@ -586,6 +621,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
GROUP BY a.MATERIAL_BASE_INFO_ID, a.EXPIRY_DATE, a.shipper_id,
a.organization_id, a.top_organization_id
<!-- 导出排序两级开关:isExport=true 用融合排序(到期日优先→同到期日按物料编码升序,与 orderByExpiryDate 融合不取代)
否则保持原有 orderByExpiryDate 分支排序 -->
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise>
<!-- 导出(queryRule=wlExpiry + orderByExpiryDate=true)按到期日分组归类:到期日倒序(日期近的在前)、
空值放最后、0库存靠后、同到期日按更新时间倒序;相同物料+相同到期日合并为一行,数量类字段SUM汇总。
不传 orderByExpiryDate 保持原有排序 -->
@@ -598,6 +640,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by sort_order, MAX(a.update_time) desc
</otherwise>
</choose>
</otherwise>
</choose>
</select>
<!-- 按货主+物料汇总:A货主物料1、A货主物料2、B货主物料1、B货主物料2 为 4 行;库位取该货主+该物料下创建时间最新的一条明细 -->
@@ -631,7 +675,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
GROUP BY a.SHIPPER_ID, a.MATERIAL_BASE_INFO_ID,
loc.warehouse_id, loc.warehouse_code, loc.warehouse_name,
loc.storage_section_id, loc.storage_code, loc.storage_name,
loc.storage_location_id, loc.storage_location_code, loc.storage_location_name order by sort_order, a.update_time desc
loc.storage_location_id, loc.storage_location_code, loc.storage_location_name
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise> order by sort_order, a.update_time desc </otherwise>
</choose>
</select>
<!-- ============ 按货主+物料+仓库+单位 汇总(库存查询第三个页签) ============ -->
@@ -691,7 +741,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
b.material_code,
a.warehouse_id,
a.organization_id, a.top_organization_id
ORDER BY sort_order, MAX(a.update_time) DESC
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise> ORDER BY sort_order, MAX(a.update_time) DESC </otherwise>
</choose>
</select>
<select id="queryListByHz" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">
@@ -704,7 +759,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectMaterialInventoryPo1"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPoWhere"/>
</where>
GROUP BY a.SHIPPER_ID, a.WAREHOUSE_ID order by sort_order, a.update_time desc
GROUP BY a.SHIPPER_ID, a.WAREHOUSE_ID
<choose>
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise> order by sort_order, a.update_time desc </otherwise>
</choose>
</select>
<resultMap type="com.mhd.wms.domain.materialInventory.repository.po.MaterialInventoryQueryListPO" id="MaterialQueryListResult">