package org.jeecg.modules.sapScheduledTask;

import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.util.InterfaceConnUtils;
import org.jeecg.modules.fbsInventory.service.IFbsInventoryService;
import org.jeecg.modules.fbsMomOrder.service.IFbsMomOrderService;
import org.jeecg.modules.pulldate.entity.PullDate;
import org.jeecg.modules.pulldate.service.IPullDateService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 功能描述：定时获取SAP生产订单
 *
 * @Author: chenchuang
 * @Date: 2022/1/20 21:05
 */
@Transactional
public class SAPPull implements Job {
    @Autowired
    IFbsMomOrderService iFbsMomOrderService;
    @Autowired
    IFbsInventoryService iFbsInventoryService;
    @Autowired
    IPullDateService iPullDateService;

    public static boolean  jobIsRuning=false;

    public static boolean  getJobIsRuningFlag(){
        return jobIsRuning;
    }

    public static boolean setJobIsRuningFlag(){
        jobIsRuning =true;
        return jobIsRuning;
    }

    public static void removeJobIsRuningFlag(){
        jobIsRuning =false;
    }
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        System.out.println("6666666666666666");
//        String a="{ \"TIMELIMIT\": { \"ST\": 20220118000000, \"ET\": 20220118240000 }, \"COMMON_INFO_REQ\": { \"API_NO\": \"KANB00001\", \"GUID\": \"1234567890\", \"USERID\": \"USERNAME\" } } ";
        if(getJobIsRuningFlag()){
            return;
        }
        setJobIsRuningFlag();
        try {
            iFbsInventoryService.implementSAPPull();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            removeJobIsRuningFlag();
        }
        //生产订单
//        iFbsMomOrderService.getPullSapMomOrderAll();
        //存货档案
//        iFbsInventoryService.addSAPInventory();
        //库存存量(全量获取)
//        iFbsInventoryService.addSAPCurrentStock();
        //产成品主子表
//        iFbsInventoryService.addSAPRdrecord10MainAndItems();
        //供应商
//        iFbsInventoryService.addSAPVendor();
        //采购订单
//        iFbsInventoryService.addSAPPO_PoMainAndItems();
        //采购到货
//        iFbsInventoryService.addSAPPuArrivalvouch();
        //领料单
//          iFbsInventoryService.addSAPMaterialappvouchMainAndItem();
        //检验单
//        iFbsInventoryService.addSAPQMCHECKVOUCHER();
        //销售出库
//        iFbsInventoryService.addSAPRdrecord32MainAndItem();
    }

}
