package com.cpp.web.service.station.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cpp.web.domain.station.ForecastPowerUltraShortTermStation;
import com.cpp.web.mapper.station.ForecastPowerUltraShortTermStationMapper;
import com.cpp.web.service.station.ForecastPowerUltraShortTermStationService;
import org.springframework.stereotype.Service;

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

/**
 * cpp_forecast_power_ultra_short_term_his
 *
 * @author tl
 * @date 2024-09-23 15:28:33
 */
@Service
public class ForecastPowerUltraShortTermStationServiceImpl extends ServiceImpl<ForecastPowerUltraShortTermStationMapper, ForecastPowerUltraShortTermStation> implements ForecastPowerUltraShortTermStationService {
    @Override
    public List<ForecastPowerUltraShortTermStation> findByStationCodeAndStartTimeAndEndTimeAndHowLongAgoAndForecastManufactor(String stationCode, Date startTime, Date endTime, Integer cdqPoint, String forecastManufactor) {
        QueryWrapper<ForecastPowerUltraShortTermStation> wrapper = new QueryWrapper<>();
        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("station_code", stationCode);
        }
        if (startTime != null && !startTime.equals("") && endTime != null && !endTime.equals("")) {
            wrapper.between("forecast_time", startTime, endTime);
        }
        if (cdqPoint != null) {
            wrapper.eq("forecast_how_long_ago", cdqPoint);
        }
        if (forecastManufactor != null) {
            wrapper.eq("forecast_manufactor", forecastManufactor);
        }
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<ForecastPowerUltraShortTermStation> findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(Long startTime, Long endTime, Integer howLongAgo, String stationCode) {
        QueryWrapper<ForecastPowerUltraShortTermStation> wrapper = new QueryWrapper<>();

        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("station_code", stationCode);
        }
        if (startTime != null && endTime != null) {
            wrapper.between("forecast_time", new Date(startTime), new Date(endTime));
        }
        wrapper.eq("forecast_how_long_ago", howLongAgo);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<ForecastPowerUltraShortTermStation> findByForecastTimeAndStationCode(Long finalTime, String stationCode) {
        QueryWrapper<ForecastPowerUltraShortTermStation> wrapper = new QueryWrapper<>();

        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("station_code", stationCode);
        }
        if (finalTime != null) {
            wrapper.eq("forecast_time", new Date(finalTime));
        }
        return baseMapper.selectList(wrapper);
    }
}
