package com.byd.emg.common;
import com.byd.emg.webservice.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
@Component
public class TimerJobs {
// @Autowired
// private ZCNIFUNCLOCMD zcnifunclocmd;
// private SAPERPPMCNFUNCLOCDATASIService saperppmcnfunclocdatasiService;
// 每分钟 采集wincc1数据到table1
@Async
@Scheduled(cron="0 0/1 * * * ?")
// 每天 采集wincc1数据到table1
// @Async
// @Scheduled(cron="0 0 0 * * ?" )
public void TimeJobByDay() {
try{
SAPERPPMCNFUNCLOCDATASIService saperppmcnfunclocdatasiService =new SAPERPPMCNFUNCLOCDATASIService();
SAPERPPMCNFUNCLOCDATASI saperppmcnfunclocdatasi= saperppmcnfunclocdatasiService.getHTTPPort();
BindingProvider bindingProvider = (BindingProvider) saperppmcnfunclocdatasi;
Map<String, Object> requestContext = bindingProvider.getRequestContext();
requestContext.put("com.sun.xml.internal.ws.connection.timeout", 10 * 1000);//建立连接的超时时间为10秒
requestContext.put("com.sun.xml.internal.ws.request.timeout", 15 * 1000);//指定请求的响应超时时间为15秒
System.out.println("超时");
// saperppmcnfunclocdatasiService.wait(1200000);
ZCNIFUNCLOCMD zcnifunclocmd =new ZCNIFUNCLOCMD();
ZCNIFUNCLOCBOM zcnifunclocbom = new ZCNIFUNCLOCBOM();
ZCNIFUNCLOCTAPL zcnifuncloctapl = new ZCNIFUNCLOCTAPL();
ZCNIFUNCLOCPLKO zcnifunclocplko =new ZCNIFUNCLOCPLKO();
ZCNIFUNCLOCPLASPLPO zcnifunclocplasplpo = new ZCNIFUNCLOCPLASPLPO();
ZCNIFUNCLOCPLMZ zcnifunclocplmz =new ZCNIFUNCLOCPLMZ();
BAPIRET2 bapiret2 =new BAPIRET2();
WERKSRANG werksrang = new WERKSRANG();
werksrang.setSIGN("I"); //‘I’ - 表示包括, 'E' - 表示排除
werksrang.setOPTION("EQ");//‘EQ’为等于,仅需赋Low;'BT'为从Low到High之间
werksrang.setLOW("CN01"); //从工厂代码,如CN79表示宿迁
werksrang.setHIGH(null);//到工厂代码,如CN01
WCSTPLNR wcstplnr = new WCSTPLNR(); //功能位置号筛选
//new WCS_TPLNR { //不输表示全部功能位置
// SIGN ="I", //‘I’ - 表示包括, 'E' - 表示排除
// OPTION ="EQ", //‘EQ’为等于,仅需赋Low;'BT'为从Low到High之间
// LOW ="CN79", //从功能位置号,如CN79表示宿迁
// HIGH =null //到功能位置号,如CN01
//}
//声明同步数据的开始时间和结束时间
String I_UPDAT_END, I_UPDAT_START;
// SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
// Calendar c = Calendar.getInstance();
// c.setTime(new Date());
// Date end = c.getTime();
// I_ERDAT_END= format.format(end);//当前日期
// c.add(Calendar.DATE, -1);
// Date start = c.getTime();
// I_ERDAT_START= format.format(start);//前一天
I_UPDAT_START="20200101";
I_UPDAT_END="20200415";
System.out.println("参数完成");
ZCNFUNCLOCINFORFC zcnfunclocinforfc=new ZCNFUNCLOCINFORFC();
zcnfunclocinforfc.setIBOM("X");
zcnfunclocinforfc.setIMD("X");
zcnfunclocinforfc.setITASK("X");
zcnfunclocinforfc.setIUPDATSTART(I_UPDAT_START);
zcnfunclocinforfc.setIUPDATEND(I_UPDAT_END);
// 设置访问接口服务器的用户名和密码
BindingProvider bp = (BindingProvider) saperppmcnfunclocdatasi;
Map<String, Object> context = bp.getRequestContext();
context.put(BindingProvider.USERNAME_PROPERTY, "MDBCPIC");
context.put(BindingProvider.PASSWORD_PROPERTY, "Mdbcpi2017!");
saperppmcnfunclocdatasi.saperpPMCNFUNCLOCDATASI(zcnfunclocinforfc);
System.out.println("通过连接");
}
catch (Exception e){
System.out.println(e);
}
System.out.println("每分钟执行一次");
}
//根据传入的年月减去一天
public String subtractDay(String date) {
SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd");
String returnDate=date;
try {
Calendar rightNow = Calendar.getInstance();
Date begin_d1=df.parse(date);
rightNow.setTime(begin_d1);
rightNow.add(Calendar.DAY_OF_MONTH,-1);
returnDate=df.format(rightNow.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return returnDate;
}
//判断当前日期是否是本月的最后一天
public static boolean isLastDayOfMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DATE, (calendar.get(Calendar.DATE) + 1));
if (calendar.get(Calendar.DAY_OF_MONTH) == 1) {
return true;
}
return false;
}
}
JAVA 调用SAP接口定时读取数据存入本地数据库
最新推荐文章于 2024-09-22 16:06:13 发布