<?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="batchFlag"    column="batch_flag"    />
        <result property="barcodeInfo"    column="barcode_info"    />
        <result property="batchCode"    column="batch_code"    />
        <result property="rfidCode"    column="rfid_code"    />
        <result property="materialId"    column="material_id"    />
        <result property="manufacturerId"    column="manufacturer_id"    />
        <result property="weight"    column="weight"    />
        <result property="amount"    column="amount"    />
        <result property="machineName"    column="machine_name"    />
        <result property="poNo"    column="po_no"    />
        <result property="productionDate"    column="production_date"    />
        <result property="acceptedDate"    column="accepted_date"    />
        <result property="limitingDate"    column="limiting_date"    />
        <result property="lastOutstockDate"    column="last_outstock_date"    />
        <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="selectMesBaseBarcodeInfoVo">
        select barcode_id, print_time, print_person, batch_flag, barcode_info, batch_code, rfid_code, material_id, manufacturer_id, weight, amount, machine_name, po_no, production_date, accepted_date, limiting_date, last_outstock_date, serial_number, remark, active_flag, create_by, create_time, update_by, update_time from mes_base_barcode_info
    </sql>

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


    <select id="selectMesBaseBarcodeInfoList" parameterType="MesBaseBarcodeInfo" resultMap="MesBaseBarcodeInfoResult">
        <include refid="selectMesBaseBarcodeInfoVo"/>
        <where>
            <if test="printTime != null "> and print_time = #{printTime}</if>
            <if test="printPerson != null  and printPerson != ''"> and print_person = #{printPerson}</if>
            <if test="barcodeInfo != null  and barcodeInfo != ''"> and barcode_info = #{barcodeInfo}</if>
            <if test="batchCode != null  and batchCode != ''"> and batch_code = #{batchCode}</if>
            <if test="rfidCode != null  and rfidCode != ''"> and rfid_code = #{rfidCode}</if>
            <if test="materialId != null "> and material_id = #{materialId}</if>
            <if test="manufacturerId != null "> and manufacturer_id = #{manufacturerId}</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="poNo != null  and poNo != ''"> and po_no = #{poNo}</if>
            <if test="productionDate != null "> and production_date = #{productionDate}</if>
            <if test="acceptedDate != null "> and accepted_date = #{acceptedDate}</if>
            <if test="limitingDate != null "> and limiting_date = #{limitingDate}</if>
            <if test="lastOutstockDate != null "> and last_outstock_date = #{lastOutstockDate}</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="selectMesBaseBarcodeInfoByBarcodeId" parameterType="Long" resultMap="MesBaseBarcodeInfoResult">
        <include refid="selectMesBaseBarcodeInfoVo"/>
        where 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="batchFlag != null and batchFlag != ''">batch_flag,</if>
            <if test="barcodeInfo != null and barcodeInfo != ''">barcode_info,</if>
            <if test="batchCode != null and batchCode != ''">batch_code,</if>
            <if test="rfidCode != null">rfid_code,</if>
            <if test="materialId != null">material_id,</if>
            <if test="manufacturerId != null">manufacturer_id,</if>
            <if test="weight != null">weight,</if>
            <if test="amount != null">amount,</if>
            <if test="machineName != null">machine_name,</if>
            <if test="poNo != null">po_no,</if>
            <if test="productionDate != null">production_date,</if>
            <if test="acceptedDate != null">accepted_date,</if>
            <if test="limitingDate != null">limiting_date,</if>
            <if test="lastOutstockDate != null">last_outstock_date,</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="barcodeInfo != null and barcodeInfo != ''">#{barcodeInfo},</if>
            <if test="batchCode != null and batchCode != ''">#{batchCode},</if>
            <if test="rfidCode != null">#{rfidCode},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="manufacturerId != null">#{manufacturerId},</if>
            <if test="weight != null">#{weight},</if>
            <if test="amount != null">#{amount},</if>
            <if test="machineName != null">#{machineName},</if>
            <if test="poNo != null">#{poNo},</if>
            <if test="productionDate != null">#{productionDate},</if>
            <if test="acceptedDate != null">#{acceptedDate},</if>
            <if test="limitingDate != null">#{limitingDate},</if>
            <if test="lastOutstockDate != null">#{lastOutstockDate},</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="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="barcodeInfo != null and barcodeInfo != ''">barcode_info = #{barcodeInfo},</if>
            <if test="batchCode != null and batchCode != ''">batch_code = #{batchCode},</if>
            <if test="rfidCode != null">rfid_code = #{rfidCode},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="manufacturerId != null">manufacturer_id = #{manufacturerId},</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="poNo != null">po_no = #{poNo},</if>
            <if test="productionDate != null">production_date = #{productionDate},</if>
            <if test="acceptedDate != null">accepted_date = #{acceptedDate},</if>
            <if test="limitingDate != null">limiting_date = #{limitingDate},</if>
            <if test="lastOutstockDate != null">last_outstock_date = #{lastOutstockDate},</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 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>
</mapper>
