<?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.mes.mapper.MesMaterialCheckResultDetailMapper">

    <resultMap type="MesMaterialCheckResultDetail" id="MesMaterialCheckResultDetailResult">
        <result property="checkResultDetailId"    column="check_result_detail_id"    />
        <result property="materialCheckResultId"    column="material_check_result_id"    />
        <result property="materialBarcode"    column="material_barcode"    />
        <result property="batchCode"    column="batch_code"    />
        <result property="checkAmount"    column="check_amount"    />
    </resultMap>

    <sql id="selectMesMaterialCheckResultDetailVo">
        select check_result_detail_id, material_check_result_id, material_barcode, batch_code, check_amount from mes_material_check_result_detail
    </sql>

    <select id="selectMesMaterialCheckResultDetailList" parameterType="MesMaterialCheckResultDetail" resultMap="MesMaterialCheckResultDetailResult">
        <include refid="selectMesMaterialCheckResultDetailVo"/>
        <where>
            <if test="materialCheckResultId != null "> and material_check_result_id = #{materialCheckResultId}</if>
            <if test="materialBarcode != null  and materialBarcode != ''"> and material_barcode = #{materialBarcode}</if>
            <if test="batchCode != null  and batchCode != ''"> and batch_code = #{batchCode}</if>
            <if test="checkAmount != null "> and check_amount = #{checkAmount}</if>
        </where>
    </select>

    <select id="selectMesMaterialCheckResultDetailByCheckResultDetailId" parameterType="Long" resultMap="MesMaterialCheckResultDetailResult">
        <include refid="selectMesMaterialCheckResultDetailVo"/>
        where check_result_detail_id = #{checkResultDetailId}
    </select>

    <insert id="insertMesMaterialCheckResultDetail" parameterType="MesMaterialCheckResultDetail" useGeneratedKeys="true" keyProperty="checkResultDetailId">
        insert into mes_material_check_result_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="materialCheckResultId != null">material_check_result_id,</if>
            <if test="materialBarcode != null and materialBarcode != ''">material_barcode,</if>
            <if test="batchCode != null and batchCode != ''">batch_code,</if>
            <if test="checkAmount != null">check_amount,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="materialCheckResultId != null">#{materialCheckResultId},</if>
            <if test="materialBarcode != null and materialBarcode != ''">#{materialBarcode},</if>
            <if test="batchCode != null and batchCode != ''">#{batchCode},</if>
            <if test="checkAmount != null">#{checkAmount},</if>
         </trim>
    </insert>

    <update id="updateMesMaterialCheckResultDetail" parameterType="MesMaterialCheckResultDetail">
        update mes_material_check_result_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="materialCheckResultId != null">material_check_result_id = #{materialCheckResultId},</if>
            <if test="materialBarcode != null and materialBarcode != ''">material_barcode = #{materialBarcode},</if>
            <if test="batchCode != null and batchCode != ''">batch_code = #{batchCode},</if>
            <if test="checkAmount != null">check_amount = #{checkAmount},</if>
        </trim>
        where check_result_detail_id = #{checkResultDetailId}
    </update>

    <delete id="deleteMesMaterialCheckResultDetailByCheckResultDetailId" parameterType="Long">
        delete from mes_material_check_result_detail where check_result_detail_id = #{checkResultDetailId}
    </delete>

    <delete id="deleteMesMaterialCheckResultDetailByCheckResultDetailIds" parameterType="String">
        delete from mes_material_check_result_detail where check_result_detail_id in
        <foreach item="checkResultDetailId" collection="array" open="(" separator="," close=")">
            #{checkResultDetailId}
        </foreach>
    </delete>
</mapper>
