<?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.yeejoin.amos.boot.module.hygf.api.tdenginemapper.TdHygfJpInverterWarnMapper">

	<select id="getCountTdHygfJpInverterWarn" resultType="map">
		SELECT `state`,count(`state`) num
    FROM house_pv_data.td_hygf_jp_inverter_warn
		<where>
			<if test="dto!=null">
				third_station_id in
				<foreach collection="dto" item="item" index="index" open="(" separator="," close=")">
                   #{item.thirdStationId}
               </foreach>
			</if>
			and `state` in ('未处理','已处理','已恢复')
		</where>

		GROUP BY  `state`
	</select>

	<select id="list" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.TdHygfJpInverterWarnDto">
		SELECT * FROM house_pv_data.td_hygf_jp_inverter_warn
		<where>
			<if test="param.states!=null">
			 AND `state` IN
			    <foreach collection="param.states" item="item" index="index" open="(" separator="," close=")">
                   #{item}
               </foreach>
		    </if>
		    <if test="param.stationIds!=null">
			 AND third_station_id IN
				<foreach collection="param.stationIds" item="item" index="index" open="(" separator="," close=")">
                   #{item}
               </foreach>
		    </if>
<!--			<if test="param.listHandlerStatus!=null">-->
<!--				AND handler_status IN-->
<!--				<foreach collection="param.listHandlerStatus" item="item" index="index" open="(" separator="," close=")">-->
<!--					#{item}-->
<!--				</foreach>-->
<!--			</if>-->
		</where>

        order by  start_time DESC
	</select>
	
	<select id="getByTime" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.TdHygfJpInverterWarnDto">
		SELECT * FROM house_pv_data.td_hygf_jp_inverter_warn
		<where>
			<if test="createdTime!=null">
			 AND created_time = #{createdTime}
		    </if>
		</where>
	</select>

	<select id="selectWarnList" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.TdHygfJpInverterWarnDto">
		SELECT
		 `level` ,
		 `state` ,
		third_station_id,
		sn_code,
		content,
		start_time,
		created_time,
		start_time as startTimeDate,
		 `time`,
		recover_time,
		treatment,
		time_long,
		recover_time as recoverTimeString,
		handler_status as handlerStatus
		FROM house_pv_data.td_hygf_jp_inverter_warn
		<where>
			<if test="state != null  and state.size>0">
				AND `state` in
				<foreach collection="state" item="item" open='(' close=')' separator=",">
					#{item}
				</foreach>
			</if>
