<?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.hw.wms.mapper.WmsProductOutstockDetailMapper">

    <resultMap type="WmsProductOutstockDetail" id="WmsProductOutstockDetailResult">
        <result property="productOutstockDetailId"    column="product_outstock_detail_id"    />
        <result property="productOutstockId"    column="product_outstock_id"    />
        <result property="warehouseId"    column="warehouse_id"    />
        <result property="locationCode"    column="location_code"    />
        <result property="productBarcode"    column="product_barcode"    />
        <result property="productBatch"    column="product_batch"    />
        <result property="productId"    column="product_id"    />
        <result property="planAmount"    column="plan_amount"    />
        <result property="outstockAmount"    column="outstock_amount"    />
        <result property="confirmAmount"    column="confirm_amount"    />
        <result property="executeStatus"    column="execute_status"    />
        <result property="erpStatus"    column="erp_status"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
        <result property="beginTime"    column="begin_time"    />
        <result property="endTime"    column="end_time"    />
    </resultMap>

    <sql id="selectWmsProductOutstockDetailVo">
        select product_outstock_detail_id, product_outstock_id, warehouse_id, location_code, product_barcode, product_batch, product_id, plan_amount, outstock_amount, execute_status, erp_status, update_by, update_date, begin_time, end_time from wms_product_outstock_detail
    </sql>

    <select id="selectWmsProductOutstockDetailList" parameterType="WmsProductOutstockDetail" resultMap="WmsProductOutstockDetailResult">
        <include refid="selectWmsProductOutstockDetailVo"/>
        <where>
            <if test="productOutstockId != null "> and product_outstock_id = #{productOutstockId}</if>
            <if test="warehouseId != null "> and warehouse_id = #{warehouseId}</if>
            <if test="locationCode != null  and locationCode != ''"> and location_code = #{locationCode}</if>
            <if test="productBarcode != null  and productBarcode != ''"> and product_barcode = #{productBarcode}</if>
            <if test="productBatch != null  and productBatch != ''"> and product_batch = #{productBatch}</if>
            <if test="productId != null "> and product_id = #{productId}</if>
            <if test="planAmount != null "> and plan_amount = #{planAmount}</if>
            <if test="outstockAmount != null "> and outstock_amount = #{outstockAmount}</if>
            <if test="executeStatus != null  and executeStatus != ''"> and execute_status = #{executeStatus}</if>
            <if test="erpStatus != null  and erpStatus != ''"> and erp_status = #{erpStatus}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="beginTime != null "> and begin_time = #{beginTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
        </where>
        order by end_time desc
    </select>

    <select id="selectWmsProductOutstockDetailByProductOutstockDetailId" parameterType="Long" resultMap="WmsProductOutstockDetailResult">
        <include refid="selectWmsProductOutstockDetailVo"/>
        where product_outstock_detail_id = #{productOutstockDetailId}
    </select>

    <insert id="insertWmsProductOutstockDetail" parameterType="WmsProductOutstockDetail" useGeneratedKeys="true" keyProperty="productOutstockDetailId">
        insert into wms_product_outstock_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productOutstockId != null">product_outstock_id,</if>
            <if test="warehouseId != null">warehouse_id,</if>
            <if test="locationCode != null and locationCode != ''">location_code,</if>
            <if test="productBarcode != null and productBarcode != ''">product_barcode,</if>
            <if test="productBatch != null">product_batch,</if>
            <if test="productId != null">product_id,</if>
            <if test="planAmount != null">plan_amount,</if>
            <if test="outstockAmount != null">outstock_amount,</if>
            <if test="executeStatus != null and executeStatus != ''">execute_status,</if>
            <if test="erpStatus != null">erp_status,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="beginTime != null">begin_time,</if>
            <if test="endTime != null">end_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productOutstockId != null">#{productOutstockId},</if>
            <if test="warehouseId != null">#{warehouseId},</if>
            <if test="locationCode != null and locationCode != ''">#{locationCode},</if>
            <if test="productBarcode != null and productBarcode != ''">#{productBarcode},</if>
            <if test="productBatch != null">#{productBatch},</if>
            <if test="productId != null">#{productId},</if>
            <if test="planAmount != null">#{planAmount},</if>
            <if test="outstockAmount != null">#{outstockAmount},</if>
            <if test="executeStatus != null and executeStatus != ''">#{executeStatus},</if>
            <if test="erpStatus != null">#{erpStatus},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="beginTime != null">#{beginTime},</if>
            <if test="endTime != null">#{endTime},</if>
         </trim>
    </insert>

    <update id="updateWmsProductOutstockDetail" parameterType="WmsProductOutstockDetail">
        update wms_product_outstock_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="productOutstockId != null">product_outstock_id = #{productOutstockId},</if>
            <if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
            <if test="locationCode != null and locationCode != ''">location_code = #{locationCode},</if>
            <if test="productBarcode != null and productBarcode != ''">product_barcode = #{productBarcode},</if>
            <if test="productBatch != null">product_batch = #{productBatch},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="planAmount != null">plan_amount = #{planAmount},</if>
            <if test="outstockAmount != null">outstock_amount = #{outstockAmount},</if>
            <if test="confirmAmount != null">confirm_amount = #{confirmAmount},</if>
            <if test="executeStatus != null and executeStatus != ''">execute_status = #{executeStatus},</if>
            <if test="erpStatus != null">erp_status = #{erpStatus},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="beginTime != null">begin_time = #{beginTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
        </trim>
        where product_outstock_detail_id = #{productOutstockDetailId}
    </update>

    <delete id="deleteWmsProductOutstockDetailByProductOutstockDetailId" parameterType="Long">
        delete from wms_product_outstock_detail where product_outstock_detail_id = #{productOutstockDetailId}
    </delete>

    <delete id="deleteWmsProductOutstockDetailByProductOutstockDetailIds" parameterType="String">
        delete from wms_product_outstock_detail where product_outstock_detail_id in
        <foreach item="productOutstockDetailId" collection="array" open="(" separator="," close=")">
            #{productOutstockDetailId}
        </foreach>
    </delete>
</mapper>
