package com.jiayue.insu.incloud.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.insu.incloud.entity.ForecastData;
import com.jiayue.insu.incloud.mapper.ForecastDataMapper;
import com.jiayue.insu.incloud.service.ForecastDataService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 预测数据业务实现
 *
 * @author yh
 * @version 1.0
 * @since 2022/5/22 11:29
 */
@Service
public class ForecastDataServiceImpl extends ServiceImpl<ForecastDataMapper, ForecastData> implements ForecastDataService {

    /**
     * 删除数据 通过场站编码和时间
     * @param station 场站编码
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 结果
     */
    @Override
    public boolean removeBetweenTimeByStation(String station, Long startTime, Long endTime) {
        LambdaQueryWrapper<ForecastData> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.between(ForecastData::getForecastTime,startTime, endTime);
        lambdaQueryWrapper.eq(ForecastData::getStationCode,station);
        this.remove(lambdaQueryWrapper);
        return Boolean.TRUE;
    }

    /**
     * 查询数据 通过场站编码和时间
     * @param station 场站编码
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 结果
     */
    @Override
    public List<ForecastData> findTimeByStation(String station, Long startTime, Long endTime) {
        LambdaQueryWrapper<ForecastData> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.between(ForecastData::getForecastTime,startTime, endTime);
        lambdaQueryWrapper.eq(ForecastData::getStationCode,station);
        return this.list(lambdaQueryWrapper);
    }


    @Override
    public List<ForecastData> findInitTimeByStation(LocalDateTime initTime,String stationCode) {
        LambdaQueryWrapper<ForecastData> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ForecastData::getInitTime,initTime);
        lambdaQueryWrapper.eq(ForecastData::getStationCode,stationCode);
        return this.list(lambdaQueryWrapper);
    }

    @Override
    public List<ForecastData> findByInitTimeAndStationCodeAndForecastTimeBetween(LocalDateTime initTime, String stationCode, Long startTime, Long endTime) {
        LambdaQueryWrapper<ForecastData> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ForecastData::getInitTime,initTime);
        lambdaQueryWrapper.eq(ForecastData::getStationCode,stationCode);
        lambdaQueryWrapper.between(ForecastData::getForecastTime,startTime,endTime);
        return this.list(lambdaQueryWrapper);
    }

    @Override
    public List<ForecastData> findByInitTimeAndStationCode(LocalDateTime initTime, String stationCode) {
        LambdaQueryWrapper<ForecastData> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ForecastData::getInitTime,initTime);
        lambdaQueryWrapper.eq(ForecastData::getStationCode,stationCode);
        return this.list(lambdaQueryWrapper);
    }
}
