<?xml version="1.0" encoding="UTF-8"?>
	<!DOCTYPE mapper
	  PUBLIC "-//mybatis.org//DTD Mapper 3.1//EN"
	  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.mapper.data.LineMapsMapper">

	<select id="queryLineMaps" parameterType="String" resultType="LineMaps" >
		select * from line_maps where line_index in
		<foreach collection="lstGDsql" item="item" open="(" separator="," close=")">
		   #{item}
		</foreach>
	</select>


	<select id="queryLineMapByAssID" parameterType="String" resultType="LineMaps" >
		select a.*
		from line_maps a,pqs_eventdetail b
		where  a.line_index=b.lineid and b.eventass_index=#{eventass_index}
	</select>

	<select id="queryLineMapsForAll" parameterType="String" resultType="LineMaps" >
		SELECT
		i."LINE_INDEX",
		i."LINE_NAME",
		i."PT1",
		i."PT2",
		i."CT1",
		i."CT2",
		i."GD_INDEX",
		i."GD_NAME",
		i."SUB_NAME",
		i."SUBV_NAME",
		i."DEVFLAG",
		i."STATUS",
		i."IP",
		i."MANUFACTURER",
		i."LONGITUDE",
		i."LATITUDE",
		NVL( h.totalcount, 0 ) totalcount
		FROM
		(
		(
		SELECT DISTINCT
		MainTable.lineid,
		NVL( SubTable.count, 0 ) totalcount
		FROM
		pqs_eventdetail MainTable
		LEFT JOIN (
		SELECT
		count( * ) count,
		lineid
		FROM
		pqs_eventdetail
		where eventass_index is null

		and timeid >= TRUNC( SYSDATE, 'YYYY' )
		GROUP BY
		lineid
		ORDER BY
		lineid
		) SubTable ON MainTable.lineid = SubTable.lineid
		) h
		RIGHT JOIN (
		SELECT
		a.line_index line_index,
		a.name line_name,
		a.pt1 pt1,
		a.pt2 pt2,
		a.ct1 ct1,
		a.ct2 ct2,
		b.gd_index gd_index,
		b.name gd_name,
		c.name sub_name,
		d.name subv_name,
		e.devflag devflag,
		e.status status,
		e.ip ip,
		h.dic_name manufacturer,
		f.longitude longitude,
		f.latitude latitude
		FROM
		pq_line a,
		pq_gdinformation b,
		pq_substation c,
		pq_subvoltage d,
		pq_device e,
		pqs_map f,
		pq_devicedetail g,
		pqs_dicdata h
		WHERE
		a.gd_index = b.gd_index
		AND a.sub_index = c.sub_index
		AND a.subv_index = d.subv_index
		AND a.dev_index = e.dev_index
		AND a.sub_index = f.sub_index
		AND e.dev_index = g.dev_index
		AND f.state = 1
		AND g.manufacturer = h.dic_index
		AND h.dic_type = 'cbb2de8a-87da-4ae9-a35c-aaab999c7bc7' --只读取实际设备

		AND e.devmodel = 1 --只读取属于暂降系统数据

		AND e.datatype IN ( 0, 2 )
		ORDER BY
		a.line_index
		) i ON h.lineid = i.line_index
		)  where LINE_INDEX in
		<foreach collection="lstGDsql" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>
</mapper>
