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


    <select id="getMonthPowerint"  resultType="com.yeejoin.amos.boot.module.hygf.api.entity.MonthPower">
        SELECT
        avg(power)  power,
        third_station_id thirdStationId
        FROM house_pv_data.td_hygf_jp_station_power_history where  created_time <![CDATA[>=]]> today()-1d-8h and   created_time <![CDATA[<]]> today()-8h  GROUP BY third_station_id
    </select>


    <select id="getSumMonthPower"  resultType="com.yeejoin.amos.boot.module.hygf.api.entity.YearPower">
        SELECT
        sum(power)  power,
        tation_id thirdStationId
        FROM house_pv_data.td_hygf_month_power where   year_month=#{date}  GROUP BY tation_id
    </select>

    <select id="getSumYearPower"  resultType="com.yeejoin.amos.boot.module.hygf.api.entity.AllPower">
        SELECT
        sum(power)  power,
        tation_id thirdStationId
        FROM house_pv_data.td_hygf_year_power where   year=#{date}  GROUP BY tation_id
    </select>



    <select id="getDayPower"  resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerCurveDto">
        SELECT
        sum(power)num,
        `time` date
        FROM house_pv_data.td_hygf_jp_station_power_history where third_station_id in
        <foreach collection="dto" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
         and `time` <![CDATA[>=]]> #{startTime} and   `time` <![CDATA[<]]> #{endTime}
        GROUP BY `time`
     </select>


    <select id="getMonthPower"  resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerCurveDto">
        SELECT
        sum(power)num,
        `day` date
        FROM house_pv_data.td_hygf_month_power where tation_id in
        <foreach collection="dto" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        and year_month = #{date}
        GROUP BY `day`
    </select>
    <select id="getYearPower"  resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerCurveDto">
        SELECT
        sum(power)num,
        `month` date
        FROM house_pv_data.td_hygf_year_power where tation_id in
        <foreach collection="dto" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        and `year` = #{date}
        GROUP BY `month`
    </select>
    <select id="getAllPower"  resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerCurveDto">
        SELECT
        sum(power)num,
        `year` date
        FROM house_pv_data.td_hygf_all_power where tation_id in
        <foreach collection="dto" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        GROUP BY `year`
    </select>

    <select id="getDayPowercount"  resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerCurveDto">
        SELECT
        sum(power)num,
        `hour` date
        FROM house_pv_data.td_hygf_day_power

        <where>
            <if test="dto!=null">
                tation_id in
                <foreach collection="dto" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>

            <if test="thirdStationId!=null and thirdStationId != ''">
                and tation_id = #{thirdStationId}
            </if>
        </where>




        and year_month_day = #{date}
        GROUP BY `hour`
    </select>



</mapper>
