<?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.zehong.system.mapper.PalletDeviceUploadHistoryMapper">
    
    <resultMap type="PalletDeviceUploadHistory" id="PalletDeviceUploadHistoryResult">
        <result property="id"    column="f_id"    />
        <result property="trayId"    column="f_tray_id"    />
        <result property="deviceCode"    column="f_device_code"    />
        <result property="row"    column="f_row"    />
        <result property="col"    column="f_col"    />
        <result property="index"    column="f_index"    />
        <result property="number"    column="f_number"    />
        <result property="bindingTime"    column="f_binding_time"    />
        <result property="unbindingTime"    column="f_unbinding_time"    />
        <result property="createTime"    column="f_create_time"    />
        <result property="status"    column="f_status"    />
        <result property="recordYear"    column="f_record_year"    />
        <result property="recordMonth"    column="f_record_month"    />
        <result property="recordDate"    column="f_record_date"    />
        <result property="recordHour"    column="f_record_hour"    />
        <result property="recordMinute"    column="f_record_minute"    />
        <result property="writeTimeStatus"    column="f_write_time_status"    />
        <result property="adjustmentZeroAd"    column="f_adjustment_zero_ad"    />
        <result property="zeroStatus"    column="f_zero_status"    />
        <result property="calibrationAd"    column="f_calibration_ad"    />
        <result property="calibrationStatus"    column="f_calibration_status"    />
        <result property="concentration"    column="f_concentration"    />
        <result property="runTimeStatus"    column="f_run_time_status"    />
        <result property="realTimeAd"    column="f_real_time_ad"    />
        <result property="realTimeAdStatus"    column="f_real_time_ad_status"    />

        <result property="calibrationConcentration"    column="f_calibration_concentration"    />
        <result property="calibrationConcentrationStatus"    column="f_calibration_concentration_status"    />
    </resultMap>

    <sql id="selectPalletDeviceUploadHistoryVo">
        select palDeviceBinding.f_id,
               palDeviceBinding.f_tray_id,
               trayInfo.f_tray_code as trayCode,
               palDeviceBinding.f_device_code,
               palDeviceBinding.f_row,
               palDeviceBinding.f_col,
               palDeviceBinding.f_index,
               palDeviceBinding.f_number,
               palDeviceBinding.f_binding_time,
               palDeviceBinding.f_unbinding_time,
               palDeviceBinding.f_create_time,
               palDeviceBinding.f_status,
               palDeviceBinding.f_record_year,
               palDeviceBinding.f_record_month,
               palDeviceBinding.f_record_date,
               palDeviceBinding.f_record_hour,
               palDeviceBinding.f_record_minute,
               palDeviceBinding.f_write_time_status,
               palDeviceBinding.f_adjustment_zero_ad,
               palDeviceBinding.f_zero_status,
               palDeviceBinding.f_calibration_ad,
               palDeviceBinding.f_calibration_status,
               palDeviceBinding.f_concentration,
               palDeviceBinding.f_run_time_status,
               palDeviceBinding.f_real_time_ad,
               palDeviceBinding.f_real_time_ad_status,
               palDeviceBinding.f_calibration_concentration,
               palDeviceBinding.f_calibration_concentration_status
        from t_pallet_device_upload_history palDeviceBinding
                 left join t_tray_info trayInfo  on trayInfo.f_tray_id = palDeviceBinding.f_tray_id
    </sql>

    <select id="selectPalletDeviceUploadHistoryList" parameterType="PalletDeviceUploadHistory" resultMap="PalletDeviceUploadHistoryResult">
        <include refid="selectPalletDeviceUploadHistoryVo"/>
        <where>
            <if test="deviceCode != null  and deviceCode != ''"> and palDeviceBinding.f_device_code = #{deviceCode}</if>
        </where>
    </select>
    
    <select id="selectPalletDeviceUploadHistoryById" parameterType="Long" resultMap="PalletDeviceUploadHistoryResult">
        <include refid="selectPalletDeviceUploadHistoryVo"/>
        where palDeviceBinding.f_id = #{id}
    </select>

    <insert id="batchInsert" parameterType="list">
        insert into t_pallet_device_upload_history
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="list != null and list.size() > 0">
                <if test="list[0].trayId != null">f_tray_id,</if>
                <if test="list[0].deviceCode != null">f_device_code,</if>
                <if test="list[0].row != null">f_row,</if>
                <if test="list[0].col != null">f_col,</if>
                <if test="list[0].index != null">f_index,</if>
                <if test="list[0].number != null">f_number,</if>
                <if test="list[0].bindingTime != null">f_binding_time,</if>
                <if test="list[0].unbindingTime != null">f_unbinding_time,</if>
                <if test="list[0].createTime != null">f_create_time,</if>
                <if test="list[0].status != null">f_status,</if>
                <if test="list[0].recordYear != null">f_record_year,</if>
                <if test="list[0].recordMonth != null">f_record_month,</if>
                <if test="list[0].recordDate != null">f_record_date,</if>
                <if test="list[0].recordHour != null">f_record_hour,</if>
                <if test="list[0].recordMinute != null">f_record_minute,</if>
                <if test="list[0].writeTimeStatus != null">f_write_time_status,</if>
                <if test="list[0].adjustmentZeroAd != null">f_adjustment_zero_ad,</if>
                <if test="list[0].zeroStatus != null">f_zero_status,</if>
                <if test="list[0].calibrationAd != null">f_calibration_ad,</if>
                <if test="list[0].calibrationStatus != null">f_calibration_status,</if>
                <if test="list[0].concentration != null">f_concentration,</if>
                <if test="list[0].runTimeStatus != null">f_run_time_status,</if>
                <if test="list[0].realTimeAd != null">f_real_time_ad,</if>
                <if test="list[0].realTimeAdStatus != null">f_real_time_ad_status,</if>
                <if test="list[0].calibrationConcentration != null">f_calibration_concentration,</if>
                <if test="list[0].calibrationConcentrationStatus != null">f_calibration_concentration_status,</if>
            </if>
        </trim>
        values
        <foreach collection="list" item="item" separator=",">
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="item.trayId != null">#{item.trayId},</if>
                <if test="item.deviceCode != null">#{item.deviceCode},</if>
                <if test="item.row != null">#{item.row},</if>
                <if test="item.col != null">#{item.col},</if>
                <if test="item.index != null">#{item.index},</if>
                <if test="item.number != null">#{item.number},</if>
                <if test="item.bindingTime != null">#{item.bindingTime},</if>
                <if test="item.unbindingTime != null">#{item.unbindingTime},</if>
                <if test="item.createTime != null">#{item.createTime},</if>
                <if test="item.status != null">#{item.status},</if>
                <if test="item.recordYear != null">#{item.recordYear},</if>
                <if test="item.recordMonth != null">#{item.recordMonth},</if>
                <if test="item.recordDate != null">#{item.recordDate},</if>
                <if test="item.recordHour != null">#{item.recordHour},</if>
                <if test="item.recordMinute != null">#{item.recordMinute},</if>
                <if test="item.writeTimeStatus != null">#{item.writeTimeStatus},</if>
                <if test="item.adjustmentZeroAd != null">#{item.adjustmentZeroAd},</if>
                <if test="item.zeroStatus != null">#{item.zeroStatus},</if>
                <if test="item.calibrationAd != null">#{item.calibrationAd},</if>
                <if test="item.calibrationStatus != null">#{item.calibrationStatus},</if>
                <if test="item.concentration != null">#{item.concentration},</if>
                <if test="item.runTimeStatus != null">#{item.runTimeStatus},</if>
                <if test="item.realTimeAd != null">#{item.realTimeAd},</if>
                <if test="item.realTimeAdStatus != null">#{item.realTimeAdStatus},</if>
                <if test="item.calibrationConcentration != null">#{item.calibrationConcentration},</if>
                <if test="item.calibrationConcentrationStatus != null">#{item.calibrationConcentrationStatus},</if>
            </trim>
        </foreach>
    </insert>
    <insert id="insertPalletDeviceUploadHistory" parameterType="PalletDeviceUploadHistory" useGeneratedKeys="true" keyProperty="id">
        insert into t_pallet_device_upload_history
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="trayId != null">f_tray_id,</if>
            <if test="deviceCode != null">f_device_code,</if>
            <if test="row != null">f_row,</if>
            <if test="col != null">f_col,</if>
            <if test="index != null">f_index,</if>
            <if test="number != null">f_number,</if>
            <if test="bindingTime != null">f_binding_time,</if>
            <if test="unbindingTime != null">f_unbinding_time,</if>
            <if test="createTime != null">f_create_time,</if>
            <if test="status != null">f_status,</if>
            <if test="recordYear != null">f_record_year,</if>
            <if test="recordMonth != null">f_record_month,</if>
            <if test="recordDate != null">f_record_date,</if>
            <if test="recordHour != null">f_record_hour,</if>
            <if test="recordMinute != null">f_record_minute,</if>
            <if test="writeTimeStatus != null">f_write_time_status,</if>
            <if test="adjustmentZeroAd != null">f_adjustment_zero_ad,</if>
            <if test="zeroStatus != null">f_zero_status,</if>
            <if test="calibrationAd != null">f_calibration_ad,</if>
            <if test="calibrationStatus != null">f_calibration_status,</if>
            <if test="concentration != null">f_concentration,</if>
            <if test="runTimeStatus != null">f_run_time_status,</if>
            <if test="realTimeAd != null">f_real_time_ad,</if>
            <if test="realTimeAdStatus != null">f_real_time_ad_status,</if>
            <if test="calibrationConcentration != null">#{calibrationConcentration},</if>
            <if test="calibrationConcentrationStatus != null">#{calibrationConcentrationStatus},</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="trayId != null">#{trayId},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="row != null">#{row},</if>
            <if test="col != null">#{col},</if>
            <if test="index != null">#{index},</if>
            <if test="number != null">#{number},</if>
            <if test="bindingTime != null">#{bindingTime},</if>
            <if test="unbindingTime != null">#{unbindingTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="recordYear != null">#{recordYear},</if>
            <if test="recordMonth != null">#{recordMonth},</if>
            <if test="recordDate != null">#{recordDate},</if>
            <if test="recordHour != null">#{recordHour},</if>
            <if test="recordMinute != null">#{recordMinute},</if>
            <if test="writeTimeStatus != null">#{writeTimeStatus},</if>
            <if test="adjustmentZeroAd != null">#{adjustmentZeroAd},</if>
            <if test="zeroStatus != null">#{zeroStatus},</if>
            <if test="calibrationAd != null">#{calibrationAd},</if>
            <if test="calibrationStatus != null">#{calibrationStatus},</if>
            <if test="concentration != null">#{concentration},</if>
            <if test="runTimeStatus != null">#{runTimeStatus},</if>
            <if test="realTimeAd != null">#{realTimeAd},</if>
            <if test="realTimeAdStatus != null">#{realTimeAdStatus},</if>
            <if test="calibrationConcentration != null">#{calibrationConcentration},</if>
            <if test="calibrationConcentrationStatus != null">#{calibrationConcentrationStatus},</if>
         </trim>
    </insert>

    <update id="updatePalletDeviceUploadHistory" parameterType="PalletDeviceUploadHistory">
        update t_pallet_device_upload_history
        <trim prefix="SET" suffixOverrides=",">
            <if test="trayId != null">f_tray_id = #{trayId},</if>
            <if test="deviceCode != null">f_device_code = #{deviceCode},</if>
            <if test="row != null">f_row = #{row},</if>
            <if test="col != null">f_col = #{col},</if>
            <if test="index != null">f_index = #{index},</if>
            <if test="number != null">f_number = #{number},</if>
            <if test="bindingTime != null">f_binding_time = #{bindingTime},</if>
            <if test="unbindingTime != null">f_unbinding_time = #{unbindingTime},</if>
            <if test="createTime != null">f_create_time = #{createTime},</if>
            <if test="status != null">f_status = #{status},</if>
            <if test="recordYear != null">f_record_year = #{recordYear},</if>
            <if test="recordMonth != null">f_record_month = #{recordMonth},</if>
            <if test="recordDate != null">f_record_date = #{recordDate},</if>
            <if test="recordHour != null">f_record_hour = #{recordHour},</if>
            <if test="recordMinute != null">f_record_minute = #{recordMinute},</if>
            <if test="writeTimeStatus != null">f_write_time_status = #{writeTimeStatus},</if>
            <if test="adjustmentZeroAd != null">f_adjustment_zero_ad = #{adjustmentZeroAd},</if>
            <if test="zeroStatus != null">f_zero_status = #{zeroStatus},</if>
            <if test="calibrationAd != null">f_calibration_ad = #{calibrationAd},</if>
            <if test="calibrationStatus != null">f_calibration_status = #{calibrationStatus},</if>
            <if test="concentration != null">f_concentration = #{concentration},</if>
            <if test="runTimeStatus != null">f_run_time_status = #{runTimeStatus},</if>
            <if test="realTimeAd != null">f_real_time_ad = #{realTimeAd},</if>
            <if test="realTimeAdStatus != null">f_real_time_ad_status = #{realTimeAdStatus},</if>
            <if test="calibrationConcentration != null">f_calibration_concentration = #{calibrationConcentration},</if>
            <if test="calibrationConcentrationStatus != null">f_calibration_concentration_status = #{calibrationConcentrationStatus},</if>
        </trim>
        where f_id = #{id}
    </update>

    <delete id="deletePalletDeviceUploadHistoryById" parameterType="Long">
        delete from t_pallet_device_upload_history where f_id = #{id}
    </delete>

    <delete id="deletePalletDeviceUploadHistoryByIds" parameterType="String">
        delete from t_pallet_device_upload_history where f_id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>