<?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.MesBindBarcodeMapper">
    
    <resultMap type="MesBindBarcode" id="MesBindBarcodeResult">
        <result property="bindBarcodeId"    column="bind_barcode_id"    />
        <result property="printTime"    column="print_time"    />
        <result property="printPerson"    column="print_person"    />
        <result property="batchFlag"    column="batch_flag"    />
        <result property="bindBarcodeInfo"    column="bind_barcode_info"    />
        <result property="barcodeInfo"    column="barcode_info"    />
        <result property="weight"    column="weight"    />
        <result property="amount"    column="amount"    />
        <result property="machineName"    column="machine_name"    />
        <result property="projectNo"    column="project_no"    />
        <result property="saleorderCode"    column="saleorder_code"    />
        <result property="planId"    column="plan_id"    />
        <result property="planDetailId"    column="plan_detail_id"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="remark"    column="remark"    />
        <result property="activeFlag"    column="active_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMesBindBarcodeVo">
        select bind_barcode_id, print_time, print_person, batch_flag, bind_barcode_info, barcode_info, weight, amount, machine_name, project_no, saleorder_code, plan_id, plan_detail_id, serial_number, remark, active_flag, create_by, create_time, update_by, update_time from mes_bind_barcode
    </sql>

    <select id="selectMesBindBarcodeList" parameterType="MesBindBarcode" resultMap="MesBindBarcodeResult">
        <include refid="selectMesBindBarcodeVo"/>
        <where>  
            <if test="printTime != null "> and print_time = #{printTime}</if>
            <if test="printPerson != null  and printPerson != ''"> and print_person = #{printPerson}</if>
            <if test="batchFlag != null  and batchFlag != ''"> and batch_flag = #{batchFlag}</if>
            <if test="bindBarcodeInfo != null  and bindBarcodeInfo != ''"> and bind_barcode_info = #{bindBarcodeInfo}</if>
            <if test="barcodeInfo != null  and barcodeInfo != ''"> and barcode_info = #{barcodeInfo}</if>
            <if test="weight != null "> and weight = #{weight}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="machineName != null  and machineName != ''"> and machine_name like concat('%', #{machineName}, '%')</if>
            <if test="projectNo != null  and projectNo != ''"> and project_no = #{projectNo}</if>
            <if test="saleorderCode != null  and saleorderCode != ''"> and saleorder_code = #{saleorderCode}</if>
            <if test="planId != null "> and plan_id = #{planId}</if>
            <if test="planDetailId != null "> and plan_detail_id = #{planDetailId}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
            <if test="activeFlag != null "> and active_flag = #{activeFlag}</if>
        </where>
    </select>
    
    <select id="selectMesBindBarcodeByBindBarcodeId" parameterType="Long" resultMap="MesBindBarcodeResult">
        <include refid="selectMesBindBarcodeVo"/>
        where bind_barcode_id = #{bindBarcodeId}
    </select>
        
    <insert id="insertMesBindBarcode" parameterType="MesBindBarcode" useGeneratedKeys="true" keyProperty="bindBarcodeId">
        insert into mes_bind_barcode
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="printTime != null">print_time,</if>
            <if test="printPerson != null">print_person,</if>
            <if test="batchFlag != null and batchFlag != ''">batch_flag,</if>
            <if test="bindBarcodeInfo != null and bindBarcodeInfo != ''">bind_barcode_info,</if>
            <if test="barcodeInfo != null and barcodeInfo != ''">barcode_info,</if>
            <if test="weight != null">weight,</if>
            <if test="amount != null">amount,</if>
            <if test="machineName != null">machine_name,</if>
            <if test="projectNo != null">project_no,</if>
            <if test="saleorderCode != null">saleorder_code,</if>
            <if test="planId != null">plan_id,</if>
            <if test="planDetailId != null">plan_detail_id,</if>
            <if test="serialNumber != null">serial_number,</if>
            <if test="remark != null">remark,</if>
            <if test="activeFlag != null">active_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="printTime != null">#{printTime},</if>
            <if test="printPerson != null">#{printPerson},</if>
            <if test="batchFlag != null and batchFlag != ''">#{batchFlag},</if>
            <if test="bindBarcodeInfo != null and bindBarcodeInfo != ''">#{bindBarcodeInfo},</if>
            <if test="barcodeInfo != null and barcodeInfo != ''">#{barcodeInfo},</if>
            <if test="weight != null">#{weight},</if>
            <if test="amount != null">#{amount},</if>
            <if test="machineName != null">#{machineName},</if>
            <if test="projectNo != null">#{projectNo},</if>
            <if test="saleorderCode != null">#{saleorderCode},</if>
            <if test="planId != null">#{planId},</if>
            <if test="planDetailId != null">#{planDetailId},</if>
            <if test="serialNumber != null">#{serialNumber},</if>
            <if test="remark != null">#{remark},</if>
            <if test="activeFlag != null">#{activeFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMesBindBarcode" parameterType="MesBindBarcode">
        update mes_bind_barcode
        <trim prefix="SET" suffixOverrides=",">
            <if test="printTime != null">print_time = #{printTime},</if>
            <if test="printPerson != null">print_person = #{printPerson},</if>
            <if test="batchFlag != null and batchFlag != ''">batch_flag = #{batchFlag},</if>
            <if test="bindBarcodeInfo != null and bindBarcodeInfo != ''">bind_barcode_info = #{bindBarcodeInfo},</if>
            <if test="barcodeInfo != null and barcodeInfo != ''">barcode_info = #{barcodeInfo},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="machineName != null">machine_name = #{machineName},</if>
            <if test="projectNo != null">project_no = #{projectNo},</if>
            <if test="saleorderCode != null">saleorder_code = #{saleorderCode},</if>
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="planDetailId != null">plan_detail_id = #{planDetailId},</if>
            <if test="serialNumber != null">serial_number = #{serialNumber},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="activeFlag != null">active_flag = #{activeFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where bind_barcode_id = #{bindBarcodeId}
    </update>

    <delete id="deleteMesBindBarcodeByBindBarcodeId" parameterType="Long">
        delete from mes_bind_barcode where bind_barcode_id = #{bindBarcodeId}
    </delete>

    <delete id="deleteMesBindBarcodeByBindBarcodeIds" parameterType="String">
        delete from mes_bind_barcode where bind_barcode_id in 
        <foreach item="bindBarcodeId" collection="array" open="(" separator="," close=")">
            #{bindBarcodeId}
        </foreach>
    </delete>
</mapper>