#
18516761980
2021-06-21 49c6acde95bd5194634455572de0d359b6ac96d7
src/main/java/com/slcf/filter/UpdateThread.java
@@ -105,15 +105,21 @@
        String encodedPassword;
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
      try {
         encodedPassword = base.encode(input.getBytes("UTF-8"));
         URL url1 = new URL(httpUrl);
           HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection();
           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)
           {
@@ -126,7 +132,12 @@
//           Map<String, List<String>> map = connection1.getHeaderFields();
//           token = map.get("x-csrf-token").toString();
      } catch (Exception e1) {
         e1.printStackTrace();
         logger.error("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
//         e1.printStackTrace();
      }finally {
         if(connection1!=null){
            connection1.disconnect();
         }
      }
        
      try {
@@ -150,16 +161,19 @@
         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);
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
              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");
@@ -227,6 +241,10 @@
            waitPakInService.upWaitPakIn(waitPakIn);
              logger.error("SAP Error sendPakInStatus--"+waitPakIn.getMatnr()+"---" + e.getMessage());
//            System.out.println(e.getMessage());
         }finally {
            if(connection!=null){
               connection.disconnect();
            }
         }
      }catch (Exception e) {
         waitPakIn.setIo_status("X");
@@ -265,12 +283,16 @@
        String encodedPassword;
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
      try {
         encodedPassword = base.encode(input.getBytes("UTF-8"));
         URL url1 = new URL(httpUrl);
           HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection();
           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");
@@ -283,10 +305,16 @@
           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) {
         e1.printStackTrace();
         logger.error("调用下架完成接口,get请求获取cookie失败" + e1.getMessage());
//         e1.printStackTrace();
      }finally{
         if(connection1!=null){
            connection1.disconnect();
         }
      }
        
      try {
@@ -325,15 +353,18 @@
         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);
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
              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);
@@ -401,6 +432,10 @@
            waitPakOutService.upWaitPakOut(waitPakOut,0);
              logger.error("出库通知档回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
//            System.out.println(e.getMessage());
         }finally{
            if(connection!=null){
               connection.disconnect();
            }
         }
      }catch (Exception e) {
         waitPakOut.setIo_status("X");
@@ -438,13 +473,17 @@
        String encodedPassword;
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
      try {
//         logger.error("TQS-----调用打印接口" + waitPakOut.getMaktx());
//         logger.error("sendPrinCommand-----调用打印接口" + waitPakOut.getMaktx());
         encodedPassword = base.encode(input.getBytes("UTF-8"));
         URL url1 = new URL(httpUrl);
           HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection();
           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");
@@ -460,12 +499,16 @@
//           Map<String, List<String>> map = connection1.getHeaderFields();
//           token = map.get("x-csrf-token").toString();
      } catch (Exception e1) {
         logger.error("TQS1-----调用打印接口" + waitPakOut.getMaktx());
         logger.error("sendPrinCommand1-----调用打印接口请求cookie失败" + waitPakOut.getMaktx() + e1.getMessage());
         e1.printStackTrace();
      }finally{
         if(connection1!=null){
            connection1.disconnect();
         }
      }
        
      try {
         logger.error("TQS2-----调用打印接口" + waitPakOut.getMaktx());
//         logger.error("sendPrinCommand2-----开始调用打印接口" + waitPakOut.getMaktx());
         JSONObject jsObj = new JSONObject();
         JSONArray arr = new JSONArray();
         for(int i=0;i<1;i++) {
@@ -493,15 +536,18 @@
         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);
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
              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);
@@ -518,7 +564,7 @@
              OutputStream out = connection.getOutputStream();
              out.write(buff);
            out.close();
            logger.error("TQS3-----调用打印接口" + waitPakOut.getMaktx());
//            logger.error("sendPrinCommand3-----调用打印接口" + waitPakOut.getMaktx());
              //读取响应
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                      connection.getInputStream()));
@@ -536,7 +582,7 @@
            JSONObject jsonItem = JSONObject.fromObject(Item);
            String results = jsonItem.get("results").toString();
            JSONArray array = JSONArray.fromObject(results);
            logger.error("TQS4-----调用打印接口" + waitPakOut.getMaktx());
            logger.error("sendPrinCommand4-----调用打印接口" + waitPakOut.getMaktx());
            if(array.size()>0) {
               for(int i=0;i<array.size();i++){
                  JSONObject job = array.getJSONObject(i);
@@ -552,11 +598,12 @@
                     waitPakOut.setAction(1);     //模式变为1单独确认
                     waitPakOut.setPrnstatus(2);  //打印完成
                     waitPakOutService.upWaitPakOut(waitPakOut,0);
//                     logger.error("调用打印接口成功,请求json数据--" + jsObj.toString());
                     logger.error("sendPrinCommand5---调用打印接口成功,请求json数据--" + jsObj.toString());
                  }else if(zstatus.equals("e")) {//上报SAP失败,更新io_status=X
                     waitPakOut.setPrnstatus(3);    //打印失败
                     waitPakOut.setMemo(message);
                     waitPakOutService.upWaitPakOut(waitPakOut,0);
                     logger.error("sendPrinCommand6---调用打印接口失败,请求json数据--" + message);
                  }
               }
            }
@@ -565,14 +612,18 @@
              waitPakOut.setPrnstatus(3);    //打印失败
            waitPakOut.setMemo(e.getMessage());
            waitPakOutService.upWaitPakOut(waitPakOut,0);
              logger.error("调用打印接口回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
              logger.error("sendPrinCommand7---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
//            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("调用打印接口回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
         logger.error("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
//         System.out.println(e.getMessage());
      }
      return result;