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.ForecastPowerShortTermRegulation;
import com.cpp.web.mapper.station.ForecastPowerShortTermRegulationMapper;
import com.cpp.web.service.station.ForecastPowerShortTermRegulationService;
import org.springframework.stereotype.Service;

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

/**
 * cpp_forecast_power_short_term_his
 *
 * @author tl
 * @date 2024-09-23 15:28:33
 */
@Service
public class ForecastPowerShortTermRegulationServiceImpl extends ServiceImpl<ForecastPowerShortTermRegulationMapper, ForecastPowerShortTermRegulation> implements ForecastPowerShortTermRegulationService {

    @Override
    public List<ForecastPowerShortTermRegulation> findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(Long startTime, Long endTime, Integer howLongAgo, String stationCode) {
        QueryWrapper<ForecastPowerShortTermRegulation> 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 ForecastPowerShortTermRegulation findByForecastTimeAndForecastHowLongAgoAndStationCode(Long time, int howLongAgo, String stationCode) {
        QueryWrapper<ForecastPowerShortTermRegulation> wrapper = new QueryWrapper<>();

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

}
