fix(wms 库存模块): 修复库存查询各页签分组维度不符合需求的问题

1. queryListByWl(物料查询):原按单物料分组会把同一物料跨仓库库存合并成一行,丢失仓库维度。子查询 partition by 增加 warehouse_id、join 增加 warehouse_id 关联、外层 GROUP BY 增加 warehouse_id,改为按"物料+仓库"汇总。
2. queryListByWlKw(物料/库位查询):GROUP BY 增加 shipper_id,改为按"货主+库位+物料"汇总,避免不同货主在同库位同物料的库存被错误合并。
3. queryListByHz(按货主查询):GROUP BY 增加 warehouse_id,改为按"货主+仓库"汇总;hzwl 分支改走 queryListByHz,符合"按货主查询:货主+仓库"需求。
This commit is contained in:
rcx
2026-08-08 15:08:01 +08:00
parent 02de8706e2
commit 969d90fff5
3 changed files with 30 additions and 29 deletions
@@ -3,7 +3,7 @@ package com.mhd.wms.domain.inventoryAdjustmentRecord.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.aliyun.oss.ServiceException;
import com.mhd.common.core.exception.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mhd.common.core.constant.SnowFlakeConstants;
import com.mhd.common.core.domain.po.UserPo;
@@ -175,7 +175,7 @@ public class InventoryAdjustmentRecordDomainService {
}
materialInventory.setAllocationQuantity(materialInventory.getAllocationQuantity().subtract(inventoryAdjustmentRecordDO.getAdjustQuantity()));
if (materialInventory.getAllocationQuantity().compareTo(BigDecimal.ZERO) < 0) {
throw new ServiceException("可用数量调整之后不能小于0");
throw new ServiceException("调整之后可用数量不能小于0");
}
}
inventoryAdjustmentRecord.setInventoryAfterQuantity(materialInventory.getInventoryQuantity());
@@ -231,7 +231,7 @@ public class InventoryAdjustmentRecordDomainService {
}
materialInventory.setAllocationQuantity(materialInventory.getAllocationQuantity().subtract(inventoryAdjustmentRecordDO.getAdjustQuantity()));
if (materialInventory.getAllocationQuantity().compareTo(BigDecimal.ZERO) < 0) {
throw new ServiceException("可用数量调整之后不能小于0");
throw new ServiceException("调整之后可用数量不能小于0");
}
inventoryAdjustmentRecord.setInventoryAfterQuantity(materialInventory.getInventoryQuantity());
inventoryAdjustmentRecord.setAllocationAfterQuantity(materialInventory.getAllocationQuantity());
@@ -78,7 +78,8 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
if ("hz".equals(queryRule)) {
return materialInventoryMapper.queryListByHz(materialInventoryDO);
} else if ("hzwl".equals(queryRule)) { // 货主查询
return materialInventoryMapper.queryListByHzWl(materialInventoryDO);
return materialInventoryMapper.queryListByHz(materialInventoryDO);
// return materialInventoryMapper.queryListByHzWl(materialInventoryDO);
} else if ("wl".equals(queryRule)) { // 物料查询
return materialInventoryMapper.queryListByWl(materialInventoryDO);
} else if ("kw".equals(queryRule)) {
@@ -406,7 +406,7 @@ 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_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 order by sort_order, a.update_time desc
</select>
<select id="queryListByKw" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">
@@ -429,30 +429,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from material_inventory a
left join material_base_info b on a.material_base_info_id = b.material_base_info_id
inner join (
select material_base_info_id, warehouse_id, warehouse_code, warehouse_name,
storage_section_id, storage_code, storage_name,
storage_location_id, storage_location_code, storage_location_name
from (
select mi.material_base_info_id, mi.warehouse_id, mi.warehouse_code, mi.warehouse_name,
mi.storage_section_id, mi.storage_code, mi.storage_name,
mi.storage_location_id, mi.storage_location_code, mi.storage_location_name,
row_number() over (partition by mi.material_base_info_id order by mi.create_time desc, mi.material_inventory_id desc) as wl_rn
from material_inventory mi
left join material_base_info b on mi.material_base_info_id = b.material_base_info_id
<where>
<include refid="selectMaterialInventoryPo1Mi"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPoWhere"/>
</where>
) wl_ranked where wl_ranked.wl_rn = 1
) loc on loc.material_base_info_id = a.material_base_info_id
select material_base_info_id, warehouse_id, warehouse_code, warehouse_name,
storage_section_id, storage_code, storage_name,
storage_location_id, storage_location_code, storage_location_name
from (
select mi.material_base_info_id, mi.warehouse_id, mi.warehouse_code, mi.warehouse_name,
mi.storage_section_id, mi.storage_code, mi.storage_name,
mi.storage_location_id, mi.storage_location_code, mi.storage_location_name,
row_number() over (partition by mi.material_base_info_id, mi.warehouse_id order by mi.create_time desc, mi.material_inventory_id desc) as wl_rn
from material_inventory mi
left join material_base_info b on mi.material_base_info_id = b.material_base_info_id
<where>
<include refid="selectMaterialInventoryPo1Mi"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPoWhere"/>
</where>
) wl_ranked where wl_ranked.wl_rn = 1
) loc on loc.material_base_info_id = a.material_base_info_id and loc.warehouse_id = a.warehouse_id
<where>
<include refid="selectMaterialInventoryPo1"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPoWhere"/>
</where>
GROUP BY 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
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
</select>
<!-- 按物料+过期日期汇总:相同物料+相同过期日期合并,不同过期日期分开 -->
@@ -534,7 +534,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
a.shipper_id,
MAX(a.shipper_code) AS shipper_code,
MAX(a.shipper_name) AS shipper_name,
b.material_base_info_id,
MAX(b.material_base_info_id) AS material_base_info_id,
MAX(b.material_code) AS material_code,
MAX(b.material_name) AS material_name,
MAX(b.SPECIFICATION_MODEL) AS SPECIFICATION_MODEL,
@@ -551,7 +551,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
MAX(b.pack_id) AS pack_id,
MAX(b.pack_code) AS pack_code,
MAX(b.pack_name) AS pack_name,
MAX(a.unit) AS unit,
MAX(a.unit) AS unit,
IFNULL(SUM(a.freeze_quantity), 0) AS freeze_quantity,
IFNULL(SUM(a.inventory_quantity), 0) AS inventory_quantity,
IFNULL(SUM(a.allocation_quantity), 0) AS allocation_quantity,
@@ -580,7 +580,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</where>
GROUP BY a.shipper_id,
b.material_base_info_id,
b.material_code,
a.warehouse_id,
a.organization_id, a.top_organization_id
ORDER BY sort_order, MAX(a.update_time) DESC
@@ -596,7 +596,7 @@ 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 order by sort_order, a.update_time desc
GROUP BY a.SHIPPER_ID, a.WAREHOUSE_ID order by sort_order, a.update_time desc
</select>
<resultMap type="com.mhd.wms.domain.materialInventory.repository.po.MaterialInventoryQueryListPO" id="MaterialQueryListResult">