/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.leaveapply.service;

import com.jeeplus.modules.workregularapply.service.WorkRegularApplyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *
 * @author ssrh
 * @version 2018-07-17
 */
@Service
@Lazy(false)
@Transactional(readOnly = true)
public class LeaveTaskService {
    @Autowired
    private LeaveApplyService leaveApplyService;
    private Logger logger = LoggerFactory.getLogger(LeaveTaskService.class);
    private static final ExecutorService threadPool = Executors.newFixedThreadPool(10);

    /* @Scheduled(cron= "0 0 2 * * ?")*/
     /*@Scheduled(cron= "0 0/1 * * * ?")*/
    public void notifyTask2() {
        logger.info("-----------凌晨2点发请假管理重置任务开始------------------");
        threadPool.execute(new Runnable() {
            @Override
            public void run() {
                leaveApplyService.resetTask();
            }
        });
        logger.info("-----------凌晨2点发请假管理重置任务结束------------------");
    }

  /* @Scheduled(cron= "0 0 3 * * ?")*/
    /*@Scheduled(cron= "0 0/3 * * * ?")*/
    public void notifyTask() {
        logger.info("-----------凌晨3点销假任务开始------------------");
        threadPool.execute(new Runnable() {
            @Override
            public void run() {
                leaveApplyService.backTask();
            }
        });
        logger.info("-----------凌晨3点销假任务结束------------------");
    }
}