|
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -29,7 +30,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
@Resource
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
-// @Value("${spring.datasource.dynamic.datasource.master.url}")
|
|
|
+ // @Value("${spring.datasource.dynamic.datasource.master.url}")
|
|
|
private String url = "ry-vue";
|
|
|
|
|
|
@Override
|
|
@@ -39,23 +40,23 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
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> list= filedList.stream().map(filed->{
|
|
|
+ List<String> list = filedList.stream().map(filed -> {
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
- stringBuilder.append(filed.getFieldName()+" ")
|
|
|
- .append(filed.getFieldType()+" ");
|
|
|
- if(filed.getIsNull()){
|
|
|
+ stringBuilder.append(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsNull()) {
|
|
|
stringBuilder.append("NOT NULL ");
|
|
|
}
|
|
|
- if(filed.getIsPrimary()){
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
stringBuilder.append("PRIMARY KEY ");
|
|
|
- if(filed.getIsAuto()){
|
|
|
+ if (filed.getIsAuto()) {
|
|
|
stringBuilder.append("AUTO_INCREMENT ");
|
|
|
}
|
|
|
}
|
|
|
- stringBuilder.append("COMMENT '"+filed.getFieldDescription()+"'");
|
|
|
+ stringBuilder.append("COMMENT '" + filed.getFieldDescription() + "'");
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
- tableInfoMapper.createMysqlDataBase(tableName,tableComment,list);
|
|
|
+ tableInfoMapper.createMysqlDataBase(tableName, tableComment, list);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -66,31 +67,31 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
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> list= filedList.stream().map(filed->{
|
|
|
+ List<String> list = filedList.stream().map(filed -> {
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
- stringBuilder.append(filed.getFieldName()+" ")
|
|
|
- .append(filed.getFieldType()+" ");
|
|
|
- if(filed.getIsNull()){
|
|
|
+ stringBuilder.append(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsNull()) {
|
|
|
stringBuilder.append("NOT NULL ");
|
|
|
}
|
|
|
- if(filed.getIsPrimary()){
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
stringBuilder.append("PRIMARY KEY ");
|
|
|
- if(filed.getIsAuto()){
|
|
|
+ if (filed.getIsAuto()) {
|
|
|
stringBuilder.append("IDENTITY(1,1) ");
|
|
|
}
|
|
|
}
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- List<String> descriptionList = filedList.stream().map(filed ->{
|
|
|
+ List<String> descriptionList = filedList.stream().map(filed -> {
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
- if(StringUtils.hasLength(filed.getFieldDescription())){
|
|
|
+ if (StringUtils.hasLength(filed.getFieldDescription())) {
|
|
|
stringBuilder.append("EXECUTE sp_addextendedproperty N'MS_Description',")
|
|
|
- .append("'"+filed.getFieldDescription()+"'")
|
|
|
+ .append("'" + filed.getFieldDescription() + "'")
|
|
|
.append(", N'user', N'dbo', N'table', N")
|
|
|
- .append("'"+tableName+"'")
|
|
|
+ .append("'" + tableName + "'")
|
|
|
.append(", N'column', N")
|
|
|
- .append("'"+filed.getFieldName()+"'");
|
|
|
+ .append("'" + filed.getFieldName() + "'");
|
|
|
}
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
@@ -100,7 +101,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
// }else {
|
|
|
// tableInfoMapper.createSqlServerDataBase(dataBaseName);
|
|
|
// tableInfoMapper.useSqlserverDatabase(dataBaseName);
|
|
|
- tableInfoMapper.createSqlServerTable(tableName,list,descriptionList,tableComment);
|
|
|
+ tableInfoMapper.createSqlServerTable(tableName, list, descriptionList, tableComment);
|
|
|
// tableInfoMapper.useSqlserverDatabase(dataSource.getDatabaseName());
|
|
|
// }
|
|
|
|
|
@@ -108,56 +109,56 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
|
|
|
@Override
|
|
|
public int mysqlTableExist(String dataBaseName, String tableName) {
|
|
|
- return tableInfoMapper.mysqlTableExist(dataBaseName,tableName);
|
|
|
+ return tableInfoMapper.mysqlTableExist(dataBaseName, tableName);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AjaxResult tableInfoList(Map<String,Object> map) {
|
|
|
+ public AjaxResult tableInfoList(Map<String, Object> map) {
|
|
|
int pageNum = Integer.valueOf(map.get("pageNum").toString());
|
|
|
int pageSize = Integer.valueOf(map.get("pageSize").toString());
|
|
|
- String databaseType = (String)map.get("databaseType");
|
|
|
- String databaseName = (String)map.get("databaseName");
|
|
|
+ String databaseType = (String) map.get("databaseType");
|
|
|
+ String databaseName = (String) map.get("databaseName");
|
|
|
//获取数据源信息
|
|
|
// if(redisTemplate.hasKey("DataSource")){
|
|
|
// DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
|
- if(databaseType.equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
|
- List<TableInfoVO> mysqlTableList = tableInfoMapper.tableInfoList(databaseName,map);
|
|
|
- AjaxResult ajaxResult = new AjaxResult();
|
|
|
- ajaxResult.put("code",200)
|
|
|
- .put("data",mysqlTableList.stream().skip((pageNum-1)*pageSize).limit(pageSize).
|
|
|
- collect(Collectors.toList()))
|
|
|
- .put("msg","操作成功")
|
|
|
- .put("total",mysqlTableList.size());
|
|
|
- return ajaxResult;
|
|
|
-
|
|
|
- }else if(databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
- List<TableInfoVO> sqlServerTableList = tableInfoMapper.sqlServerTableInfoList(databaseName,map);
|
|
|
- AjaxResult ajaxResult = new AjaxResult();
|
|
|
- ajaxResult.put("code",200)
|
|
|
- .put("data",sqlServerTableList.stream().skip((pageNum-1)*pageSize).limit(pageSize).
|
|
|
- collect(Collectors.toList()))
|
|
|
- .put("msg","操作成功")
|
|
|
- .put("total",sqlServerTableList.size());
|
|
|
- return ajaxResult;
|
|
|
-
|
|
|
- }else if(databaseType.equals(DataSourceType.DM.getDataSourceName())){
|
|
|
- List<TableInfoVO> dmTableList = tableInfoMapper.dmTableInfoList(databaseName,map);
|
|
|
- AjaxResult ajaxResult = new AjaxResult();
|
|
|
- ajaxResult.put("code",200)
|
|
|
- .put("data",dmTableList.stream().skip((pageNum-1)*pageSize).limit(pageSize).
|
|
|
- collect(Collectors.toList()))
|
|
|
- .put("msg","操作成功")
|
|
|
- .put("total",dmTableList.size());
|
|
|
- return ajaxResult;
|
|
|
- }
|
|
|
+ if (databaseType.equals(DataSourceType.MYSQL.getDataSourceName())) {
|
|
|
+ List<TableInfoVO> mysqlTableList = tableInfoMapper.tableInfoList(databaseName, map);
|
|
|
+ AjaxResult ajaxResult = new AjaxResult();
|
|
|
+ ajaxResult.put("code", 200)
|
|
|
+ .put("data", mysqlTableList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).
|
|
|
+ collect(Collectors.toList()))
|
|
|
+ .put("msg", "操作成功")
|
|
|
+ .put("total", mysqlTableList.size());
|
|
|
+ return ajaxResult;
|
|
|
+
|
|
|
+ } else if (databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())) {
|
|
|
+ List<TableInfoVO> sqlServerTableList = tableInfoMapper.sqlServerTableInfoList(databaseName, map);
|
|
|
+ AjaxResult ajaxResult = new AjaxResult();
|
|
|
+ ajaxResult.put("code", 200)
|
|
|
+ .put("data", sqlServerTableList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).
|
|
|
+ collect(Collectors.toList()))
|
|
|
+ .put("msg", "操作成功")
|
|
|
+ .put("total", sqlServerTableList.size());
|
|
|
+ return ajaxResult;
|
|
|
+
|
|
|
+ } else if (databaseType.equals(DataSourceType.DM.getDataSourceName())) {
|
|
|
+ List<TableInfoVO> dmTableList = tableInfoMapper.dmTableInfoList(databaseName, map);
|
|
|
+ AjaxResult ajaxResult = new AjaxResult();
|
|
|
+ ajaxResult.put("code", 200)
|
|
|
+ .put("data", dmTableList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).
|
|
|
+ collect(Collectors.toList()))
|
|
|
+ .put("msg", "操作成功")
|
|
|
+ .put("total", dmTableList.size());
|
|
|
+ return ajaxResult;
|
|
|
+ }
|
|
|
// }
|
|
|
- List<TableInfoVO> mysqlTableList = tableInfoMapper.tableInfoList(databaseName,map);
|
|
|
+ List<TableInfoVO> mysqlTableList = tableInfoMapper.tableInfoList(databaseName, map);
|
|
|
AjaxResult ajaxResult = new AjaxResult();
|
|
|
- ajaxResult.put("code",200)
|
|
|
- .put("data",mysqlTableList.stream().skip((pageNum-1)*pageSize).limit(pageSize).
|
|
|
+ ajaxResult.put("code", 200)
|
|
|
+ .put("data", mysqlTableList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).
|
|
|
collect(Collectors.toList()))
|
|
|
- .put("msg","操作成功")
|
|
|
- .put("total",mysqlTableList.size());
|
|
|
+ .put("msg", "操作成功")
|
|
|
+ .put("total", mysqlTableList.size());
|
|
|
return ajaxResult;
|
|
|
|
|
|
}
|
|
@@ -168,34 +169,34 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AjaxResult dropTable(Map<String,Object> map) {
|
|
|
- String tableName = (String)map.get("tableName");
|
|
|
- String databaseType = (String)map.get("databaseType");
|
|
|
- String databaseName = (String)map.get("databaseName");
|
|
|
+ public AjaxResult dropTable(Map<String, Object> map) {
|
|
|
+ String tableName = (String) map.get("tableName");
|
|
|
+ String databaseType = (String) map.get("databaseType");
|
|
|
+ String databaseName = (String) map.get("databaseName");
|
|
|
// if(redisTemplate.hasKey("DataSource")){
|
|
|
// DataSource dataSource = JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
|
- if(databaseType.equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
|
- if(tableInfoMapper.selectDataCount(tableName)>0){
|
|
|
- return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
- }
|
|
|
- tableInfoMapper.dropMysqlTable(tableName);
|
|
|
- return AjaxResult.success();
|
|
|
- }else if(databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
- if(tableInfoMapper.selectSqlServerDataCount(tableName)>0){
|
|
|
- return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
- }
|
|
|
- tableInfoMapper.dropSqlserverTable(tableName);
|
|
|
- return AjaxResult.success();
|
|
|
- }else if(databaseType.equals(DataSourceType.DM.getDataSourceName())){
|
|
|
- if(tableInfoMapper.selectDmDataCount(tableName)>0){
|
|
|
- return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
- }
|
|
|
- tableInfoMapper.dropDmTable(databaseName,tableName);
|
|
|
- return AjaxResult.success();
|
|
|
+ if (databaseType.equals(DataSourceType.MYSQL.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.selectDataCount(tableName) > 0) {
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
}
|
|
|
+ tableInfoMapper.dropMysqlTable(tableName);
|
|
|
+ return AjaxResult.success();
|
|
|
+ } else if (databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.selectSqlServerDataCount(tableName) > 0) {
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
+ }
|
|
|
+ tableInfoMapper.dropSqlserverTable(tableName);
|
|
|
+ return AjaxResult.success();
|
|
|
+ } else if (databaseType.equals(DataSourceType.DM.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.selectDmDataCount(tableName) > 0) {
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
+ }
|
|
|
+ tableInfoMapper.dropDmTable(databaseName, tableName);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
|
|
|
// }
|
|
|
- if(tableInfoMapper.selectDataCount(tableName)>0){
|
|
|
+ if (tableInfoMapper.selectDataCount(tableName) > 0) {
|
|
|
return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
}
|
|
|
tableInfoMapper.dropMysqlTable(tableName);
|
|
@@ -206,34 +207,33 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
public AjaxResult createTable(Map<String, Object> map) {
|
|
|
String dataBaseName = (String) map.get("dataBaseName");
|
|
|
String tableName = (String) map.get("tableName");
|
|
|
- String databaseType = (String)map.get("databaseType");
|
|
|
- if(databaseType.equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
|
- if(tableInfoMapper.mysqlTableExist(dataBaseName,tableName)>0){
|
|
|
+ String databaseType = (String) map.get("databaseType");
|
|
|
+ if (databaseType.equals(DataSourceType.MYSQL.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.mysqlTableExist(dataBaseName, tableName) > 0) {
|
|
|
return AjaxResult.warn("当前数据库中表已存在");
|
|
|
}
|
|
|
createMysqlDataBase(map);
|
|
|
return AjaxResult.success();
|
|
|
- }else if(databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
- if(sqlServerTableExist(dataBaseName,tableName)>0){
|
|
|
+ } else if (databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())) {
|
|
|
+ if (sqlServerTableExist(dataBaseName, tableName) > 0) {
|
|
|
return AjaxResult.warn("当前数据库中表已存在");
|
|
|
}
|
|
|
createSqlServerDataBase(map);
|
|
|
return AjaxResult.success();
|
|
|
- }else if(databaseType.equals(DataSourceType.DM.getDataSourceName())){
|
|
|
- if(tableInfoMapper.dmTableExist(dataBaseName,tableName)>0){
|
|
|
+ } else if (databaseType.equals(DataSourceType.DM.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.dmTableExist(dataBaseName, tableName) > 0) {
|
|
|
return AjaxResult.warn("当前数据库中表已存在");
|
|
|
}
|
|
|
createDmDataBase(map);
|
|
|
return AjaxResult.success();
|
|
|
- }
|
|
|
- else if(databaseType.equals(DataSourceType.ORACLE.getDataSourceName())){
|
|
|
- if(tableInfoMapper.oracleTableExist(tableName)>0){
|
|
|
+ } else if (databaseType.equals(DataSourceType.ORACLE.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.oracleTableExist(tableName) > 0) {
|
|
|
return AjaxResult.warn("当前数据库中表已存在");
|
|
|
}
|
|
|
createOracleTable(map);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
- if(tableInfoMapper.mysqlTableExist(dataBaseName,tableName)>0){
|
|
|
+ if (tableInfoMapper.mysqlTableExist(dataBaseName, tableName) > 0) {
|
|
|
return AjaxResult.warn("当前数据库中表已存在");
|
|
|
}
|
|
|
createMysqlDataBase(map);
|
|
@@ -243,32 +243,32 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
@Override
|
|
|
public AjaxResult updateTable(Map<String, Object> map) {
|
|
|
String dataBaseName = (String) map.get("dataBaseName");
|
|
|
- String databaseType = (String)map.get("databaseType");
|
|
|
+ String databaseType = (String) map.get("databaseType");
|
|
|
String tableName = (String) map.get("tableName");
|
|
|
// if(redisTemplate.hasKey("DataSource")){
|
|
|
// DataSource dataSource = JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
|
- if(databaseType.equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
|
- if(tableInfoMapper.selectDataCount(tableName)>0){
|
|
|
- return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
- }
|
|
|
- updateMysqlTable(map);
|
|
|
- return AjaxResult.success();
|
|
|
- }else if(databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
- if(tableInfoMapper.selectSqlServerDataCount(tableName)>0){
|
|
|
- return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
- }
|
|
|
- updateSqlserverTable(map);
|
|
|
- return AjaxResult.success();
|
|
|
- }else if(databaseType.equals(DataSourceType.DM.getDataSourceName())){
|
|
|
- if(tableInfoMapper.selectDmDataCount(tableName)>0){
|
|
|
- return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
- }
|
|
|
- map.put("dataBaseName",dataBaseName);
|
|
|
- updateDmTable(map);
|
|
|
- return AjaxResult.success();
|
|
|
+ if (databaseType.equals(DataSourceType.MYSQL.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.selectDataCount(tableName) > 0) {
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
+ }
|
|
|
+ updateMysqlTable(map);
|
|
|
+ return AjaxResult.success();
|
|
|
+ } else if (databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.selectSqlServerDataCount(tableName) > 0) {
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
}
|
|
|
+ updateSqlserverTable(map);
|
|
|
+ return AjaxResult.success();
|
|
|
+ } else if (databaseType.equals(DataSourceType.DM.getDataSourceName())) {
|
|
|
+ if (tableInfoMapper.selectDmDataCount(tableName) > 0) {
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
+ }
|
|
|
+ map.put("dataBaseName", dataBaseName);
|
|
|
+ updateDmTable(map);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
// }
|
|
|
- if(tableInfoMapper.selectDataCount(tableName)>0){
|
|
|
+ if (tableInfoMapper.selectDataCount(tableName) > 0) {
|
|
|
return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
}
|
|
|
updateMysqlTable(map);
|
|
@@ -276,44 +276,44 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<TableInfo> tableFieldInfo(Map<String,Object> map) {
|
|
|
+ public List<TableInfo> tableFieldInfo(Map<String, Object> map) {
|
|
|
|
|
|
- String tableName = (String)map.get("tableName");
|
|
|
- String databaseType = (String)map.get("databaseType");
|
|
|
- String databaseName = (String)map.get("databaseName");
|
|
|
+ String tableName = (String) map.get("tableName");
|
|
|
+ String databaseType = (String) map.get("databaseType");
|
|
|
+ String databaseName = (String) map.get("databaseName");
|
|
|
// if(redisTemplate.hasKey("DataSource")){
|
|
|
// DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
|
- if(databaseType.equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
|
- return tableInfoMapper.mysqlTableFieldInfo(databaseName,tableName);
|
|
|
- }else if(databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
- return tableInfoMapper.sqlserverTableFieldInfo(tableName);
|
|
|
- }else if(databaseType.equals(DataSourceType.DM.getDataSourceName())){
|
|
|
- return tableInfoMapper.dmTableFieldInfo(databaseName,tableName);
|
|
|
- }
|
|
|
+ if (databaseType.equals(DataSourceType.MYSQL.getDataSourceName())) {
|
|
|
+ return tableInfoMapper.mysqlTableFieldInfo(databaseName, tableName);
|
|
|
+ } else if (databaseType.equals(DataSourceType.SQLSERVER.getDataSourceName())) {
|
|
|
+ return tableInfoMapper.sqlserverTableFieldInfo(tableName);
|
|
|
+ } else if (databaseType.equals(DataSourceType.DM.getDataSourceName())) {
|
|
|
+ return tableInfoMapper.dmTableFieldInfo(databaseName, tableName);
|
|
|
+ }
|
|
|
// }
|
|
|
- return tableInfoMapper.mysqlTableFieldInfo(databaseName,tableName);
|
|
|
+ return tableInfoMapper.mysqlTableFieldInfo(databaseName, tableName);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateMysqlTable(Map<String, Object> map) {
|
|
|
String tableName = (String) map.get("tableName");
|
|
|
String tableComment = (String) map.get("tableComment");
|
|
|
- String databaseName = (String)map.get("databaseName");
|
|
|
+ String databaseName = (String) map.get("databaseName");
|
|
|
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.append(filed.getFieldName()+" ")
|
|
|
- .append(filed.getFieldType()+" ");
|
|
|
- if(filed.getIsNull()){
|
|
|
+ stringBuilder.append(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsNull()) {
|
|
|
stringBuilder.append("NOT NULL ");
|
|
|
}
|
|
|
- if(filed.getIsPrimary()){
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
stringBuilder.append("PRIMARY KEY ");
|
|
|
- if(filed.getIsAuto()){
|
|
|
+ if (filed.getIsAuto()) {
|
|
|
stringBuilder.append("AUTO_INCREMENT ");
|
|
|
}
|
|
|
}
|
|
|
- stringBuilder.append("COMMENT '"+filed.getFieldDescription()+"'");
|
|
|
+ stringBuilder.append("COMMENT '" + filed.getFieldDescription() + "'");
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
@@ -324,12 +324,18 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
// String dataBaseName = url;
|
|
|
// tableInfoMapper.updateMysqlTable(dataBaseName,tableName,tableComment,list);
|
|
|
// }
|
|
|
- tableInfoMapper.updateMysqlTable(databaseName,tableName,tableComment,list);
|
|
|
+
|
|
|
+ try {
|
|
|
+ tableInfoMapper.updateMysqlTable(databaseName, tableName, tableComment, list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 如果异常进行模拟回滚-》执行创建原始表结构语句
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int sqlServerTableExist(String dataBaseName,String tableName) {
|
|
|
+ public int sqlServerTableExist(String dataBaseName, String tableName) {
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
stringBuilder.append(dataBaseName)
|
|
|
.append(".dbo.")
|
|
@@ -352,41 +358,43 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
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> list= filedList.stream().map(filed->{
|
|
|
+ List<String> list = filedList.stream().map(filed -> {
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
- stringBuilder.append(filed.getFieldName()+" ")
|
|
|
- .append(filed.getFieldType()+" ");
|
|
|
- if(filed.getIsNull()){
|
|
|
+ stringBuilder.append(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsNull()) {
|
|
|
stringBuilder.append("NOT NULL ");
|
|
|
}
|
|
|
- if(filed.getIsPrimary()){
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
stringBuilder.append("PRIMARY KEY ");
|
|
|
- if(filed.getIsAuto()){
|
|
|
+ if (filed.getIsAuto()) {
|
|
|
stringBuilder.append("IDENTITY(1,1) ");
|
|
|
}
|
|
|
}
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- List<String> descriptionList = filedList.stream().map(filed ->{
|
|
|
+ List<String> descriptionList = filedList.stream().map(filed -> {
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
- if(StringUtils.hasLength(filed.getFieldDescription())){
|
|
|
+ if (StringUtils.hasLength(filed.getFieldDescription())) {
|
|
|
stringBuilder.append("EXECUTE sp_addextendedproperty N'MS_Description',")
|
|
|
- .append("'"+filed.getFieldDescription()+"'")
|
|
|
+ .append("'" + filed.getFieldDescription() + "'")
|
|
|
.append(", N'user', N'dbo', N'table', N")
|
|
|
- .append("'"+tableName+"'")
|
|
|
+ .append("'" + tableName + "'")
|
|
|
.append(", N'column', N")
|
|
|
- .append("'"+filed.getFieldName()+"'");
|
|
|
+ .append("'" + filed.getFieldName() + "'");
|
|
|
}
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
+ // 删除表
|
|
|
tableInfoMapper.dropSqlserverTable(tableName);
|
|
|
- tableInfoMapper.updateSqlserverTable(tableName,list,descriptionList,tableComment);
|
|
|
+ // 新增表
|
|
|
+ tableInfoMapper.updateSqlserverTable(tableName, list, descriptionList, tableComment);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int dmTableExist(String dataBaseName, String tableName) {
|
|
|
- return tableInfoMapper.dmTableExist(dataBaseName,tableName);
|
|
|
+ return tableInfoMapper.dmTableExist(dataBaseName, tableName);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -396,38 +404,38 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
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->{
|
|
|
+ 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(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
+ if (filed.getIsAuto()) {
|
|
|
stringBuilder.append("IDENTITY(1,1) ");
|
|
|
}
|
|
|
stringBuilder.append("PRIMARY KEY ");
|
|
|
}
|
|
|
- if(filed.getIsNull()){
|
|
|
+ if (filed.getIsNull()) {
|
|
|
stringBuilder.append("NOT NULL ");
|
|
|
}
|
|
|
|
|
|
- if(StringUtils.hasLength(filed.getFieldDescription())){
|
|
|
+ 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()+"'");
|
|
|
+ .append(filed.getFieldName() + "\" IS ")
|
|
|
+ .append("'" + filed.getFieldDescription() + "'");
|
|
|
descriptionList.add(builder.toString());
|
|
|
}
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- tableInfoMapper.createDmTable(databaseName,tableName,list);
|
|
|
- descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
|
|
|
- tableInfoMapper.addDmTableComment(databaseName,tableName,tableComment);
|
|
|
+ tableInfoMapper.createDmTable(databaseName, tableName, list);
|
|
|
+ descriptionList.stream().forEach(f -> tableInfoMapper.addTableDescription(f));
|
|
|
+ tableInfoMapper.addDmTableComment(databaseName, tableName, tableComment);
|
|
|
// if(tableInfoMapper.dmDataBaseExist(dataBaseName)>0){
|
|
|
// tableInfoMapper.createDmTable(dataBaseName,tableName,list);
|
|
|
// descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
|
|
@@ -447,38 +455,38 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
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->{
|
|
|
+ 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(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
+ if (filed.getIsAuto()) {
|
|
|
stringBuilder.append("IDENTITY(1,1) ");
|
|
|
}
|
|
|
stringBuilder.append("PRIMARY KEY ");
|
|
|
}
|
|
|
- if(filed.getIsNull()){
|
|
|
+ if (filed.getIsNull()) {
|
|
|
stringBuilder.append("NOT NULL ");
|
|
|
}
|
|
|
|
|
|
- if(StringUtils.hasLength(filed.getFieldDescription())){
|
|
|
+ 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()+"'");
|
|
|
+ .append(filed.getFieldName() + "\" IS ")
|
|
|
+ .append("'" + filed.getFieldDescription() + "'");
|
|
|
descriptionList.add(builder.toString());
|
|
|
}
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
- tableInfoMapper.dropDmTable(databaseName,tableName);
|
|
|
- tableInfoMapper.createDmTable(databaseName,tableName,list);
|
|
|
- descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
|
|
|
- tableInfoMapper.addDmTableComment(databaseName,tableName,tableComment);
|
|
|
+ tableInfoMapper.dropDmTable(databaseName, tableName);
|
|
|
+ tableInfoMapper.createDmTable(databaseName, tableName, list);
|
|
|
+ descriptionList.stream().forEach(f -> tableInfoMapper.addTableDescription(f));
|
|
|
+ tableInfoMapper.addDmTableComment(databaseName, tableName, tableComment);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -492,28 +500,28 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
String tableName = (String) map.get("tableName");
|
|
|
List<TableInfo> filedList = JSON.parseArray(JSON.toJSONString(map.get("field")), TableInfo.class);
|
|
|
List<String> descriptionList = new ArrayList<>();
|
|
|
- List<String> list= filedList.stream().map(filed->{
|
|
|
+ List<String> list = filedList.stream().map(filed -> {
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
- stringBuilder.append(filed.getFieldName()+" ")
|
|
|
- .append(filed.getFieldType()+" ");
|
|
|
- if(filed.getIsPrimary()){
|
|
|
+ stringBuilder.append(filed.getFieldName() + " ")
|
|
|
+ .append(filed.getFieldType() + " ");
|
|
|
+ if (filed.getIsPrimary()) {
|
|
|
stringBuilder.append("PRIMARY KEY ");
|
|
|
}
|
|
|
- if(filed.getIsNull()){
|
|
|
+ if (filed.getIsNull()) {
|
|
|
stringBuilder.append("NOT NULL ");
|
|
|
}
|
|
|
- if(StringUtils.hasLength(filed.getFieldDescription())){
|
|
|
+ if (StringUtils.hasLength(filed.getFieldDescription())) {
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
builder.append("comment on column ")
|
|
|
.append(tableName)
|
|
|
.append(".")
|
|
|
- .append(filed.getFieldName()+" is '")
|
|
|
- .append(filed.getFieldDescription()+"'");
|
|
|
+ .append(filed.getFieldName() + " is '")
|
|
|
+ .append(filed.getFieldDescription() + "'");
|
|
|
descriptionList.add(builder.toString());
|
|
|
}
|
|
|
return stringBuilder.toString();
|
|
|
}).collect(Collectors.toList());
|
|
|
- tableInfoMapper.createOracleTable(tableName,list);
|
|
|
- descriptionList.stream().forEach(f ->tableInfoMapper.addOracleTableDescription(f));
|
|
|
+ tableInfoMapper.createOracleTable(tableName, list);
|
|
|
+ descriptionList.stream().forEach(f -> tableInfoMapper.addOracleTableDescription(f));
|
|
|
}
|
|
|
}
|