#
18516761980
2022-08-31 a5ee5055f053cbb4f13710fc251adbd780f3a43f
src/main/java/com/slcf/filter/UpdateThread.java
@@ -1,16 +1,21 @@
package com.slcf.filter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSON;
import com.slcf.pojo.SapRequestLogBean;
import com.slcf.service.SapRequestLogService;
import com.slcf.util.HttpHandler;
import net.sf.json.JSONString;
import org.activiti.engine.impl.transformer.IntegerToString;
import org.apache.log4j.Logger;
@@ -67,24 +72,61 @@
   public void setWaitPakOutService(WaitPakOutService waitPakOutService) {
      this.waitPakOutService = waitPakOutService;
   }
   public static boolean updateFlag = true;
   public void run() {
      waitPakInService = getWaitPakInService();
      waitPakOutService = getWaitPakOutService();
      while(true) {
         try {
            if(!updateFlag) return;
            updateFlag = false;
            updateWaitPakInData(); // 入库
            sendPickPrintCmd(); // 打印
            updateWaitPakOutData(); // 出库
            updateWaitPakOutData1(); // 出库
//            sendPickPrintCmd(); // 打印
//            updateWaitPakOutData(); // 出库
            // 清空2天前的日志
            sapRequestLogService.clearSapLog();
//            updateWaitCheckData();
            Thread.sleep(15000);
         } catch (InterruptedException e) {
            e.printStackTrace();
         } finally {
            updateFlag = true;
         }
      }
   }
    public JSONObject requestSAP(JSONObject body, String url) {
      logger.info(url);
        JSONObject resp;
      HashMap<String, Object> requestHeader = new HashMap<>();
      requestHeader.put("Accept", "application/json");
      requestHeader.put("Content-Type", "application/json");
      requestHeader.put("X-Requested-With", "X");
      requestHeader.put("Authorization","Basic TElRSTpzdGFydDEu");
      requestHeader.put("sap-client","100");
        String s = null;
        try {
            s = new HttpHandler.Builder()
                    .setUri(url)
                    .setJson(body.toString())
               .setTimeout(20, TimeUnit.SECONDS)
                    .setHeaders(requestHeader)
                    .build()
                    .doPost();
        } catch (IOException e) {
         logger.error("SAP请求接口失败=URL==>>" + body.toString());
           logger.error("SAP请求接口失败=JSON==>>" + body.toString());
         logger.error("SAP请求接口失败=JSON==>>" + e.getMessage());
            throw new RuntimeException(e);
        }
        resp = JSONObject.fromObject(s);
      logger.info("返回体:" + resp);
        return resp;
    }
   /**
    * 处理入库通知档数据
@@ -94,7 +136,7 @@
//         logger.info("waitIn:" + count++);
         WaitPakInBean waitPakInBean = waitPakInService.queryWaitPakInFnh();
         if(waitPakInBean!=null) {
            String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_SRV/AsrsTrSet";
            String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_DW_SRV/AsrsTrSet";
            int result = sendPakInStatus(httpUrl,waitPakInBean);
         }
      }catch(Exception e) {
@@ -115,58 +157,58 @@
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
//        HttpURLConnection connection1 = null;
//      try {
//         encodedPassword = base.encode(input.getBytes("UTF-8"));
//         URL url1 = new URL(httpUrl);
//           connection1 = (HttpURLConnection) url1.openConnection();
//           connection1.setDoOutput(true);
//           connection1.setDoInput(true);
//           connection1.setConnectTimeout(30000);
//           connection1.setReadTimeout(30000);
//           connection1.setRequestMethod("GET");
//           connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
//           connection1.setRequestProperty("x-csrf-token","Fetch");
//
//
//           String sessionCookie = connection1.getHeaderField("Set-Cookie");
//           if(sessionCookie==null || sessionCookie.length()<1)
//           {
//              logger.error("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
//            // SAP INFO-----调用上架完成接口,日志记录
//            SapRequestLogBean logInfo = new SapRequestLogBean();
//            logInfo.setMatnr(waitPakIn.getMatnr());
//            logInfo.setRequest("获取cookie失败,cookie值:" + sessionCookie);
//            logInfo.setResponse("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
//            logInfo.setCreate_time(new Date());
//            logInfo.setType(2);
////            sapRequestLogService.addSapLog(logInfo);
//              return result;
//           }
//           String[] sessionId = sessionCookie.split(";");
//           session_value = sessionId[0];
//           token = connection1.getHeaderField("x-csrf-token");
////           Map<String, List<String>> map = connection1.getHeaderFields();
////           token = map.get("x-csrf-token").toString();
//      } catch (Exception e1) {
//         logger.error("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
//         // SAP INFO-----调用上架完成接口,日志记录
//         SapRequestLogBean logInfo = new SapRequestLogBean();
//         logInfo.setMatnr(waitPakIn.getMatnr());
//         logInfo.setRequest("获取cookie失败");
//         logInfo.setResponse("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
//         logInfo.setCreate_time(new Date());
//         logInfo.setType(2);
////         sapRequestLogService.addSapLog(logInfo);
////         e1.printStackTrace();
//      }finally {
//         if(connection1!=null){
//            connection1.disconnect();
//         }
//      }
      JSONObject jsObj = new JSONObject();
      try {
         encodedPassword = base.encode(input.getBytes("UTF-8"));
         URL url1 = new URL(httpUrl);
           connection1 = (HttpURLConnection) url1.openConnection();
           connection1.setDoOutput(true);
           connection1.setDoInput(true);
           connection1.setConnectTimeout(30000);
           connection1.setReadTimeout(30000);
           connection1.setRequestMethod("GET");
           connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
           connection1.setRequestProperty("x-csrf-token","Fetch");
           String sessionCookie = connection1.getHeaderField("Set-Cookie");
           if(sessionCookie==null || sessionCookie.length()<1)
           {
              logger.error("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
            // SAP INFO-----调用上架完成接口,日志记录
            SapRequestLogBean logInfo = new SapRequestLogBean();
            logInfo.setMatnr(waitPakIn.getMatnr());
            logInfo.setRequest("获取cookie失败,cookie值:" + sessionCookie);
            logInfo.setResponse("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
            logInfo.setCreate_time(new Date());
            logInfo.setType(2);
//            sapRequestLogService.addSapLog(logInfo);
              return result;
           }
           String[] sessionId = sessionCookie.split(";");
           session_value = sessionId[0];
           token = connection1.getHeaderField("x-csrf-token");
//           Map<String, List<String>> map = connection1.getHeaderFields();
//           token = map.get("x-csrf-token").toString();
      } catch (Exception e1) {
         logger.error("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
         // SAP INFO-----调用上架完成接口,日志记录
         SapRequestLogBean logInfo = new SapRequestLogBean();
         logInfo.setMatnr(waitPakIn.getMatnr());
         logInfo.setRequest("获取cookie失败");
         logInfo.setResponse("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
         logInfo.setCreate_time(new Date());
         logInfo.setType(2);
//         sapRequestLogService.addSapLog(logInfo);
//         e1.printStackTrace();
      }finally {
         if(connection1!=null){
            connection1.disconnect();
         }
      }
      try {
         JSONObject jsObj = new JSONObject();
         JSONArray arr = new JSONArray();
         for(int i=0;i<1;i++) {
            JSONObject json = new JSONObject();
@@ -185,48 +227,50 @@
         jsObj.put("item", arr);
         byte[] buff = jsObj.toString().getBytes();
         int buffLen = buff.length;
         //创建连接
         HttpURLConnection connection = null;
           try {
//              String input = "ZHANGX:654321";
//               BASE64Encoder base = new BASE64Encoder();
//               String encodedPassword = base.encode(input.getBytes("UTF-8"));
            JSONObject json = requestSAP(jsObj, httpUrl);
              URL url = new URL(httpUrl);
              connection = (HttpURLConnection) url.openConnection();
              connection.setDoOutput(true);
              connection.setDoInput(true);
              connection.setRequestMethod("POST");
              connection.setConnectTimeout(30000);
              connection.setReadTimeout(30000);
//              connection.setUseCaches(false);
//              connection.setInstanceFollowRedirects(true);
//              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
              connection.setRequestProperty("Cookie", session_value);
              connection.setRequestProperty("Content-Type","application/json");
              connection.setRequestProperty("Accept","application/json");
              connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
              connection.setRequestProperty("Content-Length","" + buffLen);
//              connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
              connection.setRequestProperty("x-csrf-token",token);
              //POST请求
              OutputStream out = connection.getOutputStream();
              out.write(buff);
            out.close();
              //读取响应
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                      connection.getInputStream()));
              String lines;
              StringBuffer sb = new StringBuffer("");
              while ((lines = reader.readLine()) != null) {
                  lines = new String(lines.getBytes(), "utf-8");
                  sb.append(lines);
              }
            //创建连接
//         HttpURLConnection connection = null;
//           try {
////              String input = "ZHANGX:654321";
////               BASE64Encoder base = new BASE64Encoder();
////               String encodedPassword = base.encode(input.getBytes("UTF-8"));
//
//              URL url = new URL(httpUrl);
//              connection = (HttpURLConnection) url.openConnection();
//              connection.setDoOutput(true);
//              connection.setDoInput(true);
//              connection.setRequestMethod("POST");
//              connection.setConnectTimeout(30000);
//              connection.setReadTimeout(30000);
////              connection.setUseCaches(false);
////              connection.setInstanceFollowRedirects(true);
////              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
//              connection.setRequestProperty("Cookie", session_value);
//              connection.setRequestProperty("Content-Type","application/json");
//              connection.setRequestProperty("Accept","application/json");
//              connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
//              connection.setRequestProperty("Content-Length","" + buffLen);
////              connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
//              connection.setRequestProperty("x-csrf-token",token);
//
//              //POST请求
//              OutputStream out = connection.getOutputStream();
//              out.write(buff);
//            out.close();
//
//              //读取响应
//              BufferedReader reader = new BufferedReader(new InputStreamReader(
//                      connection.getInputStream()));
//              String lines;
//              StringBuffer sb = new StringBuffer("");
//              while ((lines = reader.readLine()) != null) {
//                  lines = new String(lines.getBytes(), "utf-8");
//                  sb.append(lines);
//              }
//              logger.error("SAP INFO-----调用上架完成接口,返回JSON数据:" + sb.toString());
//              System.out.println(sb.toString());
              JSONObject json = JSONObject.fromObject(sb.toString());
//              JSONObject json = JSONObject.fromObject(sb.toString());
            String d = json.get("d").toString();
            JSONObject jsonD = JSONObject.fromObject(d);
            String Item = jsonD.get("item").toString();
@@ -250,7 +294,7 @@
                     SapRequestLogBean logInfo = new SapRequestLogBean();
                     logInfo.setMatnr(waitPakIn.getMatnr());
                     logInfo.setRequest(jsObj.toString());
                     logInfo.setResponse(sb.toString());
                     logInfo.setResponse(json.toString());
                     logInfo.setCreate_time(new Date());
                     logInfo.setRemark("上架完成接口:" + message);
                     logInfo.setType(1);
@@ -264,7 +308,7 @@
                     SapRequestLogBean logInfo = new SapRequestLogBean();
                     logInfo.setMatnr(waitPakIn.getMatnr());
                     logInfo.setRequest(jsObj.toString());
                     logInfo.setResponse(sb.toString());
                     logInfo.setResponse(json.toString());
                     logInfo.setCreate_time(new Date());
                     logInfo.setRemark("上架完成接口:" + message);
                     logInfo.setType(2);
@@ -283,20 +327,35 @@
            waitPakIn.setMemo(e.getMessage());
            waitPakInService.upWaitPakIn(waitPakIn);
              logger.error("SAP Error sendPakInStatus--"+waitPakIn.getMatnr()+"---" + e.getMessage());
            logger.error("1入库完成回报异常时ASRS请求JSON:" + jsObj.toString());
//            System.out.println(e.getMessage());
         }finally {
            if(connection!=null){
               connection.disconnect();
            }
         }
      }catch (Exception e) {
         waitPakIn.setIo_status("X");
         waitPakIn.setMemo(e.getMessage());
         waitPakInService.upWaitPakIn(waitPakIn);
         logger.error("SAP Error sendPakInStatus--"+waitPakIn.getMatnr()+"---" + e.getMessage());
//         System.out.println(e.getMessage());
      }
//      }catch (Exception e) {
//         waitPakIn.setIo_status("X");
//         waitPakIn.setMemo(e.getMessage());
//         waitPakInService.upWaitPakIn(waitPakIn);
//         logger.error("SAP Error sendPakInStatus--"+waitPakIn.getMatnr()+"---" + e.getMessage());
//         logger.error("2入库完成回报异常时ASRS请求JSON:" + jsObj.toString());
////         System.out.println(e.getMessage());
//      }
      return result;
   }
   /**
    * 处理出库通知档数据
    */
   private void updateWaitPakOutData1() {
      try {
//         logger.info("waitOut:" + count++);
         WaitPakOutBean waitPakOutBean = waitPakOutService.queryWaitPakOutFnh();
         if(waitPakOutBean!=null) {
            waitPakOutBean.setIo_status("Y");
//            waitPakOutService.upWaitPakOut(waitPakOutBean,0);
            waitPakOutService.moveToLog(waitPakOutBean);
         }
      }catch(Exception e) {
         logger.error("SAP Error updateWaitPakOutData---" + e.getMessage());
      }
   }
   /**
@@ -307,7 +366,7 @@
//         logger.info("waitOut:" + count++);
         WaitPakOutBean waitPakOutBean = waitPakOutService.queryWaitPakOutFnh();
         if(waitPakOutBean!=null) {
            String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_SRV/ToConHeadSet";
            String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_DW_SRV/ToConHeadSet";
            int result = sendPakOutStatus(httpUrl,waitPakOutBean);
         }
      }catch(Exception e) {
@@ -327,57 +386,57 @@
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
      try {
         encodedPassword = base.encode(input.getBytes("UTF-8"));
         URL url1 = new URL(httpUrl);
           connection1 = (HttpURLConnection) url1.openConnection();
           connection1.setDoOutput(true);
           connection1.setDoInput(true);
           connection1.setConnectTimeout(30000);
           connection1.setReadTimeout(30000);
           connection1.setRequestMethod("GET");
           connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
           connection1.setRequestProperty("x-csrf-token","Fetch");
           String sessionCookie = connection1.getHeaderField("Set-Cookie");
           if(sessionCookie==null || sessionCookie.length()<1)
           {
              logger.error("调用下架完成接口,get请求获取cookie失败");
            // SAP INFO-----调用上架完成接口,日志记录
            SapRequestLogBean logInfo = new SapRequestLogBean();
            logInfo.setMatnr(waitPakOut.getMatnr());
            logInfo.setRequest("获取cookie值失败,cookie:" + sessionCookie);
            logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
            logInfo.setCreate_time(new Date());
            logInfo.setType(2);
//            sapRequestLogService.addSapLog(logInfo);
              return result;
           }
           String[] sessionId = sessionCookie.split(";");
           session_value = sessionId[0];
           token = connection1.getHeaderField("x-csrf-token");
//        HttpURLConnection connection1 = null;
//      try {
//         encodedPassword = base.encode(input.getBytes("UTF-8"));
//         URL url1 = new URL(httpUrl);
//           connection1 = (HttpURLConnection) url1.openConnection();
//           connection1.setDoOutput(true);
//           connection1.setDoInput(true);
//           connection1.setConnectTimeout(30000);
//           connection1.setReadTimeout(30000);
//           connection1.setRequestMethod("GET");
//           connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
//           connection1.setRequestProperty("x-csrf-token","Fetch");
//           String sessionCookie = connection1.getHeaderField("Set-Cookie");
//           if(sessionCookie==null || sessionCookie.length()<1)
//           {
//              logger.error("调用下架完成接口,get请求获取cookie失败");
//            // SAP INFO-----调用上架完成接口,日志记录
//            SapRequestLogBean logInfo = new SapRequestLogBean();
//            logInfo.setMatnr(waitPakOut.getMatnr());
//            logInfo.setRequest("获取cookie值失败,cookie:" + sessionCookie);
//            logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
//            logInfo.setCreate_time(new Date());
//            logInfo.setType(2);
////            sapRequestLogService.addSapLog(logInfo);
//              return result;
//           }
//           String[] sessionId = sessionCookie.split(";");
//           session_value = sessionId[0];
//           token = connection1.getHeaderField("x-csrf-token");
//
////           Map<String, List<String>> map = connection1.getHeaderFields();
////           token = map.get("x-csrf-token").toString();
//      } catch (Exception e1) {
//         logger.error("调用下架完成接口,get请求获取cookie失败" + e1.getMessage());
//         // SAP INFO-----调用上架完成接口,日志记录
//         SapRequestLogBean logInfo = new SapRequestLogBean();
//         logInfo.setMatnr(waitPakOut.getMatnr());
//         logInfo.setRequest("获取cookie失败");
//         logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
//         logInfo.setCreate_time(new Date());
//         logInfo.setType(2);
////         sapRequestLogService.addSapLog(logInfo);
////         e1.printStackTrace();
//      }finally{
//         if(connection1!=null){
//            connection1.disconnect();
//         }
//      }
//           Map<String, List<String>> map = connection1.getHeaderFields();
//           token = map.get("x-csrf-token").toString();
      } catch (Exception e1) {
         logger.error("调用下架完成接口,get请求获取cookie失败" + e1.getMessage());
         // SAP INFO-----调用上架完成接口,日志记录
         SapRequestLogBean logInfo = new SapRequestLogBean();
         logInfo.setMatnr(waitPakOut.getMatnr());
         logInfo.setRequest("获取cookie失败");
         logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
         logInfo.setCreate_time(new Date());
         logInfo.setType(2);
//         sapRequestLogService.addSapLog(logInfo);
//         e1.printStackTrace();
      }finally{
         if(connection1!=null){
            connection1.disconnect();
         }
      }
      JSONObject jsObj = new JSONObject();
      try {
         JSONObject jsObj = new JSONObject();
         JSONArray arr = new JSONArray();
         for(int i=0;i<1;i++) {
            JSONObject json = new JSONObject();
@@ -403,55 +462,56 @@
            json.put("arbpl","A01-01");
            arr.add(json);
         }
         int action = 3;
         if(waitPakOut.getAction()==1 && waitPakOut.getPrnstatus()==2) {
            action = 1;
         int action = 1;
         if (waitPakOut.getAction() == 3){
            action = waitPakOut.getAction();
         }
         jsObj.put("trart", Integer.toString(action));
         jsObj.put("item", arr);
         byte[] buff = jsObj.toString().getBytes();
         int buffLen = buff.length;
         //创建连接
         HttpURLConnection connection = null;
           try {
//              String input = "ZHANGX:654321";
//               BASE64Encoder base = new BASE64Encoder();
//               String encodedPassword = base.encode(input.getBytes("UTF-8"));
              URL url = new URL(httpUrl);
              connection = (HttpURLConnection) url.openConnection();
              connection.setDoOutput(true);
              connection.setDoInput(true);
              connection.setConnectTimeout(30000);
              connection.setReadTimeout(30000);
              connection.setRequestMethod("POST");
      //        connection.setUseCaches(false);
      //        connection.setInstanceFollowRedirects(true);
//              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
              connection.setRequestProperty("Cookie", session_value);
              connection.setRequestProperty("Content-Type","application/json");
              connection.setRequestProperty("Accept","application/json");
              connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
              connection.setRequestProperty("Content-Length","" + buffLen);
//              connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
              connection.setRequestProperty("x-csrf-token",token);
              //POST请求
              OutputStream out = connection.getOutputStream();
              out.write(buff);
            out.close();
              //读取响应
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                      connection.getInputStream()));
              String lines;
              StringBuffer sb = new StringBuffer("");
              while ((lines = reader.readLine()) != null) {
                  lines = new String(lines.getBytes(), "utf-8");
                  sb.append(lines);
              }
//         HttpURLConnection connection = null;
//           try {
////              String input = "ZHANGX:654321";
////               BASE64Encoder base = new BASE64Encoder();
////               String encodedPassword = base.encode(input.getBytes("UTF-8"));
//
//              URL url = new URL(httpUrl);
//              connection = (HttpURLConnection) url.openConnection();
//              connection.setDoOutput(true);
//              connection.setDoInput(true);
//              connection.setConnectTimeout(30000);
//              connection.setReadTimeout(30000);
//              connection.setRequestMethod("POST");
//      //        connection.setUseCaches(false);
//      //        connection.setInstanceFollowRedirects(true);
////              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
//              connection.setRequestProperty("Cookie", session_value);
//              connection.setRequestProperty("Content-Type","application/json");
//              connection.setRequestProperty("Accept","application/json");
//              connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
//              connection.setRequestProperty("Content-Length","" + buffLen);
////              connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
//              connection.setRequestProperty("x-csrf-token",token);
//
//              //POST请求
//              OutputStream out = connection.getOutputStream();
//              out.write(buff);
//            out.close();
//
//              //读取响应
//              BufferedReader reader = new BufferedReader(new InputStreamReader(
//                      connection.getInputStream()));
//              String lines;
//              StringBuffer sb = new StringBuffer("");
//              while ((lines = reader.readLine()) != null) {
//                  lines = new String(lines.getBytes(), "utf-8");
//                  sb.append(lines);
//              }
//              System.out.println(sb.toString());
              JSONObject json = JSONObject.fromObject(sb.toString());
                JSONObject json = requestSAP(jsObj, httpUrl);
//              JSONObject json = JSONObject.fromObject(sb.toString());
            String d = json.get("d").toString();
            JSONObject jsonD = JSONObject.fromObject(d);
            String Item = jsonD.get("item").toString();
@@ -475,7 +535,7 @@
                     SapRequestLogBean logInfo = new SapRequestLogBean();
                     logInfo.setMatnr(waitPakOut.getMatnr());
                     logInfo.setRequest(jsObj.toString());
                     logInfo.setResponse(sb.toString());
                     logInfo.setResponse(json.toString());
                     logInfo.setCreate_time(new Date());
                     logInfo.setType(1);
                     logInfo.setRemark("出库完成接口:" + message);
@@ -489,7 +549,7 @@
                     SapRequestLogBean logInfo = new SapRequestLogBean();
                     logInfo.setMatnr(waitPakOut.getMatnr());
                     logInfo.setRequest(jsObj.toString());
                     logInfo.setResponse(sb.toString());
                     logInfo.setResponse(json.toString());
                     logInfo.setCreate_time(new Date());
                     logInfo.setType(2);
                     logInfo.setRemark("出库完成接口:" + message);
@@ -508,20 +568,18 @@
              waitPakOut.setIo_status("X");
            waitPakOut.setMemo(e.getMessage());
            waitPakOutService.upWaitPakOut(waitPakOut,0);
              logger.error("出库通知档回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
              logger.error("出库通知档回报异常1--"+waitPakOut.getMatnr() + "---" + e.getMessage());
              logger.error("1出库完成回报异常时ASRS请求JSON:" + jsObj.toString());
//            System.out.println(e.getMessage());
         }finally{
            if(connection!=null){
               connection.disconnect();
            }
         }
      }catch (Exception e) {
         waitPakOut.setIo_status("X");
         waitPakOut.setMemo(e.getMessage());
         waitPakOutService.upWaitPakOut(waitPakOut,0);
         logger.error("出库通知档回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
//         System.out.println(e.getMessage());
      }
//      }catch (Exception e) {
//         waitPakOut.setIo_status("X");
//         waitPakOut.setMemo(e.getMessage());
//         waitPakOutService.upWaitPakOut(waitPakOut,0);
//         logger.error("出库通知档回报异常2--"+waitPakOut.getMatnr() + "---" + e.getMessage());
//         logger.error("2出库完成回报异常时ASRS请求JSON:" + jsObj.toString());
////         System.out.println(e.getMessage());
//      }
      return result;
   }
@@ -532,7 +590,7 @@
      try {
         WaitPakOutBean waitPakOutBean = waitPakOutService.getWaitPakOutPrint();
         if(waitPakOutBean!=null) {
            String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_SRV/ToConHeadSet";
            String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_DW_SRV/ToConHeadSet";
            int result = sendPrinCommand(httpUrl,waitPakOutBean);
         }
      }catch(Exception e) {
@@ -551,58 +609,58 @@
        String encodedPassword;
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
      try {
//         logger.error("sendPrinCommand-----调用打印接口" + waitPakOut.getMaktx());
         encodedPassword = base.encode(input.getBytes("UTF-8"));
         URL url1 = new URL(httpUrl);
           connection1 = (HttpURLConnection) url1.openConnection();
           connection1.setDoOutput(true);
           connection1.setDoInput(true);
           connection1.setConnectTimeout(30000);
           connection1.setReadTimeout(30000);
           connection1.setRequestMethod("GET");
           connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
           connection1.setRequestProperty("x-csrf-token","Fetch");
           String sessionCookie = connection1.getHeaderField("Set-Cookie");
           if(sessionCookie==null || sessionCookie.length()<1)
           {
              logger.error("调用打印接口,get请求获取cookie失败");
              // 调用sap打印接口,记录日志
            SapRequestLogBean logInfo = new SapRequestLogBean();
            logInfo.setMatnr(waitPakOut.getMatnr());
            logInfo.setRequest("调用打印接口,get请求获取cookie失败");
            logInfo.setResponse(sessionCookie);
            logInfo.setCreate_time(new Date());
            logInfo.setType(2);
            sapRequestLogService.addSapLog(logInfo);
              return result;
           }
           String[] sessionId = sessionCookie.split(";");
           session_value = sessionId[0];
           token = connection1.getHeaderField("x-csrf-token");
//           Map<String, List<String>> map = connection1.getHeaderFields();
//           token = map.get("x-csrf-token").toString();
      } catch (Exception e1) {
         logger.error("sendPrinCommand1-----调用打印接口请求cookie失败" + waitPakOut.getMaktx() + e1.getMessage());
         // 调用sap打印接口,记录日志
         SapRequestLogBean logInfo = new SapRequestLogBean();
         logInfo.setMatnr(waitPakOut.getMatnr());
         logInfo.setRequest("sendPrinCommand1-----调用打印接口请求cookie失败"  + waitPakOut.getMaktx());
         logInfo.setResponse(e1.getMessage());
         logInfo.setCreate_time(new Date());
         logInfo.setType(2);
         sapRequestLogService.addSapLog(logInfo);
         e1.printStackTrace();
      }finally{
         if(connection1!=null){
            connection1.disconnect();
         }
      }
//
//        HttpURLConnection connection1 = null;
//      try {
////         logger.error("sendPrinCommand-----调用打印接口" + waitPakOut.getMaktx());
//         encodedPassword = base.encode(input.getBytes("UTF-8"));
//         URL url1 = new URL(httpUrl);
//           connection1 = (HttpURLConnection) url1.openConnection();
//           connection1.setDoOutput(true);
//           connection1.setDoInput(true);
//           connection1.setConnectTimeout(30000);
//           connection1.setReadTimeout(30000);
//           connection1.setRequestMethod("GET");
//           connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
//           connection1.setRequestProperty("x-csrf-token","Fetch");
//           String sessionCookie = connection1.getHeaderField("Set-Cookie");
//           if(sessionCookie==null || sessionCookie.length()<1)
//           {
//              logger.error("调用打印接口,get请求获取cookie失败");
//              // 调用sap打印接口,记录日志
//            SapRequestLogBean logInfo = new SapRequestLogBean();
//            logInfo.setMatnr(waitPakOut.getMatnr());
//            logInfo.setRequest("调用打印接口,get请求获取cookie失败");
//            logInfo.setResponse(sessionCookie);
//            logInfo.setCreate_time(new Date());
//            logInfo.setType(2);
//            sapRequestLogService.addSapLog(logInfo);
//              return result;
//           }
//           String[] sessionId = sessionCookie.split(";");
//           session_value = sessionId[0];
//           token = connection1.getHeaderField("x-csrf-token");
////           Map<String, List<String>> map = connection1.getHeaderFields();
////           token = map.get("x-csrf-token").toString();
//      } catch (Exception e1) {
//         logger.error("sendPrinCommand1-----调用打印接口请求cookie失败" + waitPakOut.getMaktx() + e1.getMessage());
//         // 调用sap打印接口,记录日志
//         SapRequestLogBean logInfo = new SapRequestLogBean();
//         logInfo.setMatnr(waitPakOut.getMatnr());
//         logInfo.setRequest("sendPrinCommand1-----调用打印接口请求cookie失败"  + waitPakOut.getMaktx());
//         logInfo.setResponse(e1.getMessage());
//         logInfo.setCreate_time(new Date());
//         logInfo.setType(2);
//         sapRequestLogService.addSapLog(logInfo);
//         e1.printStackTrace();
//      }finally{
//         if(connection1!=null){
//            connection1.disconnect();
//         }
//      }
      try {
//         logger.error("sendPrinCommand2-----开始调用打印接口" + waitPakOut.getMaktx());
         logger.error("sendPrinCommand2-----开始调用打印接口" + waitPakOut.getMatnr() + "--" + waitPakOut.getMaktx());
         JSONObject jsObj = new JSONObject();
         JSONArray arr = new JSONArray();
         for(int i=0;i<1;i++) {
@@ -630,53 +688,56 @@
         byte[] buff = jsObj.toString().getBytes();
         int buffLen = buff.length;
         //创建连接
         HttpURLConnection connection = null;
           try {
//              String input = "ZHANGX:654321";
//               BASE64Encoder base = new BASE64Encoder();
//               String encodedPassword = base.encode(input.getBytes("UTF-8"));
              URL url = new URL(httpUrl);
              connection = (HttpURLConnection) url.openConnection();
              connection.setDoOutput(true);
              connection.setDoInput(true);
              connection.setConnectTimeout(30000);
              connection.setReadTimeout(30000);
              connection.setRequestMethod("POST");
      //        connection.setUseCaches(false);
      //        connection.setInstanceFollowRedirects(true);
//              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
              connection.setRequestProperty("Cookie", session_value);
              connection.setRequestProperty("Content-Type","application/json");
              connection.setRequestProperty("Accept","application/json");
              connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
              connection.setRequestProperty("Content-Length","" + buffLen);
//              connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
              connection.setRequestProperty("x-csrf-token",token);
              //POST请求
              OutputStream out = connection.getOutputStream();
              out.write(buff);
            out.close();
//            logger.error("sendPrinCommand3-----调用打印接口" + waitPakOut.getMaktx());
              //读取响应
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                      connection.getInputStream()));
              String lines;
              StringBuffer sb = new StringBuffer("");
              while ((lines = reader.readLine()) != null) {
                  lines = new String(lines.getBytes(), "utf-8");
                  sb.append(lines);
              }
//              System.out.println(sb.toString());
              JSONObject json = JSONObject.fromObject(sb.toString());
//         HttpURLConnection connection = null;
//           try {
////              String input = "ZHANGX:654321";
////               BASE64Encoder base = new BASE64Encoder();
////               String encodedPassword = base.encode(input.getBytes("UTF-8"));
//
//              URL url = new URL(httpUrl);
//              connection = (HttpURLConnection) url.openConnection();
//              connection.setDoOutput(true);
//              connection.setDoInput(true);
//              connection.setConnectTimeout(30000);
//              connection.setReadTimeout(30000);
//              connection.setRequestMethod("POST");
//      //        connection.setUseCaches(false);
//      //        connection.setInstanceFollowRedirects(true);
////              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
//              connection.setRequestProperty("Cookie", session_value);
//              connection.setRequestProperty("Content-Type","application/json");
//              connection.setRequestProperty("Accept","application/json");
//              connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
//              connection.setRequestProperty("Content-Length","" + buffLen);
////              connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
//              connection.setRequestProperty("x-csrf-token",token);
//
//              //POST请求
//              OutputStream out = connection.getOutputStream();
//              out.write(buff);
//            out.close();
////            logger.error("sendPrinCommand3-----调用打印接口" + waitPakOut.getMaktx());
//              //读取响应
//              BufferedReader reader = new BufferedReader(new InputStreamReader(
//                      connection.getInputStream()));
//              String lines;
//              StringBuffer sb = new StringBuffer("");
//              while ((lines = reader.readLine()) != null) {
//                  lines = new String(lines.getBytes(), "utf-8");
//                  sb.append(lines);
//              }
////              System.out.println(sb.toString());
//              JSONObject json = JSONObject.fromObject(sb.toString());
            logger.error("sendPrinCommand4-----调用打印接口" + waitPakOut.getTanum() + "==" + waitPakOut.getMatnr() + "==" + waitPakOut.getMaktx());
                JSONObject json = requestSAP(jsObj, httpUrl);
            logger.error("sendPrinCommand44-----打印接口SAP返回数据===>>" + json.toString());
            String d = json.get("d").toString();
            JSONObject jsonD = JSONObject.fromObject(d);
            String Item = jsonD.get("item").toString();
            JSONObject jsonItem = JSONObject.fromObject(Item);
            String results = jsonItem.get("results").toString();
            JSONArray array = JSONArray.fromObject(results);
            logger.error("sendPrinCommand4-----调用打印接口" + waitPakOut.getMaktx());
            if(array.size()>0) {
               for(int i=0;i<array.size();i++){
                  JSONObject job = array.getJSONObject(i);
@@ -693,12 +754,12 @@
                     waitPakOut.setPrnstatus(2);  //打印完成
                     waitPakOutService.upWaitPakOut(waitPakOut,0);
                     logger.error("sendPrinCommand5---调用打印接口成功,请求json数据--" + jsObj.toString());
                     logger.info("sendPrinCommand5---调用打印接口成功,返回json数据--" + sb.toString());
                     logger.info("sendPrinCommand5---调用打印接口成功,返回json数据--" + json.toString());
                     // 调用sap打印接口,记录日志
                     SapRequestLogBean logInfo = new SapRequestLogBean();
                     logInfo.setMatnr(waitPakOut.getMatnr());
                     logInfo.setRequest(jsObj.toString());
                     logInfo.setResponse(sb.toString());
                     logInfo.setResponse(json.toString());
                     logInfo.setCreate_time(new Date());
                     logInfo.setRemark(message);
                     logInfo.setType(1);
@@ -712,7 +773,7 @@
                     SapRequestLogBean logInfo = new SapRequestLogBean();
                     logInfo.setMatnr(waitPakOut.getMatnr());
                     logInfo.setRequest(jsObj.toString());
                     logInfo.setResponse(sb.toString());
                     logInfo.setResponse(json.toString());
                     logInfo.setCreate_time(new Date());
                     logInfo.setRemark(message);
                     logInfo.setType(2);
@@ -729,34 +790,30 @@
            // 调用sap打印接口,记录日志
            SapRequestLogBean logInfo = new SapRequestLogBean();
            logInfo.setMatnr(waitPakOut.getMatnr());
            logInfo.setRequest(jsObj.toString());
//            logInfo.setRequest(jsObj.toString());
            logInfo.setResponse("sendPrinCommand7---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---");
            logInfo.setCreate_time(new Date());
            logInfo.setRemark(e.getMessage());
            logInfo.setType(2);
            sapRequestLogService.addSapLog(logInfo);
//            System.out.println(e.getMessage());
         }finally{
            if(connection!=null){
               connection.disconnect();
            }
         }
      }catch (Exception e) {
         waitPakOut.setPrnstatus(3);    //打印失败
         waitPakOut.setMemo(e.getMessage());
         waitPakOutService.upWaitPakOut(waitPakOut,0);
         logger.error("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
         // 调用sap打印接口,记录日志
         SapRequestLogBean logInfo = new SapRequestLogBean();
         logInfo.setMatnr(waitPakOut.getMatnr());
         logInfo.setRequest("打印请求失败");
         logInfo.setResponse("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---");
         logInfo.setCreate_time(new Date());
         logInfo.setRemark(e.getMessage());
         logInfo.setType(2);
         sapRequestLogService.addSapLog(logInfo);
//         System.out.println(e.getMessage());
      }
//      }catch (Exception e) {
//         waitPakOut.setPrnstatus(3);    //打印失败
//         waitPakOut.setMemo(e.getMessage());
//         waitPakOutService.upWaitPakOut(waitPakOut,0);
//         logger.error("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
//         // 调用sap打印接口,记录日志
//         SapRequestLogBean logInfo = new SapRequestLogBean();
//         logInfo.setMatnr(waitPakOut.getMatnr());
//         logInfo.setRequest("打印请求失败");
//         logInfo.setResponse("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---");
//         logInfo.setCreate_time(new Date());
//         logInfo.setRemark(e.getMessage());
//         logInfo.setType(2);
//         sapRequestLogService.addSapLog(logInfo);
////         System.out.println(e.getMessage());
//      }
      return result;
   }