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.DateUtils;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.module.attendance.model.vo.AttendanceSummaryQuery;
import com.mortals.xhx.module.attendance.service.AttendanceRecordErrorService;
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;

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

import static com.mortals.xhx.common.key.RedisKey.KEY_ATTENDANCE_STAT_CACHE;

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

    @Autowired
    private ICacheService cacheService;
    @Autowired
    private AttendanceRecordErrorService attendanceRecordErrorService;

    @Override
    public void excuteTask(ITask task) throws AppException {
        //考勤汇总前先自动处理前一天的异常考勤数据
        Calendar now = Calendar.getInstance();
        now.setTime(new Date());
        now.add(Calendar.DAY_OF_MONTH, -1); //默认查前一天数据
//        attendanceRecordErrorService.doAutoProcess(now.getTime());

        AttendanceSummaryQuery query = new AttendanceSummaryQuery();
        query.setSummaryTimeEnd(DateUtils.getStrDate(now.getTime()));
        now.add(Calendar.DAY_OF_MONTH, -19);
        query.setSummaryTimeStart(DateUtils.getStrDate(now.getTime()));
        //重新汇总最近20天的考勤数据
        cacheService.lpush(KEY_ATTENDANCE_STAT_CACHE,query);
    }

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

    }
}
