<?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.njcn.device.pq.mapper.DeviceOnlineDataMapper">

    <select id="getMinDeviceLevel" resultType="DeviceOnlineDataDTO">
        SELECT
		a.`Id` deviceId,
		e.`Line_Grade` lineGrade,
		f.`Name` levelName,
		MIN(f.Algo_Describe)
		FROM
		pq_line a,
		pq_line b,
		pq_line c,
		pq_line_detail e,
		sys_dict_data f
		WHERE
		a.Id IN
		<foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
			#{item}
		</foreach>
		AND b.Pid = a.Id
		AND c.Pid = b.Id
		AND c.Id = e.Id
		AND e.Line_Grade = f.Id
		GROUP BY
		c.Id,
		e.Line_Grade
    </select>


	<select id="getMinDeviceLevelById" resultType="DeviceOnlineDataDTO">
		SELECT
		a.`Id` deviceId,e.`Line_Grade` lineGrade,f.`Name` levelName,MIN(f.Algo_Describe)
		FROM
		pq_line a,
		pq_line b,
		pq_line c,
		pq_line_detail e,
		sys_dict_data f
		WHERE a.Id = #{deviceIds}
		AND b.Pid = a.Id
		AND c.Pid = b.Id
		AND c.Id = e.Id
		AND e.Line_Grade = f.Id
		GROUP BY e.Line_Grade
	</select>


    <select id="getDeviceFatherData" resultType="DeviceOnlineTabVO">
		SELECT
		a.`Id` deviceId,
		a.`Name` deviceName,
		b.`Name` subName,
		c.`Name` gdName,
		e.`Name` provinceName
		FROM
		pq_line a,
		pq_line b,
		pq_line c,
		pq_line d,
		sys_area e
		WHERE a.Id IN
		<foreach collection="deviceIds" item="item" open="(" close=")" separator=",">
			#{item}
		</foreach>
		AND a.Pid = b.Id
		AND b.Pid = c.Id
		AND c.Pid = d.Id
		AND d.Name = e.Id
	</select>


</mapper>