<!--			<if test="handlerStatus != null and handlerStatus != ''">-->
<!--				AND handler_status = #{handlerStatus}-->
<!--			</if>-->
			<if test="regionalCompaniesCode != null and regionalCompaniesCode != ''">
				AND regional_companies_code  =  #{regionalCompaniesCode}
			</if>
			<if test="amosCompanyCode != null and amosCompanyCode != ''">
				AND amos_company_code  =  #{amosCompanyCode}
			</if>
			<if test="thirdStationId != null and thirdStationId != ''">
				AND third_station_id  =  #{thirdStationId}
			</if>
			<!--			<if test="type != null and type != ''">-->
			<!--				AND type  =  #{type}-->
			<!--			</if>-->
			<if test="level != null and level != ''">
				AND `level` = #{level}
			</if>
			<if test="level != null and level != ''">
				AND `level` = #{level}
			</if>
			<if test="level != null and level != ''">
				AND `level` = #{level}
			</if>
			<if test="level != null and level != ''">
				AND `level` = #{level}
			</if>
			<if test="minvalue != null and minvalue != ''">
				AND time_long >= (#{minvalue}*1000)
			</if>
			<if test="maxValue != null and maxValue != ''">
			    AND time_long <![CDATA[<=]]> (#{maxValue}*1000)
			</if>
			<if test="snCode != null and snCode != ''">
				AND sn_code like #{snCode}
			</if>
			<if test="stationId != null and   stationId.size >0 ">
				AND third_station_id in
			<foreach collection="stationId" item="item" open='(' close=')' separator=",">
				#{item}
			</foreach>
			</if>
			<if test="startTime != null and startTime != ''">
				AND start_time  >=  #{startTime}
			</if>
			<if test="endTime != null and endTime != ''">
				AND start_time  <![CDATA[<=]]> #{endTime}
			</if>
			<if test="content != null and content != ''">
				AND content like #{content}
			</if>
            <if test="stationName != null and stationName != ''">
                AND station_name like #{stationName}
            </if>
		</where>
		ORDER BY start_time desc
		limit #{current},#{size}
	</select>


	<select id="selectWarnListTotal" resultType="int">
		SELECT
	count (1)
		FROM house_pv_data.td_hygf_jp_inverter_warn
		<where>
			<if test="state != null  and state.size>0">
				AND `state` in
				<foreach collection="state" item="item" open='(' close=')' separator=",">
					#{item}
				</foreach>
			</if>
			<if test="regionalCompaniesCode != null and regionalCompaniesCode != ''">
				AND regional_companies_code  =  #{regionalCompaniesCode}
			</if>
			<if test="amosCompanyCode != null and amosCompanyCode != ''">
				AND amos_company_code  =  #{amosCompanyCode}
			</if>
			<if test="thirdStationId != null and thirdStationId != ''">
				AND third_station_id  =  #{thirdStationId}
			</if>
			<!--			<if test="type != null and type != ''">-->
			<!--				AND type  =  #{type}-->
			<!--			</if>-->
<!--			<if test="handlerStatus != null and handlerStatus != ''">-->
<!--				AND handler_status = #{handlerStatus}-->
<!--			</if>-->
			<if test="level != null and level != ''">
				AND level = #{level}
			</if>
			<if test="minvalue != null and minvalue != ''">
				AND time_long >= (#{minvalue}*1000)
			</if>
			<if test="maxValue != null and maxValue != ''">
				AND time_long <![CDATA[<=]]> (#{maxValue}*1000)
			</if>
			<if test="snCode != null and snCode != ''">
				AND sn_code like #{snCode}
			</if>
			<if test="stationId != null and stationId.size >0 ">
				AND third_station_id in
				<foreach collection="stationId" item="item" open='(' close=')' separator=",">
					#{item}
				</foreach>
			</if>
			<if test="startTime != null and startTime != ''">
				AND start_time  >=  #{startTime}
			</if>
			<if test="endTime != null and endTime != ''">
				AND start_time  <![CDATA[<=]]> #{endTime}
			</if>
			<if test="content != null and content != ''">
				AND content like #{content}
			</if>
            <if test="stationName != null and stationName != ''">
                AND station_name like #{stationName}
            </if>


		</where>
	</select>




	<select id="selectWarnTotal" resultType="int">
		SELECT
		count (1)
		FROM house_pv_data.td_hygf_jp_inverter_warn
		<where>
			<if test="state != null  and state.size>0">
				 `state` in
				<foreach collection="state" item="item" open='(' close=')' separator=",">
					#{item}
				</foreach>
			</if>
			<if test="regionalCompaniesCode != null and regionalCompaniesCode != ''">
				AND regional_companies_code  =  #{regionalCompaniesCode}
			</if>
			<if test="amosCompanyCode != null and amosCompanyCode != ''">
				AND amos_company_code  =  #{amosCompanyCode}
			</if>
			<if test="thirdStationId != null and thirdStationId != ''">
				AND third_station_id  =  #{thirdStationId}
			</if>
<!--			<if test="type != null and type != ''">-->
<!--				AND type  =  #{type}-->
<!--			</if>-->



		</where>
	</select>

	<select id="queryAlarmNumber" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.TdHygfJpInverterWarnDto">
        SELECT
        `state`
        FROM house_pv_data.td_hygf_jp_inverter_warn
        <where>
            <if test="regionalCompaniesCode != null and regionalCompaniesCode.size > 0 ">
				`state` is not null and
                <foreach collection="regionalCompaniesCode" item="item"  open="(" close=")" separator="or">
					regional_companies_code like #{item}
                </foreach>
            </if>
        </where>
    </select>
</mapper>
