|
@@ -190,7 +190,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
if(tableInfoMapper.selectDmDataCount(tableName)>0){
|
|
if(tableInfoMapper.selectDmDataCount(tableName)>0){
|
|
return AjaxResult.warn("表中有数据,不能删除!");
|
|
return AjaxResult.warn("表中有数据,不能删除!");
|
|
}
|
|
}
|
|
- tableInfoMapper.dropDmTable(tableName);
|
|
|
|
|
|
+ tableInfoMapper.dropDmTable(dataSource.getDatabaseName(),tableName);
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -235,6 +235,40 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult updateTable(Map<String, Object> map) {
|
|
|
|
+ String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
|
|
|
|
+ String tableName = (String) map.get("tableName");
|
|
|
|
+ if(redisTemplate.hasKey("DataSource")){
|
|
|
|
+ DataSource dataSource = JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
|
|
+ if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
|
|
+ if(tableInfoMapper.selectDataCount(tableName)>0){
|
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
|
+ }
|
|
|
|
+ updateMysqlTable(map);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
|
+ if(tableInfoMapper.selectSqlServerDataCount(tableName)>0){
|
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
|
+ }
|
|
|
|
+ updateSqlserverTable(map);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
|
|
|
|
+ if(tableInfoMapper.selectDmDataCount(tableName)>0){
|
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
|
+ }
|
|
|
|
+ map.put("dataBaseName",dataSource.getDatabaseName());
|
|
|
|
+ updateDmTable(map);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(tableInfoMapper.selectDataCount(tableName)>0){
|
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
|
+ }
|
|
|
|
+ updateMysqlTable(map);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<TableInfo> tableFieldInfo(String tableName) {
|
|
public List<TableInfo> tableFieldInfo(String tableName) {
|
|
String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
|
|
String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
|
|
@@ -243,7 +277,9 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
return tableInfoMapper.mysqlTableFieldInfo(dataSource.getDatabaseName(),tableName);
|
|
return tableInfoMapper.mysqlTableFieldInfo(dataSource.getDatabaseName(),tableName);
|
|
}else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
}else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
-
|
|
|
|
|
|
+ return tableInfoMapper.sqlserverTableFieldInfo(tableName);
|
|
|
|
+ }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
|
|
|
|
+ return tableInfoMapper.dmTableFieldInfo(dataSource.getDatabaseName(),tableName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return tableInfoMapper.mysqlTableFieldInfo(dataBaseName,tableName);
|
|
return tableInfoMapper.mysqlTableFieldInfo(dataBaseName,tableName);
|
|
@@ -303,6 +339,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
@Override
|
|
@Override
|
|
public void updateSqlserverTable(Map<String, Object> map) {
|
|
public void updateSqlserverTable(Map<String, Object> map) {
|
|
String tableName = (String) map.get("tableName");
|
|
String tableName = (String) map.get("tableName");
|
|
|
|
+ String tableComment = (String) map.get("tableComment");
|
|
List<TableInfo> filedList = JSON.parseArray(JSON.toJSONString(map.get("field")), TableInfo.class);
|
|
List<TableInfo> filedList = JSON.parseArray(JSON.toJSONString(map.get("field")), TableInfo.class);
|
|
List<String> list= filedList.stream().map(filed->{
|
|
List<String> list= filedList.stream().map(filed->{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
@@ -333,7 +370,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
return stringBuilder.toString();
|
|
return stringBuilder.toString();
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
tableInfoMapper.dropSqlserverTable(tableName);
|
|
tableInfoMapper.dropSqlserverTable(tableName);
|
|
- tableInfoMapper.updateSqlserverTable(tableName,list,descriptionList);
|
|
|
|
|
|
+ tableInfoMapper.updateSqlserverTable(tableName,list,descriptionList,tableComment);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -388,24 +425,48 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
|
-// public int queryDmTableCount(Map<String,Object> map) {
|
|
|
|
-// String dataBaseName = (String) map.get("dataBaseName");
|
|
|
|
-// if(redisTemplate.hasKey("DataSource")){
|
|
|
|
-// DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
|
|
-// if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
|
|
-// return 0;
|
|
|
|
-//
|
|
|
|
-// }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
|
-// return 0;
|
|
|
|
-//
|
|
|
|
-// }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
|
|
|
|
-// return tableInfoMapper.queryDmTableCount(dataSource.getDatabaseName(),map);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// return 0;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void updateDmTable(Map<String, Object> map) {
|
|
|
|
+ String dataBaseName = (String) map.get("dataBaseName");
|
|
|
|
+ String tableName = (String) map.get("tableName");
|
|
|
|
+ String tableComment = (String) map.get("tableComment");
|
|
|
|
+ List<TableInfo> filedList = JSON.parseArray(JSON.toJSONString(map.get("field")), TableInfo.class);
|
|
|
|
+ List<String> descriptionList = new ArrayList<>();
|
|
|
|
+ List<String> list= filedList.stream().map(filed->{
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
+ stringBuilder.append(filed.getFieldName()+" ")
|
|
|
|
+ .append(filed.getFieldType()+" ");
|
|
|
|
+ if(filed.getIsPrimary()){
|
|
|
|
+ if(filed.getIsAuto()){
|
|
|
|
+ stringBuilder.append("IDENTITY(1,1) ");
|
|
|
|
+ }
|
|
|
|
+ stringBuilder.append("PRIMARY KEY ");
|
|
|
|
+ }
|
|
|
|
+ if(filed.getIsNull()){
|
|
|
|
+ stringBuilder.append("NOT NULL ");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(StringUtils.hasLength(filed.getFieldDescription())){
|
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
|
+ builder.append("COMMENT ON COLUMN \"")
|
|
|
|
+ .append(dataBaseName)
|
|
|
|
+ .append("\".\"")
|
|
|
|
+ .append(tableName)
|
|
|
|
+ .append("\".\"")
|
|
|
|
+ .append(filed.getFieldName()+"\" IS ")
|
|
|
|
+ .append("'"+filed.getFieldDescription()+"'");
|
|
|
|
+ descriptionList.add(builder.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return stringBuilder.toString();
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ System.err.println(dataBaseName);
|
|
|
|
+ tableInfoMapper.dropDmTable(dataBaseName,tableName);
|
|
|
|
+ tableInfoMapper.createDmTable(dataBaseName,tableName,list);
|
|
|
|
+ descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
|
|
|
|
+ tableInfoMapper.addDmTableComment(dataBaseName,tableName,tableComment);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public int oracleTableExist(String tableName) {
|
|
public int oracleTableExist(String tableName) {
|