#
18516761980
2022-03-26 f6389cceb8f63b677eec5823a86c39ce31176aa6
src/main/java/com/slcf/filter/UpdateThread.java
@@ -47,11 +47,11 @@
//   private static WaitPakInServiceImpl waitPakInService;
   @Autowired
   SapRequestLogService sapRequestLogService;
   Logger logger=Logger.getLogger(UpdateThread.class);
   public static int count=0;
   private WaitPakInService waitPakInService;
   public WaitPakInService getWaitPakInService() {
      return waitPakInService;
@@ -67,7 +67,7 @@
   public void setWaitPakOutService(WaitPakOutService waitPakOutService) {
      this.waitPakOutService = waitPakOutService;
   }
   public void run() {
      waitPakInService = getWaitPakInService();
      waitPakOutService = getWaitPakOutService();
@@ -76,14 +76,16 @@
            updateWaitPakInData(); // 入库
            sendPickPrintCmd(); // 打印
            updateWaitPakOutData(); // 出库
            // 清空2天前的日志
            sapRequestLogService.clearSapLog();
//            updateWaitCheckData();
            Thread.sleep(5000);
            Thread.sleep(15000);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }
   }
   /**
    * 处理入库通知档数据
    */
@@ -100,7 +102,7 @@
//         System.out.println(e.getMessage());
      }
   }
   /**
    * 入库完成,调用sap接口上传完成信息
    */
@@ -112,7 +114,7 @@
        String encodedPassword;
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
      try {
         encodedPassword = base.encode(input.getBytes("UTF-8"));
@@ -125,8 +127,8 @@
           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)
           {
@@ -138,7 +140,7 @@
            logInfo.setResponse("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
            logInfo.setCreate_time(new Date());
            logInfo.setType(2);
            sapRequestLogService.addSapLog(logInfo);
//            sapRequestLogService.addSapLog(logInfo);
              return result;
           }
           String[] sessionId = sessionCookie.split(";");
@@ -155,16 +157,16 @@
         logInfo.setResponse("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
         logInfo.setCreate_time(new Date());
         logInfo.setType(2);
         sapRequestLogService.addSapLog(logInfo);
//         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();
@@ -172,7 +174,7 @@
            json.put("tbnum",Long.toString(waitPakIn.getTbnum()));
            json.put("tbpos",Integer.toString(waitPakIn.getTbpos()));
            json.put("zmatid",waitPakIn.getZmatid());
            json.put("anfme",Double.toString(waitPakIn.getAnfme()));
            json.put("altme",waitPakIn.getAltme());
            json.put("nltyp","A01");
@@ -189,7 +191,7 @@
//              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);
@@ -197,7 +199,7 @@
              connection.setRequestMethod("POST");
              connection.setConnectTimeout(30000);
              connection.setReadTimeout(30000);
//              connection.setUseCaches(false);
//              connection.setUseCaches(false);
//              connection.setInstanceFollowRedirects(true);
//              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
              connection.setRequestProperty("Cookie", session_value);
@@ -207,12 +209,12 @@
              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()));
@@ -231,7 +233,7 @@
            JSONObject jsonItem = JSONObject.fromObject(Item);
            String results = jsonItem.get("results").toString();
            JSONArray array = JSONArray.fromObject(results);
            if(array.size()>0) {
               for(int i=0;i<array.size();i++){
                  JSONObject job = array.getJSONObject(i);
@@ -252,7 +254,7 @@
                     logInfo.setCreate_time(new Date());
                     logInfo.setRemark("上架完成接口:" + message);
                     logInfo.setType(1);
                     sapRequestLogService.addSapLog(logInfo);
//                     sapRequestLogService.addSapLog(logInfo);
//                  if(zstatus.equals("s")) {
                     waitPakIn.setIo_status("Y");
                     waitPakInService.upWaitPakIn(waitPakIn);
@@ -266,7 +268,7 @@
                     logInfo.setCreate_time(new Date());
                     logInfo.setRemark("上架完成接口:" + message);
                     logInfo.setType(2);
                     sapRequestLogService.addSapLog(logInfo);
//                     sapRequestLogService.addSapLog(logInfo);
                     waitPakIn.setIo_status("X");
                     waitPakIn.setMemo(message);
                     waitPakInService.upWaitPakIn(waitPakIn);
@@ -281,6 +283,7 @@
            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){
@@ -292,11 +295,12 @@
         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;
   }
   /**
    * 处理出库通知档数据
    */
@@ -312,7 +316,7 @@
         logger.error("SAP Error updateWaitPakOutData---" + e.getMessage());
      }
   }
   /**
    * 出库完成,调用sap接口上传完成信息
    */
