<?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.jxiop.biz.mapper2.IdxBizFanHealthIndexMapper">
	<select id="getHealthScoreInfo" resultType="java.math.BigDecimal">
		SELECT
        CEILING(avg( a.avgHealthIndex )) AS healthIndex
        FROM
        (
        SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex
        FROM
        idx_biz_fan_health_index
		<where>
			ANALYSIS_TYPE = '按天'
            AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURRENT_DATE
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
			<if test="stationCode != null and stationCode != ''">
                AND GATEWAY_ID = #{stationCode}
                AND ANALYSIS_OBJ_TYPE = '场站'
            </if>
			<if test="(stationCode == null or stationCode == '') and (areaCode == null or areaCode == '')">
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
		</where>
		UNION ALL
        (
        SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex
        FROM
        idx_biz_pv_health_index
		<where>
			ANALYSIS_TYPE = '按天'
            AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURRENT_DATE
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
			<if test="stationCode != null and stationCode != ''">
                AND GATEWAY_ID = #{stationCode}
                AND ANALYSIS_OBJ_TYPE = '场站'
            </if>
			<if test="(stationCode == null or stationCode == '') and (areaCode == null or areaCode == '')">
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
		</where>
		)
        ) a
	</select>
	<select id="getHealthScoreInfoByParam" resultType="java.math.BigDecimal">
		SELECT
        avg( a.avgHealthIndex ) AS healthIndex
        FROM
        (
        SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex
        FROM
        fan_health_index_latest_data
		<where>
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
              
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
			<if test="stationCode != null and stationCode != ''">
                AND GATEWAY_ID = #{stationCode}
                AND ANALYSIS_OBJ_TYPE = '场站'
            </if>
			<if test="(stationCode == null or stationCode == '') and (areaCode == null or areaCode == '')">
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
		</where>
		UNION ALL
        (
        SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex
        FROM
        pv_health_index_latest_data
		<where>
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
			<if test="stationCode != null and stationCode != ''">
                AND GATEWAY_ID = #{stationCode}
                AND ANALYSIS_OBJ_TYPE = '场站'
            </if>
			<if test="(stationCode == null or stationCode == '') and (areaCode == null or areaCode == '')">
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
		</where>
		)
        ) a
	</select>
	<select id="getHealthScoreInfoByStation" resultType="java.math.BigDecimal">
		SELECT
        round(IFNULL( HEALTH_INDEX , 100 ), 1) AS healthIndex
        FROM
        ${tableName}
		<where>
			ANALYSIS_TYPE = '按10分钟'
           <!-- AND DATE_ADD(DATE_FORMAT( REC_DATE, '%Y-%m-%d' ),INTERVAL 1 DAY) = CURRENT_DATE-->
           <!-- AND CURRENT_DATE = get_time_add(1,'DAY')-->
         <if test="stationCode != null and stationCode != ''">
             AND GATEWAY_ID = #{stationCode}
             AND ANALYSIS_OBJ_TYPE = '场站'
         </if>
     </where>
     limit 1
 </select>
    <select id="getHealthScoreInfoByStationByMinute" resultType="java.math.BigDecimal">
        SELECT
        round(IFNULL( HEALTH_INDEX , 100 ), 1) AS healthIndex
        FROM
        ${tableName}
        <where>
            ANALYSIS_TYPE = '按10分钟'
            <if test="stationCode != null and stationCode != ''">
                AND GATEWAY_ID = #{stationCode}
                AND ANALYSIS_OBJ_TYPE = '场站'
            </if>
        </where>
        order by REC_DATE DESC
        limit 1
    </select>
	<select id="getHealthListInfo" resultType="java.util.Map">
		SELECT
        CEILING(IFNULL( AVG( HEALTH_INDEX ), 100 )) AS avgHealthIndex,
        DATE_ADD( a.date, INTERVAL - 1 DAY ) as date
        FROM
        (
        SELECT
        DATE_FORMAT( DATE_ADD(( DATE( DATE_ADD( now(), INTERVAL - 15 DAY ))), INTERVAL @s DAY ), '%Y-%m-%d' ) AS date,
        @s := @s + 1 AS `index`
        FROM
        mysql.help_topic,
        ( SELECT @s := 1 ) temp
        WHERE
        DATEDIFF( now(), DATE( DATE_ADD( now(), INTERVAL - 15 DAY )) ) >= @s
        ) a
        LEFT JOIN (
        SELECT
        HEALTH_INDEX,
        DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) AS recDate
        FROM
        idx_biz_pv_health_index
		<where>
			ANALYSIS_TYPE = '按天'
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
			<if test="stationCode != null and stationCode != ''">
                AND GATEWAY_ID = #{stationCode}
                AND ANALYSIS_OBJ_TYPE = '场站'
            </if>
			<if test="(stationCode == null or stationCode == '') and (areaCode == null or areaCode == '')">
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0">
                AND GATEWAY_ID IN
                <foreach collection="gatewayIds" item="item" open="(" separator="," close=")">
                    ${item}
                </foreach>
            </if>
		</where>
		UNION ALL
        (
        SELECT
        HEALTH_INDEX,
        DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) AS recDate
        FROM
        idx_biz_fan_health_index
		<where>
			ANALYSIS_TYPE = '按天'
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
			<if test="stationCode != null and stationCode != ''">
                AND GATEWAY_ID = #{stationCode}
                AND ANALYSIS_OBJ_TYPE = '场站'
            </if>
			<if test="(stationCode == null or stationCode == '') and (areaCode == null or areaCode == '')">
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0">
                AND GATEWAY_ID IN
                <foreach collection="gatewayIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		)
        ) b ON DATE_FORMAT( b.recDate, '%Y-%m-%d' ) = a.date
        GROUP BY
        a.date
	</select>
	<select id="getAllEquipAlarmInfo" resultType="java.util.Map">
        SELECT ARAE         as area,
               WARNING_NAME as warningName,
               count(1)     as num
        FROM ${tableName} a
        where (a.DISPOSOTION_STATE = '待确认')
         <!--  or (a.DISPOSOTION_STATE = '已确认' and a.DISPOSOTION_DATE > DATE_ADD(now(), INTERVAL - 3 DAY ))-->
          or (a.DISPOSOTION_STATE = '已确认' and a.DISPOSOTION_DATE > get_time_sub(3,'DAY')
        group by ARAE,
                 WARNING_NAME
    </select>
	<select id="getHealthInfoByArea" resultType="java.util.Map">
        SELECT ARAE                           as area,
               round(avg(a.avgHealthIndex), 1) AS healthIndex
        FROM (
                 SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                        ARAE
                 FROM fan_health_index_latest_data
                 WHERE ANALYSIS_OBJ_TYPE = '片区'
                   AND ANALYSIS_TYPE = '按10分钟'
                 <!--  AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE - INTERVAL 1 DAY-->
                 <!--AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = get_time_sub(1,'DAY')-->
 
        GROUP BY ARAE
        UNION ALL
        (
            SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                   ARAE
            FROM pv_health_index_latest_data
            WHERE ANALYSIS_OBJ_TYPE = '片区'
              AND ANALYSIS_TYPE = '按10分钟'
              <!--AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE - INTERVAL 1 DAY-->
              <!--AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = get_time_sub(1,'DAY')-->
        GROUP BY ARAE
  )
) a
GROUP BY a.ARAE
</select>
<select id="getAllEquipAlarmInfoByStation" resultType="java.util.Map">
SELECT a.*
FROM (
  SELECT STATION      AS station,
         WARNING_NAME AS warningName,
         count(1)     AS num,
         (SELECT count(1)
          FROM idx_biz_fan_warning_record wr
          WHERE ((wr.DISPOSOTION_STATE = '待确认')
              or (wr.DISPOSOTION_STATE = '已确认' and
                  <!--wr.DISPOSOTION_DATE > DATE_ADD(now(), INTERVAL - 3 DAY )))-->
                                 wr.DISPOSOTION_DATE > get_time_sub(3,'DAY')
                           AND wr.STATION = STATION
                        )            AS allNum
                 FROM idx_biz_fan_warning_record
                 WHERE ((DISPOSOTION_STATE = '待确认')
                     <!--or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > DATE_ADD(now(), INTERVAL - 3 DAY )))-->
                         or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > get_time_sub(3,'DAY')
                 GROUP BY STATION,
                          WARNING_NAME
                 UNION ALL
                 SELECT STATION      AS station,
                        WARNING_NAME AS warningName,
                        count(1)     AS num,
                        (SELECT count(1)
                         FROM idx_biz_pv_warning_record wr
                         WHERE ((wr.DISPOSOTION_STATE = '待确认')
                             or (wr.DISPOSOTION_STATE = '已确认' and
                                 <!--wr.DISPOSOTION_DATE > DATE_ADD(now(), INTERVAL - 3 DAY )))-->
                                 wr.DISPOSOTION_DATE > get_time_sub(3,'DAY')
                           AND wr.STATION = STATION
                        )            AS allNum
                 FROM idx_biz_pv_warning_record
                 WHERE ((DISPOSOTION_STATE = '待确认')
                     <!--or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > DATE_ADD(now(), INTERVAL - 3 DAY )))-->
                     or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > get_time_sub(3,'DAY')
                 GROUP BY STATION,
                          WARNING_NAME
             ) a
        ORDER BY a.allNum ASC
    </select>
	<select id="getHealthInfoByStation" resultType="java.util.Map">
		SELECT
        a.STATION as station,
        round(avg( a.avgHealthIndex ), 1) AS healthIndex
        FROM
        (
        SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex,
        STATION
        FROM
        fan_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '场站'
            AND ANALYSIS_TYPE = '按10分钟'
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURRENT_DATE - INTERVAL  1 DAY-->
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = get_time_sub(1,'DAY')-->
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
            </if>
		</where>
		GROUP BY
        STATION UNION ALL
        (
        SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex,
        STATION
        FROM
        pv_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '场站'
            AND ANALYSIS_TYPE = '按10分钟'
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURRENT_DATE - INTERVAL  1 DAY-->
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = get_time_sub(1,'DAY')-->
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
            </if>
		</where>
		GROUP BY
        STATION
        )
        ) a
        GROUP BY
        a.STATION
	</select>
	<select id="equipWarningRadarMap" resultType="java.util.Map">
		SELECT
        a.warningName,
        count( 1 ) AS num
        FROM
        (
        SELECT
        WARNING_NAME AS warningName
        FROM
        idx_biz_fan_warning_record
		<where>
			((DISPOSOTION_STATE = '待确认')
            <!--or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > DATE_ADD( now(), INTERVAL - 3 DAY ) ))-->
            or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > get_time_sub(3,'DAY')
			<if test="stationCode != null and stationCode != ''">
                and GATEWAY_ID = #{stationCode}
            </if>
		</where>
		UNION ALL
        SELECT
        WARNING_NAME AS warningName
        FROM
        idx_biz_pv_warning_record
		<where>
			((DISPOSOTION_STATE = '待确认')
            <!--or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > DATE_ADD( now(), INTERVAL - 3 DAY ) ))-->
            or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > get_time_sub(3,'DAY')
			<if test="stationCode != null and stationCode != ''">
                and GATEWAY_ID = #{stationCode}
            </if>
		</where>
		) a
        GROUP BY
        a.warningName
	</select>
	<select id="getAllEquipAlarmInfoAnalysisByStationType" resultType="java.util.Map">
		SELECT
        concat(#{stationType}, '-', a.POINT_NAME) as pointName,
        a.WARNING_NAME as warningName,
        count(1) as num,
        (select count(1) from ${tableName} as tb
		<where>
			((tb.DISPOSOTION_STATE = '待确认')
            <!--or (tb.DISPOSOTION_STATE = '已确认' and tb.DISPOSOTION_DATE > DATE_ADD( now(), INTERVAL - 3 DAY ) ))-->
            or (tb.DISPOSOTION_STATE = '已确认' and tb.DISPOSOTION_DATE > get_time_sub(3,'DAY') ))
            and tb.POINT_NAME = a.POINT_NAME
			<if test="areaCode != null and areaCode != ''">
                and tb.ARAE like concat('%', #{areaCode}, '%')
            </if>
		</where>
		) AS totalNum
        FROM
        ${tableName} a
		<where>
			((a.DISPOSOTION_STATE = '待确认')
            <!--or (a.DISPOSOTION_STATE = '已确认' and a.DISPOSOTION_DATE > DATE_ADD( now(), INTERVAL - 3 DAY ) ))-->
            or (a.DISPOSOTION_STATE = '已确认' and a.DISPOSOTION_DATE > get_time_sub(3,'DAY') ))
			<if test="areaCode != null and areaCode != ''">
                and a.ARAE like concat('%', #{areaCode}, '%')
            </if>
		</where>
		group by pointName,
        warningName
        having pointName IS NOT NULL
        AND pointName != ''
        order by totalNum asc
	</select>
	<select id="getAllEquipAlarmInfoAnalysisByArea" resultType="java.util.Map">
		SELECT
        a.*
        FROM
        (
        SELECT
        wr.WARNING_NAME AS warningName,
        concat('光伏-', wr.POINT_NAME) AS pointName,
        count( 1 ) AS num,
        ( SELECT count( 1 ) FROM idx_biz_pv_warning_record
		<where>
			((DISPOSOTION_STATE = '待确认')
            <!--or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > DATE_ADD( now(), INTERVAL - 3 DAY ) ))-->
            or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > get_time_sub(3,'DAY') ))
            AND wr.POINT_NAME = POINT_NAME
			<if test="areaCode != null and areaCode != ''">
                and ARAE like concat('%', #{areaCode}, '%')
            </if>
		</where>
		) AS allNum
        FROM
        idx_biz_pv_warning_record wr
		<where>
			((wr.DISPOSOTION_STATE = '待确认')
            <!--or (wr.DISPOSOTION_STATE = '已确认' and wr.DISPOSOTION_DATE > DATE_ADD( now(), INTERVAL - 3 DAY ) ))-->
            or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > get_time_sub(3,'DAY') ))
			<if test="areaCode != null and areaCode != ''">
                and wr.ARAE like concat('%', #{areaCode}, '%')
            </if>
		</where>
		GROUP BY
        pointName,
        warningName UNION ALL
        SELECT
        wr.WARNING_NAME AS warningName,
        concat('风电-', wr.POINT_NAME) AS pointName,
        count( 1 ) AS num,
        ( SELECT count( 1 ) FROM idx_biz_fan_warning_record
		<where>
			((DISPOSOTION_STATE = '待确认')
            <!--or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > DATE_ADD( now(), INTERVAL - 3 DAY ) ))-->
            or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > get_time_sub(3,'DAY') ))
            AND wr.POINT_NAME = POINT_NAME
			<if test="areaCode != null and areaCode != ''">
                and ARAE like concat('%', #{areaCode}, '%')
            </if>
		</where>
		) AS allNum
        FROM
        idx_biz_fan_warning_record wr
		<where>
			((wr.DISPOSOTION_STATE = '待确认')
           <!--or (wr.DISPOSOTION_STATE = '已确认' and wr.DISPOSOTION_DATE > DATE_ADD( now(), INTERVAL - 3 DAY ) ))-->
           or (DISPOSOTION_STATE = '已确认' and DISPOSOTION_DATE > get_time_sub(3,'DAY') ))
			<if test="areaCode != null and areaCode != ''">
                and wr.ARAE like concat('%', #{areaCode}, '%')
            </if>
		</where>
		GROUP BY
        pointName,
        warningName
        ) a
        WHERE
        a.pointName IS NOT NULL
        AND a.pointName != ''
        order by a.allNum ASC
	</select>
	<select id="getSubSystemInfo" resultType="java.util.Map">
		SELECT
        round(IFNULL( MAX(HEALTH_INDEX), 100 ), 1) AS healthIndex,
        SUB_SYSTEM AS subSystem
        FROM
        fan_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '子系统'
            AND ANALYSIS_TYPE = '按10分钟'
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURRENT_DATE - INTERVAL  1  DAY-->
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = get_time_sub(1,'DAY')-->
			<if test="equipmentName != null and equipmentName != ''">
                AND (EQUIPMENT_NAME like concat( '%', #{equipmentName} ,'风机') or EQUIPMENT_NAME = #{equipmentName})
            </if>
			<if test="gatewayId != null and gatewayId != ''">
                AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
            </if>
		</where>
		group by subSystem
	</select>
	<select id="getFanInfoByPage" resultType="java.util.Map">
		SELECT
        EQUIPMENT_NAME as equipmentName,
        max(INDEX_ADDRESS) as indexAddress,
        max(STATION) as station
        FROM
        idx_biz_fan_point_process_variable_classification
		<where>
			(EQUIPMENT_NAME LIKE '%#%'  or EQUIPMENT_NAME='升压站')
			<if test="gatewayId != null and gatewayId != ''">
                AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
            </if>
		</where>
		GROUP BY
        EQUIPMENT_NAME
        ORDER BY
        RIGHT(EQUIPMENT_NAME, 6) ASC
	</select>
	<select id="getFanHealthInfoList" resultType="java.util.Map">
		SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex,
        EQUIPMENT_NAME as equipmentName
        FROM
        fan_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '设备'
            AND ANALYSIS_TYPE = '按10分钟'
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURRENT_DATE - INTERVAL  1  DAY-->
			<if test="gatewayId != null and gatewayId != ''">
                  AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
            </if>
		</where>
		GROUP BY
        EQUIPMENT_NAME
	</select>
	<select id="getSumSystemListByEquipment" resultType="java.util.Map">
		SELECT
        SUB_SYSTEM as subSystem,
        max(INDEX_ADDRESS) as indexAddress
        FROM
        idx_biz_fan_point_process_variable_classification
		<where>
			SUB_SYSTEM IS NOT NULL AND SUB_SYSTEM != ''
            AND TAG_CODE = '分析变量'
			<if test="equipmentName != null and equipmentName != ''">
                AND (EQUIPMENT_NAME like concat( '%', #{equipmentName} ,'风机') or EQUIPMENT_NAME = #{equipmentName})
            </if>
			<if test="gatewayId != null and gatewayId != ''">
                  AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
            </if>
		</where>
		GROUP BY
        SUB_SYSTEM
	</select>
	<select id="getPointNameListBySumSystem" resultType="java.util.Map">
		SELECT
        POINT_NAME as pointName,
        max(INDEX_ADDRESS) as indexAddress,
        max(STATION) AS station
        FROM
        idx_biz_fan_point_process_variable_classification
		<where>
            TAG_CODE = '分析变量'
			<if test="subSystem != null and subSystem != ''">
                AND SUB_SYSTEM = #{subSystem}
            </if>
			<if test="gatewayId != null and gatewayId != ''">
                  AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
            </if>
            <if test="equipmentName != null and equipmentName != ''">
                AND EQUIPMENT_NAME like #{equipmentName}
            </if>
		</where>
		GROUP BY
        POINT_NAME
	</select>
	<select id="getHealthInfoBySubSystem" resultType="java.util.Map">
		SELECT
        IFNULL(MAX(HEALTH_INDEX), 100) AS healthIndex,
        POINT_NAME AS pointName
        FROM
        fan_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE= '测点'
            AND ANALYSIS_TYPE = '按10分钟'
            AND POINT_NAME IS NOT NULL
            AND POINT_NAME != ''
			<if test="subSystem != null and subSystem != ''">
                AND SUB_SYSTEM = #{subSystem}
            </if>
			<if test="gatewayId != null and gatewayId != ''">
                  AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
            </if>
            <if test="equipmentName != null and equipmentName != ''">
                AND EQUIPMENT_NAME like #{equipmentName}
            </if>
		</where>
		GROUP BY
        POINT_NAME
	</select>
	<select id="getWarningInfoBySubSystem" resultType="java.util.Map">
		SELECT
        POINT_NAME as pointName,
        WARNING_NAME as warningName
        FROM
        idx_biz_fan_warning_record
		<where>
			DISPOSOTION_STATE = '待确认'
			<if test="subSystem != null and subSystem != ''">
                AND SUB_SYSTEM = #{subSystem}
            </if>
			<if test="gatewayId != null and gatewayId != ''">
                  AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
            </if>
		</where>
		GROUP BY
        POINT_NAME
        ORDER BY
        WARNING_NAME ASC
	</select>
	<select id="getPvInfoByPage" resultType="java.util.Map">
		SELECT
        SUBARRAY as subarray,
        Max(STATION)  AS station
        FROM
        idx_biz_pv_point_process_variable_classification
		<where>
			<if test="gatewayId != null and gatewayId != ''">
                GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId}
            </if>
		</where>
		GROUP BY
        SUBARRAY
        ORDER BY
        SUBARRAY
	</select>
	<select id="getPvHealthInfoList" resultType="java.util.Map">
		SELECT
        IFNULL ( ROUND( MAX(HEALTH_INDEX), 2 ), 0 ) AS avgHealthIndex,
        SUBARRAY as subarray
        FROM
        pv_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '子阵'
            AND ANALYSIS_TYPE = '按10分钟'
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURRENT_DATE - INTERVAL 1 DAY-->
			<if test="gatewayId != null and gatewayId != ''">
                AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
            </if>
		</where>
		GROUP BY SUBARRAY
        order by SUBARRAY
	</select>
	<select id="getPvSubSystemInfo" resultType="java.util.Map">
		SELECT
        IFNULL ( ROUND( MAX(HEALTH_INDEX), 2 ), 100 ) AS avgHealthIndex,
        EQUIPMENT_NAME AS equipmentName
        FROM
        pv_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '设备'
            AND ANALYSIS_TYPE = '按10分钟'
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURRENT_DATE - INTERVAL 1 DAY-->
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = get_time_sub(1,'DAY')-->
        <if test="subarray != null and subarray != ''">
            AND (SUBARRAY = concat('#', #{subarray}) or  SUBARRAY=#{subarray})
        </if>
        <if test="gatewayId != null and gatewayId != ''">
              AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
        </if>
    </where>
    group by EQUIPMENT_NAME
</select>
<select id="getPvSumSystemListByEquipment" resultType="java.util.Map">
    SELECT
    EQUIPMENT_NAME as equipmentName
    FROM
    idx_biz_pv_point_process_variable_classification
    <where>
        EQUIPMENT_NAME IS NOT NULL
        AND EQUIPMENT_NAME != ''
        AND TAG_CODE = '分析变量'
        <if test="subarray != null and subarray != ''">
            AND (SUBARRAY = concat('#', #{subarray}) or  SUBARRAY=#{subarray})
        </if>
        <if test="gatewayId != null and gatewayId != ''">
              AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
        </if>
    </where>
    GROUP BY
    EQUIPMENT_NAME
</select>
<select id="getPvHealthInfoBySubSystem" resultType="java.util.Map">
    SELECT
    MAX(IFNULL(HEALTH_INDEX, 100)) AS healthIndex,
    POINT_NAME AS pointName
    FROM
    pv_health_index_latest_data
    <where>
        ANALYSIS_OBJ_TYPE = '测点'
        AND ANALYSIS_TYPE = '按10分钟'
        AND POINT_NAME IS NOT NULL
        AND POINT_NAME != ''
        <if test="equipmentName != null and equipmentName != ''">
            AND EQUIPMENT_NAME = #{equipmentName}
        </if>
        <if test="gatewayId != null and gatewayId != ''">
              AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
        </if>
    </where>
    GROUP BY
    POINT_NAME
</select>
<select id="getPvWarningInfoBySubSystem" resultType="java.util.Map">
    SELECT
    POINT_NAME as pointName,
    WARNING_NAME as warningName
    FROM
    idx_biz_pv_warning_record
    <where>
        DISPOSOTION_STATE = '待确认'
        <if test="equipmentName != null and equipmentName != ''">
            AND EQUIPMENT_NAME = #{equipmentName}
        </if>
        <if test="gatewayId != null and gatewayId != ''">
              AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
        </if>
    </where>
    GROUP BY
    POINT_NAME
    ORDER BY
    WARNING_NAME ASC
</select>
<select id="getPvPointNameListBySumSystem" resultType="java.util.Map">
    SELECT
    POINT_NAME as pointName,
    MAX(INDEX_ADDRESS) as indexAddress,
    MAX(STATION) AS station
    FROM
    idx_biz_pv_point_process_variable_classification
    <where>
        TAG_CODE = '分析变量'
        <if test="equipmentName != null and equipmentName != ''">
            AND EQUIPMENT_NAME = #{equipmentName}
        </if>
        <if test="gatewayId != null and gatewayId != ''">
              AND (GATEWAY_ID = #{gatewayId} or GATEWAY_ID = #{syzGatewayId})
        </if>
    </where>
    GROUP BY
    POINT_NAME
</select>
<select id="getPointNameByIndexAddress" resultType="java.lang.String">
    select POINT_NAME
    from ${tableName}
    where INDEX_ADDRESS = #{varDesc}
          AND GATEWAY_ID = #{gatewayId}
        limit 1


</select>
<select id="getFullViewRecall" resultType="com.yeejoin.amos.boot.module.jxiop.biz.dto.FullViewRecallDataDTO">
    SELECT a.*,
           row_number() over ( ORDER BY pointName ) AS id
    FROM (
             (SELECT ARAE           AS area,
                    STATION        AS station,
                    EQUIPMENT_NAME AS equipmentName,
                    SUB_SYSTEM     AS subSystem,
                    POINT_NAME     AS pointName,
                    INDEX_ADDRESS  AS indexAddress,
                 KKS
             FROM idx_biz_fan_point_process_variable_classification
             WHERE TAG_CODE = '分析变量'
               AND ARAE is not null
               AND STATION is not null
               AND EQUIPMENT_NAME is not null
               AND SUB_SYSTEM is not null
               AND POINT_NAME is not null
               AND INDEX_ADDRESS is not null
                <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                    <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
                 )
             UNION ALL
             (SELECT ARAE           AS area,
                    STATION        AS station,
                    SUBARRAY       AS equipmentName,
                    EQUIPMENT_NAME AS subSystem,
                    POINT_NAME     AS pointName,
                    INDEX_ADDRESS  AS indexAddress,
                 KKS
             FROM idx_biz_pv_point_process_variable_classification
             WHERE TAG_CODE = '分析变量'
               AND ARAE is not null
               AND STATION is not null
               AND SUBARRAY is not null
               AND EQUIPMENT_NAME is not null
               AND POINT_NAME is not null
               AND INDEX_ADDRESS is not null
                <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                    <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            )
         ) a
    ORDER BY a.station ASC, a.equipmentName ASC, a.equipmentName asc, a.subSystem asc
</select>
<select id="getStationIndexInfo" resultType="java.util.Map">
    SELECT a.STATION                       AS station,
           ROUND(avg(a.avgHealthIndex), 2) AS healthIndex
    FROM (
             SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                    STATION                        AS STATION
             FROM idx_biz_fan_health_index
             WHERE ANALYSIS_OBJ_TYPE = '场站'
               AND ANALYSIS_TYPE = '按天'
               AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE
             GROUP BY STATION
             UNION ALL
             (
                 SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                        STATION                        AS STATION
                 FROM idx_biz_pv_health_index
                 WHERE ANALYSIS_OBJ_TYPE = '场站'
                   AND ANALYSIS_TYPE = '按天'
                   AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE
                 GROUP BY STATION
             )
         ) a
    GROUP BY a.STATION
</select>
<select id="getEquipmentIndexInfo" resultType="java.util.Map">
    SELECT a.equipmentName                 AS equipmentName,
           ROUND(avg(a.avgHealthIndex), 2) AS healthIndex
    FROM (
             SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                    EQUIPMENT_NAME                 AS equipmentName
             FROM idx_biz_fan_health_index
             WHERE ANALYSIS_OBJ_TYPE = '设备'
               AND ANALYSIS_TYPE = '按天'
               AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE
             GROUP BY EQUIPMENT_NAME
             UNION ALL
             (
                 SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                        SUBARRAY                       AS equipmentName
                 FROM idx_biz_pv_health_index
                 WHERE ANALYSIS_OBJ_TYPE = '子阵'
                   AND ANALYSIS_TYPE = '按天'
                   AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE
                 GROUP BY SUBARRAY
             )
         ) a
    where equipmentName is not null
      and equipmentName != ''
    GROUP BY
        a.equipmentName
</select>
<select id="getSubSystemIndexInfo" resultType="java.util.Map">

    SELECT a.subSystem                     AS subSystem,
           ROUND(avg(a.avgHealthIndex), 2) AS healthIndex
    FROM (
             SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                    SUB_SYSTEM                     AS subSystem
             FROM idx_biz_fan_health_index
             WHERE ANALYSIS_OBJ_TYPE = '子系统'
               AND ANALYSIS_TYPE = '按天'
               AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE
             GROUP BY SUB_SYSTEM
             UNION ALL
             (
                 SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                        EQUIPMENT_NAME                 AS subSystem
                 FROM idx_biz_pv_health_index
                 WHERE ANALYSIS_OBJ_TYPE = '设备'
                   AND ANALYSIS_TYPE = '按天'
                   AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE
                 GROUP BY EQUIPMENT_NAME
             )
         ) a
    where subSystem is not null
      and subSystem != ''
    GROUP BY
        a.subSystem

</select>
<select id="getPointNameIndexInfo" resultType="java.util.Map">

    SELECT IFNULL(MAX(HEALTH_INDEX), 100)           AS healthIndex,
           concat(MAX(STATION), '_', INDEX_ADDRESS) as gatewayIndexAddress
    FROM idx_biz_fan_health_index
    WHERE ANALYSIS_OBJ_TYPE = '测点'
      AND ANALYSIS_TYPE = '按天'
      AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE
    GROUP BY INDEX_ADDRESS
    UNION ALL
    (
        SELECT IFNULL(MAX(HEALTH_INDEX), 100)           AS healthIndex,
               concat(MAX(STATION), '_', INDEX_ADDRESS) as gatewayIndexAddress
        FROM idx_biz_pv_health_index
        WHERE ANALYSIS_OBJ_TYPE = '测点'
          AND ANALYSIS_TYPE = '按天'
          AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') = CURRENT_DATE
        GROUP BY INDEX_ADDRESS
    )
</select>
<select id="getHealthLevelInfoList" resultType="com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizFanHealthLevel">
    SELECT CONCAT(`STATUS`, '_', ANALYSIS_OBJ_TYPE) AS analysisObjType,
           HEALTH_LEVEL                             AS healthLevel,
           GROUP_LOWER_LIMIT                        AS groupLowerLimit,
           GROUP_UPPER_LIMIT                        AS groupUpperLimit
    FROM idx_biz_fan_health_level
    WHERE (STATUS IS NOT NULL
       OR STATUS != '')
    <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
        <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
            #{item}
        </foreach>
    </if>
    UNION ALL
    SELECT CONCAT(`STATUS`, '_', ANALYSIS_OBJ_TYPE) AS analysisObjType,
           HEALTH_LEVEL                             AS healthLevel,
           GROUP_LOWER_LIMIT                        AS groupLowerLimit,
           GROUP_UPPER_LIMIT                        AS groupUpperLimit
    FROM idx_biz_pv_health_level
    WHERE (STATUS IS NOT NULL
       OR STATUS != '')
    <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
        <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
            #{item}
        </foreach>
    </if>
</select>
<select id="getAddressInfo" resultType="java.lang.String">
    select index_address
    from wl_equipment_specific_index
    where gateway_id = '1668801435891929089'
      and data_type = 'analog' limit 100
</select>
<select id="queryForLeftTableList" resultType="map">
    SELECT
    b.*,
    IFNULL(CAST(HEALTH_INDEX AS UNSIGNED), 100 ) as HEALTH_INDEX ,
    IFNULL( ibfhi.HEALTH_LEVEL, '安全' ) as HEALTH_LEVEL,
    (case ibfhi.HEALTH_LEVEL
    WHEN '危险' THEN 3
    WHEN '警告' THEN 2
    WHEN '注意' THEN 1
    ELSE 0 end) as status
    FROM
    (
    SELECT
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME` AS `EQUIPMENT_NAME`,
    `idx_biz_fan_point_process_variable_classification`.`STATION` AS `STATION`
    FROM
    `idx_biz_fan_point_process_variable_classification`
    WHERE
    `idx_biz_fan_point_process_variable_classification`.`TAG_CODE` = '分析变量'
    GROUP BY
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME`
    ORDER BY
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME` ASC
    ) b
    LEFT JOIN `idx_biz_fan_health_index` `ibfhi` ON ( ( `b`.`EQUIPMENT_NAME` = `ibfhi`.`EQUIPMENT_NAME` ) )
    AND ibfhi.ANALYSIS_OBJ_TYPE = '设备' AND ANALYSIS_OBJ_TYPE = '设备' AND ANALYSIS_TYPE = '按天' AND
    DATE_FORMAT(ibfhi.REC_DATE,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
    <where>
        <if test="STATION != '' and STATION != null">
            b.STATION = #{STATION}
        </if>
        <if test="HEALTHLEVEL != '' and HEALTHLEVEL != null">
            AND HEALTH_LEVEL = #{HEALTHLEVEL}
        </if>
        <if test="EQUIPMENTNAME != '' and EQUIPMENTNAME != null">
            AND b.EQUIPMENT_NAME = #{EQUIPMENTNAME}
        </if>
    </where>
    order by HEALTH_INDEX ASC
    limit ${current},${size}
</select>
<select id="queryForLeftTableListCount" resultType="int">
    SELECT
    count(1)
    FROM
    (
    SELECT
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME` AS `EQUIPMENT_NAME`,
    `idx_biz_fan_point_process_variable_classification`.`STATION` AS `STATION`
    FROM
    `idx_biz_fan_point_process_variable_classification`
    WHERE
    `idx_biz_fan_point_process_variable_classification`.`TAG_CODE` = '分析变量'
    GROUP BY
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME`
    ORDER BY
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME` ASC
    ) b
    LEFT JOIN `idx_biz_fan_health_index` `ibfhi` ON ( ( `b`.`EQUIPMENT_NAME` = `ibfhi`.`EQUIPMENT_NAME` ) )
    AND ibfhi.ANALYSIS_OBJ_TYPE = '设备' AND ANALYSIS_OBJ_TYPE = '设备' AND ANALYSIS_TYPE = '按天' AND
    DATE_FORMAT(ibfhi.REC_DATE,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
    <where>
        <if test="STATION != '' and STATION != null">
            b.STATION = #{STATION}
        </if>
        <if test="HEALTHLEVEL != '' and HEALTHLEVEL != null">
            AND HEALTH_LEVEL = #{HEALTHLEVEL}
        </if>
        <if test="EQUIPMENTNAME != '' and EQUIPMENTNAME != null">
            AND b.EQUIPMENT_NAME = #{EQUIPMENTNAME}
        </if>
    </where>
</select>
<select id="queryForLeftTableListNum" resultType="map">
    SELECT

    CAST(ibfhi.HEALTH_INDEX AS UNSIGNED) as value
    FROM
    (
    SELECT
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME` AS `EQUIPMENT_NAME`,
    `idx_biz_fan_point_process_variable_classification`.`STATION` AS `STATION`
    FROM
    `idx_biz_fan_point_process_variable_classification`
    WHERE
    `idx_biz_fan_point_process_variable_classification`.`TAG_CODE` = '分析变量'
    GROUP BY
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME`
    ORDER BY
    `idx_biz_fan_point_process_variable_classification`.`EQUIPMENT_NAME` ASC
    ) b
    LEFT JOIN `idx_biz_fan_health_index` `ibfhi` ON ( ( `b`.`EQUIPMENT_NAME` = `ibfhi`.`EQUIPMENT_NAME` ) )
    AND ibfhi.ANALYSIS_OBJ_TYPE = '设备' AND ANALYSIS_OBJ_TYPE = '设备' AND ANALYSIS_TYPE = '按天' AND
    DATE_FORMAT(ibfhi.REC_DATE,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
    <where>
        <if test="STATION != '' and STATION != null">
            b.STATION = #{STATION}
        </if>
        <if test="HEALTHLEVEL != '' and HEALTHLEVEL != null">
            AND HEALTH_LEVEL = #{HEALTHLEVEL}
        </if>
        <if test="EQUIPMENTNAME != '' and EQUIPMENTNAME != null">
            AND b.EQUIPMENT_NAME = #{EQUIPMENTNAME}
        </if>
    </where>
</select>
<select id="queryForLeftTableListByPoint" resultType="map">
    SELECT
    b.*
    FROM
    (
    SELECT
    POINT_NAME ,
    STATION,
    CAST(HEALTH_INDEX AS UNSIGNED) as HEALTH_INDEX,
    CAST(HEALTH_INDEX AS UNSIGNED) as value,
    HEALTH_LEVEL,
    ( CASE HEALTH_LEVEL WHEN '危险' THEN 3 WHEN '警告' THEN 2 WHEN '注意' THEN 1 ELSE 0 END ) AS status,
    SUB_SYSTEM,
    REC_DATE,
    EQUIPMENT_NAME,
    INDEX_ADDRESS,
    ANALYSIS_OBJ_SEQ,
    ANALYSIS_TYPE
    FROM
    `idx_biz_fan_health_index`
    WHERE
    ANALYSIS_OBJ_TYPE = '测点'
    <!--AND ( ANALYSIS_TYPE = '按小时' AND REC_DATE >= DATE_SUB( NOW( ), INTERVAL 1 HOUR ) )-->
        AND ( ANALYSIS_TYPE = '按小时' AND REC_DATE >= get_time_sub(1,'HOUR') )
        OR ( REC_DATE >= CURRENT_DATE ( ) AND ANALYSIS_TYPE = '按天' )
        <!--OR ( ANALYSIS_TYPE = '按10分钟' AND REC_DATE >= DATE_SUB( NOW( ), INTERVAL 10 MINUTE ) )-->
        OR ( ANALYSIS_TYPE = '按10分钟' AND REC_DATE >= get_time_sub(10,'MINUTE'))
        ) b
        INNER JOIN idx_biz_fan_warning_rule_set rule ON rule.ANALYSIS_POINT_ID = b.ANALYSIS_OBJ_SEQ
        AND rule.WARNING_NAME = '注意'
        AND rule.ANALYSIS_TYPE = b.ANALYSIS_TYPE
		<where>
			<if test="STATION != null and  STATION != '' ">
                b.STATION = #{STATION}
            </if>
			<if test="EQUIPMENTNAME != null and  EQUIPMENTNAME != '' ">
                AND b.EQUIPMENT_NAME = #{EQUIPMENTNAME}
            </if>
			<if test="HEALTHLEVEL != null and  HEALTHLEVEL != '' ">
                AND b.HEALTH_LEVEL = #{HEALTHLEVEL}
            </if>
			<if test="POINTNAME != null and  POINTNAME != '' ">
                AND b.POINT_NAME = #{POINTNAME}
            </if>
		</where>
		order by b.HEALTH_INDEX ASC
        limit ${current},${size}
	</select>
	<select id="queryForLeftTableListByPointCount" resultType="int">
		SELECT
        count(1)
        FROM
        (
        SELECT
        POINT_NAME ,
        STATION,
        HEALTH_INDEX,
        HEALTH_INDEX as value,
        HEALTH_LEVEL,
        ( CASE HEALTH_LEVEL WHEN '危险' THEN 3 WHEN '警告' THEN 2 WHEN '注意' THEN 1 ELSE 0 END ) AS status,
        SUB_SYSTEM,
        REC_DATE,
        EQUIPMENT_NAME,
        INDEX_ADDRESS,
        ANALYSIS_OBJ_SEQ,
        ANALYSIS_TYPE
        FROM
        `idx_biz_fan_health_index`
        WHERE
        ANALYSIS_OBJ_TYPE = '测点'
        <!--AND ( ANALYSIS_TYPE = '按小时' AND REC_DATE >= DATE_SUB( NOW( ), INTERVAL 1 HOUR ) )-->
        AND ( ANALYSIS_TYPE = '按小时' AND REC_DATE >= get_time_sub(1,'HOUR') )
        OR ( REC_DATE >= CURRENT_DATE ( ) AND ANALYSIS_TYPE = '按天' )
        <!--OR ( ANALYSIS_TYPE = '按10分钟' AND REC_DATE >= DATE_SUB( NOW( ), INTERVAL 10 MINUTE ) )-->
        OR ( ANALYSIS_TYPE = '按10分钟' AND REC_DATE >= get_time_sub(10,'MINUTE'))
        ) b
        INNER JOIN idx_biz_fan_warning_rule_set rule ON rule.ANALYSIS_POINT_ID = b.ANALYSIS_OBJ_SEQ
        AND rule.WARNING_NAME = '注意'
        AND rule.ANALYSIS_TYPE = b.ANALYSIS_TYPE
		<where>
			<if test="STATION != null and  STATION != '' ">
                b.STATION = #{STATION}
            </if>
			<if test="EQUIPMENTNAME != null and  EQUIPMENTNAME != '' ">
                AND b.EQUIPMENT_NAME = #{EQUIPMENTNAME}
            </if>
			<if test="HEALTHLEVEL != null and  HEALTHLEVEL != '' ">
                AND b.HEALTH_LEVEL = #{HEALTHLEVEL}
            </if>
			<if test="POINTNAME != null and  POINTNAME != '' ">
                AND b.POINT_NAME = #{POINTNAME}
            </if>
		</where>
	</select>
	<select id="queryForLeftTableListByPointNum" resultType="map">
		SELECT
        b.HEALTH_INDEX as value
        FROM
        (
        SELECT
        POINT_NAME ,
        STATION,
        CAST(HEALTH_INDEX AS UNSIGNED) as HEALTH_INDEX,
        CAST(HEALTH_INDEX AS UNSIGNED) as value,
        HEALTH_LEVEL,
        ( CASE HEALTH_LEVEL WHEN '危险' THEN 3 WHEN '警告' THEN 2 WHEN '注意' THEN 1 ELSE 0 END ) AS status,
        SUB_SYSTEM,
        REC_DATE,
        EQUIPMENT_NAME,
        INDEX_ADDRESS,
        ANALYSIS_OBJ_SEQ,
        ANALYSIS_TYPE
        FROM
        `idx_biz_fan_health_index`
        WHERE
        ANALYSIS_OBJ_TYPE = '测点'
        <!--AND ( ANALYSIS_TYPE = '按小时' AND REC_DATE >= DATE_SUB( NOW( ), INTERVAL 1 HOUR ) )-->
        AND ( ANALYSIS_TYPE = '按小时' AND REC_DATE >= get_time_sub(1,'HOUR') )
        OR ( REC_DATE >= CURRENT_DATE ( ) AND ANALYSIS_TYPE = '按天' )
        <!--OR ( ANALYSIS_TYPE = '按10分钟' AND REC_DATE >= DATE_SUB( NOW( ), INTERVAL 10 MINUTE ) )-->
        OR ( ANALYSIS_TYPE = '按10分钟' AND REC_DATE >= get_time_sub(10,'MINUTE'))
        ) b
        INNER JOIN idx_biz_fan_warning_rule_set rule ON rule.ANALYSIS_POINT_ID = b.ANALYSIS_OBJ_SEQ
        AND rule.WARNING_NAME = '注意'
        AND rule.ANALYSIS_TYPE = b.ANALYSIS_TYPE
		<where>
			<if test="STATION != null and  STATION != '' ">
                b.STATION = #{STATION}
            </if>
			<if test="EQUIPMENTNAME != null and  EQUIPMENTNAME != '' ">
                AND b.EQUIPMENT_NAME = #{EQUIPMENTNAME}
            </if>
			<if test="HEALTHLEVEL != null and  HEALTHLEVEL != '' ">
                AND b.HEALTH_LEVEL = #{HEALTHLEVEL}
            </if>
			<if test="POINTNAME != null and  POINTNAME != '' ">
                AND b.POINT_NAME = #{POINTNAME}
            </if>
		</where>
	</select>
	<select id="warningData" resultType="com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizFanWarningRecord">
		SELECT
    *
    FROM
    idx_biz_fan_warning_record re
    WHERE
    re.`STATUS` = 0
		<if test="EQUIPMENTNAME != '' and EQUIPMENTNAME != null">
        AND re.EQUIPMENT_NAME = #{EQUIPMENTNAME}
    </if>
		<if test="SUBARRAY != null and  SUBARRAY != '' ">
        AND re.SUBARRAY = #{SUBARRAY}
    </if>
		<if test="STATION != null and  STATION != '' ">
        AND re.STATION = #{STATION}
    </if>
	</select>
	<select id="pointNum" resultType="int">
		SELECT
        count(1)
        FROM
        idx_biz_fan_point_process_variable_classification cl
        WHERE
        cl.TAG_CODE = '分析变量'
		<if test="EQUIPMENTNAME != '' and EQUIPMENTNAME != null">
            AND cl.EQUIPMENT_NAME = #{EQUIPMENTNAME}
        </if>
		<if test="SUBSYSTEM != null and  SUBSYSTEM != '' ">
            AND cl.SUB_SYSTEM = #{SUBSYSTEM}
        </if>
		<if test="STATION != null and  STATION != '' ">
            AND cl.STATION = #{STATION}
        </if>
	</select>
	<select id="selectPointByANALYSISTYPE" resultType="map">
		SELECT
        b.*
        FROM
        (
        SELECT
        POINT_NAME ,
        STATION,
        CAST(HEALTH_INDEX AS UNSIGNED) as HEALTH_INDEX,
        CAST(HEALTH_INDEX AS UNSIGNED) as value,
        HEALTH_LEVEL,
        ( CASE HEALTH_LEVEL WHEN '危险' THEN 3 WHEN '警告' THEN 2 WHEN '注意' THEN 1 ELSE 0 END ) AS status,
        SUB_SYSTEM,
        REC_DATE,
        EQUIPMENT_NAME,
        INDEX_ADDRESS,
        ANALYSIS_OBJ_SEQ,
        ANALYSIS_TYPE
        FROM
        `idx_biz_fan_health_index`
        WHERE
        ANALYSIS_OBJ_TYPE = '测点'
		<if test="(startTime == null or startTime == '' ) and (endTime == null or endTime =='')  ">
            <!--AND ( ANALYSIS_TYPE = '按小时' AND REC_DATE >= DATE_SUB( NOW( ), INTERVAL 15 HOUR ) )-->
	        AND ( ANALYSIS_TYPE = '按小时' AND REC_DATE >= get_time_sub(15,'HOUR'))
	        <!--OR ( REC_DATE >=DATE_SUB( NOW(), INTERVAL 15 DAY ) AND ANALYSIS_TYPE = '按天' )-->
	        OR ( ANALYSIS_TYPE = '按天' AND REC_DATE >= get_time_sub(15,'DAY'))
	        <!--OR ( ANALYSIS_TYPE = '按10分钟' AND REC_DATE >= DATE_SUB( NOW( ), INTERVAL 150 MINUTE ) )-->
	        OR ( ANALYSIS_TYPE = '按10分钟' AND REC_DATE >= get_time_sub(150,'MINUTE'))
        </if>
		<if test="startTime != null and startTime != '' or endTime != null and endTime != '' ">
            AND REC_DATE >= #{startTime}
        </if>
		<if test="endTime != null and endTime != ''">
			<![CDATA[ AND REC_DATE  <= #{endTime}]]>
		</if>
		) b
        INNER JOIN idx_biz_fan_warning_rule_set rule ON rule.ANALYSIS_POINT_ID = b.ANALYSIS_OBJ_SEQ
        AND rule.WARNING_NAME = '注意'
        AND rule.ANALYSIS_TYPE = b.ANALYSIS_TYPE
		<where>
			<if test="STATION != null and  STATION != '' ">
                b.STATION = #{STATION}
            </if>
			<if test="EQUIPMENTNAME != null and  EQUIPMENTNAME != '' ">
                AND b.EQUIPMENT_NAME = #{EQUIPMENTNAME}
            </if>
			<if test="HEALTHLEVEL != null and  HEALTHLEVEL != '' ">
                AND b.HEALTH_LEVEL = #{HEALTHLEVEL}
            </if>
			<if test="POINTNAME != null and  POINTNAME != '' ">
                AND b.POINT_NAME = #{POINTNAME}
            </if>
		</where>
	</select>
	<select id="getFanEquipStatusByStation" resultType="map">
		SELECT
            max( CASE WHEN a.HEALTH_LEVEL = '安全' THEN num ELSE 0 END ) AS 安全,
            max( CASE WHEN a.HEALTH_LEVEL = '注意' THEN num ELSE 0 END ) AS 注意,
            max( CASE WHEN a.HEALTH_LEVEL = '警告' THEN num ELSE 0 END ) AS 警告,
            max( CASE WHEN a.HEALTH_LEVEL = '危险' THEN num ELSE 0 END ) AS 危险
        FROM
            (
                SELECT
                    STATION,
                    HEALTH_LEVEL,
                    count( 1 ) AS num
                FROM
                    idx_biz_fan_health_index
                WHERE
                    ANALYSIS_TYPE = '按天'
                  AND ANALYSIS_OBJ_TYPE = '设备'
                  AND REC_DATE >= CURRENT_DATE ( )
		<if test="STATION != null and STATION != ''">
           AND STATION = #{STATION}
        </if>
		GROUP BY
                    STATION,
                    HEALTH_LEVEL
            ) a
	</select>
	<select id="getPvEquipStatusByStation" resultType="java.util.Map">
		SELECT
            max( CASE WHEN a.HEALTH_LEVEL = '安全' THEN num ELSE 0 END ) AS 安全,
            max( CASE WHEN a.HEALTH_LEVEL = '注意' THEN num ELSE 0 END ) AS 注意,
            max( CASE WHEN a.HEALTH_LEVEL = '警告' THEN num ELSE 0 END ) AS 警告,
            max( CASE WHEN a.HEALTH_LEVEL = '危险' THEN num ELSE 0 END ) AS 危险
            FROM
            (
            SELECT
            STATION,
            HEALTH_LEVEL,
            count( 1 ) AS num
            FROM
            idx_biz_pv_health_index
            WHERE
            ANALYSIS_TYPE = '按天'
            AND ANALYSIS_OBJ_TYPE = '设备'
            AND REC_DATE >= CURRENT_DATE ( )
		<if test="STATION != null and STATION != ''">
                AND STATION = #{STATION}
            </if>
		GROUP BY
            STATION,
            HEALTH_LEVEL
            ) a
	</select>
	<select id="getRecDateByIndexAddress" resultType="java.lang.String">
        SELECT
            a.REC_DATE
        FROM
            (
                SELECT
                    *,(
                    CASE

                        WHEN WARNING_NAME = '注意' THEN
                            1
                        WHEN WARNING_NAME = '警告' THEN
                            2
                        WHEN WARNING_NAME = '危险' THEN
                            3 ELSE 0
                        END
                    ) AS sort
                FROM
                    ${tableName}
                WHERE
                    INDEX_ADDRESS = #{indexAddress}
                  AND DISPOSOTION_STATE = '待确认'
                    AND GATEWAY_ID = #{fanGatewayId}
                ORDER BY
                    sort DESC,
                    REC_DATE DESC
                    LIMIT 1
            ) a
    </select>
	<select id="getInfoListByTableName" resultType="java.util.Map">
        SELECT
            *,
            CEILING(HEALTH_INDEX) as healthIndex
        FROM
            ${tableName}
        WHERE
            #{recDate} >= REC_DATE
            AND REC_DATE >= DATE_ADD( #{recDate}, INTERVAL - 12 hour )
            AND ANALYSIS_TYPE = '按10分钟'
            AND INDEX_ADDRESS = #{indexAddress}
            AND (GATEWAY_ID = #{fanGatewayId} or GATEWAY_ID = #{syzGatewayId})
    </select>
	<select id="getIsWarningByPointId" resultType="int">
        select count(1) from ${tableName}
        where INDEX_ADDRESS = #{indexAddress}
          AND (GATEWAY_ID = #{fanGatewayId} or GATEWAY_ID = #{syzGatewayId})
        and DISPOSOTION_STATE = '待确认'
    </select>
	<select id="getStationIndexInfoByParam" resultType="java.util.Map">
		SELECT a.STATION                       AS station,
               ROUND(avg(a.avgHealthIndex), 1) AS healthIndex
        FROM (
                 SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                        STATION                        AS STATION
                 FROM fan_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '场站'
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		GROUP BY STATION
                 UNION ALL
                 (
                     SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                            STATION                        AS STATION
                     FROM pv_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '场站'
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		GROUP BY STATION
                 )
             ) a
        GROUP BY a.STATION
	</select>
	<select id="getEquipmentIndexInfoByParam" resultType="java.util.Map">
		SELECT a.equipmentName                 AS equipmentName,
               ROUND(avg(a.avgHealthIndex), 1) AS healthIndex
        FROM (
                 SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                        EQUIPMENT_NAME                 AS equipmentName
                 FROM fan_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '设备'
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		GROUP BY EQUIPMENT_NAME
                 UNION ALL
                 (
                     SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                            SUBARRAY                       AS equipmentName
                     FROM pv_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '子阵'
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		GROUP BY SUBARRAY
                 )
             ) a
        where equipmentName is not null
          and equipmentName != ''
        GROUP BY
            a.equipmentName
	</select>
	<select id="getSubSystemIndexInfoByParam" resultType="java.util.Map">
		SELECT a.subSystem                     AS subSystem,
               ROUND(avg(a.avgHealthIndex), 1) AS healthIndex
        FROM (
                 SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                        SUB_SYSTEM                     AS subSystem
                 FROM fan_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '子系统'
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		GROUP BY SUB_SYSTEM
                 UNION ALL
                 (
                     SELECT IFNULL(AVG(HEALTH_INDEX), 100) AS avgHealthIndex,
                            EQUIPMENT_NAME                 AS subSystem
                     FROM pv_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '设备'
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		GROUP BY EQUIPMENT_NAME
                 )
             ) a
        where subSystem is not null
          and subSystem != ''
        GROUP BY
            a.subSystem
	</select>
	<select id="getPointNameIndexInfoByParam" resultType="java.util.Map">
		SELECT
                ROUND(IFNULL(MAX(HEALTH_INDEX), 100), 1) AS healthIndex,
               concat(MAX(STATION), '_', INDEX_ADDRESS) as gatewayIndexAddress
        FROM fan_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '测点'
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		GROUP BY INDEX_ADDRESS
        UNION ALL
        (
            SELECT IFNULL(MAX(HEALTH_INDEX), 100)           AS healthIndex,
                   concat(MAX(STATION), '_', INDEX_ADDRESS) as gatewayIndexAddress
            FROM pv_health_index_latest_data
		<where>
			ANALYSIS_OBJ_TYPE = '测点'
			<if test="analysisType == '按天' or analysisType == null or analysisType == ''">
                AND ANALYSIS_TYPE = '按天'
                <!-- AND DATE_FORMAT(REC_DATE, '%Y-%m-%d') =  CURDATE() - INTERVAL 1 DAY -->
            </if>
			<if test="analysisType == '按小时'">
                AND ANALYSIS_TYPE = '按小时'
                <!--AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 59 MINUTE ) -->
            </if>
			<if test="analysisType == '按10分钟'">
                AND ANALYSIS_TYPE = '按10分钟'
                <!-- AND REC_DATE >= DATE_SUB( NOW(), INTERVAL 9 MINUTE ) -->

            </if>
            <if test="gatewayIds != null and gatewayIds.size() > 0"> and GATEWAY_ID in
                <foreach item="item" index="index" collection="gatewayIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
		</where>
		GROUP BY INDEX_ADDRESS
        )
	</select>
	<select id="queryIndexByArae" resultType="map">
		SELECT
            CAST(AVG(b.HEALTH_INDEX)  as SIGNED) HEALTHINDEX,
            b.REC_DATE,
            b.ANALYSIS_TIME as ANALYSISTIME
        FROM
            (
        SELECT
        ANALYSIS_TIME,
        REC_DATE,
        HEALTH_INDEX
        FROM
        `idx_biz_fan_health_index`
		<where>
			<if test='startTimeTop != null and startTimeTop != ""'>
                AND REC_DATE >= #{startTimeTop}
            </if>
			<if test='endTimeTop != null and endTimeTop != ""'>
				<![CDATA[ AND REC_DATE  <= #{endTimeTop}]]>
			</if>
			<if test='ARAE != null and ARAE != ""'>
                AND ARAE = #{ARAE}
            </if>
			<if test='ANALYSISTYPE != null and ANALYSISTYPE != ""'>
                AND ANALYSIS_TYPE = #{ANALYSISTYPE}
            </if>
		</where>
		UNION ALL
        SELECT
        ANALYSIS_TIME,
        REC_DATE,
        HEALTH_INDEX
        FROM
        `idx_biz_PV_health_index`
		<where>
			<if test=' startTimeTop != null and startTimeTop != ""'>
                AND REC_DATE >= #{startTimeTop}
            </if>
			<if test='endTimeTop != null and endTimeTop != ""'>
				<![CDATA[ AND REC_DATE  <= #{endTimeTop}]]>
			</if>
			<if test='ARAE != null and ARAE != ""'>
                AND ARAE = #{ARAE}
            </if>
			<if test='ANALYSISTYPE != null and ANALYSISTYPE !=""'>
                AND ANALYSIS_TYPE = #{ANALYSISTYPE}
            </if>
		</where>
		)b
        GROUP BY REC_DATE
	</select>
	<select id="getHealthScoreInfoByLatest" resultType="java.math.BigDecimal">
		SELECT
        round(avg( a.avgHealthIndex ), 1) AS healthIndex
        FROM
        (
        SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex
        FROM
        fan_health_index_latest_data
		<where>
            ANALYSIS_TYPE = '按10分钟'
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURDATE() - INTERVAL 1 DAY-->
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = get_time_sub(1,'DAY') -->
			<if test="areaCode != null and areaCode != ''">
                AND ARAE like concat('%', #{areaCode}, '%')
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
			<if test="stationCode != null and stationCode != ''">
                AND GATEWAY_ID = #{stationCode}
                AND ANALYSIS_OBJ_TYPE = '场站'
            </if>
			<if test="(stationCode == null or stationCode == '') and (areaCode == null or areaCode == '')">
                AND ANALYSIS_OBJ_TYPE = '片区'
            </if>
		</where>
		UNION ALL
        (
        SELECT
        IFNULL( AVG( HEALTH_INDEX ), 100 ) AS avgHealthIndex
        FROM
        pv_health_index_latest_data
		<where>
            ANALYSIS_TYPE = '按10分钟'
            <!-- AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = CURDATE() - INTERVAL 1 DAY-->
            <!--AND DATE_FORMAT( REC_DATE, '%Y-%m-%d' ) = get_time_sub(1,'DAY')-->
    <if test="areaCode != null and areaCode != ''">
        AND ARAE like concat('%', #{areaCode}, '%')
        AND ANALYSIS_OBJ_TYPE = '片区'
    </if>
    <if test="stationCode != null and stationCode != ''">
        AND GATEWAY_ID = #{stationCode}
        AND ANALYSIS_OBJ_TYPE = '场站'
    </if>
    <if test="(stationCode == null or stationCode == '') and (areaCode == null or areaCode == '')">
        AND ANALYSIS_OBJ_TYPE = '片区'
    </if>
</where>
)
) a
</select>
<!--<select id="getDateInfoBy15" resultType="java.util.Map">
SELECT
    DATE_FORMAT( DATE_ADD(( DATE( DATE_ADD(  CURDATE() - INTERVAL 1 DAY, INTERVAL - 15 DAY ))), INTERVAL @s DAY ), '%Y-%m-%d' ) AS date,
@s := @s + 1 AS `index`
FROM
    mysql.help_topic,
    ( SELECT @s := 1 ) temp
WHERE
    DATEDIFF(  CURDATE() - INTERVAL 1 DAY, DATE( DATE_ADD(  CURDATE() - INTERVAL 1 DAY, INTERVAL - 15 DAY )) ) >= @s
</select>
<select id="getDateInfo" resultType="java.util.Map">
SELECT
    DATE_FORMAT( DATE_ADD(( DATE( DATE_ADD( #{endTime}, INTERVAL - DATEDIFF( #{endTime}, #{startTime})-1 DAY ))), INTERVAL @s DAY ), '%Y-%m-%d' ) AS date,
@s := @s + 1 AS `index`
FROM
    mysql.help_topic,
    ( SELECT @s := 1 ) temp
WHERE
    DATEDIFF( #{endTime}, DATE( DATE_ADD( #{endTime}, INTERVAL - DATEDIFF( #{endTime}, #{startTime})-1 DAY )) ) >= @s
</select>
<select id="getHourInfo" resultType="java.util.Map">
SELECT
DATE_FORMAT( DATE_ADD(( DATE(#{startTime})), INTERVAL @s-1 HOUR ), '%Y-%m-%d %H:%i:%s' ) AS date,
( @s := @s + 1 )- 1 AS `index`
FROM
mysql.help_topic,
( SELECT @s := 1 ) temp
WHERE
TIMESTAMPDIFF( HOUR,  #{startTime} , #{endTime}) >= @s-1
</select>
<select id="getMomentInfo" resultType="java.util.Map">
SELECT
DATE_FORMAT( DATE_ADD(( DATE(#{startTime})), INTERVAL (@s-1)*10 MINUTE ), '%Y-%m-%d %H:%i:%s' ) AS date,
( @s := @s + 1 )- 1 AS `index`
FROM
mysql.help_topic,
( SELECT @s := 1 ) temp
WHERE
TIMESTAMPDIFF( MINUTE,  #{startTime} , #{endTime})/10 >= @s-1
 </select>-->

	<select id="getHealthIndexByIndexAddress" resultType="java.util.Map">
        select ROUND(ifnull(HEALTH_INDEX, 100.0), 1) as healthIndex,
        STATION as station
        from fan_health_index_latest_data
        where
        INDEX_ADDRESS = #{indexAddress}
          AND GATEWAY_ID = #{gatewayId}
        and ANALYSIS_OBJ_TYPE = '测点'
        and ANALYSIS_TYPE = '按天'
        limit 1
    </select>

	<select id="getHealthIndexByIndexAddressPv" resultType="java.util.Map">
        select ROUND(ifnull(HEALTH_INDEX, 100.0), 1) as healthIndex,
        STATION as station
        from pv_health_index_latest_data
        where
        INDEX_ADDRESS = #{indexAddress}
          AND GATEWAY_ID = #{gatewayId}
        and ANALYSIS_OBJ_TYPE = '测点'
        and ANALYSIS_TYPE = '按天'
        limit 1
    </select>
</mapper>
