<?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.fastbee.iot.mapper.DeviceReportInfoMapper">

    <resultMap type="DeviceReportInfo" id="DeviceReportInfoResult">
        <result property="id"    column="id"    />
        <result property="imei"    column="imei"    />
        <result property="iccid"    column="iccid"    />
        <result property="mcuId"    column="mcu_id"    />
        <result property="bspType"    column="bsp_type"    />
        <result property="lteType"    column="lte_type"    />
        <result property="mcuType"    column="mcu_type"    />
        <result property="mcuFw"    column="mcu_fw"    />
        <result property="lteFw"    column="lte_fw"    />
        <result property="lcdManufacturer"    column="lcd_manufacturer"    />
        <result property="voiceManufacturer"    column="voice_manufacturer"    />
        <result property="framModel"    column="fram_model"    />
        <result property="replaceManufacturer"    column="replace_manufacturer"    />
        <result property="testRecord"    column="test_record"    />
        <result property="batchNumber"    column="batch_number"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="qrCode"    column="qr_code"    />
        <result property="name"    column="name"    />
        <result property="lcdManufacturerName"    column="lcd_manufacturer_name"    />
        <result property="voiceManufacturerName"    column="voice_manufacturer_name"    />
        <result property="replaceManufacturerName"    column="replace_manufacturer_name"    />
        <result property="deviceId"    column="device_id"    />
        <result property="status"    column="status"    />
        <result property="powersTime"    column="powers_time"    />
        <result property="type"    column="type"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="onLine"    column="on_line"    />
        <result property="areaCode"    column="area_code"    />
        <result property="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectDeviceReportInfoVo">
        select id, imei, iccid, mcu_id, bsp_type, lte_type, mcu_type, mcu_fw, lte_fw, lcd_manufacturer, voice_manufacturer, fram_model, replace_manufacturer, test_record, batch_number, serial_number, qr_code, name, lcd_manufacturer_name, voice_manufacturer_name, replace_manufacturer_name, device_id, status, powers_time, type, longitude, latitude,on_line,area_code,dept_id from iot_device_report_info
    </sql>

    <select id="selectDeviceReportInfoList" parameterType="DeviceReportInfo" resultMap="DeviceReportInfoResult">
        <include refid="selectDeviceReportInfoVo"/>
        <where>
            <if test="imei != null  and imei != ''"> and imei like concat('%', #{imei}, '%')</if>
            <if test="iccid != null  and iccid != ''"> and iccid = #{iccid}</if>
            <if test="mcuId != null  and mcuId != ''"> and mcu_id = #{mcuId}</if>
            <if test="bspType != null  and bspType != ''"> and bsp_type = #{bspType}</if>
            <if test="lteType != null  and lteType != ''"> and lte_type = #{lteType}</if>
            <if test="mcuType != null  and mcuType != ''"> and mcu_type = #{mcuType}</if>
            <if test="mcuFw != null  and mcuFw != ''"> and mcu_fw = #{mcuFw}</if>
            <if test="lteFw != null  and lteFw != ''"> and lte_fw = #{lteFw}</if>
            <if test="lcdManufacturer != null "> and lcd_manufacturer = #{lcdManufacturer}</if>
            <if test="voiceManufacturer != null "> and voice_manufacturer = #{voiceManufacturer}</if>
            <if test="framModel != null  and framModel != ''"> and fram_model = #{framModel}</if>
            <if test="replaceManufacturer != null "> and replace_manufacturer = #{replaceManufacturer}</if>
            <if test="testRecord != null  and testRecord != ''"> and test_record = #{testRecord}</if>
            <if test="batchNumber != null  and batchNumber != ''"> and batch_number = #{batchNumber}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number like concat('%', #{serialNumber}, '%') </if>
            <if test="qrCode != null  and qrCode != ''"> and qr_code = #{qrCode}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="lcdManufacturerName != null  and lcdManufacturerName != ''"> and lcd_manufacturer_name like concat('%', #{lcdManufacturerName}, '%')</if>
            <if test="voiceManufacturerName != null  and voiceManufacturerName != ''"> and voice_manufacturer_name like concat('%', #{voiceManufacturerName}, '%')</if>
            <if test="replaceManufacturerName != null  and replaceManufacturerName != ''"> and replace_manufacturer_name like concat('%', #{replaceManufacturerName}, '%')</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="powersTime != null "> and powers_time = #{powersTime}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="onLine != null "> and on_line = #{onLine}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
        <!-- 添加排序 -->
        order by powers_time desc
    </select>

    <select id="selectDeviceReportInfoById" parameterType="Long" resultMap="DeviceReportInfoResult">
        <include refid="selectDeviceReportInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertDeviceReportInfo" parameterType="DeviceReportInfo" useGeneratedKeys="true" keyProperty="id">
        insert into iot_device_report_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="imei != null and imei != ''">imei,</if>
            <if test="iccid != null and iccid != ''">iccid,</if>
            <if test="mcuId != null and mcuId != ''">mcu_id,</if>
            <if test="bspType != null and bspType != ''">bsp_type,</if>
            <if test="lteType != null and lteType != ''">lte_type,</if>
            <if test="mcuType != null and mcuType != ''">mcu_type,</if>
            <if test="mcuFw != null and mcuFw != ''">mcu_fw,</if>
            <if test="lteFw != null and lteFw != ''">lte_fw,</if>
            <if test="lcdManufacturer != null">lcd_manufacturer,</if>
            <if test="voiceManufacturer != null">voice_manufacturer,</if>
            <if test="framModel != null and framModel != ''">fram_model,</if>
            <if test="replaceManufacturer != null">replace_manufacturer,</if>
            <if test="testRecord != null">test_record,</if>
            <if test="batchNumber != null">batch_number,</if>
            <if test="serialNumber != null">serial_number,</if>
            <if test="qrCode != null">qr_code,</if>
            <if test="name != null">name,</if>
            <if test="lcdManufacturerName != null">lcd_manufacturer_name,</if>
            <if test="voiceManufacturerName != null">voice_manufacturer_name,</if>
            <if test="replaceManufacturerName != null">replace_manufacturer_name,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="status != null">status,</if>
            <if test="powersTime != null">powers_time,</if>
            <if test="type != null">type,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="onLine != null">on_line,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="imei != null and imei != ''">#{imei},</if>
            <if test="iccid != null and iccid != ''">#{iccid},</if>
            <if test="mcuId != null and mcuId != ''">#{mcuId},</if>
            <if test="bspType != null and bspType != ''">#{bspType},</if>
            <if test="lteType != null and lteType != ''">#{lteType},</if>
            <if test="mcuType != null and mcuType != ''">#{mcuType},</if>
            <if test="mcuFw != null and mcuFw != ''">#{mcuFw},</if>
            <if test="lteFw != null and lteFw != ''">#{lteFw},</if>
            <if test="lcdManufacturer != null">#{lcdManufacturer},</if>
            <if test="voiceManufacturer != null">#{voiceManufacturer},</if>
            <if test="framModel != null and framModel != ''">#{framModel},</if>
            <if test="replaceManufacturer != null">#{replaceManufacturer},</if>
            <if test="testRecord != null">#{testRecord},</if>
            <if test="batchNumber != null">#{batchNumber},</if>
            <if test="serialNumber != null">#{serialNumber},</if>
            <if test="qrCode != null">#{qrCode},</if>
            <if test="name != null">#{name},</if>
            <if test="lcdManufacturerName != null">#{lcdManufacturerName},</if>
            <if test="voiceManufacturerName != null">#{voiceManufacturerName},</if>
            <if test="replaceManufacturerName != null">#{replaceManufacturerName},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="status != null">#{status},</if>
            <if test="powersTime != null">#{powersTime},</if>
            <if test="type != null">#{type},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="onLine != null">#{onLine},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateDeviceReportInfo" parameterType="DeviceReportInfo">
        update iot_device_report_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="imei != null and imei != ''">imei = #{imei},</if>
            <if test="iccid != null and iccid != ''">iccid = #{iccid},</if>
            <if test="mcuId != null and mcuId != ''">mcu_id = #{mcuId},</if>
            <if test="bspType != null and bspType != ''">bsp_type = #{bspType},</if>
            <if test="lteType != null and lteType != ''">lte_type = #{lteType},</if>
            <if test="mcuType != null and mcuType != ''">mcu_type = #{mcuType},</if>
            <if test="mcuFw != null and mcuFw != ''">mcu_fw = #{mcuFw},</if>
            <if test="lteFw != null and lteFw != ''">lte_fw = #{lteFw},</if>
            <if test="lcdManufacturer != null">lcd_manufacturer = #{lcdManufacturer},</if>
            <if test="voiceManufacturer != null">voice_manufacturer = #{voiceManufacturer},</if>
            <if test="framModel != null and framModel != ''">fram_model = #{framModel},</if>
            <if test="replaceManufacturer != null">replace_manufacturer = #{replaceManufacturer},</if>
            <if test="testRecord != null">test_record = #{testRecord},</if>
            <if test="batchNumber != null">batch_number = #{batchNumber},</if>
            <if test="serialNumber != null">serial_number = #{serialNumber},</if>
            <if test="qrCode != null">qr_code = #{qrCode},</if>
            <if test="name != null">name = #{name},</if>
            <if test="lcdManufacturerName != null">lcd_manufacturer_name = #{lcdManufacturerName},</if>
            <if test="voiceManufacturerName != null">voice_manufacturer_name = #{voiceManufacturerName},</if>
            <if test="replaceManufacturerName != null">replace_manufacturer_name = #{replaceManufacturerName},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="powersTime != null">powers_time = #{powersTime},</if>
            <if test="type != null">type = #{type},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="onLine != null">on_line = #{onLine},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeviceReportInfoById" parameterType="Long">
        delete from iot_device_report_info where id = #{id}
    </delete>

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