@@ -324,7 +328,7 @@
        String encodedPassword;
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
      try {
         encodedPassword = base.encode(input.getBytes("UTF-8"));
@@ -348,13 +352,13 @@
            logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
            logInfo.setCreate_time(new Date());
            logInfo.setType(2);
            sapRequestLogService.addSapLog(logInfo);
//            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) {
@@ -366,26 +370,26 @@
         logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
         logInfo.setCreate_time(new Date());
         logInfo.setType(2);
         sapRequestLogService.addSapLog(logInfo);
//         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();
            json.put("lgnum",waitPakOut.getLgnum());
            json.put("tanum",Long.toString(waitPakOut.getTanum()));
            json.put("tapos",Integer.toString(waitPakOut.getTapos()));
            double nista =  waitPakOut.getNista();
//            if(nista>0)
            if(nista>=-1 && (int)nista!=0)
//            if(nista>0)
            if(nista>=-1 && (int)nista!=0)
            {
               double vsolm = waitPakOut.getVsolm();
               if( (int)nista == -1 ) {
@@ -415,7 +419,7 @@
//              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);
@@ -423,7 +427,7 @@
              connection.setConnectTimeout(30000);
              connection.setReadTimeout(30000);
              connection.setRequestMethod("POST");
      //        connection.setUseCaches(false);
      //        connection.setUseCaches(false);
      //        connection.setInstanceFollowRedirects(true);
//              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
              connection.setRequestProperty("Cookie", session_value);
@@ -433,12 +437,12 @@
              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()));
@@ -456,7 +460,8 @@
            JSONObject jsonItem = JSONObject.fromObject(Item);
            String results = jsonItem.get("results").toString();
            JSONArray array = JSONArray.fromObject(results);
            logger.info("出库通知档SAP返回数据集大小 ===>> " + array.size());
            if(array.size()>0) {
               for(int i=0;i<array.size();i++){
                  JSONObject job = array.getJSONObject(i);
@@ -476,7 +481,7 @@
                     logInfo.setCreate_time(new Date());
                     logInfo.setType(1);
                     logInfo.setRemark("出库完成接口:" + message);
                     sapRequestLogService.addSapLog(logInfo);
//                     sapRequestLogService.addSapLog(logInfo);
//                  if(zstatus.equals("s")) {//上报SAP成功,转历史档
                     waitPakOut.setIo_status("Y");
                     waitPakOutService.upWaitPakOut(waitPakOut,0);
@@ -490,7 +495,7 @@
                     logInfo.setCreate_time(new Date());
                     logInfo.setType(2);
                     logInfo.setRemark("出库完成接口:" + message);
                     sapRequestLogService.addSapLog(logInfo);
//                     sapRequestLogService.addSapLog(logInfo);
                     waitPakOut.setIo_status("X");
                     waitPakOut.setMemo(message);
                     waitPakOutService.upWaitPakOut(waitPakOut,0);
@@ -505,7 +510,8 @@
              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){
@@ -516,12 +522,13 @@
         waitPakOut.setIo_status("X");
         waitPakOut.setMemo(e.getMessage());
         waitPakOutService.upWaitPakOut(waitPakOut,0);
         logger.error("出库通知档回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
         logger.error("出库通知档回报异常2--"+waitPakOut.getMatnr() + "---" + e.getMessage());
         logger.error("2出库完成回报异常时ASRS请求JSON:" + jsObj.toString());
//         System.out.println(e.getMessage());
      }
      return result;
   }
   /**
    * 处理打印标签需求
    */
@@ -536,7 +543,7 @@
         logger.error("SAP Error updateWaitPakOutData---" + e.getMessage());
      }
   }
   /**
    * 拣料站,调用SAP打印标签接口,action=2
    */
@@ -548,7 +555,7 @@
        String encodedPassword;
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
      try {
//         logger.error("sendPrinCommand-----调用打印接口" + waitPakOut.getMaktx());
@@ -597,7 +604,7 @@
            connection1.disconnect();
         }
      }
      try {
//         logger.error("sendPrinCommand2-----开始调用打印接口" + waitPakOut.getMaktx());
         JSONObject jsObj = new JSONObject();
@@ -607,9 +614,9 @@
            json.put("lgnum",waitPakOut.getLgnum());
            json.put("tanum",Long.toString(waitPakOut.getTanum()));
            json.put("tapos",Integer.toString(waitPakOut.getTapos()));
            double nista =  waitPakOut.getNista();
            if(nista>0)
            if(nista>0)
            {
               double vsolm = waitPakOut.getVsolm();
               double ndifa = vsolm - nista;
@@ -632,7 +639,7 @@
//              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);
@@ -640,7 +647,7 @@
              connection.setConnectTimeout(30000);
              connection.setReadTimeout(30000);
              connection.setRequestMethod("POST");
      //        connection.setUseCaches(false);
      //        connection.setUseCaches(false);
      //        connection.setInstanceFollowRedirects(true);
//              connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
              connection.setRequestProperty("Cookie", session_value);
@@ -650,7 +657,7 @@
              connection.setRequestProperty("Content-Length","" + buffLen);
//              connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
              connection.setRequestProperty("x-csrf-token",token);
              //POST请求
              OutputStream out = connection.getOutputStream();
              out.write(buff);
@@ -756,7 +763,7 @@
      }
      return result;
   }
   /**
    * 处理盘点通知档数据
    */
@@ -764,10 +771,10 @@
      try {
//         logger.info("waitCheck:" + count++);
      }catch(Exception e) {
      }
   }
   public static void main(String[] args) {
      UpdateThread Thread1=new UpdateThread();
      Thread mThread1=new Thread(Thread1,"线程1");