新增MySQL和pg数据库的同步
This commit is contained in:
@@ -27,8 +27,23 @@ public class dbController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/getApiSourceTables")
|
@GetMapping("/getApiSourceTables")
|
||||||
public ApiResult<List<String>> listSourceTables(String token, String dbId) {
|
public ApiResult<List<String>> listSourceTables(String token, String dbId) {
|
||||||
if (vToken.isValidToken(token)) {
|
// 1. 验证token有效性
|
||||||
DbConfig dbConfig = dbConfigService.getById(dbId);
|
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);
|
JdbcTemplate jdbcTemplate = DataSourceConfig.createJdbcTemplate(dbConfig);
|
||||||
// 补充参数传递,修复SQL参数绑定问题
|
// 补充参数传递,修复SQL参数绑定问题
|
||||||
String querySql = "SELECT table_name FROM information_schema.tables WHERE table_schema = ?";
|
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())
|
.map(row -> row.values().iterator().next().toString())
|
||||||
.toList();
|
.toList();
|
||||||
return ApiResult.success(data);
|
return ApiResult.success(data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ApiResult.error(101, e.getMessage());
|
||||||
}
|
}
|
||||||
return ApiResult.error();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user