package com.youchain.modules.quartz.task;

import cn.hutool.core.date.DateUtil;
import com.youchain.businessdata.inputJson.OrderInfo;
import com.youchain.businessdata.inputJson.OrderParams;
import com.youchain.businessdata.rest.MlsController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 获取送货单定时任务
 */

@Slf4j
@Service
public class orderTask {

    private final MlsController mlsController;

    @Autowired
    public orderTask(MlsController mlsController) {
        this.mlsController = mlsController;
    }

    public void orderTask() {

        Date date = new Date();
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setIfaceCode("MLS-WQ-002");
        orderInfo.setSourceSystem("WQ");

        Set invCodes = new HashSet<>();
        invCodes.add("MA2111");

        String startTime = DateUtil.format(DateUtil.beginOfDay(date), "yyyy-MM-dd HH:mm:ss");
        String endTime = DateUtil.format(DateUtil.endOfDay(date), "yyyy-MM-dd HH:mm:ss");
        OrderParams params = new OrderParams(100059, invCodes, "", startTime, endTime, 1, 100);

        orderInfo.setParams(params);

        try {
            log.info("获取送货单信息");
            mlsController.getOrderInfo(orderInfo);
        } catch (Exception e) {
            throw new RuntimeException("MLS异常信息:" + e);
        }


    }

}
