Browse Source

数据上报0831

19266 1 year ago
parent
commit
5508e4bcd1

+ 10 - 4
src/main/java/com/data/datarepo/controller/DataController.java

@@ -115,10 +115,16 @@ public class DataController {
     @RequestMapping("/repoBJ")
     public String datarepoBJ(String[] repo_name) throws SQLException {
         String[] value2 = new String[repo_name.length];
-        String temp = repo_name[0];
-        String[] itempsplit = temp.split("-");
-        value2[0] = itempsplit[1];
-        dataService.testSelectBJ(value2[0]);
+        String[] repo_names = new String[repo_name.length];
+        String[] up_nums = new String[repo_name.length];
+        for (int i = 0; i < repo_name.length; i++) {
+            String temp = repo_name[i];
+            String[] itempsplit = temp.split("-");
+            repo_names[i] = itempsplit[0];
+            up_nums[i] = itempsplit[1];
+            dataService.testSelectBJ(repo_names[i],up_nums[i]);
+        }
+
         return "redirect:/data/list";
     }
 

+ 3 - 2
src/main/java/com/data/datarepo/services/DataCenterService.java

@@ -72,7 +72,7 @@ public class DataCenterService extends DataSourceOra {
 
     public void insertUpnum(DataRepoTable dataRepoTable) throws SQLException {
         Connection connection = null;
-        String selectSQL = "insert into data_sync_upnum(table_name,repo_name,table_comment,equipmentNo,create_time_str)values (?,?,?,?,NOW())";
+        String selectSQL = "insert into data_sync_upnum(table_name,repo_name,table_comment,equipmentNo,create_time_str)values (?,?,?,?,date_format(now(),'%Y%m%d'))";
         PreparedStatement prepStmt = null;
         try {
             MysqlDataSource basicDS = DataSource.getInstance().getMySqlDS();
@@ -153,7 +153,7 @@ public class DataCenterService extends DataSourceOra {
             }
             sb.append("?");
             sb.append(")");
-            System.out.println(sb.toString());
+
             PreparedStatement pstmt = conn.prepareStatement(sb.toString());
             while (rs.next()) {
                 for (int i = 1; i <= numberOfColumns - 1; i++) {
@@ -174,6 +174,7 @@ public class DataCenterService extends DataSourceOra {
                         pstmt.setDate(i, startDate);
                         continue;
                     }
+                    System.out.println(value);
                     pstmt.setString(i, value);
                 }
                 pstmt.setObject(numberOfColumns, up_num);

+ 11 - 4
src/main/java/com/data/datarepo/services/DataLoadService.java

@@ -10,14 +10,18 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 public class DataLoadService extends DataSourceOra{
-    public void testLoad(String up_num) throws SQLException {
+    public void testLoad(String repo_name,String up_num) throws SQLException {
         Connection conn=null;
-        CallableStatement cstmt=null;
+        PreparedStatement cstmt=null;
+        PreparedStatement dstmt=null;
         try{
             conn=this.getConn();
-            cstmt=conn.prepareCall("{ call DATAREP.largedata_insert(?)}");
+            dstmt=conn.prepareStatement("delete from "+repo_name+"");
+            dstmt.executeUpdate();
+//            cstmt=conn.prepareCall("{ call YLSJSB.largedata_insert(?)}");
+            cstmt = conn.prepareStatement("insert into "+repo_name+" select * from "+repo_name+"_OLD where UP_NUM =?");
             cstmt.setString(1,up_num);
-            cstmt.execute();
+            cstmt.executeUpdate();
             System.out.println("执行成功!");
         }
         catch(Exception e)
@@ -31,6 +35,9 @@ public class DataLoadService extends DataSourceOra{
             if(cstmt!=null){
                 cstmt.close();
             }
+            if(dstmt!=null){
+                dstmt.close();
+            }
         }
     }
 

+ 2 - 93
src/main/java/com/data/datarepo/services/DataMySQL2OracleService.java

@@ -30,16 +30,10 @@ public class DataMySQL2OracleService extends DataSourceOra {
 
 
         Statement stmt = connSource.createStatement();
-        Statement stmtI = connSource.createStatement();
-        Statement stmtU = connSource.createStatement();
-        Statement stmtL = connSource.createStatement();
         Statement stmtC = connSource.createStatement();
         Statement stmtS = connSource.createStatement();
         Statement stmtT = connSource.createStatement();
         ResultSet rs = null;
-        ResultSet rsI = null;
-        ResultSet rsU = null;
-        ResultSet rsL = null;
         ResultSet rsC = null;
         ResultSet rsS = null;
         ResultSet rsT = null;
@@ -58,25 +52,14 @@ public class DataMySQL2OracleService extends DataSourceOra {
 //            System.out.println(inSql);
         }
         try {
-            String sqlL = "select create_time_str from data_sync_upnum where table_id=(select max( table_id ) from data_sync_upnum where repo_name='" + repo_name + "')";
-            rsL = stmtL.executeQuery(sqlL);
             rs = stmt.executeQuery("select * from " + table_name);
-            if (rsL.next()) {
-                timeL = rsL.getString("create_time_str");
-                String sqlI = "select * from " + table_name + " where date_format(create_date,'%Y%m%d')> date_format('" + timeL + "','%Y%m%d')";
-//                System.out.println(sqlI);
-                rsI = stmtI.executeQuery(sqlI);
-                String sqlU = "select * from " + table_name + " where date_format(create_date,'%Y%m%d')<date_format('" + timeL + "','%Y%m%d') and date_format(update_date,'%Y%m%d')>date_format('" + timeL + "','%Y%m%d')";
-//                System.out.println(sqlU);
-                rsU = stmtU.executeQuery(sqlU);
-            }
             DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             Date beginTime = new Date();
             String start = df.format(beginTime);
             Long begin = beginTime.getTime();
             System.out.println("任务开始,开始时间为:" + start);
 
-            ResultSetMetaData rsmd = rs.getMetaData();
+//            ResultSetMetaData rsmd = rs.getMetaData();
 //            rsS.last();
 //            int numberOfColumns = rsmd.getColumnCount();
             int numberOfColumns = 0;
@@ -91,61 +74,6 @@ public class DataMySQL2OracleService extends DataSourceOra {
             }
             pstmt = connDest.prepareStatement(inSql);
 
-            rsL.beforeFirst();
-
-            if (rsL.next()) {
-                rsI.beforeFirst();
-                rsU.beforeFirst();
-//                if (rsI.next()) {
-                int j = 0;
-                while (rsI.next()) {
-                    j++;
-                    for (int i = 1; i <= numberOfColumns - 2; i++) {
-                        String value = rsI.getString(i);
-                        String column_name=rsI.getMetaData().getColumnName(i);
-                        String issm=(String)smMap.get(column_name);
-                        if("0".equals(issm)){
-                            SM4Utils sm4 = new SM4Utils();
-                            sm4.secretKey = "1234567887654321";
-                            value = sm4.decryptData_ECB(value);
-                        }
-                        pstmt.setString(i, value);
-                    }
-                    pstmt.setObject(numberOfColumns - 1, "I");
-                    pstmt.setObject(numberOfColumns, up_num);
-//                        System.out.print("-");
-                    pstmt.addBatch();
-                    if (j % 500 == 0) {
-                        pstmt.executeBatch();
-                    }
-                    pstmt.executeBatch();
-                }
-//                }else if(rsU.next()) {
-                while (rsU.next()) {
-                    j++;
-                    for (int i = 1; i <= numberOfColumns - 2; i++) {
-                        String value = rsU.getString(i);
-                        String column_name=rsU.getMetaData().getColumnName(i);
-                        String issm=(String)smMap.get(column_name);
-                        if("0".equals(issm)){
-                            SM4Utils sm4 = new SM4Utils();
-                            sm4.secretKey = "1234567887654321";
-                            value = sm4.decryptData_ECB(value);
-                        }
-                        pstmt.setString(i, value);
-                    }
-                    pstmt.setObject(numberOfColumns - 1, "U");
-                    pstmt.setObject(numberOfColumns, up_num);
-//                        System.out.print("-");
-                    pstmt.addBatch();
-                    if (j % 500 == 0) {
-                        pstmt.executeBatch();
-                    }
-                    pstmt.executeBatch();
-                }
-//                }
-                pstmt.executeBatch();
-            } else {
                 int j = 0;
                 while (rs.next()) {
                     j++;
@@ -164,14 +92,13 @@ public class DataMySQL2OracleService extends DataSourceOra {
                     }
                     pstmt.setObject(numberOfColumns - 1, "I");
                     pstmt.setObject(numberOfColumns, up_num);
-//                    System.out.print("-");
+//                    pstmt.executeUpdate();
                     pstmt.addBatch();
                     if (j % 500 == 0) {
                         pstmt.executeBatch();
                     }
                 }
                 pstmt.executeBatch();
-            }
             Date finishTime = new Date();
             Long end = finishTime.getTime();
             long timeLag = end - begin;
@@ -196,15 +123,6 @@ public class DataMySQL2OracleService extends DataSourceOra {
             if (rs != null) {
                 rs.close();
             }
-            if (rsI != null) {
-                rsI.close();
-            }
-            if (rsU != null) {
-                rsU.close();
-            }
-            if (rsL != null) {
-                rsL.close();
-            }
             if (rsC != null) {
                 rsC.close();
             }
@@ -217,15 +135,6 @@ public class DataMySQL2OracleService extends DataSourceOra {
             if (stmt != null) {
                 stmt.close();
             }
-            if (stmtI != null) {
-                stmtI.close();
-            }
-            if (stmtU != null) {
-                stmtU.close();
-            }
-            if (stmtL != null) {
-                stmtL.close();
-            }
             if (stmtC != null) {
                 stmtC.close();
             }

+ 2 - 2
src/main/java/com/data/datarepo/services/DataService.java

@@ -171,8 +171,8 @@ public class DataService {
     }
 
 
-    public void testSelectBJ(String up_num) throws SQLException {
-        dataLoadService.testLoad(up_num);
+    public void testSelectBJ(String repo_name,String up_num) throws SQLException {
+        dataLoadService.testLoad(repo_name,up_num);
     }
 
     public DataRepoTable testSelectResult(String repo_name, String up_num, String table_name, String table_comment) throws SQLException {

+ 7 - 7
src/main/java/com/data/datarepo/utils/DataSource.java

@@ -6,13 +6,13 @@ import com.mysql.cj.jdbc.MysqlDataSource;
 public class DataSource {
 
     private static final String DRIVER_CLASS = "com.mysql.cj.jdbc.Driver";
-//    private static final String DB_CONNECTION_URL = "jdbc:mysql://19.135.92.130:56612/mz-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
-//    private static final String DB_CONNECTION_URL = "jdbc:mysql://10.16.4.7:3306/mz-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
-    private static final String DB_CONNECTION_URL = "jdbc:mysql://127.0.0.1:3306/mz-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
-//    private static final String DB_USER = "dev";
-//    private static final String DB_PWD = "sckj2022@123";
-    private static final String DB_USER = "root";
-    private static final String DB_PWD = "sckjadmin";
+//    private static final String DB_CONNECTION_URL = "jdbc:mysql://127.0.0.1:56612/mz-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
+    private static final String DB_CONNECTION_URL = "jdbc:mysql://121.36.73.159:56612/mz-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
+//    private static final String DB_USER = "root";
+    private static final String DB_USER = "dev";
+    private static final String DB_PWD = "sckj2022@123";
+//    private static final String DB_USER = "root";
+//    private static final String DB_PWD = "sckjadmin";
 //    private static final String DB_PWD = "root";
     private static DataSource ds;
     private MysqlDataSource mySqlDS = new MysqlDataSource();

+ 3 - 0
src/main/java/com/data/datarepo/utils/DataSourceOra.java

@@ -17,10 +17,13 @@ public class DataSourceOra {
 //    private static final String DB_PWD = "ylxt";
     public static final String DRIVER="oracle.jdbc.driver.OracleDriver";
     public static final String URL="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
+//    public static final String URL="jdbc:oracle:thin:@59.198.199.42:54653:mzt";
 //    public static final String URL="jdbc:oracle:thin:@10.16.4.7:1521:helowin";
     public static final String UID="DATAREP";
+//    public static final String UID="ylsjsb";
 //    public static final String UID="ylxt";
     public static final String PWD="sckjadmin";
+//    public static final String PWD="ylsjsb";
 //    public static final String PWD="ylxt";
 
     /***

+ 1 - 0
src/main/resources/application.properties

@@ -1 +1,2 @@
 server.port=8099
+server.max-http-header-size=102400