执行历史关联数据源,执行时长和影响条数展示

This commit is contained in:
暮光:城中城
2019-08-28 22:19:12 +08:00
parent 04f36bf3ad
commit 38e1f28305
11 changed files with 57 additions and 16 deletions

View File

@@ -82,8 +82,9 @@ public class DbSqlExecutorController {
}
@PostMapping(value = "/history/list")
public ResponseJson historyList() {
public ResponseJson historyList(Long sourceId) {
UpdateWrapper<DbHistory> wrapper = new UpdateWrapper<>();
wrapper.eq(sourceId != null, "datasource_id", sourceId);
wrapper.orderByDesc("id");
List<DbHistory> favoriteList = dbHistoryService.list(wrapper);
return DocDbResponseJson.ok(favoriteList);

View File

@@ -12,16 +12,19 @@ import java.util.Map;
*/
public class ExecuteResult {
private int updateCount;
private long useTime;
private List<Map<String, Object>> result;
public ExecuteResult() {
this.updateCount = 0;
this.useTime = 0;
this.result = Collections.emptyList();
}
public ExecuteResult(int updateCount, List<Map<String, Object>> result) {
public ExecuteResult(int updateCount, List<Map<String, Object>> result, long useTime) {
this.updateCount = updateCount;
this.result = result;
this.useTime = useTime;
}
public int getUpdateCount() {
@@ -39,4 +42,12 @@ public class ExecuteResult {
public void setResult(List<Map<String, Object>> result) {
this.result = result;
}
public long getUseTime() {
return useTime;
}
public void setUseTime(long useTime) {
this.useTime = useTime;
}
}

View File

@@ -81,13 +81,14 @@ public class SqlExecutor {
String sqlStr = SqlLogUtil.getSqlString(paramMap, boundSql);
logger.info("sql ==> {}", sqlStr);
// 保留历史记录
dbHistoryService.saveHistory(sqlStr);
dbHistoryService.saveHistory(sqlStr, factoryBean.getId());
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
PreparedStatement preparedStatement = null;
DruidPooledConnection connection = null;
// 执行查询
try {
long startTime = System.currentTimeMillis();
connection = factoryBean.getDataSource().getConnection();
preparedStatement = connection.prepareStatement(sql);
// 设置当前的PreparedStatement
@@ -122,7 +123,8 @@ public class SqlExecutor {
// 更新的数量
int updateCount = preparedStatement.getUpdateCount();
updateCount = (updateCount < 0) ? 0 : updateCount;
return new ExecuteResult(updateCount, resultList);
long useTime = System.currentTimeMillis() - startTime;
return new ExecuteResult(updateCount, resultList, useTime);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {