<?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.WmsProductInstockDetailMapper">

    <resultMap type="WmsProductInstockDetail" id="WmsProductInstockDetailResult">
        <result property="productInstockDetailId"    column="product_instock_detail_id"    />
        <result property="productInstockId"    column="product_instock_id"    />
        <result property="locationCode"    column="location_code"    />
        <result property="productId"    column="product_id"    />
        <result property="productBarcode"    column="product_barcode"    />
        <result property="productBatch"    column="product_batch"    />
        <result property="executeStatus"    column="execute_status"    />
        <result property="erpStatus"    column="erp_status"    />
        <result property="planAmount"    column="plan_amount"    />
        <result property="instockAmount"    column="instock_amount"    />
        <result property="instockBy"    column="instock_by"    />
        <result property="instockDate"    column="instock_date"    />
        <result property="instockWay"    column="instock_way"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
    </resultMap>

    <sql id="selectWmsProductInstockDetailVo">
        select product_instock_detail_id, product_instock_id, location_code, product_id, product_barcode, product_batch, execute_status, erp_status, plan_amount, instock_amount, instock_by, instock_date, instock_way, update_by, update_date from wms_product_instock_detail
    </sql>

    <select id="selectWmsProductInstockDetailList" parameterType="WmsProductInstockDetail" resultMap="WmsProductInstockDetailResult">
        <include refid="selectWmsProductInstockDetailVo"/>
        <where>
            <if test="productInstockId != null "> and product_instock_id = #{productInstockId}</if>
            <if test="locationCode != null  and locationCode != ''"> and location_code = #{locationCode}</if>
            <if test="productId != null "> and product_id = #{productId}</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="executeStatus != null  and executeStatus != ''"> and execute_status = #{executeStatus}</if>
            <if test="erpStatus != null  and erpStatus != ''"> and erp_status = #{erpStatus}</if>
            <if test="planAmount != null "> and plan_amount = #{planAmount}</if>
            <if test="instockAmount != null "> and instock_amount = #{instockAmount}</if>
            <if test="instockBy != null  and instockBy != ''"> and instock_by = #{instockBy}</if>
            <if test="instockDate != null "> and instock_date = #{instockDate}</if>
            <if test="instockWay != null  and instockWay != ''"> and instock_way = #{instockWay}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
        </where>
    </select>

    <select id="selectWmsProductInstockDetailByProductInstockDetailId" parameterType="Long" resultMap="WmsProductInstockDetailResult">
        <include refid="selectWmsProductInstockDetailVo"/>
        where product_instock_detail_id = #{productInstockDetailId}
    </select>

    <insert id="insertWmsProductInstockDetail" parameterType="WmsProductInstockDetail" useGeneratedKeys="true" keyProperty="productInstockDetailId">
        insert into wms_product_instock_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productInstockId != null">product_instock_id,</if>
            <if test="locationCode != null and locationCode != ''">location_code,</if>
            <if test="productId != null">product_id,</if>
            <if test="productBarcode != null and productBarcode != ''">product_barcode,</if>
            <if test="productBatch != null">product_batch,</if>
            <if test="executeStatus != null and executeStatus != ''">execute_status,</if>
            <if test="erpStatus != null">erp_status,</if>
            <if test="planAmount != null">plan_amount,</if>
            <if test="instockAmount != null">instock_amount,</if>
            <if test="instockBy != null">instock_by,</if>
            <if test="instockDate != null">instock_date,</if>
            <if test="instockWay != null and instockWay != ''">instock_way,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productInstockId != null">#{productInstockId},</if>
            <if test="locationCode != null and locationCode != ''">#{locationCode},</if>
            <if test="productId != null">#{productId},</if>
            <if test="productBarcode != null and productBarcode != ''">#{productBarcode},</if>
            <if test="productBatch != null">#{productBatch},</if>
            <if test="executeStatus != null and executeStatus != ''">#{executeStatus},</if>
            <if test="erpStatus != null">#{erpStatus},</if>
            <if test="planAmount != null">#{planAmount},</if>
            <if test="instockAmount != null">#{instockAmount},</if>
            <if test="instockBy != null">#{instockBy},</if>
            <if test="instockDate != null">#{instockDate},</if>
            <if test="instockWay != null and instockWay != ''">#{instockWay},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
         </trim>
    </insert>

    <update id="updateWmsProductInstockDetail" parameterType="WmsProductInstockDetail">
        update wms_product_instock_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="productInstockId != null">product_instock_id = #{productInstockId},</if>
            <if test="locationCode != null and locationCode != ''">location_code = #{locationCode},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="productBarcode != null and productBarcode != ''">product_barcode = #{productBarcode},</if>
            <if test="productBatch != null">product_batch = #{productBatch},</if>
            <if test="executeStatus != null and executeStatus != ''">execute_status = #{executeStatus},</if>
            <if test="erpStatus != null">erp_status = #{erpStatus},</if>
            <if test="planAmount != null">plan_amount = #{planAmount},</if>
            <if test="instockAmount != null">instock_amount = #{instockAmount},</if>
            <if test="instockBy != null">instock_by = #{instockBy},</if>
            <if test="instockDate != null">instock_date = #{instockDate},</if>
            <if test="instockWay != null and instockWay != ''">instock_way = #{instockWay},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
        </trim>
        where product_instock_detail_id = #{productInstockDetailId}
    </update>

    <delete id="deleteWmsProductInstockDetailByProductInstockDetailId" parameterType="Long">
        delete from wms_product_instock_detail where product_instock_detail_id = #{productInstockDetailId}
    </delete>

    <delete id="deleteWmsProductInstockDetailByProductInstockDetailIds" parameterType="String">
        delete from wms_product_instock_detail where product_instock_detail_id in
        <foreach item="productInstockDetailId" collection="array" open="(" separator="," close=")">
            #{productInstockDetailId}
        </foreach>
    </delete>
</mapper>
