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
@@ -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,16 +427,25 @@ 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"/>
<!-- 导出(queryRule=wlExpiry + orderByExpiryDate=true)按到期日分组归类:到期日倒序(日期近的在前)、
空值放最后、0库存靠后、同到期日按更新时间倒序;相同物料+相同到期日合并为一行,数量类字段SUM汇总。
不传 orderByExpiryDate 保持原有排序 -->
<!-- 导出排序两级开关:isExport=true 用融合排序(到期日优先→同到期日按物料编码升序,与 orderByExpiryDate 融合不取代)
否则保持原有 orderByExpiryDate 分支排序 -->
<choose>
<when test="orderByExpiryDate != null and orderByExpiryDate == true">
order by CASE WHEN a.expiry_date IS NULL THEN 1 ELSE 0 END ASC, a.expiry_date DESC,
sort_order, MAX(a.update_time) DESC
<when test="isExport != null and isExport == true">
<include refid="exportOrderByMaterialCode"/>
</when>
<otherwise>
order by sort_order, MAX(a.update_time) desc
<!-- 导出(queryRule=wlExpiry + orderByExpiryDate=true)按到期日分组归类:到期日倒序(日期近的在前)、
空值放最后、0库存靠后、同到期日按更新时间倒序;相同物料+相同到期日合并为一行,数量类字段SUM汇总。
不传 orderByExpiryDate 保持原有排序 -->
<choose>
<when test="orderByExpiryDate != null and orderByExpiryDate == true">
order by CASE WHEN a.expiry_date IS NULL THEN 1 ELSE 0 END ASC, a.expiry_date DESC,
sort_order, MAX(a.update_time) DESC
</when>
<otherwise>
order by sort_order, MAX(a.update_time) desc
</otherwise>
</choose>
</otherwise>
</choose>
</select>
@@ -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">