<?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.mapper.configuration.DeviceMapper'>
	<select id="getIPByEventIndex" resultType="String">
		SELECT
			T3.IP
		FROM
			PQS_EVENTDETAIL t1,
			PQ_LINE t2,
			PQ_DEVICE t3
		WHERE
			T1.LINEID = T2.LINE_INDEX
		AND T2.DEV_INDEX = T3.DEV_INDEX
		AND T1.EVENTDETAIL_INDEX = #{index}
	</select>
	<select id="getDeviceIndex" resultType="int">
		select distinct
		t.dev_index
		from
		pq_line t
		where
		t.LINE_INDEX in
		<foreach collection="list" open="(" close=")" separator="," item="item">
			#{item}
		</foreach>
	</select>
	<select id="getStates" resultType="int">
	SELECT
		count(DISTINCT com.UPDATETIME)
	FROM
		PQS_COMINFORMATION com
	WHERE
		com.LINE_INDEX IN ( SELECT LINE_INDEX FROM PQ_LINE line WHERE line.DEV_INDEX = #{devIndex} )
	AND com.TYPE = 0
	AND to_char( com.UPDATETIME, 'YYYY-MM-DD' ) = #{timeId}
	</select>

	<select id="getState" resultType="int">
		SELECT
		count( DISTINCT com.LINE_INDEX )
	FROM
		PQS_COMINFORMATION com
	WHERE
		com.LINE_INDEX IN ( SELECT LINE_INDEX FROM PQ_LINE line WHERE line.DEV_INDEX in
		<foreach collection="list" open="(" close=")" separator="," item="item">
			#{item}
		</foreach>
		 )
	AND com.TYPE = 0
	AND to_char( com.UPDATETIME, 'YYYY-MM-DD' ) =#{timeId}
	</select>
</mapper>