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

    <resultMap type="MesBaseBarcodeInfo" id="MesBaseBarcodeInfoResult">
        <result property="barcodeId" column="barcode_id"/>
        <result property="printTime" column="print_time"/>
        <result property="printPerson" column="print_person"/>
        <result property="printFlag" column="print_flag"/>
        <result property="batchFlag" column="batch_flag"/>
        <result property="barcodeType" column="barcode_type"/>
        <result property="barcodeInfo" column="barcode_info"/>
        <result property="batchCode" column="batch_code"/>
        <result property="palletInfoCode" column="pallet_info_code"/>
        <result property="bindBarcode" column="bind_barcode"/>
        <result property="materialId" column="material_id"/>
        <result property="manufacturerId" column="manufacturer_id"/>
        <result property="amount" column="amount"/>
        <result property="machineName" column="machine_name"/>
        <result property="printNumber" column="print_number"/>
        <result property="poNo" column="po_no"/>
        <result property="productionDate" column="production_date"/>
        <result property="acceptedDate" column="accepted_date"/>
        <result property="lastOutstockDate" column="last_outstock_date"/>
        <result property="planCode" column="plan_code"/>
        <result property="planDetailCode" column="plan_detail_code"/>
        <result property="saleOrderId" column="sale_order_id"/>
        <result property="saleorderCode" column="saleorder_code"/>
        <result property="projectNo" column="project_no"/>
        <result property="serialNumber" column="serial_number"/>
        <result property="remark" column="remark"/>
        <result property="bindStatus" column="bind_status"/>
        <result property="bindBy" column="bind_by"/>
        <result property="bindTime" column="bind_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="materialName" column="material_name"/>
    </resultMap>

    <sql id="selectMesBaseBarcodeInfoVo">
        select bbi.barcode_id,
               bbi.print_time,
               bbi.print_person,
               bbi.batch_flag,
               bbi.barcode_type,
               bbi.barcode_info,
               bbi.batch_code,
               bbi.pallet_info_code,
               bbi.bind_barcode,
               bbi.material_id,
               bmi.material_name,
               bbi.manufacturer_id,
               bbi.amount,
               bbi.machine_name,
               bbi.print_number,
               bbi.po_no,
               bbi.production_date,
               bbi.accepted_date,
               bbi.last_outstock_date,
               bbi.plan_code,
               bbi.plan_detail_code,
               bbi.sale_order_id,
               bbi.saleorder_code,
               bbi.project_no,
               bbi.print_flag,
               bbi.serial_number,
               bbi.remark,
               bbi.bind_status,
               bbi.bind_by,
               bbi.bind_time,
               bbi.update_by,
               bbi.update_time
        from mes_base_barcode_info bbi
                 left join mes_base_material_info bmi on bmi.material_id = bbi.material_id
    </sql>

    <select id="selectMesBaseBarcodeInfoList" parameterType="MesBaseBarcodeInfo" resultMap="MesBaseBarcodeInfoResult">
        <include refid="selectMesBaseBarcodeInfoVo"/>
        <where>
            <if test="printTime != null ">and bbi.print_time = #{printTime}</if>
            <if test="printPerson != null  and printPerson != ''">and bbi.print_person = #{printPerson}</if>
            <if test="printFlag != null  and printFlag != ''">and bbi.print_flag = #{printFlag}</if>
            <if test="batchFlag != null  and batchFlag != ''">and bbi.batch_flag = #{batchFlag}</if>
            <if test="barcodeType != null  and barcodeType != ''">and bbi.barcode_type = #{barcodeType}</if>
            <if test="barcodeInfo != null  and barcodeInfo != ''">and bbi.barcode_info = #{barcodeInfo}</if>
            <if test="batchCode != null  and batchCode != ''">and bbi.batch_code = #{batchCode}</if>
            <if test="palletInfoCode != null  and palletInfoCode != ''">and bbi.pallet_info_code = #{palletInfoCode}</if>
            <if test="materialId != null ">and bbi.material_id = #{materialId}</if>
            <if test="manufacturerId != null ">and bbi.manufacturer_id = #{manufacturerId}</if>
            <if test="amount != null ">and bbi.amount = #{amount}</if>
            <if test="machineName != null  and machineName != ''">and bbi.machine_name like concat('%', #{machineName},
                '%')
            </if>
            <if test="printNumber != null ">and bbi.print_number = #{printNumber}</if>
            <if test="poNo != null  and poNo != ''">and bbi.po_no = #{poNo}</if>
            <if test="productionDate != null ">and bbi.production_date = #{productionDate}</if>
            <if test="acceptedDate != null ">and bbi.accepted_date = #{acceptedDate}</if>
            <if test="lastOutstockDate != null ">and bbi.last_outstock_date = #{lastOutstockDate}</if>
            <if test="planCode != null  and planCode != ''">and bbi.plan_code = #{planCode}</if>
            <if test="planDetailCode != null  and planDetailCode != ''">and bbi.plan_detail_code = #{planDetailCode}</if>
            <if test="saleOrderId != null ">and bbi.sale_order_id = #{saleOrderId}</if>
            <if test="saleorderCode != null  and saleorderCode != ''">and bbi.saleorder_code = #{saleorderCode}</if>
            <if test="projectNo != null  and projectNo != ''">and bbi.project_no = #{projectNo}</if>
            <if test="serialNumber != null  and serialNumber != ''">and bbi.serial_number = #{serialNumber}</if>
            <if test="bindStatus != null  and bindStatus != ''">and bbi.bind_status = #{bindStatus}</if>
            <if test="bindBy != null  and bindBy != ''">and bbi.bind_by = #{bindBy}</if>
            <if test="bindTime != null ">and bbi.bind_time = #{bindTime}</if>
            <if test="updateBy != null  and updateBy != ''">and bbi.update_by = #{updateBy}</if>
            <if test="updateTime != null ">and bbi.update_time = #{updateTime}</if>
        </where>
    </select>

    <select id="selectMesBaseBarcodeInfoByBarcodeId" parameterType="Long" resultMap="MesBaseBarcodeInfoResult">
        <include refid="selectMesBaseBarcodeInfoVo"/>
        where bbi.barcode_id = #{barcodeId}
    </select>

    <insert id="insertMesBaseBarcodeInfo" parameterType="MesBaseBarcodeInfo" useGeneratedKeys="true"
            keyProperty="barcodeId">
        insert into mes_base_barcode_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="printTime != null">print_time,</if>
            <if test="printPerson != null">print_person,</if>
            <if test="printFlag != null and printFlag != ''">print_flag,</if>
            <if test="batchFlag != null and batchFlag != ''">batch_flag,</if>
            <if test="barcodeType != null and barcodeType != ''">barcode_type,</if>
            <if test="barcodeInfo != null and barcodeInfo != ''">barcode_info,</if>
            <if test="batchCode != null and batchCode != ''">batch_code,</if>
            <if test="palletInfoCode != null">pallet_info_code,</if>
            <if test="materialId != null">material_id,</if>
            <if test="manufacturerId != null">manufacturer_id,</if>
            <if test="amount != null">amount,</if>
            <if test="machineName != null">machine_name,</if>
            <if test="printNumber != null">print_number,</if>
            <if test="poNo != null">po_no,</if>
            <if test="productionDate != null">production_date,</if>
            <if test="acceptedDate != null">accepted_date,</if>
            <if test="lastOutstockDate != null">last_outstock_date,</if>
            <if test="planCode != null">plan_code,</if>
            <if test="planDetailCode != null">plan_detail_code,</if>
            <if test="saleOrderId != null">sale_order_id,</if>
            <if test="saleorderCode != null">saleorder_code,</if>
            <if test="projectNo != null">project_no,</if>
            <if test="serialNumber != null">serial_number,</if>
            <if test="remark != null">remark,</if>
            <if test="bindStatus != null">bind_status,</if>
            <if test="bindBy != null">bind_by,</if>
            <if test="bindTime != null">bind_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="printFlag != null and printFlag != ''">#{printFlag},</if>
            <if test="batchFlag != null and batchFlag != ''">#{batchFlag},</if>
            <if test="barcodeType != null and barcodeType != ''">#{barcodeType},</if>
            <if test="barcodeInfo != null and barcodeInfo != ''">#{barcodeInfo},</if>
            <if test="batchCode != null and batchCode != ''">#{batchCode},</if>
            <if test="palletInfoCode != null">#{palletInfoCode},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="manufacturerId != null">#{manufacturerId},</if>
            <if test="amount != null">#{amount},</if>
            <if test="machineName != null">#{machineName},</if>
            <if test="printNumber != null">#{printNumber},</if>
            <if test="poNo != null">#{poNo},</if>
            <if test="productionDate != null">#{productionDate},</if>
            <if test="acceptedDate != null">#{acceptedDate},</if>
            <if test="lastOutstockDate != null">#{lastOutstockDate},</if>
            <if test="planCode != null">#{planCode},</if>
            <if test="planDetailCode != null">#{planDetailCode},</if>
            <if test="saleOrderId != null">#{saleOrderId},</if>
            <if test="saleorderCode != null">#{saleorderCode},</if>
            <if test="projectNo != null">#{projectNo},</if>
            <if test="serialNumber != null">#{serialNumber},</if>
            <if test="remark != null">#{remark},</if>
            <if test="bindStatus != null">#{bindStatus},</if>
            <if test="bindBy != null">#{bindBy},</if>
            <if test="bindTime != null">#{bindTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateMesBaseBarcodeInfo" parameterType="MesBaseBarcodeInfo">
        update mes_base_barcode_info
        <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="printFlag != null and printFlag != ''">print_flag = #{printFlag},</if>
            <if test="barcodeType != null and barcodeType != ''">barcode_type = #{barcodeType},</if>
            <if test="barcodeInfo != null and barcodeInfo != ''">barcode_info = #{barcodeInfo},</if>
            <if test="batchCode != null and batchCode != ''">batch_code = #{batchCode},</if>
            <if test="palletInfoCode != null">pallet_info_code = #{palletInfoCode},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="manufacturerId != null">manufacturer_id = #{manufacturerId},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="machineName != null">machine_name = #{machineName},</if>
            <if test="printNumber != null">print_number = #{printNumber},</if>
            <if test="poNo != null">po_no = #{poNo},</if>
            <if test="productionDate != null">production_date = #{productionDate},</if>
            <if test="acceptedDate != null">accepted_date = #{acceptedDate},</if>
            <if test="lastOutstockDate != null">last_outstock_date = #{lastOutstockDate},</if>
            <if test="planCode != null">plan_code = #{planCode},</if>
            <if test="planDetailCode != null">plan_detail_code = #{planDetailCode},</if>
            <if test="saleOrderId != null">sale_order_id = #{saleOrderId},</if>
            <if test="saleorderCode != null">saleorder_code = #{saleorderCode},</if>
            <if test="projectNo != null">project_no = #{projectNo},</if>
            <if test="serialNumber != null">serial_number = #{serialNumber},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="bindBarcode != null">bind_barcode = #{bindBarcode},</if>
            <if test="bindStatus != null">bind_status = #{bindStatus},</if>
            <if test="bindBy != null">bind_by = #{bindBy},</if>
            <if test="bindTime != null">bind_time = #{bindTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where barcode_id = #{barcodeId}
    </update>

    <delete id="deleteMesBaseBarcodeInfoByBarcodeId" parameterType="Long">
        delete
        from mes_base_barcode_info
        where barcode_id = #{barcodeId}
    </delete>

    <delete id="deleteMesBaseBarcodeInfoByBarcodeIds" parameterType="String">
        delete from mes_base_barcode_info where barcode_id in
        <foreach item="barcodeId" collection="array" open="(" separator="," close=")">
            #{barcodeId}
        </foreach>
    </delete>

    <select id="selectMesBaseBarcodeInfoByBarcodeInfo" parameterType="String" resultMap="MesBaseBarcodeInfoResult">
        <include refid="selectMesBaseBarcodeInfoVo"/>
        where bbi.barcode_info = #{barcodeInfo} limit 1
    </select>
</mapper>
