<?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.yfd.platform.modules.basedata.mapper.SubstationPatroldeviceMapper">

    <select id="getCameraStat" resultType="java.util.Map">
        SELECT * FROM ( SELECT
        sp.patroldevice_id,
        sp.patroldevice_code,
        sp.patroldevice_name,
        sp.ipaddr,
        nvr.patroldevice_name nvrname,
        nvr.deviceId,
        nvr.channelId,
        sp.station_id,
        CASE
        WHEN DATEDIFF( NOW(), sp.production_date ) &lt; 90 THEN
        '0' ELSE '1'
        END AS flag,
        sp.`online`
        FROM
        iis_substation_patroldevice sp
        LEFT JOIN (
        SELECT
        dc.deviceId,
        dc.channelId,
        dc.ipAddress,
        dc.`name`,
        sp1.patroldevice_name
        FROM
        mon_device_channel dc,
        iis_substation_patroldevice sp1
        WHERE
        sp1.patroldevice_code = dc.deviceId
        AND deviceId IN ( SELECT patroldevice_code FROM iis_substation_patroldevice WHERE type = '11' )) nvr ON sp.ipaddr = nvr.ipAddress
        WHERE sp.type='10'
        ) t
        WHERE 1=1
        <if test="stationId != null and stationId != ''">
            AND t.station_id = #{stationId}
        </if>
        <if test="patrolDeviceName != null and patrolDeviceName != ''">
            AND t.patroldevice_name like concat('%',#{patrolDeviceName},'%')
        </if>

        <if test="flag != null and flag != ''">
            AND t.flag = #{flag}
        </if>
        ORDER BY
        t.patroldevice_code
    </select>
    <select id="getCameraStatReport" resultType="java.util.Map">
        SELECT
        t.patroldevice_id,
        t.deviceId,
        t.channelId,
        t.id,
        t.online,
        t.nvrname,
        t.patroldevice_name,
        t.patroldevice_code
        FROM (
        SELECT
        t1.patroldevice_id,
        t1.patroldevice_name,
        t1.online,
        t1.deviceId,
        t1.channelId,
        t1.nvrname,
        t1.id,
        t1.patroldevice_code
        FROM
        ( SELECT
        sp.patroldevice_id,
        sp.patroldevice_code,
        sp.online,
        patroldevice_name,
        dc.deviceId,
        dc.channelId,
        (SELECT DISTINCT sp1.patroldevice_name FROM iis_substation_patroldevice sp1 JOIN mon_device_channel dc1 ON dc1.deviceId = sp1.patroldevice_code WHERE dc1.address &lt;&gt; 'Address') nvrname,
        dc.id
        FROM
        mon_device_channel dc
        INNER JOIN iis_substation_patroldevice sp ON dc.deviceId = sp.patroldevice_code
        WHERE sp.type='10' AND (sp.robots_code IS NULL OR sp.robots_code ='')
        <if test="stationCode != null and stationCode != ''">
            AND station_code =#{stationCode}
        </if>
        ORDER BY
        sp.patroldevice_code,
        dc.channelId) t1
        ) t
    </select>
    <select id="getDockInfoBySn" resultType="java.util.Map">
        select * from dock_info where dock_sn = #{dockSn}
    </select>
</mapper>
