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

import com.jeeplus.modules.workregularapply.service.WorkRegularApplyTaskService;
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.text.ParseException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**考勤Service
 * @author ssrh
 * @version 2018-07-17
 */
@Service
@Lazy(false)
@Transactional(readOnly = true)
public class WorkAttendanceTaskService {

    @Autowired
    private WorkAttendanceInfoService workAttendanceInfoService;
    private Logger logger = LoggerFactory.getLogger(WorkRegularApplyTaskService.class);
    private static final ExecutorService threadPool = Executors.newFixedThreadPool(10);

//
   /* @Scheduled(cron= "0 20 1 * * ?")*/
    public void attendanceTask() {
        logger.info("-----------员工考勤数据定时生成------------------");

        threadPool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    workAttendanceInfoService.startTask();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });
        logger.info("------------员工考勤数据任务结束------------------");
    }

    /*@Scheduled(cron= "0 40 1 * * ?")*/
    public void attendanceMonthTask() {
        logger.info("-----------员工月考勤数据定时生成------------------");

        threadPool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    workAttendanceInfoService.startMonthTask();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });
        logger.info("------------员工月考勤数据任务结束------------------");
    }
   /* @Scheduled(cron= "0 50 1 * * ?")*/
    public void attendanceMonthCountTask() {
        logger.info("-----------员工月考勤数据定时生成------------------");

        threadPool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    workAttendanceInfoService.startMonthCountTask();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });
        logger.info("------------员工月考勤数据任务结束------------------");
    }
  /*  @Scheduled(cron= "0 20 2 * * ?")*/
    public void attendanceMonthNotifyTask() {
        logger.info("-----------考勤数据推送给部门负责人定时生成------------------");

        threadPool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    workAttendanceInfoService.startMonthNotifyTask();
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });
        logger.info("------------考勤数据推送给部门负责人任务结束------------------");
    }
}