提交 d80510c9 authored 作者: Matrix's avatar Matrix

fix(SQL执行器): 添加了执行器页面的WEB接口

上级 e9f21513
...@@ -29,7 +29,6 @@ public class BaseBootApplication implements CommandLineRunner { ...@@ -29,7 +29,6 @@ public class BaseBootApplication implements CommandLineRunner {
private String password; private String password;
@Value("${spring.datasource.dynamic.datasource.master.driverClassName}") @Value("${spring.datasource.dynamic.datasource.master.driverClassName}")
private String driverClassName; private String driverClassName;
private final IDataSourceService dataSourceService; private final IDataSourceService dataSourceService;
public BaseBootApplication(IDataSourceService dataSourceService) { public BaseBootApplication(IDataSourceService dataSourceService) {
......
...@@ -216,7 +216,6 @@ public class SqlExpActuator implements Actuator { ...@@ -216,7 +216,6 @@ public class SqlExpActuator implements Actuator {
private List<Map<String, Object>> runSql(DynamicVariable dynamicVar, Long envId) { private List<Map<String, Object>> runSql(DynamicVariable dynamicVar, Long envId) {
String sqlExp = dynamicVar.getSqlExpDetail().getSqlExp(); String sqlExp = dynamicVar.getSqlExpDetail().getSqlExp();
Long connectId = dynamicVar.getSqlExpDetail().getPoolId(); Long connectId = dynamicVar.getSqlExpDetail().getPoolId();
DataSourceDTO dataSourceDTO = Optional.of(connectService.getById(connectId)) DataSourceDTO dataSourceDTO = Optional.of(connectService.getById(connectId))
.orElseThrow(() -> new GlobalException(String.format("没有找到id = %d 的连接池connect对象", connectId))) .orElseThrow(() -> new GlobalException(String.format("没有找到id = %d 的连接池connect对象", connectId)))
.toDataSourceDTO(); .toDataSourceDTO();
......
package org.matrix.autotest.controller;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.matrix.actuators.datasource.IDataSourceService;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* SqlController.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2022/1/24 at 8:57 PM
* Suffering is the most powerful teacher of life.
*/
@RequestMapping("/db")
@RestController
@AllArgsConstructor
public class SqlController {
private final JdbcTemplate jdbcTemplate;
private final IDataSourceService dataSourceService;
@SuppressWarnings("FieldCanBeLocal")
private final String GET_ALL_TABLES = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='key_stone';";
/**
* 运行一段SQL
*
* @param sql 要查询的SQL语句
* @return SQL结果 以MAP的JSON形式传,但是字段数量不固定
*/
@GetMapping("/sql")
@ApiOperation("运行一段SQL")
public ResponseEntity<List<Map<String, Object>>> runSql(@RequestParam String sql) {
// todo 这里要增加切换数据源的部分
dataSourceService.switchMainDataSource();
return ResponseEntity.ok(jdbcTemplate.queryForList(sql));
}
/**
* 获得默认主库的所有表的名称
*
* @return 默认主库的所有表的名称
*/
@GetMapping("/tableNames")
@ApiOperation("获得默认主库的所有表的名称")
public ResponseEntity<List<Map<String, Object>>> getTableNames() {
return ResponseEntity.ok(jdbcTemplate.queryForList(GET_ALL_TABLES));
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论