Browse Source

同步HANA数据库冻结经销商

njs 1 year ago
parent
commit
2dba5a443c

+ 5 - 0
suishenbang-quartz/src/main/java/com/dgtly/quartz/task/RyTask.java

@@ -81,6 +81,11 @@ public class RyTask
         hanaOrderComponent.hanaSelfReviewedDeliverOrderSync();
     }
 
+    /**HANA已冻结经销商**/
+    public void hanaFreezeCustomer()throws Exception{
+        hanaOrderComponent.hanaFreezeCustomer();
+    }
+
 
     /*关联经销商上线定时任务*/
     public void relationCustomerOnlineSync() throws Exception {

+ 133 - 0
suishenbang-sync/suishenbang-sync-common/src/main/java/com/dgtly/sync/service/HanaOrderComponent.java

@@ -397,6 +397,19 @@ public class HanaOrderComponent {
         return j;
     }
 
+    /**HANA已冻结经销商**/
+    public void hanaFreezeCustomer()throws Exception{
+        Connection con = this.getHanaConnection();
+        PreparedStatement pstmt = con.prepareStatement("SELECT DISTINCT KUNNR FROM ERP.KNVV x WHERE LIFSD IS NOT NULL AND LIFSD != ''");
+        Long startTime = System.currentTimeMillis();
+        ResultSet rs = pstmt.executeQuery();
+        Long endTime = System.currentTimeMillis();
+        log.info("FreezeCustomer查询用时:" + (endTime - startTime)+"毫秒");
+        this.createFreezeCustomerTxt(rs);
+        this.runLoadFreezeCustomer();
+        this.closeConnection(con, pstmt);
+    }
+
     /**HANA已复核线下月底手动过账的交货单仍需自提同步*/
     public void hanaSelfReviewedDeliverOrderSync() throws Exception{
         Connection con = this.getHanaConnection();
@@ -559,6 +572,87 @@ public class HanaOrderComponent {
         this.closeConnection(con, pstmt);
 
     }*/
+
+
+    private int createFreezeCustomerTxt(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()+"freezeCustomer/"));
+            log.info("freezeCustomer数据缓存路径:" + Global.getTemdataPath()+"freezeCustomer/");
+            if(!file.exists()){
+                file.mkdir();
+            }
+
+            file = new File(Global.getTemdataPath()+"freezeCustomer/"+j+".txt");
+            if(!file.exists()){
+                file.createNewFile();
+            }else {
+                //取得这个目录下的所有子文件对象
+                File[] files = new File(Global.getTemdataPath()+"freezeCustomer/").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("KUNNR"));
+
+                fw.flush();
+                i++;
+                if (i%50000==0){
+                    j++;
+                    //创建IO需求的条件,并声明输出路径
+                    file = new File(Global.getTemdataPath()+"freezeCustomer/"+j+".txt");
+                    if(!file.exists()){
+                        file.createNewFile();
+                    }else {
+                        file.delete();
+                        file.createNewFile();
+                    }
+                    fw = new FileWriter(file);
+
+                }
+            }
+            Long endTime = System.currentTimeMillis();
+            log.info("生成freezeCustomer-TXT用时:" + (endTime - startTime) + "毫秒");
+        }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 createSelfReviewedDeliverOrderTxt(ResultSet result)throws Exception{
         File file = null;
         FileWriter fw = null;
@@ -930,6 +1024,45 @@ public class HanaOrderComponent {
 //        String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table sap_hana_sales_order fields terminated by '?' lines terminated by '\\n'";
         //生产表
     }
+
+    public void runLoadFreezeCustomer()throws Exception{
+        //生产表
+        Connection conn = null;
+        PreparedStatement pstm =null;
+        try {
+            conn = getMysqlConnection();
+            //生产表
+            String sql = "TRUNCATE TABLE meta_hana_freeze_customer";
+            pstm = conn.prepareStatement(sql);
+            pstm.execute();
+            String testSql = "LOAD DATA LOCAL INFILE 'testIO.txt' into table meta_hana_freeze_customer fields terminated by '$$' lines terminated by '\\n'";
+            long beginTime=System.currentTimeMillis();
+            int rows=this.bulkLoadFromInputStream(testSql, mergeGetStream(new File((Global.getTemdataPath()+"freezeCustomer/"))));
+            long endTime=System.currentTimeMillis();
+            log.info("importing freezeCustomer := "+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 runLoadSelfReviewedDeliverOrder()throws Exception{
         //生产表
         Connection conn = null;