出库单编辑计划数量不变问题,库存查询显示问题

This commit is contained in:
秦鸿展
2026-05-12 15:36:04 +08:00
parent 97b4e5028e
commit ff95284448
7 changed files with 213 additions and 5 deletions
@@ -33,6 +33,8 @@ public interface MaterialInventoryMapper extends BaseMapper<MaterialInventory>
public List<MaterialInventoryPO> queryListByWl(MaterialInventoryDO materialInventoryDO);
//查物料库存列表-货主
public List<MaterialInventoryPO> queryListByHz(MaterialInventoryDO materialInventoryDO);
//查物料库存列表-货主+物料(同一物料在不同货主下各一行)
public List<MaterialInventoryPO> queryListByHzWl(MaterialInventoryDO materialInventoryDO);
/**
* @description 批量增加库存
@@ -74,6 +74,8 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
String queryRule = materialInventoryDO.getQueryRule();
if ("hz".equals(queryRule)) {
return materialInventoryMapper.queryListByHz(materialInventoryDO);
} else if ("hzwl".equals(queryRule)) {
return materialInventoryMapper.queryListByHzWl(materialInventoryDO);
} else if ("wl".equals(queryRule)) {
return materialInventoryMapper.queryListByWl(materialInventoryDO);
} else if ("kw".equals(queryRule)) {
@@ -230,7 +230,7 @@ public class MaterialInventoryDO extends MaterialBaseDO {
@Excel(name = "ExtAttr4", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date extAttr4;
//查询规则 hz:货主,wl:物料,kw:库位,wlkw:物料库位,all:全部
//查询规则 hz:货主,hzwl:货主+物料,wl:物料,kw:库位,wlkw:物料库位,all:全部listAll 传入 hz 时会改为 hzwl
private String queryRule;
@ApiModelProperty("冻结数量大于0条件")
@@ -1649,6 +1649,11 @@ public class StockOutOrderDomainService {
outMaterialDetailDO.setPackCode(materialBaseInfoPO.getPackCode());
outMaterialDetailDO.setPackName(materialBaseInfoPO.getPackName());
// 将出库数量赋值给计划数量
if (outMaterialDetailDO.getOutboundQuantity() != null) {
outMaterialDetailDO.setQuantity(outMaterialDetailDO.getOutboundQuantity());
}
//获取包装详情
/*AjaxResult packDetailResult = systemServiceFeign.getInfoByPackIdAndUnitCode(materialBaseInfoPO.getPackId(), "EA");
if(!"200".equals(String.valueOf(packDetailResult.get("code")))){
@@ -162,7 +162,7 @@ public class MaterialInventoryDTO extends MaterialBaseDTO {
@ApiModelProperty("箱号/卡板号")
@Excel(name = "箱号/卡板号")
private String boxPalletNo;
//查询规则 hz:货主,wl:物料,kw:库位,wlkw:物料库位,all:全部
//查询规则 hz:货主,hzwl:货主+物料,wl:物料,kw:库位,wlkw:物料库位,all:全部materialInventoryApi/listAll 传 hz 时后端按货主+物料分组)
private String queryRule;
@ApiModelProperty("净重(KG)")
@@ -128,12 +128,16 @@ public class MaterialInventoryApi extends BaseController {
return tableDataInfo;
}
@ApiOperation("查询物料库存列表不分页")
@ApiOperation("查询物料库存列表不分页queryRule=hz 时按货主+物料分组(同一物料在不同货主各占一行)")
@GetMapping("/listAll")
public TableDataInfo listAll(MaterialInventoryDTO materialInventoryDTO)
{
//转换实体
MaterialInventoryDO materialInventoryDO = materialInventoryAssembler.toDO(materialInventoryDTO);
// 不分页列表按货主查询:需按「货主+物料」汇总;分页 /list 仍用 hz 表示仅按货主一行
if ("hz".equals(materialInventoryDO.getQueryRule())) {
materialInventoryDO.setQueryRule("hzwl");
}
List<MaterialInventoryPO> list = materialInventoryApplicationService.queryList(materialInventoryDO);
return getDataTable(list);
}
@@ -89,6 +89,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
a.in_order_number,a.lot_number
</sql>
<!-- 按物料(wl)汇总:仓库/库区/库位取创建时间最新的一条明细(与 queryListByWl 中 loc 子查询一致;并列时取 material_inventory_id 更大) -->
<sql id="selectMaterialInventoryPoWl">
a.material_inventory_id, a.organization_id, a.organization_name, a.top_organization_id,
a.shipper_id, a.shipper_code, a.shipper_name,
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, a.material_base_info_id,a.material_detail_id,
a.batch_number,a.material_status_code,a.material_status_name,a.container_id,a.container_code,a.container_type,a.container_type_name
,IFNULL (sum(a.freeze_quantity), 0) freeze_quantity,a.is_able,
IFNULL (sum(a.inventory_quantity), 0) inventory_quantity,
IFNULL (sum(a.allocation_quantity), 0) allocation_quantity,
a.remark, a.create_time, a.create_by, a.create_by_name, a.update_time, a.update_by, a.update_by_name,
a.del_flag,a.unit,
IFNULL (sum(a.area), 0) area,
IFNULL (sum(a.NET_WEIGHT), 0) NET_WEIGHT,
IFNULL (sum(a.GROSS_WEIGHT), 0) GROSS_WEIGHT,
IFNULL (sum(a.VOLUME), 0) VOLUME,
a.ext_attr_1, a.ext_attr_2, a.ext_attr_3, a.ext_attr_4,
a.production_date, a.expiry_date, a.inventory_date,
a.BATCH_REF_NO, a.SHEET_REF_NO, a.BOX_PALLET_NO,nvl(a.unit_name,b.unit_name) as unit_name,
a.bar_code as inv_bar_code,
a.in_order_number,a.lot_number
</sql>
<sql id="selectMaterialInventoryPo1">
<if test="materialInventoryId != null ">
and a.material_inventory_id = #{materialInventoryId}
@@ -211,6 +234,124 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</sql>
<!-- 与 selectMaterialInventoryPo1 相同条件,表别名为 mi(用于 queryListByWl 最新明细子查询) -->
<sql id="selectMaterialInventoryPo1Mi">
<if test="materialInventoryId != null ">
and mi.material_inventory_id = #{materialInventoryId}
</if>
<if test="organizationId != null ">
and mi.organization_id = #{organizationId}
</if>
<if test="organizationName != null and organizationName != ''">
and mi.organization_name like concat('%', #{organizationName}, '%')
</if>
<if test="topOrganizationId != null ">
and mi.top_organization_id = #{topOrganizationId}
</if>
<if test="warehouseId != null ">
and mi.warehouse_id = #{warehouseId}
</if>
<if test="shipperId != null ">
and mi.shipper_id = #{shipperId}
</if>
<if test="warehouseCode != null and warehouseCode != ''">
and mi.warehouse_code = #{warehouseCode}
</if>
<if test="warehouseName != null and warehouseName != ''">
and mi.warehouse_name like concat('%', #{warehouseName}, '%')
</if>
<if test="storageSectionId != null ">
and mi.storage_section_id = #{storageSectionId}
</if>
<if test="storageCode != null and storageCode != ''">
and mi.storage_code = #{storageCode}
</if>
<if test="storageName != null and storageName != ''">
and mi.storage_name like concat('%', #{storageName}, '%')
</if>
<if test="storageLocationId != null ">
and mi.storage_location_id = #{storageLocationId}
</if>
<if test="storageLocationCode != null and storageLocationCode != ''">
and mi.storage_location_code = #{storageLocationCode}
</if>
<if test="storageLocationName != null and storageLocationName != ''">
and mi.storage_location_name like concat('%', #{storageLocationName}, '%')
</if>
<if test="materialBaseInfoId != null ">
and mi.material_base_info_id = #{materialBaseInfoId}
</if>
<if test="materialDetailId != null ">
and mi.material_detail_id, = #{materialDetailId}
</if>
<choose>
<when test="containerOrBatch != null and containerOrBatch != ''">
and (mi.container_code like concat('%', #{containerOrBatch}, '%') or mi.batch_number like concat('%', #{containerOrBatch}, '%'))
</when>
<when test="batchNumber != null and batchNumber != '' and containerCode != null and containerCode != '' and batchNumber == containerCode">
and (mi.batch_number like concat('%', #{batchNumber}, '%') or mi.container_code like concat('%', #{containerCode}, '%'))
</when>
<otherwise>
<if test="batchNumber != null and batchNumber != ''">
and mi.batch_number like concat('%', #{batchNumber}, '%')
</if>
<if test="containerCode != null and containerCode != ''">
and mi.container_code like concat('%', #{containerCode}, '%')
</if>
</otherwise>
</choose>
<if test="materialStatusCode != null and materialStatusCode != ''">
and mi.material_status_code like concat('%', #{materialStatusCode}, '%')
</if>
<if test="materialStatusName != null and materialStatusName != ''">
and mi.material_status_name like concat('%', #{materialStatusName}, '%')
</if>
<if test="containerId != null ">
and mi.container_id = #{containerId}
</if>
<if test="containerType != null and containerType != ''">
and mi.container_type like concat('%', #{containerType}, '%')
</if>
<if test="containerTypeName != null and containerTypeName != ''">
and mi.container_type_name like concat('%', #{containerTypeName}, '%')
</if>
<if test="inventoryQuantity != null ">
and mi.inventory_quantity = #{inventoryQuantity}
</if>
<if test="allocationQuantity != null ">
and mi.allocation_quantity = #{allocationQuantity}
</if>
<if test="freezeQuantity != null ">
and mi.freeze_quantity = #{freezeQuantity}
</if>
<if test="excludeZeroInventoryQuantity != null and excludeZeroInventoryQuantity == true">
and COALESCE(mi.inventory_quantity, 0) &gt; 0
</if>
<if test="createByName != null and createByName != ''">
and mi.create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and mi.update_by_name like concat('%', #{updateByName}, '%')
</if>
<choose>
<when test="delFlag != null"> and mi.del_flag = #{delFlag} </when>
<otherwise> and mi.del_flag = 1 </otherwise>
</choose>
<if test="storageInfo != null and storageInfo != ''">
and (mi.storage_location_code = #{storageInfo} or material_code = #{storageInfo} or material_name like concat('%', #{storageInfo}, '%') or bar_code = #{storageInfo})
</if>
<if test="batchRefNo != null and batchRefNo != ''">
and mi.BATCH_REF_NO like concat('%', #{batchRefNo}, '%')
</if>
<if test="sheetRefNo != null and sheetRefNo != ''">
and mi.SHEET_REF_NO like concat('%', #{sheetRefNo}, '%')
</if>
<if test="boxPalletNo != null and boxPalletNo != ''">
and mi.BOX_PALLET_NO like concat('%', #{boxPalletNo}, '%')
</if>
</sql>
<select id="queryList" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">
select
<include refid="selectMaterialInventoryPo"/>
@@ -252,15 +393,69 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="queryListByWl" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">
select
<include refid="selectMaterialInventoryPo"/>
<include refid="selectMaterialInventoryPoWl"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPo"/>
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
<where>
<include refid="selectMaterialInventoryPo1"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPoWhere"/>
</where>
GROUP BY a.MATERIAL_BASE_INFO_ID
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
</select>
<!-- 按货主+物料汇总:A货主物料1、A货主物料2、B货主物料1、B货主物料2 为 4 行;库位取该货主+该物料下创建时间最新的一条明细 -->
<select id="queryListByHzWl" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">
select
<include refid="selectMaterialInventoryPoWl"/>
<include refid="com.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper.JoinMaterialBaseInfoPo"/>
from material_inventory a
left join material_base_info b on a.material_base_info_id = b.material_base_info_id
inner join (
select shipper_id, 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.shipper_id, 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.shipper_id, mi.material_base_info_id order by mi.create_time desc, mi.material_inventory_id desc) as hzwl_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>
) hzwl_ranked where hzwl_ranked.hzwl_rn = 1
) loc on loc.shipper_id = a.shipper_id and loc.material_base_info_id = a.material_base_info_id
<where>
<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,
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
</select>
<select id="queryListByHz" parameterType="com.mhd.wms.domain.materialInventory.repository.todo.MaterialInventoryDO" resultMap="MaterialInventoryResult">