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

    <resultMap type="WmsTransferDetail" id="WmsTransferDetailResult">
        <result property="transferDetailId"    column="transfer_detail_id"    />
        <result property="transferId"    column="transfer_id"    />
        <result property="locationCode"    column="location_code"    />
        <result property="materialBarcode"    column="material_barcode"    />
        <result property="instockBatch"    column="instock_batch"    />
        <result property="materialId"    column="material_id"    />
        <result property="planAmount"    column="plan_amount"    />
        <result property="realAmount"    column="real_amount"    />
        <result property="executeStatus"    column="execute_status"    />
        <result property="executePerson"    column="execute_person"    />
        <result property="executeTime"    column="execute_time"    />
        <result property="transferDetailType"    column="transfer_detail_type"    />
        <result property="machineName"    column="machine_name"    />
        <result property="createBy"    column="create_by"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
        <result property="activeFlag"    column="active_flag"    />
    </resultMap>

    <sql id="selectWmsTransferDetailVo">
        select transfer_detail_id, transfer_id, location_code, material_barcode, instock_batch, material_id, plan_amount, real_amount, execute_status, execute_person, execute_time, transfer_detail_type, machine_name, create_by, create_date, update_by, update_date, active_flag from wms_transfer_detail
    </sql>

    <select id="selectWmsTransferDetailList" parameterType="WmsTransferDetail" resultMap="WmsTransferDetailResult">
        <include refid="selectWmsTransferDetailVo"/>
        <where>
            <if test="transferId != null "> and transfer_id = #{transferId}</if>
            <if test="locationCode != null  and locationCode != ''"> and location_code = #{locationCode}</if>
            <if test="materialBarcode != null  and materialBarcode != ''"> and material_barcode = #{materialBarcode}</if>
            <if test="instockBatch != null  and instockBatch != ''"> and instock_batch = #{instockBatch}</if>
            <if test="materialId != null "> and material_id = #{materialId}</if>
            <if test="planAmount != null "> and plan_amount = #{planAmount}</if>
            <if test="realAmount != null "> and real_amount = #{realAmount}</if>
            <if test="executeStatus != null  and executeStatus != ''"> and execute_status = #{executeStatus}</if>
            <if test="executePerson != null  and executePerson != ''"> and execute_person = #{executePerson}</if>
            <if test="executeTime != null "> and execute_time = #{executeTime}</if>
            <if test="transferDetailType != null  and transferDetailType != ''"> and transfer_detail_type = #{transferDetailType}</if>
            <if test="machineName != null  and machineName != ''"> and machine_name like concat('%', #{machineName}, '%')</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="activeFlag != null  and activeFlag != ''"> and active_flag = #{activeFlag}</if>
        </where>
    </select>

    <select id="selectWmsTransferDetailByTransferDetailId" parameterType="Long" resultMap="WmsTransferDetailResult">
        <include refid="selectWmsTransferDetailVo"/>
        where transfer_detail_id = #{transferDetailId}
    </select>

    <insert id="insertWmsTransferDetail" parameterType="WmsTransferDetail" useGeneratedKeys="true" keyProperty="transferDetailId">
        insert into wms_transfer_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="transferId != null">transfer_id,</if>
            <if test="locationCode != null and locationCode != ''">location_code,</if>
            <if test="materialBarcode != null and materialBarcode != ''">material_barcode,</if>
            <if test="instockBatch != null">instock_batch,</if>
            <if test="materialId != null">material_id,</if>
            <if test="planAmount != null">plan_amount,</if>
            <if test="realAmount != null">real_amount,</if>
            <if test="executeStatus != null and executeStatus != ''">execute_status,</if>
            <if test="executePerson != null">execute_person,</if>
            <if test="executeTime != null">execute_time,</if>
            <if test="transferDetailType != null and transferDetailType != ''">transfer_detail_type,</if>
            <if test="machineName != null">machine_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="activeFlag != null">active_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="transferId != null">#{transferId},</if>
            <if test="locationCode != null and locationCode != ''">#{locationCode},</if>
            <if test="materialBarcode != null and materialBarcode != ''">#{materialBarcode},</if>
            <if test="instockBatch != null">#{instockBatch},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="planAmount != null">#{planAmount},</if>
            <if test="realAmount != null">#{realAmount},</if>
            <if test="executeStatus != null and executeStatus != ''">#{executeStatus},</if>
            <if test="executePerson != null">#{executePerson},</if>
            <if test="executeTime != null">#{executeTime},</if>
            <if test="transferDetailType != null and transferDetailType != ''">#{transferDetailType},</if>
            <if test="machineName != null">#{machineName},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="activeFlag != null">#{activeFlag},</if>
         </trim>
    </insert>

    <update id="updateWmsTransferDetail" parameterType="WmsTransferDetail">
        update wms_transfer_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="transferId != null">transfer_id = #{transferId},</if>
            <if test="locationCode != null and locationCode != ''">location_code = #{locationCode},</if>
            <if test="materialBarcode != null and materialBarcode != ''">material_barcode = #{materialBarcode},</if>
            <if test="instockBatch != null">instock_batch = #{instockBatch},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="planAmount != null">plan_amount = #{planAmount},</if>
            <if test="realAmount != null">real_amount = #{realAmount},</if>
            <if test="executeStatus != null and executeStatus != ''">execute_status = #{executeStatus},</if>
            <if test="executePerson != null">execute_person = #{executePerson},</if>
            <if test="executeTime != null">execute_time = #{executeTime},</if>
            <if test="transferDetailType != null and transferDetailType != ''">transfer_detail_type = #{transferDetailType},</if>
            <if test="machineName != null">machine_name = #{machineName},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="activeFlag != null">active_flag = #{activeFlag},</if>
        </trim>
        where transfer_detail_id = #{transferDetailId}
    </update>

    <delete id="deleteWmsTransferDetailByTransferDetailId" parameterType="Long">
        delete from wms_transfer_detail where transfer_detail_id = #{transferDetailId}
    </delete>

    <delete id="deleteWmsTransferDetailByTransferDetailIds" parameterType="String">
        delete from wms_transfer_detail where transfer_detail_id in
        <foreach item="transferDetailId" collection="array" open="(" separator="," close=")">
            #{transferDetailId}
        </foreach>
    </delete>
</mapper>
