Files
nanguangszwlback/mhd_wms/src/main/resources/mapper/OutMaterialDetail/OutMaterialDetailMapper.xml
T
rcx be5e3fc5ee feat(oms,wms): 出库全链路物料明细/单头增加库存锁定模式字段(存储+回显)
- 出库业务单明细/执行单明细/WMS出库明细/拣货明细/复核明细新增stockLockMode; 业务单单头新增JSON数组字段、执行单单头新增单值字段
- 下单/编辑时按明细行仓库实时判定(1-下单冻结 2-分配库存冻结默认), 下发后沿 执行单→WMS推单→拣货→复核 逐级复制继承, 交接单回显内存组装
- 业务单单头JSON两段式: 下单按仓写入(无执行单号), 下发覆盖为执行单级(带CK执行单号)
- WMS自建/通知/调拨单明细固定2; TZPD外部推入/老预约单下发路径固定2
- 达梦SQL脚本(OMS库4表+WMS库3表), 明细列DEFAULT 2存量自动回填
2026-09-15 09:30:54 +08:00

690 lines
36 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mhd.wms.domain.outMaterialDetail.repository.mapper.OutMaterialDetailMapper">
<resultMap type="com.mhd.wms.domain.outMaterialDetail.repository.po.OutMaterialDetailPO" id="MaterialDetailResult">
<result property="materialDetailId" column="material_detail_id" />
<result property="organizationId" column="organization_id" />
<result property="organizationName" column="organization_name" />
<result property="topOrganizationId" column="top_organization_id" />
<result property="uniqueId" column="unique_id" />
<result property="outOrderNumber" column="out_order_number" />
<result property="materialBaseInfoId" column="material_base_info_id" />
<result property="materialCode" column="material_code" />
<result property="materialName" column="material_name" />
<result property="barCode" column="bar_code" />
<result property="weightLimit" column="weight_limit" />
<result property="volumeLimit" column="volume_limit" />
<result property="quantity" column="quantity" />
<result property="allocationQuantity" column="allocation_quantity" />
<result property="pickingQuantity" column="picking_quantity" />
<result property="checkQuantity" column="check_quantity" />
<result property="waitCheckQuantity" column="WAIT_CHECK_QUANTITY" />
<result property="packId" column="pack_id" />
<result property="packCode" column="pack_code" />
<result property="packName" column="pack_name" />
<result property="packDetailId" column="pack_detail_id" />
<result property="unitCode" column="unit_code" />
<result property="unitName" column="unit_name" />
<result property="materialWarehouseControlId" column="material_warehouse_control_id" />
<result property="serialNumberManage" column="serial_number_manage" />
<result property="materialInventoryId" column="material_inventory_id" />
<result property="warehouseId" column="warehouse_id" />
<result property="stockLockMode" column="stock_lock_mode" />
<result property="warehouseCode" column="warehouse_code" />
<result property="warehouseName" column="warehouse_name" />
<result property="storageSectionId" column="storage_section_id" />
<result property="storageCode" column="storage_code" />
<result property="storageName" column="storage_name" />
<result property="storageLocationId" column="storage_location_id" />
<result property="storageLocationCode" column="storage_location_code" />
<result property="storageLocationName" column="storage_location_name" />
<result property="level" column="level" />
<result property="parentUniqueId" column="parent_unique_id" />
<result property="remark" column="remark" />
<result property="createTime" column="create_time" />
<result property="createBy" column="create_by" />
<result property="createByName" column="create_by_name" />
<result property="updateTime" column="update_time" />
<result property="updateBy" column="update_by" />
<result property="updateByName" column="update_by_name" />
<result property="delFlag" column="del_flag" />
<result property="overStockId" column="over_stock_id" />
<result property="overStockStatus" column="over_stock_status" />
<result property="overStockType" column="over_stock_type" />
<result property="commodityName" column="COMMODITY_NAME" />
<result property="commodityNo" column="COMMODITY_NO" />
<result property="materialNo" column="MATERIAL_NO" />
<result property="specificationModel" column="SPECIFICATION_MODEL" />
<result property="skucode" column="SKUCODE" />
<result property="invoiceNo" column="INVOICE_NO" />
<result property="liter" column="LITER" />
<result property="size" column="SIZE" />
<result property="declareUnit" column="DECLARE_UNIT" />
<result property="batchRefNo" column="BATCH_REF_NO" />
<result property="sheetRefNo" column="SHEET_REF_NO" />
<result property="countryOfOrigin" column="COUNTRY_OF_ORIGIN" />
<result property="boxPalletNo" column="BOX_PALLET_NO" />
<result property="currency" column="CURRENCY" />
<result property="declareQuantity" column="DECLARE_QUANTITY" />
<result property="caseCount" column="CASE_COUNT" />
<result property="pieceCount" column="PIECE_COUNT" />
<result property="outboundQuantity" column="OUTBOUND_QUANTITY" />
<result property="totalNetWeight" column="TOTAL_NET_WEIGHT" />
<result property="totalGrossWeight" column="TOTAL_GROSS_WEIGHT" />
<result property="totalVolume" column="TOTAL_VOLUME" />
<result property="totalArea" column="TOTAL_AREA" />
<result property="totalAmount" column="TOTAL_AMOUNT" />
<result property="unit" column="UNIT" />
<result property="extAttr1" column="EXT_ATTR_1" />
<result property="extAttr2" column="EXT_ATTR_2" />
<result property="productionDate" column="PRODUCTION_DATE" />
<result property="expiryDate" column="EXPIRY_DATE" />
<result property="inventoryDate" column="INVENTORY_DATE" />
<result property="extAttr3" column="EXT_ATTR_3" />
<result property="extAttr4" column="EXT_ATTR_4" />
<result property="contractFee" column="contract_fee" />
<result property="monthlyWarehouseFee" column="monthly_warehouse_fee" />
<result property="halfMonthWhFee" column="half_month_wh_fee" />
<result property="discountRate" column="discount_rate" />
<result property="singleVolume" column="single_volume" />
<result property="singleGrossWeight" column="single_gross_weight" />
<result property="lotNo" column="lot_no" />
<result property="inOrderNumber" column="in_order_number" />
<result property="stockUnit" column="stock_unit" />
<result property="stockQuantity" column="stock_quantity" />
<result property="copyTotalWeight" column="COPY_TOTAL_WEIGHT" />
<result property="copyCodeReferenceIds" column="COPY_CODE_REFERENCE_IDS" />
<result property="lineNumGw" column="line_num_gw" />
<result property="specGw" column="spec_gw" />
<result property="unitGw" column="unit_gw" />
<result property="qtyGw" column="qty_gw" />
<result property="erpCurrGw" column="erp_curr_gw" />
<result property="erpPriceGw" column="erp_price_gw" />
<result property="amountGw" column="amount_gw" />
<result property="inOrderNumberGw" column="in_order_number_gw" />
<result property="inLineNumGw" column="in_line_num_gw" />
<result property="outWeight" column="OUT_WEIGHT" />
<result property="outVolume" column="OUT_VOLUME" />
<result property="outQuantity" column="OUT_QUANTITY" />
</resultMap>
<sql id="selectMaterialDetailPo">
a.contract_fee ,
a.monthly_warehouse_fee ,
a.half_month_wh_fee ,
a.discount_rate ,
a.single_volume ,
a.single_gross_weight ,
a.lot_no ,
a.stock_quantity ,
a.stock_unit ,a.in_order_number ,
a.OUT_WEIGHT,a.OUT_VOLUME,a.OUT_QUANTITY,
a.material_detail_id, a.organization_id, a.organization_name, a.top_organization_id, a.unique_id, a.out_order_number, a.material_base_info_id, a.line_number, a.material_code, a.material_name, a.bar_code, a.weight_limit, a.volume_limit,
a.quantity, a.already_allocation_quantity, a.allocation_quantity, a.picking_quantity, a.check_quantity, ROUND(GREATEST(0, IFNULL(a.quantity, 0) - IFNULL(a.check_quantity, 0), IFNULL(a.picking_quantity, 0) - IFNULL(a.check_quantity, 0)), 2) AS wait_check_quantity,
a.pack_id, a.pack_code, a.pack_name, a.pack_detail_id, a.unit_code, a.unit_name, a.material_warehouse_control_id, a.serial_number_manage,
a.warehouse_id, a.stock_lock_mode, a.warehouse_code, a.warehouse_name, a.storage_section_id, a.storage_code, a.storage_name, a.storage_location_id, a.storage_location_code, a.storage_location_name, a.level, a.parent_unique_id, a.allow_modify,
a.material_inventory_id, a.batch_number, a.container_id, a.container_code, a.container_type, a.container_type_name, a.material_status_code, a.material_status_name,
a.remark, a.create_time, a.create_by,gen_picking_order,
a.create_by_name, a.update_time, a.update_by, a.update_by_name, a.del_flag, a.over_stock_id, a.over_stock_status, a.over_stock_type,
a.COMMODITY_NAME,
a.COMMODITY_NO,
a.MATERIAL_NO ,
a.SPECIFICATION_MODEL,
a.SKUCODE ,
a.INVOICE_NO,
a.LITER,
a.SIZE,
a.DECLARE_UNIT,
a.BATCH_REF_NO,
a.SHEET_REF_NO,
a.COUNTRY_OF_ORIGIN,
a.BOX_PALLET_NO,
a.CURRENCY,
a.DECLARE_QUANTITY,
a.CASE_COUNT,
a.PIECE_COUNT,
a.OUTBOUND_QUANTITY,
a.TOTAL_NET_WEIGHT,
a.TOTAL_GROSS_WEIGHT,
a.TOTAL_VOLUME,
a.TOTAL_AREA,
a.TOTAL_AMOUNT,
a.UNIT,
a.EXT_ATTR_1,
a.EXT_ATTR_2,
a.PRODUCTION_DATE,
a.EXPIRY_DATE,
a.INVENTORY_DATE,
a.EXT_ATTR_3,
a.EXT_ATTR_4,
a.COPY_TOTAL_WEIGHT,
a.COPY_CODE_REFERENCE_IDS,
a.INVENTORY_QUANTITY,
a.line_num_gw,
a.spec_gw,
a.unit_gw,
a.qty_gw,
a.erp_curr_gw,
a.erp_price_gw,
a.amount_gw,
a.in_order_number_gw,
a.in_line_num_gw
</sql>
<sql id="selectMaterialDetailPo1">
<if test="organizationId != null ">
and a.organization_id = #{organizationId}
</if>
<if test="organizationName != null and organizationName != ''">
and a.organization_name like concat('%', #{organizationName}, '%')
</if>
<if test="topOrganizationId != null ">
and a.top_organization_id = #{topOrganizationId}
</if>
<if test="outOrderNumber != null and outOrderNumber != '' ">
and a.out_order_number = #{outOrderNumber}
</if>
<if test="materialBaseInfoId != null ">
and a.material_base_info_id = #{materialBaseInfoId}
</if>
<if test="materialCode != null and materialCode != ''">
and a.material_code = #{materialCode}
</if>
<if test="materialName != null and materialName != ''">
and a.material_name like concat('%', #{materialName}, '%')
</if>
<if test="barCode != null and barCode != ''">
and a.bar_code = #{barCode}
</if>
<if test="quantity != null ">
and a.quantity = #{quantity}
</if>
<if test="allocationQuantity != null ">
and a.allocation_quantity = #{allocationQuantity}
</if>
<if test="pickingQuantity != null ">
and a.picking_quantity = #{pickingQuantity}
</if>
<if test="checkQuantity != null ">
and a.check_quantity = #{checkQuantity}
</if>
<if test="packId != null ">
and a.pack_id = #{packId}
</if>
<if test="packCode != null and packCode != ''">
and a.pack_code = #{packCode}
</if>
<if test="packName != null and packName != ''">
and a.pack_name like concat('%', #{packName}, '%')
</if>
<if test="packDetailId != null and packDetailId != ''">
and a.pack_detail_id = #{packDetailId}
</if>
<if test="unitCode != null and unitCode != ''">
and a.unit_code = #{unitCode}
</if>
<if test="unitName != null and unitName != ''">
and a.unit_name like concat('%', #{unitName}, '%')
</if>
<if test="materialWarehouseControlId != null ">
and a.material_warehouse_control_id = #{materialWarehouseControlId}
</if>
<if test="serialNumberManage != null ">
and a.serial_number_manage = #{serialNumberManage}
</if>
<if test="warehouseId != null ">
and a.warehouse_id = #{warehouseId}
</if>
<if test="warehouseCode != null and warehouseCode != ''">
and a.warehouse_code = #{warehouseCode}
</if>
<if test="warehouseName != null and warehouseName != ''">
and a.warehouse_name like concat('%', #{warehouseName}, '%')
</if>
<if test="storageSectionId != null ">
and a.storage_section_id = #{storageSectionId}
</if>
<if test="storageCode != null and storageCode != ''">
and a.storage_code = #{storageCode}
</if>
<if test="storageName != null and storageName != ''">
and a.storage_name like concat('%', #{storageName}, '%')
</if>
<if test="storageLocationId != null ">
and a.storage_location_id = #{storageLocationId}
</if>
<if test="storageLocationCode != null and storageLocationCode != ''">
and a.storage_location_code = #{storageLocationCode}
</if>
<if test="storageLocationName != null and storageLocationName != ''">
and a.storage_location_name like concat('%', #{storageLocationName}, '%')
</if>
<if test="level != null ">
and a.level = #{level}
</if>
<if test="genPickingOrder != null ">
and a.gen_picking_order = #{genPickingOrder}
</if>
<if test="parentUniqueId != null ">
and a.parent_unique_id = #{parentUniqueId}
</if>
<if test="createByName != null and createByName != ''">
and a.create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and a.update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="outOrderNumberList != null and outOrderNumberList.size > 0 ">
and a.out_order_number in
<foreach collection="outOrderNumberList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<choose>
<when test="delFlag != null"> and a.del_flag = #{delFlag} </when>
<otherwise> and a.del_flag = 1 </otherwise>
</choose>
</sql>
<sql id="joinMaterialDetailPoWhere">
<if test="organizationId != null ">
and a.organization_id = #{organizationId}
</if>
<if test="organizationName != null and organizationName != ''">
and a.organization_name like concat('%', #{organizationName}, '%')
</if>
<if test="topOrganizationId != null ">
and a.top_organization_id = #{topOrganizationId}
</if>
<if test="overStockStatus != null ">
and a.over_stock_status = #{overStockStatus}
</if>
<if test="materialBaseInfoId != null ">
and a.material_base_info_id = #{materialBaseInfoId}
</if>
<if test="materialBaseInfoIdList != null and materialBaseInfoIdList != ''">
and a.material_base_info_id in
<foreach collection="materialBaseInfoIdList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<choose>
<when test="delFlag != null"> and a.del_flag = #{delFlag} </when>
<otherwise> and a.del_flag = 1 </otherwise>
</choose>
</sql>
<sql id="joinStockOutOrderPoWhere">
<if test="outOrderNumber != null and outOrderNumber != ''">
and b.out_order_number = #{outOrderNumber}
</if>
<if test="warehouseId != null and warehouseId != '' ">
and b.warehouse_id = #{warehouseId}
</if>
<if test="shipperId != null and shipperId != ''">
and b.shipper_id = #{shipperId}
</if>
<if test="shipperIdList != null and shipperIdList != ''">
and b.shipper_id in
<foreach collection="shipperIdList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="outOrderExpectStartTime != null and outOrderExpectStartTime != ''"><!-- 开始时间检索 -->
and date_format(b.expect_time,'%y%m%d') &gt;= date_format(#{outOrderExpectStartTime},'%y%m%d')
</if>
<if test="outOrderExpectEndTime != null and outOrderExpectEndTime != ''"><!-- 结束时间检索 -->
and date_format(b.expect_time,'%y%m%d') &lt;= date_format(#{outOrderExpectEndTime},'%y%m%d')
</if>
<if test="outOrderTypeCode != null and outOrderTypeCode != ''">
and b.order_type_code = #{outOrderTypeCode}
</if>
<!-- 出库状态: 1-已创建 2-已审核 3-部分分配 4-已分配 5-拣货中 6-波次中 7-拣货完成 8-复核中 9-已出库 10-已取消 11-已关闭 -->
<if test="outStatus != null ">
and b.status = #{outStatus}
</if>
<choose>
<when test="delFlag != null"> and b.del_flag = #{delFlag} </when>
<otherwise> and b.del_flag = 1 </otherwise>
</choose>
</sql>
<select id="queryList" parameterType="com.mhd.wms.domain.outMaterialDetail.repository.todo.OutMaterialDetailDO" resultMap="MaterialDetailResult">
select
<include refid="selectMaterialDetailPo"/>
from out_material_detail a
<where>
<include refid="selectMaterialDetailPo1"/>
</where>
</select>
<select id="queryOutOrderList" parameterType="com.mhd.wms.domain.overStock.repository.todo.QueryOrderOverStockDO" resultMap="MaterialDetailResult">
select
<include refid="selectMaterialDetailPo"/>
<include refid="com.mhd.wms.domain.stockOutOrder.repository.mapper.StockOutOrderMapper.joinStockOutOrderPo"/>
from out_material_detail a
left join stock_out_order b on a.out_order_number = b.out_order_number and b.del_flag = 1 and a.del_flag = 1
<where>
<include refid="joinMaterialDetailPoWhere"/>
<include refid="joinStockOutOrderPoWhere"/>
</where>
</select>
<!-- 出库明细查询结果(关联出库单),在物料明细基础上追加单头通知单号/类型/货主/客户/预计出货时间/出仓日期与货品保额 -->
<resultMap type="com.mhd.wms.domain.outMaterialDetail.repository.po.OutMaterialDetailWithOrderPO" id="OutMaterialDetailWithOrderResult" extends="MaterialDetailResult">
<result property="noticeNumber" column="notice_number" />
<result property="shipperId" column="shipper_id" />
<result property="shipperCode" column="shipper_code" />
<result property="shipperName" column="shipper_name" />
<result property="orderTypeCode" column="order_type_code" />
<result property="orderTypeName" column="order_type_name" />
<result property="customerId" column="customer_id" />
<result property="customerCode" column="customer_code" />
<result property="customerName" column="customer_name" />
<result property="expectTime" column="expect_time" />
<result property="supplyChainNumber" column="supply_chain_number" />
<result property="priorityLevelCode" column="priority_level_code" />
<result property="priorityLevelName" column="priority_level_name" />
<result property="directWarehouse" column="direct_warehouse" />
<result property="annexUrl" column="annex_url" />
<result property="outOrderStatus" column="out_order_status" />
<result property="status" column="status" />
<result property="outOrderAuditStatus" column="out_order_audit_status"/>
<result property="outboundDate" column="outbound_date" />
<result property="completeTime" column="complete_time" />
<result property="insureAmount" column="insure_amount" />
<result property="goodsType" column="goods_type" />
<result property="materialClassifyName" column="material_classify_name" />
</resultMap>
<!--
出库明细查询(关联出库单):
口径:仅已出库及后续完成状态(b.status in (9,12,13):已出库/已复核/已交接,与出库排名统计同口径);
仅取 level=1 主行防父子行重复计数;
实际出仓日期筛选 b.outbound_date
注意:达梦数据库分页包裹查询不允许重复列名,单头列需与明细表 a 列名错开
b.out_order_number、b.warehouse_*、b.quantity 等与明细同名的列不重复查,明细行自带)
-->
<select id="queryOutOrderDetailList" parameterType="com.mhd.wms.domain.overStock.repository.todo.QueryOrderOverStockDO" resultMap="OutMaterialDetailWithOrderResult">
select
<include refid="selectMaterialDetailPo"/>
, b.notice_number
, b.shipper_id, b.shipper_code, b.shipper_name
, b.order_type_code, b.order_type_name
, b.customer_id, b.customer_code, b.customer_name
, b.expect_time
, b.supply_chain_number
, b.priority_level_code, b.priority_level_name
, b.direct_warehouse
, b.annex_url
, b.status as out_order_status
, b.status as status
, b.audit_status as out_order_audit_status
, b.outbound_date
, b.complete_time
, c.insure_amount, c.goods_type, c.material_classify_name
from out_material_detail a
join stock_out_order b on a.out_order_number = b.out_order_number
left join material_base_info c on a.material_base_info_id = c.material_base_info_id
<where>
<if test="organizationId != null ">
and a.organization_id = #{organizationId}
</if>
<if test="topOrganizationId != null ">
and a.top_organization_id = #{topOrganizationId}
</if>
<if test="materialBaseInfoId != null ">
and a.material_base_info_id = #{materialBaseInfoId}
</if>
<if test="materialCode != null and materialCode != ''">
and a.material_code = #{materialCode}
</if>
<if test="materialName != null and materialName != ''">
and a.material_name like concat('%', #{materialName}, '%')
</if>
<if test="outOrderNumber != null and outOrderNumber != ''">
and b.out_order_number like concat('%', #{outOrderNumber}, '%')
</if>
<if test="warehouseId != null ">
and b.warehouse_id = #{warehouseId}
</if>
<if test="warehouseCode != null and warehouseCode != ''">
and b.warehouse_code = #{warehouseCode}
</if>
<if test="warehouseName != null and warehouseName != ''">
and b.warehouse_name like concat('%', #{warehouseName}, '%')
</if>
<if test="shipperId != null ">
and b.shipper_id = #{shipperId}
</if>
<if test="shipperName != null and shipperName != ''">
and b.shipper_name like concat('%', #{shipperName}, '%')
</if>
<if test="outOrderTypeCode != null and outOrderTypeCode != ''">
and b.order_type_code = #{outOrderTypeCode}
</if>
<if test="orderTypeCode != null and orderTypeCode != ''">
and b.order_type_code = #{orderTypeCode}
</if>
<if test="orderTypeName != null and orderTypeName != ''">
and b.order_type_name like concat('%', #{orderTypeName}, '%')
</if>
<!-- 出库状态: 1-已创建 2-已审核 3-部分分配 4-已分配 5-波次中 6-拣货中 7-拣货完成 8-复核中 9-已出库 10-已取消 11-已关闭 12-已复核 13-已交接,只统计已出库(9/12/13)的明细 -->
and b.status in (9, 12, 13)
<!-- 实际出仓日期区间,用于统计当天出库(严格按出仓日期outbound_date过滤) -->
<if test="outboundDateStart != null and outboundDateStart != ''">
and date_format(b.outbound_date, '%Y-%m-%d') &gt;= #{outboundDateStart}
</if>
<if test="outboundDateEnd != null and outboundDateEnd != ''">
and date_format(b.outbound_date, '%Y-%m-%d') &lt;= #{outboundDateEnd}
</if>
and a.level = 1
and a.del_flag = 1
and b.del_flag = 1
</where>
order by a.create_time desc
</select>
<!--
出库明细导出(专用列集,列别名对应 OutMaterialDetailExportPO 属性):
客户编号/名称取出库单自身字段,客户预约名称取通知单 notice_order 的客户订单号(经 b.notice_number 关联);
饮用日期出库明细无此列,按入库单号+物料标量子查询回查入库明细的饮用日期(MAX 防多行);
火险保费 WMS 库暂无数据来源,导出空列(CAST(NULL)占位);
过滤口径与 queryOutOrderDetailList 完全一致(仅已出库(9/12/13)、level=1、实际出仓日期区间)
-->
<select id="exportOutOrderDetailList" parameterType="com.mhd.wms.domain.overStock.repository.todo.QueryOrderOverStockDO" resultType="com.mhd.wms.domain.outMaterialDetail.repository.po.OutMaterialDetailExportPO">
select
a.out_order_number as outOrderNumber,
b.outbound_date as outboundDate,
a.create_time as createTime,
b.customer_code as customerCode,
b.customer_name as customerName,
a.lot_no as lotNo,
n.customer_order_number as customerOrderNumber,
a.material_name as materialName,
a.material_code as materialCode,
a.stock_unit as stockUnit,
a.PIECE_COUNT as pieceCount,
a.warehouse_name as warehouseName,
(select MAX(i.DRINK_DATE) from in_material_detail i
where i.in_order_number = a.in_order_number
and i.material_base_info_id = a.material_base_info_id
and i.del_flag = 1) as drinkDate,
a.storage_location_name as storageLocationName,
a.weight_limit as weightLimit,
a.single_volume as singleVolume,
a.unit_price as unitPrice,
a.TOTAL_AMOUNT as totalPrice,
a.discount_rate as discountRate,
a.monthly_warehouse_fee as monthlyWarehouseFee,
a.half_month_wh_fee as halfMonthWhFee,
a.contract_fee as contractFee,
CAST(NULL AS DECIMAL) as fireInsureFee,
a.remark as remark,
a.TOTAL_GROSS_WEIGHT as totalGrossWeight,
a.storage_name as storageName,
a.in_order_number as inOrderNumber,
c.material_classify_name as materialClassifyName,
CAST(NULL AS DECIMAL) as totalAmount,
b.status as outOrderStatus,
b.order_type_name as orderTypeName
from out_material_detail a
join stock_out_order b on a.out_order_number = b.out_order_number
left join material_base_info c on a.material_base_info_id = c.material_base_info_id
left join notice_order n on b.notice_number = n.notice_number and n.del_flag = 1
<where>
<if test="organizationId != null ">
and a.organization_id = #{organizationId}
</if>
<if test="topOrganizationId != null ">
and a.top_organization_id = #{topOrganizationId}
</if>
<if test="materialBaseInfoId != null ">
and a.material_base_info_id = #{materialBaseInfoId}
</if>
<if test="materialCode != null and materialCode != ''">
and a.material_code = #{materialCode}
</if>
<if test="materialName != null and materialName != ''">
and a.material_name like concat('%', #{materialName}, '%')
</if>
<if test="outOrderNumber != null and outOrderNumber != ''">
and b.out_order_number like concat('%', #{outOrderNumber}, '%')
</if>
<if test="warehouseId != null ">
and b.warehouse_id = #{warehouseId}
</if>
<if test="warehouseCode != null and warehouseCode != ''">
and b.warehouse_code = #{warehouseCode}
</if>
<if test="warehouseName != null and warehouseName != ''">
and b.warehouse_name like concat('%', #{warehouseName}, '%')
</if>
<if test="shipperId != null ">
and b.shipper_id = #{shipperId}
</if>
<if test="shipperName != null and shipperName != ''">
and b.shipper_name like concat('%', #{shipperName}, '%')
</if>
<if test="outOrderTypeCode != null and outOrderTypeCode != ''">
and b.order_type_code = #{outOrderTypeCode}
</if>
<if test="orderTypeCode != null and orderTypeCode != ''">
and b.order_type_code = #{orderTypeCode}
</if>
<if test="orderTypeName != null and orderTypeName != ''">
and b.order_type_name like concat('%', #{orderTypeName}, '%')
</if>
and b.status in (9, 12, 13)
<if test="outboundDateStart != null and outboundDateStart != ''">
and date_format(b.outbound_date, '%Y-%m-%d') &gt;= #{outboundDateStart}
</if>
<if test="outboundDateEnd != null and outboundDateEnd != ''">
and date_format(b.outbound_date, '%Y-%m-%d') &lt;= #{outboundDateEnd}
</if>
and a.level = 1
and a.del_flag = 1
and b.del_flag = 1
</where>
order by a.create_time desc
</select>
<update id="batchAddAllocationQuantityByIds" parameterType="com.mhd.wms.domain.outMaterialDetail.repository.todo.OutMaterialDetailDO">
UPDATE out_material_detail
<set>
allocation_quantity = CASE material_detail_id
<foreach collection="children" item="item" index="index" separator=",">
WHEN #{item.materialDetailId} THEN allocation_quantity + #{item.allocationQuantity}
</foreach>
END,
update_by = #{item.updateBy},
update_by_name = #{item.updateByName},
update_time = now()
</set>
WHERE material_detail_id IN
<foreach collection="children" item="item" index="index" open="(" separator="," close=")">
#{item.materialDetailId}
</foreach>
</update>
<update id="batchAddPickingQuantityByIds" parameterType="com.mhd.wms.domain.outMaterialDetail.repository.todo.OutMaterialDetailDO">
UPDATE out_material_detail
<set>
picking_quantity = CASE material_detail_id
<foreach collection="children" item="item" index="index" separator=",">
WHEN #{item.materialDetailId} THEN picking_quantity + #{item.pickingQuantity}
</foreach>
END,
update_by = #{updateBy},
update_by_name = #{updateByName},
update_time = now()
</set>
WHERE material_detail_id IN
<foreach collection="children" item="item" index="index" open="(" separator="," close=")">
#{item.materialDetailId}
</foreach>
</update>
<update id="batchAddPickingQuantityByUniqueIds" parameterType="com.mhd.wms.domain.outMaterialDetail.repository.todo.OutMaterialDetailDO">
UPDATE out_material_detail
<set>
picking_quantity = CASE unique_id
<foreach collection="children" item="item" index="index" separator=",">
WHEN #{item.uniqueId} THEN picking_quantity + #{item.pickingQuantity}
</foreach>
END,
<trim prefix="picking_quantity = CASE unique_id" suffix="END,">
<foreach collection="children" item="item" index="index">
WHEN #{item.uniqueId} THEN picking_quantity + #{item.pickingQuantity}
</foreach>
</trim>
update_by = #{updateBy},
update_by_name = #{updateByName},
update_time = now()
</set>
WHERE unique_id IN
<foreach collection="children" item="item" index="index" open="(" separator="," close=")">
#{item.uniqueId}
</foreach>
</update>
<!-- 出库列表:按单号批量聚合(仅 level=1,与列表上对父行汇总一致) -->
<select id="selectAggregatesForStockOutList" resultType="com.mhd.wms.domain.outMaterialDetail.repository.po.OutStockListMaterialAgg">
SELECT
a.out_order_number AS outOrderNumber,
COALESCE(SUM(a.outbound_quantity), 0) AS totalOutboundQuantity,
COALESCE(SUM(a.check_quantity), 0) AS checkQuantitySum,
COUNT(DISTINCT CASE
WHEN a.material_base_info_id IS NOT NULL THEN CAST(a.material_base_info_id AS VARCHAR(50))
ELSE a.material_code
END) AS materialKindCountDistinct
FROM out_material_detail a
WHERE a.del_flag = 1
AND a.level = 1
AND a.out_order_number IN
<foreach collection="outOrderNumbers" item="num" open="(" separator="," close=")">
#{num}
</foreach>
GROUP BY a.out_order_number
</select>
<!-- 出库列表页:按出库单号批量取去重后的 Invoice No -->
<select id="selectDistinctInvoiceNoForStockOutList" resultType="com.mhd.wms.domain.outMaterialDetail.repository.po.OutStockListMaterialAgg">
SELECT DISTINCT
a.out_order_number AS outOrderNumber,
a.INVOICE_NO AS invoiceNo
FROM out_material_detail a
WHERE a.del_flag = 1
AND a.level = 1
AND a.INVOICE_NO IS NOT NULL
AND a.INVOICE_NO != ''
AND a.out_order_number IN
<foreach collection="outOrderNumbers" item="num" open="(" separator="," close=")">
#{num}
</foreach>
</select>
</mapper>