ソースを参照

fix 数据迁移 导出sql脚本, 统一处理null

lvxianyun 2 年 前
コミット
2d00b257f7

+ 26 - 65
adm-business/adm-middleware/src/main/java/com/persagy/proxy/migration/service/Impl/DefineInfoMigration.java

@@ -22,7 +22,6 @@ 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.IDefineDataMigration;
-import com.persagy.proxy.migration.service.Impl.MigrationAbstractServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -147,77 +146,39 @@ public class DefineInfoMigration extends MigrationAbstractServiceImpl<ObjectInfo
         sqls.append(" delete from dt_define_info where project_id='"+context.getProjectId()+"' or group_code='"+context.getGroupCode()+"'; \n ");
         sqls.append(MigrationConstant.DEF_FUNCID_SQL_PRE);
         admDefineList.forEach(infoDefine -> {
+
             sqls.append("(");
             sqls.append("'").append(infoDefine.getId()).append("',");
-            sqls.append("'").append(infoDefine.getCode()).append("',");
-            sqls.append("'").append(infoDefine.getName()).append("',");
-            sqls.append("'").append(infoDefine.getAliasCode()).append("',");
-            sqls.append("'").append(infoDefine.getAliasName()).append("',");
-            sqls.append("'").append(infoDefine.getClassCode()).append("',");
-            sqls.append("'").append(infoDefine.getGroupCode()).append("',");
-            sqls.append("'").append(infoDefine.getProjectId()).append("',");
-            sqls.append("'").append(infoDefine.getCategory()).append("',");
-            sqls.append("'").append(infoDefine.getFirstTag()).append("',");
-            if (infoDefine.getSecondTag() == null) {
-                sqls.append(infoDefine.getSecondTag()).append(",");
-            } else {
-                sqls.append("'").append(infoDefine.getSecondTag()).append("',");
-            }
-
-            sqls.append("'").append(infoDefine.getPriority()).append("',");
-            sqls.append("'").append(infoDefine.getInputMode()).append("',");
-
-            if (infoDefine.getUnit() == null) {
-                sqls.append(infoDefine.getUnit()).append(",");
-            } else {
-                sqls.append("'").append(infoDefine.getUnit()).append("',");
-            }
+            super.processNull(sqls, infoDefine.getCode());
+            super.processNull(sqls, infoDefine.getName());
+            super.processNull(sqls, infoDefine.getAliasCode());
+            super.processNull(sqls, infoDefine.getAliasName());
+            super.processNull(sqls, infoDefine.getClassCode());
+            super.processNull(sqls, infoDefine.getGroupCode());
+            super.processNull(sqls, infoDefine.getProjectId());
+
+            super.processNull(sqls, infoDefine.getCategory());
+            super.processNull(sqls, infoDefine.getFirstTag());
+            super.processNull(sqls, infoDefine.getSecondTag());
+            super.processNull(sqls, infoDefine.getPriority());
+            super.processNull(sqls, infoDefine.getInputMode());
+            super.processNull(sqls, infoDefine.getUnit());
+            super.processNull(sqls, infoDefine.getDataType());
 
-            sqls.append("'").append(infoDefine.getDataType()).append("',");
             sqls.append(infoDefine.getIsMultiple()?1:0).append(",");
             sqls.append(infoDefine.getIsRegion()?1:0).append(",");
-
-            if (infoDefine.getFormater() == null) {
-                sqls.append(infoDefine.getFormater()).append(",");
-            } else {
-                sqls.append("'").append(infoDefine.getFormater()).append("',");
-            }
-
-            if (infoDefine.getDataSource() == null) {
-                sqls.append(infoDefine.getDataSource()).append(",");
-            } else {
-                sqls.append("'").append(infoDefine.getDataSource()).append("',");
-            }
-
-            if (infoDefine.getRemark() == null) {
-                sqls.append(infoDefine.getRemark()).append(",");
-            } else {
-                sqls.append("'").append(infoDefine.getRemark()).append("',");
-            }
+            super.processNull(sqls, infoDefine.getFormater());
+            super.processNull(sqls, infoDefine.getDataSource());
+            super.processNull(sqls, infoDefine.getRemark());
             sqls.append(infoDefine.getSubFlag()?1:0).append(",");
             sqls.append(infoDefine.getWeakPoint()?1:0).append(",");
-            sqls.append(infoDefine.getShowOrder()).append(",");
-
-            if (infoDefine.getVersion() == null) {
-                sqls.append(infoDefine.getVersion()).append(",");
-            } else {
-                sqls.append("'").append(infoDefine.getVersion()).append("',");
-            }
-
-            sqls.append(infoDefine.getSourceFrom()).append(",");
-            sqls.append("'").append(infoDefine.getCreator()).append("',");
-            sqls.append("'").append(infoDefine.getCreationTime()).append("',");
-            if (infoDefine.getModifier() == null) {
-                sqls.append(infoDefine.getModifier()).append(",");
-            } else {
-                sqls.append("'").append(infoDefine.getModifier()).append("',");
-            }
-
-            if (infoDefine.getModifiedTime() == null) {
-                sqls.append(infoDefine.getModifiedTime()).append(",");
-            } else {
-                sqls.append("'").append(infoDefine.getModifiedTime()).append("',");
-            }
+            super.processNull(sqls, infoDefine.getShowOrder());
+            super.processNull(sqls, infoDefine.getVersion());
+            super.processNull(sqls, infoDefine.getSourceFrom());
+            super.processNull(sqls, infoDefine.getCreator());
+            super.processNull(sqls, infoDefine.getCreationTime());
+            super.processNull(sqls, infoDefine.getModifier());
+            super.processNull(sqls, infoDefine.getModifiedTime());
             sqls.append(infoDefine.getValid());
             sqls.append(")\n ,");
         });

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

