package com.mortals.xhx.daemon.task;

import cn.hutool.core.date.DateUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.common.code.StaffSatusEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.attendance.model.*;
import com.mortals.xhx.module.attendance.service.*;
import com.mortals.xhx.module.holiday.model.HolidayEntity;
import com.mortals.xhx.module.holiday.model.HolidayQuery;
import com.mortals.xhx.module.holiday.service.HolidayService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 定时计算当天全缺席人员
 */
@Slf4j
@Service("CalculateDayAttendTask")
public class CalculateDayAttendTaskImpl implements ITaskExcuteService {

    @Autowired
    private AttendanceRecordHikService recordHikService;
    @Autowired
    private AttendanceRecordService attendanceRecordService;
    @Autowired
    private AttendanceRecordDetailService attendanceRecordDetailService;


    @Override
    public void excuteTask(ITask task) throws AppException {
        //查询当日考勤记录，查询未考勤人员，构造一条假记录方便计算
        try {
            //清除当天考勤记录缓存
            //attendanceRecordDetailService.loadCache();

            AttendanceRecordHikQuery recordHikQuery = new AttendanceRecordHikQuery();
            recordHikQuery.setAttendanceDateStart(DateUtil.today());
            recordHikQuery.setAttendanceDateEnd(DateUtil.today());
            recordHikQuery.setAttendanceDateStart(DateUtil.today());
            recordHikQuery.setAttendanceDateEnd(DateUtil.today());
            recordHikService.buildAllCustomHikRecord(recordHikQuery, null);
        } catch (Exception e) {

        }

        int delCount = attendanceRecordService.getDao().deleteDuplicateRecord();

        log.info("删除重复记录条数：{}", delCount);

        //初始化添加考勤记录到每个人


    }


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

    }
}
