新增MySQL和pg数据库的同步
This commit is contained in:
@@ -27,8 +27,23 @@ public class dbController {
|
||||
*/
|
||||
@GetMapping("/getApiSourceTables")
|
||||
public ApiResult<List<String>> listSourceTables(String token, String dbId) {
|
||||
if (vToken.isValidToken(token)) {
|
||||
DbConfig dbConfig = dbConfigService.getById(dbId);
|
||||
// 1. 验证token有效性
|
||||
if (!vToken.isValidToken(token)) {
|
||||
return ApiResult.error(401, "无效的访问令牌");
|
||||
}
|
||||
|
||||
// 2. 校验dbId参数
|
||||
if (dbId == null || dbId.trim().isEmpty()) {
|
||||
return ApiResult.error(400, "数据库ID不能为空");
|
||||
}
|
||||
|
||||
// 3. 查询数据库配置并校验
|
||||
DbConfig dbConfig = dbConfigService.getById(dbId);
|
||||
if (dbConfig == null) {
|
||||
return ApiResult.error(404, "未找到ID为[" + dbId + "]的数据库配置");
|
||||
}
|
||||
|
||||
try {
|
||||
JdbcTemplate jdbcTemplate = DataSourceConfig.createJdbcTemplate(dbConfig);
|
||||
// 补充参数传递,修复SQL参数绑定问题
|
||||
String querySql = "SELECT table_name FROM information_schema.tables WHERE table_schema = ?";
|
||||
@@ -37,7 +52,8 @@ public class dbController {
|
||||
.map(row -> row.values().iterator().next().toString())
|
||||
.toList();
|
||||
return ApiResult.success(data);
|
||||
} catch (Exception e) {
|
||||
return ApiResult.error(101, e.getMessage());
|
||||
}
|
||||
return ApiResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user