@@ -9,7 +9,6 @@ import com.persagy.dmp.basic.utils.JsonNodeUtils;
 import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.dmp.common.model.entity.BaseEntity;
 import com.persagy.dmp.define.client.DigitalDefineFacade;
-import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.rwd.migrate.entity.SyncData;
 import com.persagy.proxy.adm.request.AdmResponse;
@@ -23,7 +22,6 @@ 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.IDefineDataMigration;
-import com.persagy.proxy.migration.service.Impl.MigrationAbstractServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -149,6 +147,7 @@ public class DefineTypeMigration extends MigrationAbstractServiceImpl<ObjectType
         StringBuffer sqls = new StringBuffer(" \n -- 数据迁移  dt_define_type ------ \n");
         sqls.append(" delete from dt_define_type where project_id='"+context.getProjectId()+"' or group_code='"+context.getGroupCode()+"'; \n ");
         sqls.append(MigrationConstant.DEF_CLASS_SQL_PRE);
+
         admDefineList.forEach(typeDefine ->{
             sqls.append("(");
             sqls.append("'").append(typeDefine.getId()).append("',");
@@ -160,38 +159,16 @@ public class DefineTypeMigration extends MigrationAbstractServiceImpl<ObjectType
             sqls.append("'").append(typeDefine.getGroupCode()).append("',");
             sqls.append("'").append(typeDefine.getProjectId()).append("',");
 
-            if (typeDefine.getMajorCode() == null) {
-                sqls.append(typeDefine.getMajorCode()).append(",");
-            } else {
-                sqls.append("'").append(typeDefine.getMajorCode()).append("',");
-            }
-
-            sqls.append("'").append(typeDefine.getSystemCode()).append("',");
-
-            if (typeDefine.getEquipmentCode() == null) {
-                sqls.append(typeDefine.getEquipmentCode()).append(",");
-            } else {
-                sqls.append("'").append(typeDefine.getEquipmentCode()).append("',");
-            }
-
-            sqls.append("'").append(typeDefine.getParentCode()).append("',");
-            sqls.append("'").append(typeDefine.getVersion()).append("',");
-            sqls.append(typeDefine.getSourceFrom()).append(",");
-            sqls.append("'").append(typeDefine.getCreator()).append("',");
-            sqls.append("'").append(typeDefine.getCreationTime()).append("',");
-
-            if (typeDefine.getModifier() == null) {
-                sqls.append(typeDefine.getModifier()).append(",");
-            } else {
-                sqls.append("'").append(typeDefine.getModifier()).append("',");
-            }
-
-            if (typeDefine.getModifiedTime() == null) {
-                sqls.append(typeDefine.getModifiedTime()).append(",");
-            } else {
-                sqls.append("'").append(typeDefine.getModifiedTime()).append("',");
-            }
-
+            super.processNull(sqls, typeDefine.getMajorCode());
+            super.processNull(sqls, typeDefine.getSystemCode());
+            super.processNull(sqls, typeDefine.getEquipmentCode());
+            super.processNull(sqls, typeDefine.getParentCode());
+            super.processNull(sqls, typeDefine.getVersion());
+            super.processNull(sqls, typeDefine.getSourceFrom());
+            super.processNull(sqls, typeDefine.getCreator());
+            super.processNull(sqls, typeDefine.getCreationTime());
+            super.processNull(sqls, typeDefine.getModifier());
+            super.processNull(sqls, typeDefine.getModifiedTime());
             sqls.append(typeDefine.getValid());
             sqls.append(")\n ,");
         });

+ 14 - 1
adm-business/adm-middleware/src/main/java/com/persagy/proxy/migration/service/Impl/MigrationAbstractServiceImpl.java

@@ -472,7 +472,7 @@ public class MigrationAbstractServiceImpl<T> implements IMigrationAbstractServic
         return targetsMap;
     }
 
-
+    /** 查询对象类型 **/
     public List<String> getObjTypes(InstanceUrlParam context){
         QueryCriteria queryCriteria = new QueryCriteria();
         ObjectNode criteria = JsonNodeFactory.instance.objectNode();
@@ -485,4 +485,17 @@ public class MigrationAbstractServiceImpl<T> implements IMigrationAbstractServic
         Map<String,List<ObjectTypeDefine>> objType = types.stream().collect(Collectors.groupingBy(ObjectTypeDefine::getObjType));
         return objType.keySet().stream().collect(Collectors.toList());
     }
