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,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">