同步功能修改
This commit is contained in:
parent
e50c4662dc
commit
b94e7e75f3
|
|
@ -102,6 +102,23 @@ public class StasDataSourceController extends JeecgController<StasDataSource, IS
|
|||
return Result.error("获取源端用户为空");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据源表字段
|
||||
*
|
||||
* @param sourceId
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "查询数据源表字段")
|
||||
@Operation(summary = "查询数据源表字段")
|
||||
@GetMapping(value = "/fieldList")
|
||||
public Result<?> fieldList(String sourceId, String username, String tableName) {
|
||||
List<String> columnNameList= stasDataSourceService.queryColumnList(sourceId, username, tableName);
|
||||
if (columnNameList != null && !"".equals(columnNameList)){
|
||||
return Result.OK(columnNameList);
|
||||
}
|
||||
return Result.error("获取源端表字段为空");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库连接测试
|
||||
* @param sourceId
|
||||
|
|
|
|||
|
|
@ -57,7 +57,13 @@ import java.util.List;
|
|||
* @param username
|
||||
* @return
|
||||
*/
|
||||
List<String> queryTableList(String sourceId, String username);
|
||||
List<String> queryTableList(String sourceId, String username); /**
|
||||
* 查询数据源所有表名称
|
||||
* @param sourceId
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
List<String> queryColumnList(String sourceId, String username, String tableName);
|
||||
|
||||
/**
|
||||
* 查询指定数据源中表的列名列表
|
||||
|
|
|
|||
|
|
@ -93,6 +93,12 @@ public class StasDataSourceServiceImpl extends ServiceImpl<StasDataSourceMapper,
|
|||
return queryDatabaseMetadata(sourceId, sql, "TABLE_NAME", username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryColumnList(String sourceId, String username, String tableName) {
|
||||
String sql = "SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE OWNER = ? AND TABLE_NAME = ?";
|
||||
return queryDatabaseMetadata(sourceId, sql, "COLUMN_NAME", username, tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用数据库元数据查询方法
|
||||
* @param sourceId 数据源ID
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package org.jeecg.stasSyncStrategy.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
|
|
@ -62,15 +64,21 @@ public class StasSyncStrategyController extends JeecgController<StasSyncStrategy
|
|||
/**
|
||||
* 在目标库创建表结构
|
||||
*
|
||||
* @param stasSyncStrategy
|
||||
* @param stasSyncStrategys
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "同步策略表-在目标库创建表结构")
|
||||
@Operation(summary="同步策略表-在目标库创建表结构")
|
||||
@PostMapping(value = "/createTargetTables")
|
||||
public Result<String> createTargetTables(@RequestBody StasSyncStrategy stasSyncStrategy) {
|
||||
if(stasSyncStrategyService.validateTables(stasSyncStrategy)){
|
||||
stasSyncStrategyService.createTargetTables(stasSyncStrategy);
|
||||
public Result<String> createTargetTables(@RequestBody List<StasSyncStrategy> stasSyncStrategys) {
|
||||
if(null != stasSyncStrategys && stasSyncStrategys.size() > 0) {
|
||||
String taskId = stasSyncStrategys.get(0).getTaskId();
|
||||
stasSyncStrategyService.remove(new LambdaQueryWrapper<StasSyncStrategy>().eq(StasSyncStrategy::getTaskId, taskId));
|
||||
for (StasSyncStrategy stasSyncStrategy : stasSyncStrategys) {
|
||||
if(stasSyncStrategyService.validateTables(stasSyncStrategy)){
|
||||
stasSyncStrategyService.createTargetTables(stasSyncStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,8 +105,9 @@ public class StasSyncStrategyServiceImpl extends ServiceImpl<StasSyncStrategyMap
|
|||
throw new JeecgBootException(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
throw new JeecgBootException(String.format("在用户%s中,%s表已存在,请删除已存在的表!",
|
||||
stasSyncStrategy.getTargetOwner(), stasSyncStrategy.getTableName()));
|
||||
this.baseMapper.insert(stasSyncStrategy);
|
||||
// throw new JeecgBootException(String.format("在用户%s中,%s表已存在,请删除已存在的表!",
|
||||
// stasSyncStrategy.getTargetOwner(), stasSyncStrategy.getTableName()));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new JeecgBootException(String.format("处理表: %s时出错", stasSyncStrategy.getTableName()));
|
||||
|
|
@ -280,17 +281,20 @@ public class StasSyncStrategyServiceImpl extends ServiceImpl<StasSyncStrategyMap
|
|||
if (SourceDataTypeEnum.ORACLE.getKey().equals(dbType)) {
|
||||
sql = "SELECT COUNT(*) FROM all_tables WHERE owner = ? AND (table_name = ? OR table_name = ?)";
|
||||
} else if (SourceDataTypeEnum.POSTGRES.getKey().equals(dbType)) {
|
||||
sql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?";
|
||||
sql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = ?";
|
||||
} else {
|
||||
throw new SQLException("不支持的数据库类型: " + dbType);
|
||||
}
|
||||
|
||||
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
pstmt.setString(1, schema.toUpperCase());
|
||||
pstmt.setString(2, tableName.toUpperCase());
|
||||
|
||||
|
||||
if (SourceDataTypeEnum.ORACLE.getKey().equals(dbType)) {
|
||||
pstmt.setString(1, schema.toUpperCase());
|
||||
pstmt.setString(2, tableName.toUpperCase());
|
||||
pstmt.setString(3, tableName); // Oracle需要检查大小写两种形式
|
||||
}else if (SourceDataTypeEnum.POSTGRES.getKey().equals(dbType)) {
|
||||
pstmt.setString(1, tableName.toUpperCase());
|
||||
}
|
||||
|
||||
try (ResultSet rs = pstmt.executeQuery()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user