package org.fouram.service;

import org.fouram.core.util.DateUtil;
import org.fouram.core.util.LoggerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CheckTaskService {
	
	@Autowired
	private WxUserService wxUserService;
	@Autowired
	private WxDepartService wxDepartService;
	@Autowired
	private SapCheckService sapCheckService;
	@Autowired
	private SapCheckdateService sapCheckdateService;
	@Autowired
	private SapCheckOptionService sapCheckOptionService;
	@Autowired
	private SapEmployeeTimeService employeeTimeService;
	@Autowired
	private SapApprovalInfoService sapApprovalInfoService;

	public void executeBiz(String checkinDay) {
		if(DateUtil.getHour().equals("10") || DateUtil.getHour().equals("20")) {
			String startDay = checkinDay;
			String endDay = checkinDay;
			try {
				wxDepartService.saveDeparts();
				wxUserService.saveUsers();
				sapCheckService.saveCheckInOffOuts(startDay, endDay);
				// 判断打卡记录小于10条记录认为是假期
				if(sapCheckService.queryCheckInTotal() < 10) {
					return;
				}
				sapCheckdateService.saveCheckout(startDay);
				employeeTimeService.saveEmployeeTimes();
				sapCheckOptionService.saveOptions(endDay);
				sapApprovalInfoService.saveApprovalInfos(endDay.substring(0, 7));
				sapCheckService.saveReportResultData(startDay, endDay);
			} catch (Exception e) {
				LoggerUtil.error(e);
			}
		}
	}
}
