<?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="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="materialId"    column="material_id"    />
        <result property="manufacturerId"    column="manufacturer_id"    />
        <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="lastOutstockDate"    column="last_outstock_date"    />
        <result property="planCode"    column="plan_code"    />
        <result property="planDetailCode"    column="plan_detail_code"    />
        <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"    />
    </resultMap>

    <sql id="selectMesBaseBarcodeInfoVo">
        select barcode_id, print_time, print_person, batch_flag, barcode_type, barcode_info, batch_code, pallet_info_code, material_id, manufacturer_id, amount, machine_name, po_no, production_date, accepted_date, last_outstock_date, plan_code, plan_detail_code, saleorder_code, project_no, serial_number, remark, bind_status, bind_by, bind_time, update_by, update_time from mes_base_barcode_info
    </sql>

    <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="batchFlag != null  and batchFlag != ''"> and batch_flag = #{batchFlag}</if>
            <if test="barcodeType != null  and barcodeType != ''"> and barcode_type = #{barcodeType}</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="palletInfoCode != null  and palletInfoCode != ''"> and pallet_info_code = #{palletInfoCode}</if>
            <if test="materialId != null "> and material_id = #{materialId}</if>
            <if test="manufacturerId != null "> and manufacturer_id = #{manufacturerId}</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="lastOutstockDate != null "> and last_outstock_date = #{lastOutstockDate}</if>
            <if test="planCode != null  and planCode != ''"> and plan_code = #{planCode}</if>
            <if test="planDetailCode != null  and planDetailCode != ''"> and plan_detail_code = #{planDetailCode}</if>
            <if test="saleorderCode != null  and saleorderCode != ''"> and saleorder_code = #{saleorderCode}</if>
            <if test="projectNo != null  and projectNo != ''"> and project_no = #{projectNo}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
            <if test="bindStatus != null  and bindStatus != ''"> and bind_status = #{bindStatus}</if>
            <if test="bindBy != null  and bindBy != ''"> and bind_by = #{bindBy}</if>
            <if test="bindTime != null "> and bind_time = #{bindTime}</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="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="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="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="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="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="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="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="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="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="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 barcode_info = #{barcodeInfo} limit 1
    </select>


</mapper>
