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.domain.station.ForecastPowerShortTermSend;
import com.cpp.web.mapper.station.ForecastPowerShortTermRegulationMapper;
import com.cpp.web.mapper.station.ForecastPowerShortTermSendMapper;
import com.cpp.web.service.station.ForecastPowerShortTermRegulationService;
import com.cpp.web.service.station.ForecastPowerShortTermSendService;
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 ForecastPowerShortTermSendServiceImpl extends ServiceImpl<ForecastPowerShortTermSendMapper, ForecastPowerShortTermSend> implements ForecastPowerShortTermSendService {

    @Override
    public List<ForecastPowerShortTermSend> findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(Long startTime, Long endTime, Integer howLongAgo, String stationCode) {
        QueryWrapper<ForecastPowerShortTermSend> 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));
        }
        if (howLongAgo != -99){
            wrapper.eq("forecast_how_long_ago", howLongAgo);
        }
        return baseMapper.selectList(wrapper);
    }

    @Override
    public ForecastPowerShortTermSend findByForecastTimeAndForecastHowLongAgoAndStationCode(Long time, int howLongAgo, String stationCode) {
        QueryWrapper<ForecastPowerShortTermSend> wrapper = new QueryWrapper<>();

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

}
