package com.mortals.xhx.daemon.task;

import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.module.attendance.service.AttendanceStatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 考勤汇总
 */
@Slf4j
@Service("AttendanceSummaryTask")
public class AttendanceSummaryTaskImpl  implements ITaskExcuteService {

    @Autowired
    private AttendanceStatService attendanceStatService;
    @Autowired
    private ICacheService cacheService;

    private static String SUMMARY_TASK_KEY ="attendanceSummaryTask:run";

    @Override
    public void excuteTask(ITask task) throws AppException {
        try {
            String verify = cacheService.get(SUMMARY_TASK_KEY);
            if(StringUtils.isNotEmpty(verify)&&verify.equals("true")){
                Thread.sleep(600*1000);
            }
            cacheService.set(SUMMARY_TASK_KEY,"true",600);
            attendanceStatService.doAttendanceSummary(null);
            cacheService.expire(SUMMARY_TASK_KEY,1);
        }catch (Exception e){

        }

    }

    @Override
    public void stopTask(ITask task) throws AppException {

    }
}
