package com.cpp.web.mapper.station;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cpp.web.domain.cloud.ForecastPowerShortTermCloud;
import com.cpp.web.domain.station.ForecastPowerShortTermStation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * cpp_forecast_power_short_term_his
 *
 * @author tl
 * @date 2024-09-23 15:28:33
 */
@Mapper
public interface ForecastPowerShortTermStationMapper extends BaseMapper<ForecastPowerShortTermStation> {

    @Select("SELECT * FROM (  \n" +
            "    SELECT *,  \n" +
            "           ROW_NUMBER() OVER (PARTITION BY time ORDER BY forecast_how_long_ago ASC) as rn  \n" +
            "    FROM cpp_forecast_power_short_term_station  \n" +
            "    WHERE station_code = #{stationCode}  \n" +
            "      AND time BETWEEN #{startTime} AND #{endTime}  \n" +
            ") subquery  \n" +
            "WHERE rn = 1;")
    List<ForecastPowerShortTermStation> findByTimeBetweenAndStationCode(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("stationCode") String stationCode);

}
