package com.jiayue.ipp.idp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.ipp.common.data.entity.ForecastPowerShortTermHis;
import com.jiayue.ipp.common.data.entity.ForecastPowerUltraShortTerm;
import com.jiayue.ipp.common.data.entity.ForecastPowerUltraShortTermHis;
import com.jiayue.ipp.idp.mapper.ForecastPowerUltraShortTermHisMapper;
import com.jiayue.ipp.idp.service.ForecastPowerUltraShortTermHisService;
import org.springframework.stereotype.Service;

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

/**
 * idp_forecast_power_ultra_short_term_his
 *
 * @author whc
 * @date 2022-03-18 15:49:01
 */
@Service
public class ForecastPowerUltraShortTermHisServiceImpl extends ServiceImpl<ForecastPowerUltraShortTermHisMapper, ForecastPowerUltraShortTermHis> implements ForecastPowerUltraShortTermHisService {
    @Override
    public List<ForecastPowerUltraShortTermHis> findByStationCodeAndStartTimeAndEndTimeAndHowLongAgoAndForecastManufactor(String stationCode, Date startTime, Date endTime, Integer cdqPoint, String forecastManufactor) {
        QueryWrapper<ForecastPowerUltraShortTermHis> 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<ForecastPowerUltraShortTermHis> findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(Long startTime, Long endTime, Integer howLongAgo, String stationCode) {
        QueryWrapper<ForecastPowerUltraShortTermHis> 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<ForecastPowerUltraShortTermHis> findByForecastTimeAndStationCode(Long finalTime, String stationCode) {
        QueryWrapper<ForecastPowerUltraShortTermHis> 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);
    }
}