+
+    /**
+     * 处理空字段
+     * @param sqls
+     * @param targerStr
+     */
+    public void processNull(StringBuffer sqls ,Object targerStr){
+        if(targerStr == null){
+            sqls.append(targerStr).append(",");
+        }else{
+            sqls.append("'").append(targerStr).append("',");
+        }
+    }
 }

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

@@ -152,6 +152,7 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
             ObjectDigital objectDigital = JsonNodeUtils.toEntity(obj, ObjectDigital.class, "infos");
             sqls.append("(");
             sqls.append("'").append(objectDigital.getId()).append("',");
+
             if (objectDigital.getName() == null) {
                 sqls.append(objectDigital.getName()).append(",");
             } else {
@@ -185,20 +186,13 @@ public class ObjectDigitalMigration extends MigrationAbstractServiceImpl<ObjectD
                 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(",");
-            } else {
-                sqls.append("'").append(objectDigital.getCreateApp()).append("',");
-            }
-            if (objectDigital.getUpdateApp() == null) {
-                sqls.append(objectDigital.getUpdateApp()).append(",");
-            } else {
-                sqls.append("'").append(objectDigital.getUpdateApp()).append("',");
-            }
-            sqls.append("'").append(objectDigital.getCreator()).append("',");
-            sqls.append("'").append(objectDigital.getCreationTime()).append("',");
-            sqls.append("'").append(objectDigital.getModifier()).append("',");
-            sqls.append("'").append(objectDigital.getModifiedTime()).append("',");
+            super.processNull(sqls, objectDigital.getCreateApp());
+            super.processNull(sqls, objectDigital.getUpdateApp());
+            super.processNull(sqls, objectDigital.getCreator());
+            super.processNull(sqls, objectDigital.getCreationTime());
+            super.processNull(sqls, objectDigital.getModifier());
+            super.processNull(sqls, objectDigital.getModifiedTime());
+
             sqls.append(objectDigital.getValid());
             String sql = sqls.toString().replaceAll("\\\\n","\\\\\\\\n");
             sqlsAll.append(sql).append(")\n ,");

+ 12 - 39
adm-business/adm-middleware/src/main/java/com/persagy/proxy/migration/service/Impl/ObjectRelationMigration.java

@@ -202,46 +202,19 @@ public class ObjectRelationMigration extends MigrationAbstractServiceImpl<Object
             sqls.append("'").append(relation.getId()).append("',");
             sqls.append("'").append(relation.getGroupCode()).append("',");
             sqls.append("'").append(relation.getProjectId()).append("',");
-            if (relation.getGraphId() == null) {
-                sqls.append(relation.getGraphId()).append(",");
-            } else {
-                sqls.append("'").append(relation.getGraphId()).append("',");
-            }
-            sqls.append("'").append(relation.getGraphCode()).append("',");
-            sqls.append("'").append(relation.getRelCode()).append("',");
-
-            if (relation.getRelValue() == null) {
-                sqls.append(relation.getRelValue()).append(",");
-            } else {
-                sqls.append("'").append(relation.getRelValue()).append("',");
-            }
-
-            if (relation.getObjFrom() == null) {
-                sqls.append(relation.getObjFrom()).append(",");
-            } else {
-                sqls.append("'").append(relation.getObjFrom()).append("',");
-            }
+            super.processNull(sqls, relation.getGraphId());
+            super.processNull(sqls, relation.getGraphCode());
+            super.processNull(sqls, relation.getRelCode());
+            super.processNull(sqls, relation.getRelValue());
+            super.processNull(sqls, relation.getObjFrom());
+            super.processNull(sqls, relation.getObjTo());
+            super.processNull(sqls, relation.getCreateApp());
+            super.processNull(sqls, relation.getUpdateApp());
+            super.processNull(sqls, relation.getCreator());
+            super.processNull(sqls, relation.getCreationTime());
+            super.processNull(sqls, relation.getModifier());
+            super.processNull(sqls, relation.getModifiedTime());
 
-            if (relation.getObjTo() == null) {
-                sqls.append(relation.getObjTo()).append(",");
-            } else {
-                sqls.append("'").append(relation.getObjTo()).append("',");
-            }
-
-            if (relation.getCreateApp() == null) {
-                sqls.append(relation.getCreateApp()).append(",");
-            } else {
-                sqls.append("'").append(relation.getCreateApp()).append("',");
-            }
-            if (relation.getUpdateApp() == null) {
-                sqls.append(relation.getUpdateApp()).append(",");
-            } else {
-                sqls.append("'").append(relation.getUpdateApp()).append("',");
-            }
-            sqls.append("'").append(relation.getCreator()).append("',");
-            sqls.append("'").append(relation.getCreationTime()).append("',");
-            sqls.append("'").append(relation.getModifier()).append("',");
-            sqls.append("'").append(relation.getModifiedTime()).append("',");
             sqls.append(relation.getValid());
             sqls.append(")\n ,");
         });