<?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="iot.lidee.iot.mapper.bygz.DevGzbxWxgdMapper">

    <select id="selectWxgdByType"  resultType="iot.lidee.iot.model.bygz.DevGzbxWxgdDO">
        SELECT
            w.id,
            w.gzbx_id,
            w.is_deleted,
            w.update_time,
            w.update_user,
            w.create_dept,
            w.create_time,
            w.create_user,
            w.create_user,
            w.fault_type,
            s.dev_name AS name,
            w.dev_no,
            w.dev_name,
            w.priority,
            w.type,
            w.number,
            w.fault_remark,
            w.dev_type,
            w.maintenance_person,
            w.is_top,
            w.is_filing,
            w.reporter,
            w.phone_number,
            w.processing_status,
            w.level,
            w.completion_time,
            w.acceptance_time,
            w.create_user_name,
            w.solution,
            w.repair_date,
            w.repair_time,
            w.accessories,
            w.leader_user_id,
            w.assign_dept_id,
            w.assign_dept_leader,
            w.leader_user_yj,
            w.leader_ys_zt,
            w.assign_ys_zt,
            w.leader_ys_yj,
            w.assign_ys_yj
        FROM
            dev_gzbx_wxgd w
        LEFT JOIN
            sys_device s ON s.id = w.dev_name
        WHERE
            w.is_deleted = 0
            <if test="devtype != null">
                AND w.dev_type = #{devtype}
            </if>
    </select>

    <select id="deviceList"  resultType="iot.lidee.iot.domain.Device">
        SELECT
            w.*
        FROM
            iot_device w
        LEFT JOIN
            iot_device_group g ON g.device_id = w.device_id
        WHERE
            w.del_flag = 0
            <if test="devtype != null">
                AND g.group_id = #{devtype}
            </if>
    </select>


    <select id="deviceLogList"  resultType="iot.lidee.iot.domain.DeviceLog">

        SELECT
               *
        FROM (
                 SELECT *,
                        ROW_NUMBER() OVER (PARTITION BY identity ORDER BY create_time DESC) AS rn
                 FROM
                      iot_device_log
                 WHERE
                       serial_number = #{serialNumber}
             ) t
        WHERE rn = 1
    </select>

</mapper>
