package com.base.track.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.orbit.utils.DateUtils;
import com.base.track.mapper.AstronomicalForecastMapper;
import com.base.track.model.entity.AstronomicalForecast;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AstronomicalForecastService extends ServiceImpl<AstronomicalForecastMapper, AstronomicalForecast> {

    /**
     * 查询指定星、指定站和指定时间范围内日凌的天文事件信息
     *
     * @param satelliteIdList 卫星id
     * @param stationIdList   地面站id
     * @param startTime       开始时间
     * @param endTime         结束时间
     * @return
     */
    public List<AstronomicalForecast> getAstronomicalForecastList(List<String> satelliteIdList, List<String> stationIdList, String startTime, String endTime, String astroEvent) {
        QueryWrapper<AstronomicalForecast> queryWrapper = new QueryWrapper<>();
        if (!satelliteIdList.isEmpty())
            queryWrapper.in("satellite_id", satelliteIdList);
        if (!stationIdList.isEmpty())
            queryWrapper.in("station_id", stationIdList);
        if (startTime!=null){
            queryWrapper.ge("start_time", DateUtils.string2LocalDateTime(startTime, DateUtils.YYYY_MM_DD_HH_MM_SS));
        }
        if (endTime!=null){
            queryWrapper.le("end_time", DateUtils.string2LocalDateTime(endTime, DateUtils.YYYY_MM_DD_HH_MM_SS));
        }
        if (astroEvent!=null){
            queryWrapper.eq("astro_event", astroEvent);
        }
        return list(queryWrapper);
    }

    public void deleteAstronomicalForecastList(List<String> satelliteIdList, List<String> stationIdList, String startTime, String endTime) {
        QueryWrapper<AstronomicalForecast> queryWrapper = new QueryWrapper<>();
        if (!satelliteIdList.isEmpty())
            queryWrapper.in("satellite_id", satelliteIdList);
        if (!stationIdList.isEmpty())
            queryWrapper.in("station_id", stationIdList);
        queryWrapper.ge("start_time", DateUtils.string2LocalDateTime(startTime, DateUtils.YYYY_MM_DD_HH_MM_SS));
        queryWrapper.le("end_time", DateUtils.string2LocalDateTime(endTime, DateUtils.YYYY_MM_DD_HH_MM_SS));
        remove(queryWrapper);
    }

}
