执行器查询展示增加多窗口展示
This commit is contained in:
@@ -27,10 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* sql执行器
|
||||
@@ -61,18 +58,28 @@ public class DbSqlExecutorController {
|
||||
if (!manageAuth && !select && !update) {
|
||||
return DocDbResponseJson.warn("没有该数据源的执行权限");
|
||||
}
|
||||
try {
|
||||
Map<String, Object> paramMap = JSON.parseObject(params);
|
||||
ExecuteType executeType = (!manageAuth && select) ? ExecuteType.SELECT : ExecuteType.ALL;
|
||||
ExecuteResult executeResult = sqlExecutor.execute(sourceId, executeId, executeType, sql, paramMap);
|
||||
SerializeConfig mapping = new SerializeConfig();
|
||||
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
mapping.put(Timestamp.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
String resultJsonStr = JSON.toJSONString(executeResult, mapping, SerializerFeature.WriteMapNullValue);
|
||||
return DocDbResponseJson.ok(resultJsonStr);
|
||||
} catch (Exception e) {
|
||||
return DocDbResponseJson.warn(StringUtil.getException(e));
|
||||
List<String> resultList = new LinkedList<>();
|
||||
// 支持;分割的多个sql执行
|
||||
String[] sqlArr = sql.split(";");
|
||||
for (String sqlItem : sqlArr) {
|
||||
if (StringUtils.isBlank(sqlItem)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
Map<String, Object> paramMap = JSON.parseObject(params);
|
||||
ExecuteType executeType = (!manageAuth && select) ? ExecuteType.SELECT : ExecuteType.ALL;
|
||||
ExecuteResult executeResult = sqlExecutor.execute(sourceId, executeId, executeType, sqlItem, paramMap);
|
||||
SerializeConfig mapping = new SerializeConfig();
|
||||
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
mapping.put(Timestamp.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
String resultJsonStr = JSON.toJSONString(executeResult, mapping, SerializerFeature.WriteMapNullValue);
|
||||
resultList.add(resultJsonStr);
|
||||
} catch (Exception e) {
|
||||
ExecuteResult executeResult = ExecuteResult.error(StringUtil.getException(e));
|
||||
resultList.add(JSON.toJSONString(executeResult));
|
||||
}
|
||||
}
|
||||
return DocDbResponseJson.ok(resultList);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/cancel")
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.Map;
|
||||
public class ExecuteResult {
|
||||
private int updateCount;
|
||||
private long useTime;
|
||||
private String errMsg;
|
||||
private String sql;
|
||||
private List<Map<String, Object>> result;
|
||||
|
||||
public ExecuteResult() {
|
||||
@@ -21,10 +23,11 @@ public class ExecuteResult {
|
||||
this.result = Collections.emptyList();
|
||||
}
|
||||
|
||||
public ExecuteResult(int updateCount, List<Map<String, Object>> result, long useTime) {
|
||||
public ExecuteResult(int updateCount, List<Map<String, Object>> result, long useTime, String sql) {
|
||||
this.updateCount = updateCount;
|
||||
this.result = result;
|
||||
this.useTime = useTime;
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public int getUpdateCount() {
|
||||
@@ -50,4 +53,26 @@ public class ExecuteResult {
|
||||
public void setUseTime(long useTime) {
|
||||
this.useTime = useTime;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
public void setErrMsg(String errMsg) {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public static ExecuteResult error(String errMsg) {
|
||||
ExecuteResult executeResult = new ExecuteResult();
|
||||
executeResult.setErrMsg(errMsg);
|
||||
return executeResult;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public void setSql(String sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class SqlExecutor {
|
||||
int updateCount = preparedStatement.getUpdateCount();
|
||||
updateCount = (updateCount < 0) ? 0 : updateCount;
|
||||
long useTime = System.currentTimeMillis() - startTime;
|
||||
return new ExecuteResult(updateCount, resultList, useTime);
|
||||
return new ExecuteResult(updateCount, resultList, useTime, sql);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user