Sfoglia il codice sorgente

Merge branch 'linshi订单同步捕获异常' into prd

njs 2 anni fa
parent
commit
750c17b555

+ 232 - 51
suishenbang-sync/suishenbang-sync-common/src/main/java/com/dgtly/sync/service/HanaOrderComponent.java

@@ -366,13 +366,13 @@ public class HanaOrderComponent {
             Long endTime = System.currentTimeMillis();
             log.info("生成salesOrder-TXT用时:" + (endTime - startTime) + "毫秒");
 
-            conn = getMysqlConnection();
+            //conn = getMysqlConnection();
             //测试表
 //            String sql = "TRUNCATE TABLE sap_hana_sales_order";
             //生产表
-            String sql = "TRUNCATE TABLE meta_hana_sales_order";
+            /*String sql = "TRUNCATE TABLE meta_hana_sales_order";
             pstm = conn.prepareStatement(sql);
-            pstm.execute();
+            pstm.execute();*/
         }catch (Exception e){
             e.printStackTrace();
         }finally {
@@ -397,6 +397,20 @@ public class HanaOrderComponent {
         return j;
     }
 
+    /**HANA已复核线下月底手动过账的交货单仍需自提同步*/
+    public void hanaSelfReviewedDeliverOrderSync() throws Exception{
+        Connection con = this.getHanaConnection();
+        PreparedStatement pstmt = con.prepareStatement("SELECT MANDT,VBELN,DATUM from ERP.ZSDT_POST_IN_ADV where DATUM >= TO_CHAR(add_months(CURRENT_DATE ,-3),'YYYYMMDD')and DATUM<= TO_CHAR(CURRENT_DATE,'YYYYMMDD')");
+
+        Long startTime = System.currentTimeMillis();
+        ResultSet rs = pstmt.executeQuery();
+        Long endTime = System.currentTimeMillis();
+        log.info("DeliverOrder查询用时:" + (endTime - startTime)+"毫秒");
+        this.createSelfReviewedDeliverOrderTxt(rs);
+        this.runLoadSelfReviewedDeliverOrder();
+        this.closeConnection(con, pstmt);
+    }
+
     public void hanaDeliverOrderSync() throws Exception {
         Connection con = this.getHanaConnection();
         PreparedStatement pstmt = con.prepareStatement("SELECT\n" +
@@ -545,6 +559,91 @@ public class HanaOrderComponent {
         this.closeConnection(con, pstmt);
 
     }*/
+    private int createSelfReviewedDeliverOrderTxt(ResultSet result)throws Exception{
+        File file = null;
+        FileWriter fw = null;
+        Connection conn = null;
+        PreparedStatement pstm =null;
+        int j =0;
+        try {
+            long i =0;
+
+            //创建IO需求的条件,并声明输出路径
+            file = new File((Global.getTemdataPath()+"selfDeliverOrder/"));
+            log.info("selfDeliverOrder数据缓存路径:" + Global.getTemdataPath()+"selfDeliverOrder/");
+            if(!file.exists()){
+                file.mkdir();
+            }
+
+            file = new File(Global.getTemdataPath()+"selfDeliverOrder/"+j+".txt");
+            if(!file.exists()){
+                file.createNewFile();
+            }else {
+                //取得这个目录下的所有子文件对象
+                File[] files = new File(Global.getTemdataPath()+"selfDeliverOrder/").listFiles();
+                //遍历该目录下的文件对象
+                for (File f: files){
+                    f.delete();
+                }
+                file.delete();
+                file.createNewFile();
+            }
+            fw = new FileWriter(file);
+            Long startTime = System.currentTimeMillis();
+            while (result.next()){
+
+                fw.write(
+                        result.getString("MANDT")
+                                +"$$"+result.getString("VBELN")
+                                +"$$"+result.getString("DATUM")
+                                + "\r\n");
+
+                fw.flush();
+                i++;
+                if (i%50000==0){
+                    j++;
+                    //创建IO需求的条件,并声明输出路径
+                    file = new File(Global.getTemdataPath()+"selfDeliverOrder/"+j+".txt");
+                    if(!file.exists()){
+                        file.createNewFile();
+                    }else {
+                        file.delete();
+                        file.createNewFile();
+                    }
+                    fw = new FileWriter(file);
+
+                }
+            }
+            Long endTime = System.currentTimeMillis();
+            log.info("生成selfDeliverOrder-TXT用时:" + (endTime - startTime) + "毫秒");
+            /* conn = getMysqlConnection();
+            //生产表
+            String sql = "TRUNCATE TABLE meta_hana_self_deliver_order";
+            pstm = conn.prepareStatement(sql);
+            pstm.execute();*/
+        }catch (Exception e){
+            e.printStackTrace();
+        }finally {
+            fw.close();
+            if(pstm!=null){
+                try {
+                    pstm.close();
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                    throw new RuntimeException(e);
+                }
+            }
+            if(conn!=null){
+                try {
+                    conn.close();
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+        return j;
+    }
 
     private int createDeliverOrderTxt(ResultSet result) throws Exception {
         File file = null;
@@ -554,14 +653,12 @@ public class HanaOrderComponent {
         int j =0;
         try {
             long i =0;
-
             //创建IO需求的条件,并声明输出路径
             file = new File((Global.getTemdataPath()+"deliverOrder/"));
             log.info("deliverOrder数据缓存路径:" + Global.getTemdataPath()+"deliverOrder/");
             if(!file.exists()){
                 file.mkdir();
             }
-
             file = new File(Global.getTemdataPath()+"deliverOrder/"+j+".txt");
 //            file = new File("C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\testIO"+j+".txt");
             if(!file.exists()){
@@ -581,44 +678,44 @@ public class HanaOrderComponent {
             while (result.next()){
 
                 fw.write(
-                result.getString("VBELN")
-                +"$$"+result.getString("POSNR")
-                +"$$"+result.getString("VGBEL")
-                +"$$"+result.getString("VGPOS")
-                +"$$"+result.getString("VKORG")
-                +"$$"+result.getString("VKORG_TXT")
-                +"$$"+result.getString("VTWEG")
-                +"$$"+result.getString("KUNAG")
-                +"$$"+result.getString("KUNAG_TXT")
-                +"$$"+result.getString("SPART")
-                +"$$"+result.getString("VKGRP")
-                +"$$"+result.getString("WERKS")
-                +"$$"+result.getString("WERKS_NAME")
-                +"$$"+result.getString("AUART_S")
-                +"$$"+result.getString("LFART")
-                +"$$"+result.getString("MATNR")
-                +"$$"+result.getString("ZMAKTXX")
-                +"$$"+result.getString("GROES")
-                +"$$"+result.getString("ZTKNUM")
-                +"$$"+""
-                +"$$"+result.getString("ZSTREET")
-                +"$$"+result.getString("ERDAT_S")
-                +"$$"+result.getString("ZERDAT2")
-                +"$$"+result.getString("ERDAT")
-                +"$$"+result.getString("WADAT_IST")
-                +"$$"+""
-                +"$$"+""
-                +"$$"+""
-                +"$$"+result.getString("STATUS")
-                +"$$"+result.getBigDecimal("ZKWMENG")
-                +"$$"+result.getBigDecimal("NTGEW_VBAP")
-                +"$$"+result.getBigDecimal("LFIMG")
-                +"$$"+result.getBigDecimal("NTGEW")
-                +"$$"+result.getBigDecimal("KZWI4")
-                +"$$"+result.getString("WADAT_IST")
-                +"$$"+result.getString("BOLNR")
-                +"$$"+result.getString("ERZET")
-                + "\r\n");
+                        result.getString("VBELN")
+                                +"$$"+result.getString("POSNR")
+                                +"$$"+result.getString("VGBEL")
+                                +"$$"+result.getString("VGPOS")
+                                +"$$"+result.getString("VKORG")
+                                +"$$"+result.getString("VKORG_TXT")
+                                +"$$"+result.getString("VTWEG")
+                                +"$$"+result.getString("KUNAG")
+                                +"$$"+result.getString("KUNAG_TXT")
+                                +"$$"+result.getString("SPART")
+                                +"$$"+result.getString("VKGRP")
+                                +"$$"+result.getString("WERKS")
+                                +"$$"+result.getString("WERKS_NAME")
+                                +"$$"+result.getString("AUART_S")
+                                +"$$"+result.getString("LFART")
+                                +"$$"+result.getString("MATNR")
+                                +"$$"+result.getString("ZMAKTXX")
+                                +"$$"+result.getString("GROES")
+                                +"$$"+result.getString("ZTKNUM")
+                                +"$$"+""
+                                +"$$"+result.getString("ZSTREET")
+                                +"$$"+result.getString("ERDAT_S")
+                                +"$$"+result.getString("ZERDAT2")
+                                +"$$"+result.getString("ERDAT")
+                                +"$$"+result.getString("WADAT_IST")
+                                +"$$"+""
+                                +"$$"+""
+                                +"$$"+""
+                                +"$$"+result.getString("STATUS")
+                                +"$$"+result.getBigDecimal("ZKWMENG")
+                                +"$$"+result.getBigDecimal("NTGEW_VBAP")
+                                +"$$"+result.getBigDecimal("LFIMG")
+                                +"$$"+result.getBigDecimal("NTGEW")
+                                +"$$"+result.getBigDecimal("KZWI4")
+                                +"$$"+result.getString("WADAT_IST")
+                                +"$$"+result.getString("BOLNR")
+                                +"$$"+result.getString("ERZET")
+                                + "\r\n");
 
                 fw.flush();
                 i++;
@@ -639,13 +736,13 @@ public class HanaOrderComponent {
             Long endTime = System.currentTimeMillis();
             log.info("生成deliverOrder-TXT用时:" + (endTime - startTime) + "毫秒");
 
-            conn = getMysqlConnection();
+        /*    conn = getMysqlConnection();
             //测试表
 //            String sql = "TRUNCATE TABLE sap_hana_deliver_order";
             //生产表
             String sql = "TRUNCATE TABLE meta_hana_deliver_order";
             pstm = conn.prepareStatement(sql);
-            pstm.execute();
+            pstm.execute();*/
         }catch (Exception e){
             e.printStackTrace();
         }finally {
@@ -792,30 +889,97 @@ public class HanaOrderComponent {
         }
         return result;
     }
-
+//订单
     public void runLoadSalesOrder() throws Exception{
-        //测试表
-//        String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table sap_hana_sales_order fields terminated by '?' lines terminated by '\\n'";
         //生产表
-        String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_sales_order fields terminated by '$$' lines terminated by '\\n'";
-        try {
+        Connection conn = null;
+        PreparedStatement pstm =null;
+        try{
+            conn = getMysqlConnection();
+            String sql = "TRUNCATE TABLE meta_hana_sales_order";
+            pstm = conn.prepareStatement(sql);
+            pstm.execute();
+            String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_sales_order fields terminated by '$$' lines terminated by '\\n'";
             long beginTime=System.currentTimeMillis();
             int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"salesOrder/"))));
             long endTime=System.currentTimeMillis();
             log.info("importing salesOrder := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
             String result = HttpUtils.sendGet(orderGetDataHook);
             log.info("清空salesOrder缓存:"+result);
+        }catch (Exception e){
+            e.printStackTrace();
+        }finally {
+            if(pstm!=null){
+                try {
+                    pstm.close();
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                    throw new RuntimeException(e);
+                }
+            }
+            if(conn!=null){
+                try {
+                    conn.close();
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+        //测试表
+//        String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table sap_hana_sales_order fields terminated by '?' lines terminated by '\\n'";
+        //生产表
+    }
+    public void runLoadSelfReviewedDeliverOrder()throws Exception{
+        //生产表
+        Connection conn = null;
+        PreparedStatement pstm =null;
+        try {
+            conn = getMysqlConnection();
+            //生产表
+            String sql = "TRUNCATE TABLE meta_hana_self_deliver_order";
+            pstm = conn.prepareStatement(sql);
+            pstm.execute();
+            String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_self_deliver_order fields terminated by '$$' lines terminated by '\\n'";
+            long beginTime=System.currentTimeMillis();
+            int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"selfDeliverOrder/"))));
+            long endTime=System.currentTimeMillis();
+            log.info("importing selfDeliverOrder := "+rows+" rows data into mysql and cost "+(endTime-beginTime)+" ms!");
         } catch (SQLException e) {
             e.printStackTrace();
+        }finally {
+            if(pstm!=null){
+                try {
+                    pstm.close();
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                    throw new RuntimeException(e);
+                }
+            }
+            if(conn!=null){
+                try {
+                    conn.close();
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                    throw new RuntimeException(e);
+                }
+            }
         }
     }
 
     public void runLoadDeliverOrder() throws Exception{
+        Connection conn = null;
+        PreparedStatement pstm =null;
         //测试表
 //        String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table sap_hana_deliver_order fields terminated by '?' lines terminated by '\\n'";
         //生产表
-        String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_deliver_order fields terminated by '$$' lines terminated by '\\n'";
         try {
+            conn = getMysqlConnection();
+            //生产表
+            String sql = "TRUNCATE TABLE meta_hana_deliver_order";
+            pstm = conn.prepareStatement(sql);
+            pstm.execute();
+            String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_deliver_order fields terminated by '$$' lines terminated by '\\n'";
             long beginTime=System.currentTimeMillis();
             int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"deliverOrder/"))));
             long endTime=System.currentTimeMillis();
@@ -824,6 +988,23 @@ public class HanaOrderComponent {
             log.info("清空deliverOrder缓存:"+result);
         } catch (SQLException e) {
             e.printStackTrace();
+        }finally {
+            if(pstm!=null){
+                try {
+                    pstm.close();
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                    throw new RuntimeException(e);
+                }
+            }
+            if(conn!=null){
+                try {
+                    conn.close();
+                } catch (SQLException e) {
+                    e.printStackTrace();
+                    throw new RuntimeException(e);
+                }
+            }
         }
     }