|
@@ -10,6 +10,8 @@ import com.customer.pojo.TableInfo;
|
|
import com.customer.service.ICustomerService;
|
|
import com.customer.service.ICustomerService;
|
|
import com.customer.service.IDataSourceService;
|
|
import com.customer.service.IDataSourceService;
|
|
import com.customer.service.ITableInfoService;
|
|
import com.customer.service.ITableInfoService;
|
|
|
|
+import com.customer.utils.AjaxResult;
|
|
|
|
+import com.customer.utils.PageUtil;
|
|
import com.customer.vo.TableInfoVO;
|
|
import com.customer.vo.TableInfoVO;
|
|
import org.apache.ibatis.session.RowBounds;
|
|
import org.apache.ibatis.session.RowBounds;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -43,6 +45,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
public void createMysqlDataBase(Map<String, Object> map) {
|
|
public void createMysqlDataBase(Map<String, Object> map) {
|
|
String dataBaseName = (String) map.get("dataBaseName");
|
|
String dataBaseName = (String) map.get("dataBaseName");
|
|
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();
|
|
@@ -60,7 +63,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
stringBuilder.append("COMMENT '"+filed.getFieldDescription()+"'");
|
|
stringBuilder.append("COMMENT '"+filed.getFieldDescription()+"'");
|
|
return stringBuilder.toString();
|
|
return stringBuilder.toString();
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
- tableInfoMapper.createMysqlDataBase(dataBaseName,tableName,list);
|
|
|
|
|
|
+ tableInfoMapper.createMysqlDataBase(dataBaseName,tableName,tableComment,list);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -116,19 +119,19 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
public List<TableInfoVO> tableInfoList(Map<String,Object> map) {
|
|
public List<TableInfoVO> tableInfoList(Map<String,Object> map) {
|
|
int pageNum = (int)map.get("pageNum");
|
|
int pageNum = (int)map.get("pageNum");
|
|
int pageSize = (int)map.get("pageSize");
|
|
int pageSize = (int)map.get("pageSize");
|
|
-
|
|
|
|
|
|
+ RowBounds rowBounds = PageUtil.getPageParam(pageNum,pageSize);
|
|
//获取数据源信息
|
|
//获取数据源信息
|
|
if(redisTemplate.hasKey("DataSource")){
|
|
if(redisTemplate.hasKey("DataSource")){
|
|
DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
|
|
- return tableInfoMapper.tableInfoList(dataSource.getDatabaseName(),map,new RowBounds(pageNum,pageSize));
|
|
|
|
|
|
+ return tableInfoMapper.tableInfoList(dataSource.getDatabaseName(),map,rowBounds);
|
|
}else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
}else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
return tableInfoMapper.sqlServerTableInfoList(dataSource.getDatabaseName());
|
|
return tableInfoMapper.sqlServerTableInfoList(dataSource.getDatabaseName());
|
|
}else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
|
|
}else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
|
|
return tableInfoMapper.dmTableInfoList(dataSource.getDatabaseName());
|
|
return tableInfoMapper.dmTableInfoList(dataSource.getDatabaseName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return tableInfoMapper.tableInfoList(url.substring(url.lastIndexOf("/") + 1),map,new RowBounds(pageNum,pageSize));
|
|
|
|
|
|
+ return tableInfoMapper.tableInfoList(url.substring(url.lastIndexOf("/") + 1),map,rowBounds);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -137,11 +140,77 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
return tableInfoMapper.selectDataCount(tableName);
|
|
return tableInfoMapper.selectDataCount(tableName);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// @Override
|
|
|
|
+// public void dropMysqlTable(String tableName) {
|
|
|
|
+// tableInfoMapper.dropMysqlTable(tableName);
|
|
|
|
+// }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public void dropMysqlTable(String tableName) {
|
|
|
|
|
|
+ public AjaxResult dropTable(String 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("表中有数据,不能删除!");
|
|
|
|
+ }
|
|
|
|
+ tableInfoMapper.dropMysqlTable(tableName);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
|
+ if(tableInfoMapper.selectSqlServerDataCount(tableName)>0){
|
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
|
+ }
|
|
|
|
+ tableInfoMapper.dropSqlserverTable(tableName);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
|
|
|
|
+ if(tableInfoMapper.selectDmDataCount(tableName)>0){
|
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
|
+ }
|
|
|
|
+ tableInfoMapper.dropDmTable(tableName);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if(tableInfoMapper.selectDataCount(tableName)>0){
|
|
|
|
+ return AjaxResult.warn("表中有数据,不能删除!");
|
|
|
|
+ }
|
|
tableInfoMapper.dropMysqlTable(tableName);
|
|
tableInfoMapper.dropMysqlTable(tableName);
|
|
|
|
+ return AjaxResult.success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult createTable(Map<String, Object> map) {
|
|
|
|
+ String dataBaseName = (String) map.get("dataBaseName");
|
|
|
|
+ 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.mysqlTableExist(dataBaseName,tableName)>0){
|
|
|
|
+ return AjaxResult.warn("当前数据库中表已存在");
|
|
|
|
+ }
|
|
|
|
+ createMysqlDataBase(map);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
|
|
|
|
+ if(sqlServerTableExist(dataBaseName,tableName)>0){
|
|
|
|
+ return AjaxResult.warn("当前数据库中表已存在");
|
|
|
|
+ }
|
|
|
|
+ createSqlServerDataBase(map);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
|
|
|
|
+ if(tableInfoMapper.dmTableExist(dataBaseName,tableName)>0){
|
|
|
|
+ return AjaxResult.warn("当前数据库中表已存在");
|
|
|
|
+ }
|
|
|
|
+ createDmDataBase(map);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(tableInfoMapper.mysqlTableExist(dataBaseName,tableName)>0){
|
|
|
|
+ return AjaxResult.warn("当前数据库中表已存在");
|
|
|
|
+ }
|
|
|
|
+ createMysqlDataBase(map);
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<TableInfo> mysqlTableFieldInfo(String tableName) {
|
|
public List<TableInfo> mysqlTableFieldInfo(String tableName) {
|
|
String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
|
|
String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
|
|
@@ -155,6 +224,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
@Override
|
|
@Override
|
|
public void updateMysqlTable(Map<String, Object> map) {
|
|
public void updateMysqlTable(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();
|
|
@@ -175,10 +245,10 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
|
|
|
|
if(redisTemplate.hasKey("DataSource")){
|
|
if(redisTemplate.hasKey("DataSource")){
|
|
DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
|
|
- tableInfoMapper.updateMysqlTable(dataSource.getDatabaseName(),tableName,list);
|
|
|
|
|
|
+ tableInfoMapper.updateMysqlTable(dataSource.getDatabaseName(),tableName,tableComment,list);
|
|
}else {
|
|
}else {
|
|
String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
|
|
String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
|
|
- tableInfoMapper.updateMysqlTable(dataBaseName,tableName,list);
|
|
|
|
|
|
+ tableInfoMapper.updateMysqlTable(dataBaseName,tableName,tableComment,list);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -288,13 +358,11 @@ public class TableInfoServiceImpl implements ITableInfoService {
|
|
return stringBuilder.toString();
|
|
return stringBuilder.toString();
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
if(tableInfoMapper.dmDataBaseExist(dataBaseName)>0){
|
|
if(tableInfoMapper.dmDataBaseExist(dataBaseName)>0){
|
|
- tableInfoMapper.useDmDataBase(dataBaseName);
|
|
|
|
- tableInfoMapper.createDmTable(tableName,list);
|
|
|
|
|
|
+ tableInfoMapper.createDmTable(dataBaseName,tableName,list);
|
|
descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
|
|
descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
|
|
}else {
|
|
}else {
|
|
tableInfoMapper.createDmDataBase(dataBaseName);
|
|
tableInfoMapper.createDmDataBase(dataBaseName);
|
|
- tableInfoMapper.useDmDataBase(dataBaseName);
|
|
|
|
- tableInfoMapper.createDmTable(tableName,list);
|
|
|
|
|
|
+ tableInfoMapper.createDmTable(dataBaseName,tableName,list);
|
|
descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
|
|
descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
|
|
}
|
|
}
|
|
}
|
|
}
|