Browse Source

fix 数据迁移 导出脚本文件 特殊字符处理

lvxianyun 2 years ago
parent
commit
62b3da1416

+ 1 - 1
adm-business/adm-middleware/src/main/java/com/persagy/proxy/migration/constant/MigrationConstant.java

@@ -10,7 +10,7 @@ public class MigrationConstant {
 
     public final static String ERROR = "目标地址错误不能正常访问!";
 
-    public final static int BATCH_SUBMIT_DATA_COUNT = 500;
+    public final static int BATCH_SUBMIT_DATA_COUNT = 5000;
 
     /** 数据拼接 用于list->map 时key和value拼接 **/
     public final static String SPLITER = "_";

+ 40 - 11
adm-business/adm-middleware/src/main/java/com/persagy/proxy/migration/service/Impl/ObjectDigitalMigration.java

@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.basic.utils.JsonNodeUtils;
 import com.persagy.dmp.common.constant.ResponseCode;
+import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.digital.client.DigitalObjectFacade;
 import com.persagy.dmp.digital.entity.ObjectDigital;
 import com.persagy.dmp.rwd.migrate.entity.SyncData;
@@ -97,30 +98,50 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
      */
     @Override
     public String migrateForSql(InstanceUrlParam context) {
-        StringBuffer sqls = new StringBuffer(" \n -- 数据迁移  dt_object ------ \n");
         //获取已经采集的数据
-        String sqls_temp = "";
-        List<String> objTypes = getObjTypes(context);
+        String sqls_temp = "\n -- 数据迁移  dt_object ------ \n  ";
+        //List<String> objTypes = getObjTypes(context);
+        List<String> objTypes = Arrays.asList("equipment");
         for(String objType : objTypes){
             QueryCriteria queryCriteria = getQueryCriteria(objType);
-            List<ObjectNode> admData = getAdmData(context,queryCriteria);
+            queryCriteria.setSize(MigrationConstant.BATCH_SUBMIT_DATA_COUNT*1L);
+            CommonResult<List<ObjectNode>> result = getAdmDataPage(context,queryCriteria);
+            List<ObjectNode> admData = result.getData();
             if(CollUtil.isEmpty(admData)){
                 continue;
             }
-            sqls_temp += appendValues(admData).toString();
+            sqls_temp += processSqlStr(appendValues(admData).toString());
+
+            if(result.getCount() > MigrationConstant.BATCH_SUBMIT_DATA_COUNT){
+                long page = result.getCount() / MigrationConstant.BATCH_SUBMIT_DATA_COUNT + 1;
+                for(long i = 2; i<=page; i++){
+                    queryCriteria.setPage(i);
+                    result = getAdmDataPage(context,queryCriteria);
+                    admData = result.getData();
+                    if(CollUtil.isEmpty(admData)){
+                        continue;
+                    }
+                    sqls_temp += processSqlStr(appendValues(admData).toString());
+                }
+            }
         }
         if(sqls_temp.length() == 0){
             return "";
         }
-        sqls.append(MigrationConstant.DT_OBJECT_SQL_PRE);
-        sqls.append(sqls_temp);
-        String sql = sqls.toString();
+        return sqls_temp;
+    }
+
+    private String processSqlStr(String sql){
         sql = sql.substring(0, sql.lastIndexOf(","));
         sql += ";";
         sql = sql.replaceAll("\"","\\\\\"");
-        return sql;
+        sql = sql.replaceAll("\n","\\n");
+        sql = sql.replaceAll("\r","\\r");
+        StringBuffer sqls = new StringBuffer("\r");
+        sqls.append(MigrationConstant.DT_OBJECT_SQL_PRE);
+        sqls.append(sql);
+        return  sqls.toString();
     }
-
     private StringBuffer appendValues(List<ObjectNode> admData){
         StringBuffer sqls = new StringBuffer();
         admData.forEach(obj -> {
@@ -171,7 +192,7 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
             sqls.append("'").append(objectDigital.getModifier()).append("',");
             sqls.append("'").append(objectDigital.getModifiedTime()).append("',");
             sqls.append(objectDigital.getValid());
-            sqls.append(")\n ,");
+            sqls.append(") ,");
         });
         return sqls;
     }
@@ -336,6 +357,14 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
         return digitalList;
     }
 
+    public CommonResult<List<ObjectNode>> getAdmDataPage(InstanceUrlParam context, QueryCriteria queryCriteria) {
+        CommonResult<List<ObjectNode>> digitalList = DigitalObjectFacade.queryPrototype(context.getGroupCode(),context.getProjectId(),context.getUserId(),context.getUserId(),queryCriteria);
+        if(CollUtil.isEmpty(digitalList.getData())){
+            return null;
+        }
+        return digitalList;
+    }
+
     /**
      * 根据map转为需要处理的对象集合
      * @param fromMap