package com.srs.quartz.task;

import com.srs.routine.domain.RtStuDisciplinaryApplication;
import com.srs.routine.service.IRtStuDisciplinaryApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.List;

@Component("expirationDateTask")
public class ExpirationDateTask {
    @Autowired
    IRtStuDisciplinaryApplicationService rtStuDisciplinaryApplicationService;

    public void expirationDate() {
        RtStuDisciplinaryApplication application = new RtStuDisciplinaryApplication();
        application.setPenaltyStatus(0L);
        List<RtStuDisciplinaryApplication> rtStuDisciplinaryApplications = rtStuDisciplinaryApplicationService.selectRtStuDisciplinaryApplicationList(application);
        LocalDate currentDate = LocalDate.now();
        for (RtStuDisciplinaryApplication rtStuDisciplinaryApplication : rtStuDisciplinaryApplications) {
            // 判断rtStuDisciplinaryApplication.getExpirationDate()时间，如果距离当前时间还有两周发一次通知，距离当前时间还有一周发一次，距离当前时间还有三天发一次通知
            LocalDate expirationDate = rtStuDisciplinaryApplication.getExpirationDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

            long daysUntilExpiration = ChronoUnit.DAYS.between(currentDate, expirationDate);

            if (daysUntilExpiration == 14) {
                // 发送通知 - 距离当前时间还有两周
            } else if (daysUntilExpiration == 7) {
                // 发送通知 - 距离当前时间还有一周
            } else if (daysUntilExpiration == 3) {
                // 发送通知 - 距离当前时间还有三天
            }
        }
    }

}
