package cn.com.ctop.job.bytedance.handler;


import cn.com.ctop.oa.modules.service.IWechatCheckinDataService;
import cn.com.ctop.oa.modules.service.IWechatUserListService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.enums.NoEn;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.jeecg.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class WechatAttendanceJob {
    @Autowired
    private IWechatCheckinDataService wechatCheckinDataService;
    @Autowired
    private IWechatUserListService wechatUserInfoService;

    /**
     * 每日考勤和人员数据入库
     * 员工打卡明细表 每日凌晨2点统计前一天的考勤数据 cron:0 0 2 * * ?
     * <p>
     * 人员信息表 每日凌晨2点统计前一天的人员数据 cron:0 0 2 * * ?
     *
     * @author ZHAOXA
     */
    @XxlJob("wechatAttendanceJob")
    public void execute() throws Exception {
        XxlJobHelper.log("--------考勤和人员数据入库 start ");
        String beforeDay = DateUtils.getLastDay(DateUtils.formatDate(new Date()), NoEn.NO1.valueInt());
        //更新员工打卡明细表
        wechatCheckinDataService.getCheckinData(beforeDay + " 00:00:00", beforeDay + " 23:59:59");
        XxlJobHelper.log("--------考勤数据入库 end ");
        //更新人员信息表
        wechatUserInfoService.getUserList();
        XxlJobHelper.log("--------人员数据入库 end ");
    }
}
