|
@@ -8,16 +8,13 @@ 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.entity.AuditableEntity;
|
|
|
-import com.persagy.dmp.common.model.entity.BaseEntity;
|
|
|
-import com.persagy.dmp.define.entity.ObjectTypeDefine;
|
|
|
+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;
|
|
|
import com.persagy.proxy.adm.request.AdmResponse;
|
|
|
import com.persagy.proxy.common.entity.InstanceUrlParam;
|
|
|
import com.persagy.proxy.migration.constant.MigrationConstant;
|
|
|
-import com.persagy.proxy.migration.constant.MigrationObjType;
|
|
|
import com.persagy.proxy.migration.constant.MigrationTable;
|
|
|
import com.persagy.proxy.migration.constant.MigrationType;
|
|
|
import com.persagy.proxy.migration.model.DataMigrationExcel;
|
|
@@ -25,7 +22,6 @@ import com.persagy.proxy.migration.model.DataMigrationResponse;
|
|
|
import com.persagy.proxy.migration.model.MigrationInfo;
|
|
|
import com.persagy.proxy.migration.service.IDataMigration;
|
|
|
import com.persagy.proxy.migration.service.IDataMigrationProcess;
|
|
|
-import com.persagy.proxy.migration.service.Impl.MigrationAbstractServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -55,14 +51,14 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
|
|
|
log.info("######################### dt_object 数据迁移内容获取开始 #########################");
|
|
|
long start = System.currentTimeMillis();
|
|
|
List<DataMigrationExcel> dataMigrationExcels = new ArrayList<>();
|
|
|
+ List<String> objTypes = getObjTypes(context);
|
|
|
+ for(String objType : objTypes){
|
|
|
+ log.info("######################### dt_object "+objType+"数据迁移内容获取开始 #########################");
|
|
|
|
|
|
- for(MigrationObjType objType : MigrationObjType.values()){
|
|
|
- log.info("######################### dt_object "+objType.getCode()+"数据迁移内容获取开始 #########################");
|
|
|
-
|
|
|
- QueryCriteria queryCriteria = getQueryCriteria(objType.getCode());
|
|
|
+ QueryCriteria queryCriteria = getQueryCriteria(objType);
|
|
|
dataMigrationExcels.addAll(startMigrateForExcel(context,migrationInfo,queryCriteria));
|
|
|
|
|
|
- log.info("######################### dt_object "+objType.getCode()+"数据迁移内容获取结束 #########################");
|
|
|
+ log.info("######################### dt_object "+objType+"数据迁移内容获取结束 #########################");
|
|
|
}
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
@@ -80,13 +76,14 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
|
|
|
public AdmResponse migrateForLog(InstanceUrlParam context, MigrationInfo migrationInfo) {
|
|
|
log.info("######################### dt_object 同步开始 #########################");
|
|
|
long start = System.currentTimeMillis();
|
|
|
- for(MigrationObjType objType : MigrationObjType.values()){
|
|
|
- log.info("######################### dt_object "+objType.getCode()+"同步开始 #########################");
|
|
|
+ List<String> objTypes = getObjTypes(context);
|
|
|
+ for(String objType : objTypes){
|
|
|
+ log.info("######################### dt_object "+objType+"同步开始 #########################");
|
|
|
|
|
|
- QueryCriteria queryCriteria = getQueryCriteria(objType.getCode());
|
|
|
+ QueryCriteria queryCriteria = getQueryCriteria(objType);
|
|
|
startMigrateForLog(context,migrationInfo,queryCriteria);
|
|
|
|
|
|
- log.info("######################### dt_object "+objType.getCode()+"同步结束 #########################");
|
|
|
+ log.info("######################### dt_object "+objType+"同步结束 #########################");
|
|
|
}
|
|
|
long end = System.currentTimeMillis();
|
|
|
log.info("######################### dt_object 数据迁移已结束 时间:"+(end-start)+" #########################");
|
|
@@ -101,29 +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 = "";
|
|
|
- for(MigrationObjType objType : MigrationObjType.values()){
|
|
|
- QueryCriteria queryCriteria = getQueryCriteria(objType.getCode());
|
|
|
- List<ObjectNode> admData = getAdmData(context,queryCriteria);
|
|
|
+ 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);
|
|
|
+ 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 -> {
|
|
@@ -133,18 +151,18 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
|
|
|
if (objectDigital.getName() == null) {
|
|
|
sqls.append(objectDigital.getName()).append(",");
|
|
|
} else {
|
|
|
- sqls.append("'").append(objectDigital.getName()).append("',");
|
|
|
+ sqls.append("'").append(objectDigital.getName().replaceAll("\\'","\\\\'")).append("',");
|
|
|
}
|
|
|
|
|
|
if (objectDigital.getLocalId() == null) {
|
|
|
sqls.append(objectDigital.getLocalId()).append(",");
|
|
|
} else {
|
|
|
- sqls.append("'").append(objectDigital.getLocalId()).append("',");
|
|
|
+ sqls.append("'").append(objectDigital.getLocalId().replaceAll("\\'","\\\\'")).append("',");
|
|
|
}
|
|
|
if (objectDigital.getLocalName() == null) {
|
|
|
sqls.append(objectDigital.getLocalName()).append(",");
|
|
|
} else {
|
|
|
- sqls.append("'").append(objectDigital.getLocalName()).append("',");
|
|
|
+ sqls.append("'").append(objectDigital.getLocalName().replaceAll("\\'","\\\\'")).append("',");
|
|
|
}
|
|
|
sqls.append("'").append(objectDigital.getGroupCode()).append("',");
|
|
|
sqls.append("'").append(objectDigital.getProjectId()).append("',");
|
|
@@ -155,7 +173,9 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
|
|
|
if (objectDigital.getVirtualCodes() == null) {
|
|
|
sqls.append(objectDigital.getVirtualCodes()).append(",");
|
|
|
} else {
|
|
|
- sqls.append("'").append(objectDigital.getVirtualCodes()).append("',");
|
|
|
+ StringBuilder temp = new StringBuilder();
|
|
|
+ objectDigital.getVirtualCodes().forEach(str -> temp.append("\"").append(str).append("\"").append(","));
|
|
|
+ sqls.append("'[").append(StrUtil.sub(temp.toString(),0,-1)).append("]',");
|
|
|
}
|
|
|
if (objectDigital.getCreateApp() == null) {
|
|
|
sqls.append(objectDigital.getCreateApp()).append(",");
|
|
@@ -172,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;
|
|
|
}
|
|
@@ -337,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
|