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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cpp.web.domain.accuracy.AccuracyPassRate;
import com.cpp.web.domain.enums.DataSourcesEnum;
import com.cpp.web.domain.enums.ForecastTypeEnum;
import com.cpp.web.mapper.accuracy.AccuracyPassRateMapper;
import com.cpp.web.service.accuracy.AccuracyPassRateService;
import org.springframework.stereotype.Service;

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

/**
 * idp_forecast_power_short_term
 *
 * @author tl
 * @date 2024-09-23 15:28:33
 */
@Service
public class AccuracyPassRateServiceImpl extends ServiceImpl<AccuracyPassRateMapper, AccuracyPassRate> implements AccuracyPassRateService {


    @Override
    public List<AccuracyPassRate> findByTimeBetweenAndForecastTypeAndDataSourcesAndAgoAndForecastModelAndStationCode(Date startTime, Date endTime, ForecastTypeEnum forecastType, DataSourcesEnum dataSources, Integer ago, String forecastModel, String stationCode) {
        QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("station_code", stationCode);
        }
        if (startTime != null && endTime != null) {
            wrapper.between("time", startTime, endTime);
        }
        if (forecastType != null && !forecastType.equals("")) {
            wrapper.eq("forecast_type", forecastType);
        }
        if (dataSources != null && !dataSources.equals("")) {
            wrapper.eq("data_sources", dataSources);
        }
        if (forecastModel != null && !forecastModel.equals("")) {
            wrapper.eq("forecast_model", forecastModel);
        }
        if (ago != null && !ago.equals("")) {
            wrapper.eq("forecast_how_long_ago", ago);
        }
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<AccuracyPassRate> findByTimeBetweenAndStationCode(Date startTime, Date endTime, String stationCode) {
        QueryWrapper<AccuracyPassRate> wrapper = new QueryWrapper<>();
        if (null != startTime && null != endTime){
            wrapper.between("time",startTime,endTime);
        }
        if (null != stationCode && !"".equals(stationCode)){
            wrapper.eq("station_code",stationCode);
        }
        wrapper.eq("data_sources","E2");
        wrapper.eq("forecast_how_long_ago",1);
        return list(wrapper);
    }
}
