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.SapGrService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class GrScheduling {
    @Autowired
    private SapGrService sapGrService;

    @XxlJob("sapGrScheduling")
    public void sapGrScheduling() {
        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);
        //一天前时间字符串
        sapGrService.sendGr(nowStr, yesterdayStr, sapDate, sapTime, false);
    }

    @XxlJob("sapGrSchedulingTest")
    public void sapGrSchedulingTest() {
        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);
        //一天前时间字符串
        sapGrService.sendGr(nowStr, yesterdayStr, sapDate, sapTime,true);
    }
}
