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.ForecastPowerUltraShortTermRegulation;
import com.cpp.web.mapper.station.ForecastPowerUltraShortTermRegulationMapper;
import com.cpp.web.service.station.ForecastPowerUltraShortTermRegulationService;
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 ForecastPowerUltraShortTermRegulationServiceImpl extends ServiceImpl<ForecastPowerUltraShortTermRegulationMapper, ForecastPowerUltraShortTermRegulation> implements ForecastPowerUltraShortTermRegulationService {

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

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

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

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

    @Override
    public List<ForecastPowerUltraShortTermRegulation> findByForecastTimeBetweenAndHowLongAgo(Date startTime, Date endTime, Integer howLongAgo) {
        QueryWrapper<ForecastPowerUltraShortTermRegulation> wrapper = new QueryWrapper<>();

        if (startTime != null && endTime != null) {
            wrapper.between("time", startTime, endTime);
        }
        wrapper.eq("forecast_how_long_ago", howLongAgo);
        return baseMapper.selectList(wrapper);
    }
}
