package com.ssj.task;

import com.ssj.framework.core.util.SystemResourceLocator;
import com.ssj.service.weixin.library.service.ILibBorrowHisService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

@DisallowConcurrentExecution
@Component
public class ReadLastFiveDayTask implements Job {

    private static Logger logger = LoggerFactory.getLogger(ReadLastFiveDayTask.class);

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        try {
            logger.info("每月倒数第五天推送提醒给家长");
            Date date = new Date();
            Calendar ca = Calendar.getInstance();
            ca.setTime(date);
            int days = ca.get(Calendar.DAY_OF_MONTH);
            int lastDay = ca.getActualMaximum(Calendar.DAY_OF_MONTH);
            //第五天
            if(lastDay-days==4){
                ILibBorrowHisService hisService = SystemResourceLocator.getBean(ILibBorrowHisService.class);
                hisService.pushReadNoticeToUser();
            }

        } catch (Exception e) {
            logger.error("每月倒数第五天推送提醒给家长异常-->"+e.getMessage());
        }finally{
            logger.info("每月倒数第五天推送提醒给家长结束");
        }

    }

    public static void main(String[] args) {
        Date date = new Date();
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        int days = ca.get(Calendar.DAY_OF_MONTH);
        int lastDay = ca.getActualMaximum(Calendar.DAY_OF_MONTH);
        System.out.println(lastDay-days);
    }
}
