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.idp.mapper.ForecastPowerShortTermHisMapper;
import com.jiayue.ipp.idp.service.ForecastPowerShortTermHisService;
import org.springframework.stereotype.Service;

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

/**
 * idp_forecast_power_short_term_his
 *
 * @author whc
 * @date 2022-03-18 15:48:57
 */
@Service
public class ForecastPowerShortTermHisServiceImpl extends ServiceImpl<ForecastPowerShortTermHisMapper, ForecastPowerShortTermHis> implements ForecastPowerShortTermHisService {
    @Override
    public ForecastPowerShortTermHis findByForecastTimeAndForecastHowLongAgoAndStationCodeAndForecastManufactor(Long pointEndTime, int howLongAgo, String stationCode, String forecastManufactor) {
        QueryWrapper<ForecastPowerShortTermHis> wrapper = new QueryWrapper<>();

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

    @Override
    public List<ForecastPowerShortTermHis> findByForecastTimeBetweenAndForecastHowLongAgoAndStationCodeAndForecastManufactor(Long startTime, Long endTime, Integer howLongAgo, String stationCode, String forecastManufactor) {
        QueryWrapper<ForecastPowerShortTermHis> wrapper = new QueryWrapper<>();
        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("forecast_manufactor", forecastManufactor);
        }
        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 ForecastPowerShortTermHis findByForecastTimeAndForecastHowLongAgoAndStationCode(Long time, int howLongAgo, String stationCode) {
        QueryWrapper<ForecastPowerShortTermHis> 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);
    }


    @Override
    public List<ForecastPowerShortTermHis> findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(Long startTime, Long endTime, Integer howLongAgo, String stationCode) {
        QueryWrapper<ForecastPowerShortTermHis> 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);
    }

//
//    /**
//     * 气象站数据业务层实现类
//     *
//     * @author tl
//     * @date 2022-05-11 18:07:03
//     */
//    @Service
//    public static class ForecastManufactorServiceImpl extends ServiceImpl<ForecastManufactorMapper, ForecastManufactor> implements ForecastManufactorService {
//
//    }
}
