package com.sw.mes.yb.scheduled;

import com.sw.mes.core.utils.DateUtil;
import com.sw.mes.core.utils.WbServiceUtils;
import com.sw.mes.third.service.SapWorkHourOutputService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class WorkHourScheduling {

    @Autowired
    private SapWorkHourOutputService sapWorkHourOutputService;

    @XxlJob("sapWorkHourScheduling")
    public void sapWorkHourScheduling() {
        Date nowTime = new Date();
        String sapDate = WbServiceUtils.getSapDate(nowTime);
        String sapTime = WbServiceUtils.getSapTime(nowTime);
        //当前时间字符串
        String nowStr = DateUtil.formatDate(nowTime, DateUtil.longFormat);
        String yesterdayStr = DateUtil.formatDate(DateUtil.addDay(nowTime, -1), DateUtil.longFormat);
        //一天前时间字符串
        sapWorkHourOutputService.sendWorkHour(nowStr, yesterdayStr, sapDate, sapTime, false);
    }

    @XxlJob("sapWorkHourSchedulingTest")
    public void sapWorkHourSchedulingTest() {
        Date nowTime = new Date();
        String sapDate = WbServiceUtils.getSapDate(nowTime);
        String sapTime = WbServiceUtils.getSapTime(nowTime);
        //当前时间字符串
        String nowStr = DateUtil.formatDate(nowTime, DateUtil.longFormat);
        String yesterdayStr = DateUtil.formatDate(DateUtil.addDay(nowTime, -1), DateUtil.longFormat);
        //一天前时间字符串
        sapWorkHourOutputService.sendWorkHour(nowStr, yesterdayStr, sapDate, sapTime, true);
    }
}
