package com.lutao.cloud.oil.runner;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lutao.cloud.oil.service.AtmosphereMonitorInfoService;
import com.lutao.entity.AtmosphereMonitorInfo;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

@Component
public class RemoveAtmosphereMonitorInfoExecutor {

    @Resource
    private AtmosphereMonitorInfoService atmosphereMonitorInfoService;

    /**
     * 删除气象信息旧数据
     */
    @Scheduled(cron = "0 0 3 * * ?")
    public void execute() {
        // 获取当前的 LocalDateTime
        LocalDateTime now = LocalDateTime.now();
        // 设置时间部分为当天的最小时间
        LocalDateTime startOfDay = now.with(LocalTime.MIN);
        LocalDateTime minus = startOfDay.minusDays(1);

        //删除前一天以前的数据
        atmosphereMonitorInfoService.remove(Wrappers.lambdaQuery(AtmosphereMonitorInfo.class)
                .lt(AtmosphereMonitorInfo::getCreateTime, minus));
    }
}
