<?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.TemporaryDataMapper">



    <select id="timingTemporarysSorageData" resultType="map">

        SELECT ROUND( sum(value),2)as value ,
        created_time as createdTime ,
        equipmentIndexName
        FROM
        `temporary_data`
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                gatewayId in( ${gatewayId})
            </if>
            <if test="gatewayId == null or gatewayId == ''">
                equipmentNumber is not null and  equipmentIndexName is not null
            </if>
            AND equipmentIndexName='有功功率'
        </where>
        GROUP BY created_time ,equipmentIndexName;
    </select>


    <select id="getStatisticsInfo" resultType="map">
        SELECT
            avg( VALUE ) AS mean,
            ( SELECT created_time FROM temporary_data WHERE
        equipmentIndexName =#{equipmentIndexName}
        <if test="gatewayId != null and gatewayId != ''">
            and   gatewayId = #{gatewayId}
        </if>
         ORDER BY `value` LIMIT 1 ) AS minTime,
	        max( `value` ) AS max,
	     ( SELECT created_time FROM temporary_data WHERE
        equipmentIndexName =#{equipmentIndexName}
        <if test="gatewayId != null and gatewayId != ''">
            and   gatewayId = #{gatewayId}
        </if> ORDER BY `value` DESC LIMIT 1 ) AS maxTime,
	      min( `value` ) AS min
        FROM
            `temporary_data`
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                gatewayId = #{gatewayId}  and equipmentIndexName =#{equipmentIndexName}
            </if>
            <if test="gatewayId == null or gatewayId == ''">
                equipmentNumber is not null and  equipmentIndexName is not null and equipmentIndexName =#{equipmentIndexName}
            </if>
        </where>
    </select>


    <select id="getAllData" resultType="com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESWindSpeed">
        SELECT
           *
        FROM
            `temporary_data`

    </select>


    <select id="getStationWindSpeedStatistics" resultType="map">
        SELECT avg(value) as value ,
        created_time as createdTime ,
        equipmentIndexName
        FROM
        `temporary_data`
        <where>
            <if test="gatewayId != null and gatewayId != ''">
                and gatewayId = #{gatewayId}
            </if>
            <if test="gatewayId == null or gatewayId == ''">
                and equipmentNumber is not null and  equipmentIndexName is not null
            </if>
            <if test="equipmentIndexName != null and equipmentIndexName != ''">
                and equipmentIndexName = #{equipmentIndexName}
            </if>
        </where>
        GROUP BY batch_no ,equipmentIndexName;
    </select>
</mapper>
