sql执行器开发
This commit is contained in:
@@ -0,0 +1,118 @@
|
|||||||
|
package com.zyplayer.doc.data.repository.manage.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import java.util.Date;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019-08-21
|
||||||
|
*/
|
||||||
|
public class DbFavorite implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键自增ID
|
||||||
|
*/
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收藏标题
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收藏内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人ID
|
||||||
|
*/
|
||||||
|
private Long createUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人名字
|
||||||
|
*/
|
||||||
|
private String createUserName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否有效 0=无效 1=有效
|
||||||
|
*/
|
||||||
|
private Integer yn;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
public Long getCreateUserId() {
|
||||||
|
return createUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateUserId(Long createUserId) {
|
||||||
|
this.createUserId = createUserId;
|
||||||
|
}
|
||||||
|
public String getCreateUserName() {
|
||||||
|
return createUserName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateUserName(String createUserName) {
|
||||||
|
this.createUserName = createUserName;
|
||||||
|
}
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
public Integer getYn() {
|
||||||
|
return yn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYn(Integer yn) {
|
||||||
|
this.yn = yn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DbFavorite{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name=" + name +
|
||||||
|
", content=" + content +
|
||||||
|
", createUserId=" + createUserId +
|
||||||
|
", createUserName=" + createUserName +
|
||||||
|
", createTime=" + createTime +
|
||||||
|
", yn=" + yn +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package com.zyplayer.doc.data.repository.manage.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import java.util.Date;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019-08-21
|
||||||
|
*/
|
||||||
|
public class DbHistory implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键自增ID
|
||||||
|
*/
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sql内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人ID
|
||||||
|
*/
|
||||||
|
private Long createUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人名字
|
||||||
|
*/
|
||||||
|
private String createUserName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否有效 0=无效 1=有效
|
||||||
|
*/
|
||||||
|
private Integer yn;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
public Long getCreateUserId() {
|
||||||
|
return createUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateUserId(Long createUserId) {
|
||||||
|
this.createUserId = createUserId;
|
||||||
|
}
|
||||||
|
public String getCreateUserName() {
|
||||||
|
return createUserName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateUserName(String createUserName) {
|
||||||
|
this.createUserName = createUserName;
|
||||||
|
}
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
public Integer getYn() {
|
||||||
|
return yn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYn(Integer yn) {
|
||||||
|
this.yn = yn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DbHistory{" +
|
||||||
|
"id=" + id +
|
||||||
|
", content=" + content +
|
||||||
|
", createUserId=" + createUserId +
|
||||||
|
", createUserName=" + createUserName +
|
||||||
|
", createTime=" + createTime +
|
||||||
|
", yn=" + yn +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.zyplayer.doc.data.repository.manage.mapper;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbFavorite;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019-08-21
|
||||||
|
*/
|
||||||
|
public interface DbFavoriteMapper extends BaseMapper<DbFavorite> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.zyplayer.doc.data.repository.manage.mapper;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbHistory;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019-08-21
|
||||||
|
*/
|
||||||
|
public interface DbHistoryMapper extends BaseMapper<DbHistory> {
|
||||||
|
|
||||||
|
@Update("delete a from db_history a,(select id from db_history order by id desc limit 100, 1) b where a.id < b.id")
|
||||||
|
void deleteHistory();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,8 +19,8 @@ public class CodeGenerator {
|
|||||||
final String moduleName = "manage";
|
final String moduleName = "manage";
|
||||||
// final String[] tableName = { "zyplayer_storage", "auth_info", "user_auth", "user_info", "db_datasource" };
|
// final String[] tableName = { "zyplayer_storage", "auth_info", "user_auth", "user_info", "db_datasource" };
|
||||||
// final String[] tableName = { "wiki_space", "wiki_page", "wiki_page_content", "wiki_page_file", "wiki_page_comment", "wiki_page_zan" };
|
// final String[] tableName = { "wiki_space", "wiki_page", "wiki_page_content", "wiki_page_file", "wiki_page_comment", "wiki_page_zan" };
|
||||||
// final String[] tableName = { "db_datasource" };
|
// final String[] tableName = { "db_datasource", "es_datasource", "db_favorite" };
|
||||||
final String[] tableName = { "es_datasource" };
|
final String[] tableName = { "db_history" };
|
||||||
|
|
||||||
// 代码生成器
|
// 代码生成器
|
||||||
AutoGenerator mpg = new AutoGenerator();
|
AutoGenerator mpg = new AutoGenerator();
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.zyplayer.doc.data.service.manage;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbFavorite;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019-08-21
|
||||||
|
*/
|
||||||
|
public interface DbFavoriteService extends IService<DbFavorite> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.zyplayer.doc.data.service.manage;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbHistory;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019-08-21
|
||||||
|
*/
|
||||||
|
public interface DbHistoryService extends IService<DbHistory> {
|
||||||
|
|
||||||
|
void saveHistory(String content);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.zyplayer.doc.data.service.manage.impl;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbFavorite;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.mapper.DbFavoriteMapper;
|
||||||
|
import com.zyplayer.doc.data.service.manage.DbFavoriteService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019-08-21
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class DbFavoriteServiceImpl extends ServiceImpl<DbFavoriteMapper, DbFavorite> implements DbFavoriteService {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.zyplayer.doc.data.service.manage.impl;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbHistory;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.mapper.DbHistoryMapper;
|
||||||
|
import com.zyplayer.doc.data.service.manage.DbHistoryService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019-08-21
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class DbHistoryServiceImpl extends ServiceImpl<DbHistoryMapper, DbHistory> implements DbHistoryService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DbHistoryMapper dbHistoryMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveHistory(String content) {
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
DbHistory dbHistory = new DbHistory();
|
||||||
|
dbHistory.setContent(content);
|
||||||
|
dbHistory.setCreateTime(new Date());
|
||||||
|
dbHistory.setCreateUserId(currentUser.getUserId());
|
||||||
|
dbHistory.setCreateUserName(currentUser.getUsername());
|
||||||
|
dbHistory.setYn(1);
|
||||||
|
this.save(dbHistory);
|
||||||
|
// 删除多余的数据
|
||||||
|
dbHistoryMapper.deleteHistory();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.zyplayer.doc.data.repository.manage.mapper.DbFavoriteMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.zyplayer.doc.data.repository.manage.mapper.DbHistoryMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -1,19 +1,35 @@
|
|||||||
package com.zyplayer.doc.db.controller;
|
package com.zyplayer.doc.db.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||||
import com.zyplayer.doc.core.json.ResponseJson;
|
import com.zyplayer.doc.core.json.ResponseJson;
|
||||||
import com.zyplayer.doc.core.util.StringUtil;
|
import com.zyplayer.doc.core.util.StringUtil;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbFavorite;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbHistory;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.mapper.DbFavoriteMapper;
|
||||||
|
import com.zyplayer.doc.data.service.manage.DbFavoriteService;
|
||||||
|
import com.zyplayer.doc.data.service.manage.DbHistoryService;
|
||||||
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteResult;
|
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteResult;
|
||||||
import com.zyplayer.doc.db.framework.db.mapper.base.SqlExecutor;
|
import com.zyplayer.doc.db.framework.db.mapper.base.SqlExecutor;
|
||||||
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
|
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sql执行器
|
* sql执行器
|
||||||
@@ -28,13 +44,23 @@ public class DbSqlExecutorController {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
SqlExecutor sqlExecutor;
|
SqlExecutor sqlExecutor;
|
||||||
|
@Resource
|
||||||
|
DbHistoryService dbHistoryService;
|
||||||
|
@Resource
|
||||||
|
DbFavoriteService dbFavoriteService;
|
||||||
|
|
||||||
@PostMapping(value = "/execute")
|
@PostMapping(value = "/execute")
|
||||||
public ResponseJson execute(Long sourceId, String executeId, String sql, String params) {
|
public ResponseJson execute(Long sourceId, String executeId, String sql, String params) {
|
||||||
Map<String, Object> paramMap = JSON.parseObject(params);
|
if (StringUtils.isBlank(sql)) {
|
||||||
|
return DocDbResponseJson.warn("执行的SQL不能为空");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
Map<String, Object> paramMap = JSON.parseObject(params);
|
||||||
ExecuteResult executeResult = sqlExecutor.execute(sourceId, executeId, sql, paramMap);
|
ExecuteResult executeResult = sqlExecutor.execute(sourceId, executeId, sql, paramMap);
|
||||||
String resultJsonStr = JSON.toJSONString(executeResult, SerializerFeature.WriteMapNullValue);
|
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);
|
return DocDbResponseJson.ok(resultJsonStr);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return DocDbResponseJson.warn(StringUtil.getException(e));
|
return DocDbResponseJson.warn(StringUtil.getException(e));
|
||||||
@@ -46,5 +72,43 @@ public class DbSqlExecutorController {
|
|||||||
sqlExecutor.cancel(executeId);
|
sqlExecutor.cancel(executeId);
|
||||||
return DocDbResponseJson.ok();
|
return DocDbResponseJson.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/history/list")
|
||||||
|
public ResponseJson historyList() {
|
||||||
|
UpdateWrapper<DbHistory> wrapper = new UpdateWrapper<>();
|
||||||
|
wrapper.orderByDesc("id");
|
||||||
|
List<DbHistory> favoriteList = dbHistoryService.list(wrapper);
|
||||||
|
return DocDbResponseJson.ok(favoriteList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/favorite/list")
|
||||||
|
public ResponseJson favoriteList() {
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
UpdateWrapper<DbFavorite> wrapper = new UpdateWrapper<>();
|
||||||
|
wrapper.eq("create_user_id", currentUser.getUserId());
|
||||||
|
wrapper.eq("yn", 1);
|
||||||
|
wrapper.orderByDesc("id");
|
||||||
|
List<DbFavorite> favoriteList = dbFavoriteService.list(wrapper);
|
||||||
|
return DocDbResponseJson.ok(favoriteList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/favorite/add")
|
||||||
|
public ResponseJson addFavorite(DbFavorite dbFavorite) {
|
||||||
|
Integer yn = Optional.ofNullable(dbFavorite.getYn()).orElse(1);
|
||||||
|
if (yn == 1 && StringUtils.isBlank(dbFavorite.getContent())) {
|
||||||
|
return DocDbResponseJson.warn("收藏的SQL不能为空");
|
||||||
|
}
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
if (dbFavorite.getId() != null && dbFavorite.getId() > 0) {
|
||||||
|
dbFavoriteService.updateById(dbFavorite);
|
||||||
|
} else {
|
||||||
|
dbFavorite.setCreateTime(new Date());
|
||||||
|
dbFavorite.setCreateUserId(currentUser.getUserId());
|
||||||
|
dbFavorite.setCreateUserName(currentUser.getUsername());
|
||||||
|
dbFavorite.setYn(1);
|
||||||
|
dbFavoriteService.save(dbFavorite);
|
||||||
|
}
|
||||||
|
return DocDbResponseJson.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
package com.zyplayer.doc.db.framework.db.mapper.base;
|
package com.zyplayer.doc.db.framework.db.mapper.base;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbFavorite;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.DbHistory;
|
||||||
|
import com.zyplayer.doc.data.service.manage.DbFavoriteService;
|
||||||
|
import com.zyplayer.doc.data.service.manage.DbHistoryService;
|
||||||
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean;
|
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean;
|
||||||
import com.zyplayer.doc.db.framework.db.bean.DatabaseRegistrationBean;
|
import com.zyplayer.doc.db.framework.db.bean.DatabaseRegistrationBean;
|
||||||
import com.zyplayer.doc.db.framework.db.interceptor.SqlLogUtil;
|
import com.zyplayer.doc.db.framework.db.interceptor.SqlLogUtil;
|
||||||
@@ -33,6 +39,8 @@ public class SqlExecutor {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
DatabaseRegistrationBean databaseRegistrationBean;
|
DatabaseRegistrationBean databaseRegistrationBean;
|
||||||
|
@Resource
|
||||||
|
DbHistoryService dbHistoryService;
|
||||||
|
|
||||||
// 执行中的PreparedStatement信息,用于强制取消执行
|
// 执行中的PreparedStatement信息,用于强制取消执行
|
||||||
private static final Map<String, PreparedStatement> statementMap = new ConcurrentHashMap<>();
|
private static final Map<String, PreparedStatement> statementMap = new ConcurrentHashMap<>();
|
||||||
@@ -80,7 +88,11 @@ public class SqlExecutor {
|
|||||||
StaticSqlSource parse = (StaticSqlSource) sqlSourceBuilder.parse(sql, Object.class, paramMap);
|
StaticSqlSource parse = (StaticSqlSource) sqlSourceBuilder.parse(sql, Object.class, paramMap);
|
||||||
BoundSql boundSql = parse.getBoundSql(new Object());
|
BoundSql boundSql = parse.getBoundSql(new Object());
|
||||||
sql = boundSql.getSql();
|
sql = boundSql.getSql();
|
||||||
logger.info("sql ==> {}", SqlLogUtil.getSqlString(paramMap, boundSql));
|
String sqlStr = SqlLogUtil.getSqlString(paramMap, boundSql);
|
||||||
|
logger.info("sql ==> {}", sqlStr);
|
||||||
|
// 保留历史记录
|
||||||
|
dbHistoryService.saveHistory(sqlStr);
|
||||||
|
|
||||||
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
|
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
// 执行查询
|
// 执行查询
|
||||||
@@ -100,8 +112,8 @@ public class SqlExecutor {
|
|||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||||
for (int i = 0; i < metaData.getColumnCount(); i++) {
|
for (int i = 1; i < metaData.getColumnCount() + 1; i++) {
|
||||||
resultMap.put(metaData.getColumnName(i + 1), resultSet.getObject(i + 1));
|
resultMap.put(metaData.getColumnName(i), resultSet.getObject(i));
|
||||||
}
|
}
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
handler.handleResult(resultMap);
|
handler.handleResult(resultMap);
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
--
|
||||||
|
-- !!重要说明!!
|
||||||
|
-- 1、本sql文件分为:从1.0.3版本升级 和 全新的库,即增量和全量的区分,请选择性执行
|
||||||
|
-- 2、建议数据库版本:5.7.25
|
||||||
|
--
|
||||||
|
|
||||||
|
-- ------------------------从1.0.3版本升级:------------------------
|
||||||
|
|
||||||
|
CREATE TABLE `db_favorite` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增ID',
|
||||||
|
`name` varchar(50) DEFAULT NULL COMMENT '收藏标题',
|
||||||
|
`content` varchar(10000) DEFAULT NULL COMMENT '收藏内容',
|
||||||
|
`create_user_id` bigint(20) DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`create_user_name` varchar(20) DEFAULT NULL COMMENT '创建人名字',
|
||||||
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
|
`yn` tinyint(4) DEFAULT NULL COMMENT '是否有效 0=无效 1=有效',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
|
||||||
|
|
||||||
|
CREATE TABLE `db_history` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增ID',
|
||||||
|
`content` varchar(10000) DEFAULT NULL COMMENT 'sql内容',
|
||||||
|
`create_user_id` bigint(20) DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`create_user_name` varchar(20) DEFAULT NULL COMMENT '创建人名字',
|
||||||
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
|
`yn` tinyint(4) DEFAULT NULL COMMENT '是否有效 0=无效 1=有效',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ------------------------全新的库:------------------------
|
||||||
29
zyplayer-doc-ui/db-ui/package-lock.json
generated
29
zyplayer-doc-ui/db-ui/package-lock.json
generated
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "element-starter",
|
"name": "console-ui",
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -239,7 +239,7 @@
|
|||||||
},
|
},
|
||||||
"async-validator": {
|
"async-validator": {
|
||||||
"version": "1.8.5",
|
"version": "1.8.5",
|
||||||
"resolved": "https://registry.npm.taobao.org/async-validator/download/async-validator-1.8.5.tgz",
|
"resolved": "https://registry.npm.taobao.org/async-validator/download/async-validator-1.8.5.tgz?cache=0&sync_timestamp=1565685468183&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fasync-validator%2Fdownload%2Fasync-validator-1.8.5.tgz",
|
||||||
"integrity": "sha1-3D4I7B/Q3dtn5ghC8CwM0c7G1/A=",
|
"integrity": "sha1-3D4I7B/Q3dtn5ghC8CwM0c7G1/A=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"babel-runtime": "6.x"
|
"babel-runtime": "6.x"
|
||||||
@@ -2014,7 +2014,7 @@
|
|||||||
},
|
},
|
||||||
"deepmerge": {
|
"deepmerge": {
|
||||||
"version": "1.5.2",
|
"version": "1.5.2",
|
||||||
"resolved": "http://registry.npm.taobao.org/deepmerge/download/deepmerge-1.5.2.tgz",
|
"resolved": "https://registry.npm.taobao.org/deepmerge/download/deepmerge-1.5.2.tgz",
|
||||||
"integrity": "sha1-EEmdhohEza1P7ghC34x/bwyVp1M="
|
"integrity": "sha1-EEmdhohEza1P7ghC34x/bwyVp1M="
|
||||||
},
|
},
|
||||||
"define-properties": {
|
"define-properties": {
|
||||||
@@ -2237,9 +2237,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"element-ui": {
|
"element-ui": {
|
||||||
"version": "2.8.2",
|
"version": "2.11.1",
|
||||||
"resolved": "https://registry.npm.taobao.org/element-ui/download/element-ui-2.8.2.tgz",
|
"resolved": "https://registry.npm.taobao.org/element-ui/download/element-ui-2.11.1.tgz",
|
||||||
"integrity": "sha1-Iaeky5Jhaw+LddTU5jfToc2MCd4=",
|
"integrity": "sha1-K2f57uPtouaISHPBxYnL4w2anWA=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"async-validator": "~1.8.1",
|
"async-validator": "~1.8.1",
|
||||||
"babel-helper-vue-jsx-merge-props": "^2.0.0",
|
"babel-helper-vue-jsx-merge-props": "^2.0.0",
|
||||||
@@ -2770,7 +2770,8 @@
|
|||||||
"ansi-regex": {
|
"ansi-regex": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"aproba": {
|
"aproba": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
@@ -3185,7 +3186,8 @@
|
|||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"safer-buffer": {
|
"safer-buffer": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
@@ -3241,6 +3243,7 @@
|
|||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"ansi-regex": "^2.0.0"
|
"ansi-regex": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -3284,12 +3287,14 @@
|
|||||||
"wrappy": {
|
"wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"yallist": {
|
"yallist": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -4637,7 +4642,7 @@
|
|||||||
},
|
},
|
||||||
"normalize-wheel": {
|
"normalize-wheel": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "http://registry.npm.taobao.org/normalize-wheel/download/normalize-wheel-1.0.1.tgz",
|
"resolved": "https://registry.npm.taobao.org/normalize-wheel/download/normalize-wheel-1.0.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnormalize-wheel%2Fdownload%2Fnormalize-wheel-1.0.1.tgz",
|
||||||
"integrity": "sha1-rsiGr/2wRQcNhWRH32Ls+GFG7EU="
|
"integrity": "sha1-rsiGr/2wRQcNhWRH32Ls+GFG7EU="
|
||||||
},
|
},
|
||||||
"nth-check": {
|
"nth-check": {
|
||||||
@@ -6032,7 +6037,7 @@
|
|||||||
},
|
},
|
||||||
"resize-observer-polyfill": {
|
"resize-observer-polyfill": {
|
||||||
"version": "1.5.1",
|
"version": "1.5.1",
|
||||||
"resolved": "http://registry.npm.taobao.org/resize-observer-polyfill/download/resize-observer-polyfill-1.5.1.tgz",
|
"resolved": "https://registry.npm.taobao.org/resize-observer-polyfill/download/resize-observer-polyfill-1.5.1.tgz",
|
||||||
"integrity": "sha1-DpAg3T0hAkRY1OvSfiPkAmmBBGQ="
|
"integrity": "sha1-DpAg3T0hAkRY1OvSfiPkAmmBBGQ="
|
||||||
},
|
},
|
||||||
"resolve": {
|
"resolve": {
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
<span slot="title">系统管理</span>
|
<span slot="title">系统管理</span>
|
||||||
</template>
|
</template>
|
||||||
<el-menu-item index="/data/datasourceManage"><i class="el-icon-coin"></i>数据源管理</el-menu-item>
|
<el-menu-item index="/data/datasourceManage"><i class="el-icon-coin"></i>数据源管理</el-menu-item>
|
||||||
<el-menu-item index="/data/export"><i class="el-icon-finished"></i>数据库表导出</el-menu-item>
|
|
||||||
<el-menu-item index="/data/executor"><i class="el-icon-video-play"></i>SQL执行器</el-menu-item>
|
<el-menu-item index="/data/executor"><i class="el-icon-video-play"></i>SQL执行器</el-menu-item>
|
||||||
|
<el-menu-item index="/data/export"><i class="el-icon-finished"></i>数据库表导出</el-menu-item>
|
||||||
</el-submenu>
|
</el-submenu>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
<el-tree :props="defaultProps" :data="databaseList" @node-click="handleNodeClick"
|
<el-tree :props="defaultProps" :data="databaseList" @node-click="handleNodeClick"
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ var URL = {
|
|||||||
|
|
||||||
executeSql: '/zyplayer-doc-db/executor/execute',
|
executeSql: '/zyplayer-doc-db/executor/execute',
|
||||||
executeSqlCancel: '/zyplayer-doc-db/executor/cancel',
|
executeSqlCancel: '/zyplayer-doc-db/executor/cancel',
|
||||||
|
updateFavorite: '/zyplayer-doc-db/executor/favorite/add',
|
||||||
|
favoriteList: '/zyplayer-doc-db/executor/favorite/list',
|
||||||
|
historyList: '/zyplayer-doc-db/executor/history/list',
|
||||||
|
|
||||||
systemUpgradeInfo: '/system/info/upgrade',
|
systemUpgradeInfo: '/system/info/upgrade',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,10 +12,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<pre id="sqlExecutorEditor" style="width: 100%;height: 500px;"></pre>
|
<pre id="sqlExecutorEditor" style="width: 100%;height: 500px;"></pre>
|
||||||
<div>
|
<div>
|
||||||
<el-button v-on:click="doExecutorSql" type="primary" plain size="small" icon="el-icon-video-play">执行</el-button>
|
<el-button v-if="sqlExecuting" v-on:click="cancelExecutorSql" type="primary" plain size="small" icon="el-icon-video-pause">取消执行</el-button>
|
||||||
|
<el-button v-else v-on:click="doExecutorSql" type="primary" plain size="small" icon="el-icon-video-play">执行</el-button>
|
||||||
<div style="float: right;">
|
<div style="float: right;">
|
||||||
<el-button v-on:click="" plain size="small" icon="el-icon-star-off">收藏</el-button>
|
<el-button v-on:click="addFavorite('')" plain size="small" icon="el-icon-star-off">收藏</el-button>
|
||||||
<el-button v-on:click="" plain size="small" icon="el-icon-tickets">历史记录</el-button>
|
<el-button v-on:click="loadHistoryAndFavoriteList" plain size="small" icon="el-icon-tickets">收藏及历史</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
@@ -24,15 +25,43 @@
|
|||||||
{{executeError}}
|
{{executeError}}
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<el-table :data="executeResultList" stripe border style="width: 100%; margin-bottom: 5px;">
|
<el-table :data="executeResultList" stripe border style="width: 100%; margin-bottom: 5px;" v-loading="sqlExecuting">
|
||||||
|
<el-table-column width="60px" v-if="executeResultCols.length > 0">
|
||||||
|
<template slot-scope="scope">{{scope.row._index}}</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column v-for="item in executeResultCols" :prop="item.prop" :label="item.prop"></el-table-column>
|
<el-table-column v-for="item in executeResultCols" :prop="item.prop" :label="item.prop"></el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
<el-drawer title="我是外面的 Drawer" :visible.sync="historyDrawerVisible" size="50%">
|
<el-drawer title="收藏及历史" :visible.sync="historyDrawerVisible" size="50%" class="data-executor-vue-out">
|
||||||
<div>
|
<div style="padding: 10px;">
|
||||||
<el-button @click="">打开里面的!</el-button>
|
<el-tabs value="favorite">
|
||||||
|
<el-tab-pane label="我的收藏" name="favorite">
|
||||||
|
<el-table :data="myFavoriteList" stripe border style="width: 100%; margin-bottom: 5px;">
|
||||||
|
<!-- <el-table-column prop="name" label="标题"></el-table-column>-->
|
||||||
|
<el-table-column prop="content" label="SQL"></el-table-column>
|
||||||
|
<!-- <el-table-column prop="createTime" label="收藏时间" width="160px"></el-table-column>-->
|
||||||
|
<el-table-column label="操作" width="150px">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row.content)">输入</el-button>
|
||||||
|
<el-button size="mini" type="danger" v-on:click="delFavorite(scope.row)">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-tab-pane>
|
||||||
|
<el-tab-pane label="历史记录" name="history">
|
||||||
|
<el-table :data="myHistoryListList" stripe border style="width: 100%; margin-bottom: 5px;">
|
||||||
|
<el-table-column prop="content" label="SQL"></el-table-column>
|
||||||
|
<el-table-column label="操作" width="150px">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row.content)">输入</el-button>
|
||||||
|
<el-button size="mini" type="success" v-on:click="addFavorite(scope.row.content)">收藏</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-tab-pane>
|
||||||
|
</el-tabs>
|
||||||
</div>
|
</div>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
</div>
|
</div>
|
||||||
@@ -53,18 +82,21 @@
|
|||||||
databaseList: [],
|
databaseList: [],
|
||||||
choiceDatabase: "",
|
choiceDatabase: "",
|
||||||
|
|
||||||
|
sqlExecuting: false,
|
||||||
executeResultList: [],
|
executeResultList: [],
|
||||||
executeResultCols: [],
|
executeResultCols: [],
|
||||||
sqlExecutorEditor: {},
|
sqlExecutorEditor: {},
|
||||||
nowExecutorId: 1,
|
nowExecutorId: 1,
|
||||||
executeError: "",
|
executeError: "",
|
||||||
|
// 收藏及历史
|
||||||
historyDrawerVisible: false,
|
historyDrawerVisible: false,
|
||||||
|
myFavoriteList: [],
|
||||||
|
myHistoryListList: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
app = this;
|
app = this;
|
||||||
window.tableMetaInfo = "helloWorld";
|
window.tableMetaInfo = "";
|
||||||
app.sqlExecutorEditor = app.initAceEditor("sqlExecutorEditor", 20);
|
app.sqlExecutorEditor = app.initAceEditor("sqlExecutorEditor", 20);
|
||||||
this.loadDatasourceList();
|
this.loadDatasourceList();
|
||||||
},
|
},
|
||||||
@@ -87,6 +119,45 @@
|
|||||||
app.$message.success("取消成功");
|
app.$message.success("取消成功");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
loadHistoryAndFavoriteList() {
|
||||||
|
this.historyDrawerVisible = true;
|
||||||
|
this.loadHistoryList();
|
||||||
|
this.loadFavoriteList();
|
||||||
|
},
|
||||||
|
loadFavoriteList() {
|
||||||
|
this.common.post(this.apilist1.favoriteList, {}, function (json) {
|
||||||
|
app.myFavoriteList = json.data || [];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
loadHistoryList() {
|
||||||
|
this.common.post(this.apilist1.historyList, {}, function (json) {
|
||||||
|
app.myHistoryListList = json.data || [];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
addFavorite(sqlValue) {
|
||||||
|
if (!sqlValue) {
|
||||||
|
sqlValue = this.sqlExecutorEditor.getSelectedText();
|
||||||
|
if (!sqlValue) {
|
||||||
|
sqlValue = this.sqlExecutorEditor.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var param = {name: '我的收藏', content: sqlValue};
|
||||||
|
this.common.post(this.apilist1.updateFavorite, param, function (json) {
|
||||||
|
app.$message.success("收藏成功");
|
||||||
|
app.loadFavoriteList();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
delFavorite(row) {
|
||||||
|
var param = {id: row.id, yn: 0};
|
||||||
|
this.common.post(this.apilist1.updateFavorite, param, function (json) {
|
||||||
|
app.$message.success("删除成功");
|
||||||
|
app.loadFavoriteList();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
inputFavoriteSql(content) {
|
||||||
|
this.sqlExecutorEditor.setValue(content);
|
||||||
|
this.historyDrawerVisible = false;
|
||||||
|
},
|
||||||
doExecutorSql() {
|
doExecutorSql() {
|
||||||
if (!this.choiceDatasourceId) {
|
if (!this.choiceDatasourceId) {
|
||||||
app.$message.error("请先选择数据源");
|
app.$message.error("请先选择数据源");
|
||||||
@@ -97,32 +168,43 @@
|
|||||||
app.executeResultCols = [];
|
app.executeResultCols = [];
|
||||||
|
|
||||||
this.nowExecutorId = (new Date()).getTime() + Math.ceil(Math.random() * 1000);
|
this.nowExecutorId = (new Date()).getTime() + Math.ceil(Math.random() * 1000);
|
||||||
var sql = this.sqlExecutorEditor.getValue();
|
var sqlValue = this.sqlExecutorEditor.getSelectedText();
|
||||||
|
if (!sqlValue) {
|
||||||
|
sqlValue = this.sqlExecutorEditor.getValue();
|
||||||
|
}
|
||||||
|
this.sqlExecuting = true;
|
||||||
this.common.postNonCheck(this.apilist1.executeSql, {
|
this.common.postNonCheck(this.apilist1.executeSql, {
|
||||||
sourceId: this.choiceDatasourceId,
|
sourceId: this.choiceDatasourceId,
|
||||||
executeId: this.nowExecutorId,
|
executeId: this.nowExecutorId,
|
||||||
sql: sql,
|
sql: sqlValue,
|
||||||
params: '',
|
params: '',
|
||||||
}, function (json) {
|
}, function (json) {
|
||||||
|
app.sqlExecuting = false;
|
||||||
if (json.errCode != 200) {
|
if (json.errCode != 200) {
|
||||||
app.executeError = json.errMsg;
|
app.executeError = json.errMsg;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var resultData = JSON.parse(json.data) || {};
|
var resultData = JSON.parse(json.data) || {};
|
||||||
var dataList = resultData.result || [];
|
var dataList = resultData.result || [];
|
||||||
app.executeResultList = dataList;
|
|
||||||
var executeResultCols = [];
|
var executeResultCols = [];
|
||||||
if (dataList.length > 0) {
|
if (dataList.length > 0) {
|
||||||
for (var key in dataList[0]) {
|
for (var key in dataList[0]) {
|
||||||
executeResultCols.push({prop: key});
|
executeResultCols.push({prop: key});
|
||||||
}
|
}
|
||||||
|
for (var i = 0; i < dataList.length; i++) {
|
||||||
|
dataList[i]._index = i + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
app.executeResultList = dataList;
|
||||||
app.executeResultCols = executeResultCols;
|
app.executeResultCols = executeResultCols;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
loadDatasourceList() {
|
loadDatasourceList() {
|
||||||
this.common.post(this.apilist1.datasourceList, {}, function (json) {
|
this.common.post(this.apilist1.datasourceList, {}, function (json) {
|
||||||
app.datasourceList = json.data || [];
|
app.datasourceList = json.data || [];
|
||||||
|
if (app.datasourceList.length > 0) {
|
||||||
|
app.choiceDatasourceId = app.datasourceList[0].id;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
datasourceChangeEvents() {
|
datasourceChangeEvents() {
|
||||||
@@ -144,4 +226,17 @@
|
|||||||
.data-executor-vue .el-card__body{
|
.data-executor-vue .el-card__body{
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
.data-executor-vue .el-table td, .el-table th{
|
||||||
|
padding: 6px 0;
|
||||||
|
}
|
||||||
|
.data-executor-vue-out .el-tabs__nav-scroll{
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
.data-executor-vue-out .el-button+.el-button{
|
||||||
|
margin-left: 0px;
|
||||||
|
}
|
||||||
|
.data-executor-vue-out .el-table__body-wrapper{
|
||||||
|
height: calc(100vh - 180px);
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user