package com.ruoyi.benyun.job;

import com.ruoyi.benyun.mapper.WdInfoDao;
import com.ruoyi.benyun.utils.WdRedisStoreage;
import com.ruoyi.common.annotation.Log;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;

@Slf4j
@Component
public class WriteRedisJob implements Job {

    @Autowired
    WdRedisStoreage wdRedisStoreage;

    @Autowired
    WdInfoDao wdInfoDao;

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Boolean aBoolean = redisTemplate.hasKey("4501");
        if (aBoolean){
            LocalDateTime now = LocalDateTime.now(ZoneId.of("Asia/Shanghai"));
            LocalDateTime localDateTime = now.plusDays(-1);
            log.info("开始载入redis：" + localDateTime.toString());
            wdRedisStoreage.writeWdGeoRedis1(localDateTime.toString());
        }else {
            LocalDateTime localDateTime = LocalDateTime.of(2023, 6, 1, 0,0);
            log.info("开始载入redis：" + localDateTime.toString());
            wdRedisStoreage.writeWdGeoRedis1(localDateTime.toString());
        }
    }
}
