Files
nanguangszwlback/mhd_wms/src/main/resources/mapper/pickingMaterialDetail/PickingMaterialDetailMapper.xml
T

292 lines
16 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.pickingMaterialDetail.repository.mapper.PickingMaterialDetailMapper">
<resultMap type="com.mhd.wms.domain.pickingMaterialDetail.repository.po.PickingMaterialDetailPO" id="PickingMaterialDetailResult">
<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="pickingOrderNumber" column="picking_order_number" />
<result property="inOrderNumber" column="in_order_number" />
<result property="lotNumber" column="lot_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="size" column="SIZE" />
<result property="weightLimit" column="weight_limit" />
<result property="volumeLimit" column="volume_limit" />
<result property="quantity" column="quantity" />
<result property="pickingQuantity" column="picking_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="warehouseId" column="warehouse_id" />
<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="remark" column="remark" />
<result property="batchRefNo" column="BATCH_REF_NO" />
<result property="sheetRefNo" column="SHEET_REF_NO" />
<result property="boxPalletNo" column="BOX_PALLET_NO" />
<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="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="totalArea" column="total_area" />
<result property="totalGrossWeight" column="total_gross_weight" />
<result property="totalNetWeight" column="total_net_weight" />
<result property="totalVolume" column="total_volume" />
<result property="outUniqueId" column="out_unique_id" />
<result property="copyCodeReferenceIds" column="COPY_CODE_REFERENCE_IDS" />
</resultMap>
<sql id="selectPickingMaterialDetailPo">
a.material_detail_id, a.organization_id, a.organization_name, a.top_organization_id, a.unique_id,
a.picking_order_number, a.material_base_info_id, a.material_code, a.material_name, a.bar_code, a.SIZE, a.weight_limit,
a.volume_limit, a.quantity, a.picking_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.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.warehouse_id, 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.remark,
a.BATCH_REF_NO, a.SHEET_REF_NO, a.BOX_PALLET_NO, 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.create_time, a.create_by, a.create_by_name, a.update_time, a.update_by, a.update_by_name, a.del_flag,
a.total_area, a.total_gross_weight, a.total_net_weight, a.total_volume, a.out_unique_id,
a.COPY_CODE_REFERENCE_IDS,
omd.in_order_number, omd.lot_no as lot_number
</sql>
<sql id="selectPickingMaterialDetailPo1">
<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="uniqueId != null ">
and a.unique_id = #{uniqueId}
</if>
<if test="pickingOrderNumber != null and pickingOrderNumber != ''">
and a.picking_order_number = #{pickingOrderNumber}
</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="weightLimit != null ">
and a.weight_limit = #{weightLimit}
</if>
<if test="volumeLimit != null ">
and a.volume_limit = #{volumeLimit}
</if>
<if test="quantity != null ">
and a.quantity = #{quantity}
</if>
<if test="pickingQuantity != null ">
and a.picking_quantity = #{pickingQuantity}
</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="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>
<choose>
<when test="delFlag != null"> and a.del_flag = #{delFlag} </when>
<otherwise> and a.del_flag = 1 </otherwise>
</choose>
</sql>
<select id="queryList" parameterType="com.mhd.wms.domain.pickingMaterialDetail.repository.todo.PickingMaterialDetailDO" resultMap="PickingMaterialDetailResult">
select
<include refid="selectPickingMaterialDetailPo"/>
from picking_material_detail a
left join out_material_detail omd on a.out_unique_id = omd.unique_id and omd.del_flag = 1
<where>
<include refid="selectPickingMaterialDetailPo1"/>
</where>
</select>
<select id="queryTotalsByOutNumberAndBaseId" resultType="com.mhd.wms.domain.pickingMaterialDetail.repository.po.PickingMaterialDetailPO">
SELECT
COALESCE(SUM(b.PICKING_QUANTITY), 0) AS picking_quantity,
COALESCE(SUM(b.TOTAL_AREA), 0) AS total_area,
COALESCE(SUM(b.TOTAL_VOLUME), 0) AS total_volume,
COALESCE(SUM(b.TOTAL_NET_WEIGHT), 0) AS total_net_weight,
COALESCE(SUM(b.TOTAL_GROSS_WEIGHT), 0) AS total_gross_weight
FROM
PICKING_MATERIAL_DETAIL b
WHERE
b.OUT_UNIQUE_ID = #{outUniqueId}
AND b.DEL_FLAG = 1
</select>
<select id="sumPickingQuantityByOutOrderNumber" resultType="java.math.BigDecimal">
SELECT COALESCE(SUM(pmd.PICKING_QUANTITY), 0)
FROM picking_material_detail pmd
INNER JOIN out_material_detail omd ON pmd.OUT_UNIQUE_ID = omd.UNIQUE_ID AND omd.DEL_FLAG = 1
WHERE omd.OUT_ORDER_NUMBER = #{outOrderNumber}
AND pmd.DEL_FLAG = 1
</select>
<select id="countMaterialTypesByOutOrderNumber" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT pmd.MATERIAL_BASE_INFO_ID)
FROM picking_material_detail pmd
INNER JOIN out_material_detail omd ON pmd.OUT_UNIQUE_ID = omd.UNIQUE_ID AND omd.DEL_FLAG = 1
WHERE omd.OUT_ORDER_NUMBER = #{outOrderNumber}
AND pmd.DEL_FLAG = 1
AND COALESCE(pmd.PICKING_QUANTITY, 0) > 0
</select>
<select id="selectOutUniqueIdsWithPickingByOutOrderNumber" resultType="java.lang.Long">
SELECT DISTINCT pmd.OUT_UNIQUE_ID
FROM picking_material_detail pmd
INNER JOIN out_material_detail omd ON pmd.OUT_UNIQUE_ID = omd.UNIQUE_ID AND omd.DEL_FLAG = 1
WHERE omd.OUT_ORDER_NUMBER = #{outOrderNumber}
AND pmd.DEL_FLAG = 1
AND COALESCE(pmd.PICKING_QUANTITY, 0) > 0
</select>
<update id="addQuantity" parameterType="com.mhd.wms.domain.pickingMaterialDetail.repository.todo.PickingMaterialDetailDOByUpdate">
UPDATE picking_material_detail
<set>
<trim prefix="picking_quantity = CASE unique_id" suffix="END,">
<foreach collection="pickingMaterialDetailList" item="item" index="index">
WHEN #{item.uniqueId} THEN LEAST(picking_quantity + #{item.pickingQuantity}, quantity)
</foreach>
</trim>
<!-- 净重、毛重、体积、面积:拣货填写值直接覆盖,不累加 -->
<trim prefix="total_net_weight = CASE unique_id" suffix="END,">
<foreach collection="pickingMaterialDetailList" item="item" index="index">
WHEN #{item.uniqueId} THEN COALESCE(#{item.totalNetWeight}, total_net_weight)
</foreach>
</trim>
<trim prefix="total_gross_weight = CASE unique_id" suffix="END,">
<foreach collection="pickingMaterialDetailList" item="item" index="index">
WHEN #{item.uniqueId} THEN COALESCE(#{item.totalGrossWeight}, total_gross_weight)
</foreach>
</trim>
<trim prefix="total_volume = CASE unique_id" suffix="END,">
<foreach collection="pickingMaterialDetailList" item="item" index="index">
WHEN #{item.uniqueId} THEN COALESCE(#{item.totalVolume}, total_volume)
</foreach>
</trim>
<trim prefix="total_area = CASE unique_id" suffix="END,">
<foreach collection="pickingMaterialDetailList" item="item" index="index">
WHEN #{item.uniqueId} THEN COALESCE(#{item.totalArea}, total_area)
</foreach>
</trim>
update_by = #{updateBy},
update_by_name = #{updateByName},
update_time = #{updateTime}
</set>
WHERE
unique_id IN
<foreach collection="pickingMaterialDetailList" item="item" index="index" separator="," open="(" close=")">
#{item.uniqueId}
</foreach>
</update>
<!-- 复核提交时:先将该 out_unique_id 下所有行置0 -->
<update id="resetWeightVolumeByOutUniqueId">
UPDATE picking_material_detail SET total_net_weight = 0, total_gross_weight = 0, total_volume = 0, total_area = 0
WHERE out_unique_id = #{outUniqueId} AND del_flag = 1
</update>
<!-- 复核提交时:将第一行设为复核值,保证 queryTotalsByOutNumberAndBaseId 汇总正确(first 为达梦保留字,改用 first_row -->
<update id="updateFirstRowWeightVolumeByOutUniqueId">
UPDATE picking_material_detail pmd
INNER JOIN (SELECT unique_id FROM picking_material_detail WHERE out_unique_id = #{outUniqueId} AND del_flag = 1 ORDER BY unique_id LIMIT 1) first_row ON pmd.unique_id = first_row.unique_id
SET pmd.total_net_weight = #{totalNetWeight}, pmd.total_gross_weight = #{totalGrossWeight}, pmd.total_volume = #{totalVolume}, pmd.total_area = #{totalArea},
pmd.update_by = #{updateBy}, pmd.update_by_name = #{updateByName}, pmd.update_time = #{updateTime}
WHERE pmd.out_unique_id = #{outUniqueId} AND pmd.del_flag = 1
</update>
</mapper>