添加TableName注解,Db模块更改返回类型
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
package com.zyplayer.doc.db.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbDatasource;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.data.repository.support.consts.DocAuthConst;
|
||||
import com.zyplayer.doc.data.repository.support.consts.DocSysModuleType;
|
||||
import com.zyplayer.doc.data.repository.support.consts.DocSysType;
|
||||
import com.zyplayer.doc.data.service.manage.DbDatasourceService;
|
||||
import com.zyplayer.doc.data.service.manage.UserAuthService;
|
||||
import com.zyplayer.doc.db.controller.vo.DatabaseExportVo;
|
||||
import com.zyplayer.doc.db.controller.vo.TableColumnVo;
|
||||
import com.zyplayer.doc.db.controller.vo.TableColumnVo.TableInfoVo;
|
||||
@@ -28,7 +23,6 @@ import com.zyplayer.doc.db.framework.utils.PoiUtil;
|
||||
import com.zyplayer.doc.db.service.database.DatabaseServiceFactory;
|
||||
import com.zyplayer.doc.db.service.database.DbBaseService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -49,40 +43,24 @@ import java.util.stream.Stream;
|
||||
@RestController
|
||||
@RequestMapping("/zyplayer-doc-db/doc-db")
|
||||
public class DatabaseDocController {
|
||||
|
||||
|
||||
@Resource
|
||||
DatabaseRegistrationBean databaseRegistrationBean;
|
||||
@Resource
|
||||
DbDatasourceService dbDatasourceService;
|
||||
@Resource
|
||||
UserAuthService userAuthService;
|
||||
@Resource
|
||||
DatabaseServiceFactory databaseServiceFactory;
|
||||
|
||||
@PostMapping(value = "/getDataSourceList")
|
||||
public ResponseJson getDataSourceList() {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
QueryWrapper<DbDatasource> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("yn", 1);
|
||||
// 没管理权限只返回有权限的数据源
|
||||
if (!DocUserUtil.haveAuth(DocAuthConst.DB_DATASOURCE_MANAGE)) {
|
||||
QueryWrapper<UserAuth> updateWrapper = new QueryWrapper<>();
|
||||
updateWrapper.eq("sys_type", DocSysType.DB.getType());
|
||||
updateWrapper.eq("sys_module_type", DocSysModuleType.Db.DATASOURCE.getType());
|
||||
updateWrapper.eq("del_flag", 0);
|
||||
updateWrapper.eq("user_id", currentUser.getUserId());
|
||||
List<UserAuth> userAuthList = userAuthService.list(updateWrapper);
|
||||
if (userAuthList == null || userAuthList.isEmpty()) {
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
List<Long> userAuthDbIds = userAuthList.stream().map(UserAuth::getSysModuleId).collect(Collectors.toList());
|
||||
wrapper.in("id", userAuthDbIds);
|
||||
}
|
||||
wrapper.select("id", "name", "group_name");
|
||||
List<DbDatasource> datasourceList = dbDatasourceService.list(wrapper);
|
||||
return DocDbResponseJson.ok(datasourceList);
|
||||
|
||||
/**
|
||||
* 获取数据源列表(管理员返回所有数据源,用户返回有权限的数据源)
|
||||
* @return ResponseJson
|
||||
*/
|
||||
@PostMapping("/getDataSourceList")
|
||||
public DocDbResponseJson getDataSourceList() {
|
||||
List<DbDatasource> dataSourceList = dbDatasourceService.getDataSourceList();
|
||||
return DocDbResponseJson.ok(dataSourceList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据源基本信息
|
||||
*
|
||||
@@ -90,50 +68,50 @@ public class DatabaseDocController {
|
||||
* @return 基本信息
|
||||
*/
|
||||
@PostMapping(value = "/getSourceBaseInfo")
|
||||
public ResponseJson getSourceBaseInfo(Long sourceId) {
|
||||
public DocDbResponseJson getSourceBaseInfo(Long sourceId) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
Map<String, Object> dbResultMap = new HashMap<>();
|
||||
dbResultMap.put("product", dbBaseService.getDatabaseProduct().name().toLowerCase());
|
||||
return DocDbResponseJson.ok(dbResultMap);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getTableDdl")
|
||||
public ResponseJson getTableDdl(Long sourceId, String dbName, String tableName) {
|
||||
public DocDbResponseJson getTableDdl(Long sourceId, String dbName, String tableName) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
TableDdlVo tableDdlVo = dbBaseService.getTableDdl(sourceId, dbName, tableName);
|
||||
return DocDbResponseJson.ok(tableDdlVo);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getDatabaseList")
|
||||
public ResponseJson getDatabaseList(Long sourceId) {
|
||||
public DocDbResponseJson getDatabaseList(Long sourceId) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
List<DatabaseInfoDto> databaseList = dbBaseService.getDatabaseList(sourceId);
|
||||
return DocDbResponseJson.ok(databaseList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getTableStatus")
|
||||
public ResponseJson getTableStatus(Long sourceId, String dbName, String tableName) {
|
||||
public DocDbResponseJson getTableStatus(Long sourceId, String dbName, String tableName) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
TableStatusVo tableStatusVo = dbBaseService.getTableStatus(sourceId, dbName, tableName);
|
||||
return DocDbResponseJson.ok(tableStatusVo);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getTableList")
|
||||
public ResponseJson getTableList(Long sourceId, String dbName) {
|
||||
public DocDbResponseJson getTableList(Long sourceId, String dbName) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
List<TableInfoDto> tableList = dbBaseService.getTableList(sourceId, dbName);
|
||||
return DocDbResponseJson.ok(tableList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getTableColumnList")
|
||||
public ResponseJson getTableColumnList(Long sourceId, String dbName, String tableName) {
|
||||
public DocDbResponseJson getTableColumnList(Long sourceId, String dbName, String tableName) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
TableColumnVo tableColumnVo = dbBaseService.getTableColumnList(sourceId, dbName, tableName);
|
||||
return DocDbResponseJson.ok(tableColumnVo);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getTableAndColumnBySearch")
|
||||
public ResponseJson getTableAndColumnBySearch(Long sourceId, String dbName, String searchText) {
|
||||
public DocDbResponseJson getTableAndColumnBySearch(Long sourceId, String dbName, String searchText) {
|
||||
if (StringUtils.isBlank(searchText)) {
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
@@ -141,32 +119,32 @@ public class DatabaseDocController {
|
||||
List<QueryTableColumnDescDto> columnDescDto = dbBaseService.getTableAndColumnBySearch(sourceId, dbName, searchText);
|
||||
return DocDbResponseJson.ok(columnDescDto);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getTableDescList")
|
||||
public ResponseJson getTableDescList(Long sourceId, String dbName, String tableName) {
|
||||
public DocDbResponseJson getTableDescList(Long sourceId, String dbName, String tableName) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
List<TableDescDto> tableDescList = dbBaseService.getTableDescList(sourceId, dbName, tableName);
|
||||
return DocDbResponseJson.ok(tableDescList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/updateTableDesc")
|
||||
public ResponseJson updateTableDesc(Long sourceId, String dbName, String tableName, String newDesc) {
|
||||
public DocDbResponseJson updateTableDesc(Long sourceId, String dbName, String tableName, String newDesc) {
|
||||
this.judgeAuth(sourceId, DbAuthType.DESC_EDIT.getName(), "没有修改该表注释的权限");
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
dbBaseService.updateTableDesc(sourceId, dbName, tableName, newDesc);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/updateTableColumnDesc")
|
||||
public ResponseJson updateTableColumnDesc(Long sourceId, String dbName, String tableName, String columnName, String newDesc) {
|
||||
public DocDbResponseJson updateTableColumnDesc(Long sourceId, String dbName, String tableName, String columnName, String newDesc) {
|
||||
this.judgeAuth(sourceId, DbAuthType.DESC_EDIT.getName(), "没有修改该表字段注释的权限");
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
dbBaseService.updateTableColumnDesc(sourceId, dbName, tableName, columnName, newDesc);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/exportDatabase")
|
||||
public ResponseJson exportDatabase(HttpServletResponse response, Long sourceId, String dbName, String tableNames, Integer exportType, Integer exportFormat) {
|
||||
public DocDbResponseJson exportDatabase(HttpServletResponse response, Long sourceId, String dbName, String tableNames, Integer exportType, Integer exportFormat) {
|
||||
if (StringUtils.isBlank(tableNames)) {
|
||||
return DocDbResponseJson.warn("请选择需要导出的表");
|
||||
}
|
||||
@@ -178,7 +156,7 @@ public class DatabaseDocController {
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
private DocDbResponseJson exportForTableDdl(HttpServletResponse response, Long sourceId, String dbName, List<String> tableNameList, Integer exportFormat) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
Map<String, String> ddlSqlMap = new HashMap<>();
|
||||
@@ -196,7 +174,7 @@ public class DatabaseDocController {
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
private DocDbResponseJson exportForTableDoc(HttpServletResponse response, Long sourceId, String dbName, List<String> tableNameList, Integer exportFormat) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
// 数据组装
|
||||
@@ -222,7 +200,7 @@ public class DatabaseDocController {
|
||||
return DocDbResponseJson.error("导出失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权限判断
|
||||
*
|
||||
@@ -235,4 +213,3 @@ public class DatabaseDocController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.util.TypeUtils;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.db.controller.download.FormatDownloadConst;
|
||||
import com.zyplayer.doc.db.controller.download.FormatDownloadService;
|
||||
import com.zyplayer.doc.db.controller.param.DataViewParam;
|
||||
@@ -45,7 +44,7 @@ import java.util.*;
|
||||
@RequestMapping("/zyplayer-doc-db/data-view")
|
||||
public class DbDataViewController {
|
||||
private static Logger logger = LoggerFactory.getLogger(DbDataViewController.class);
|
||||
|
||||
|
||||
@Resource
|
||||
ExecuteAuthService executeAuthService;
|
||||
@Resource
|
||||
@@ -57,7 +56,7 @@ public class DbDataViewController {
|
||||
// 最大允许导出的行数,设置的过大有可能会导致内存溢出,默认10W条
|
||||
@Value("${zyplayer.doc.db.download-max-row:100000}")
|
||||
Integer downloadMaxRow;
|
||||
|
||||
|
||||
/**
|
||||
* 数据查询接口
|
||||
*
|
||||
@@ -65,7 +64,7 @@ public class DbDataViewController {
|
||||
* @since 2021-08-14
|
||||
*/
|
||||
@PostMapping(value = "/query")
|
||||
public ResponseJson query(DataViewParam param) {
|
||||
public DocDbResponseJson query(DataViewParam param) {
|
||||
// 数据查询
|
||||
ExecuteType executeType = executeAuthService.getExecuteType(param.getSourceId());
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(param.getSourceId());
|
||||
@@ -84,20 +83,20 @@ public class DbDataViewController {
|
||||
}
|
||||
return responseJson;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除表数据
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
*/
|
||||
@PostMapping(value = "/deleteTableLineData")
|
||||
public ResponseJson deleteTableLineData(Long sourceId, String dbName, String tableName, String lineJson) {
|
||||
public DocDbResponseJson deleteTableLineData(Long sourceId, String dbName, String tableName, String lineJson) {
|
||||
JSONArray lineJsonArr = JSON.parseArray(lineJson);
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
dbBaseService.deleteTableLineData(sourceId, dbName, tableName, lineJsonArr);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 多表下载
|
||||
*
|
||||
@@ -107,7 +106,7 @@ public class DbDataViewController {
|
||||
* @author 暮光:城中城
|
||||
*/
|
||||
@PostMapping(value = "/downloadMultiple")
|
||||
public ResponseJson downloadMultiple(HttpServletResponse response, DataViewParam param) {
|
||||
public DocDbResponseJson downloadMultiple(HttpServletResponse response, DataViewParam param) {
|
||||
if (StringUtils.isBlank(param.getTableNames())) {
|
||||
return DocDbResponseJson.warn("请选择导出的表");
|
||||
}
|
||||
@@ -130,7 +129,7 @@ public class DbDataViewController {
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据总条数
|
||||
*
|
||||
@@ -148,7 +147,7 @@ public class DbDataViewController {
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行数据查询
|
||||
*
|
||||
@@ -174,4 +173,3 @@ public class DbDataViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbDatasource;
|
||||
@@ -36,14 +35,14 @@ import java.util.stream.Collectors;
|
||||
@AuthMan(DocAuthConst.DB_DATASOURCE_MANAGE)
|
||||
@RequestMapping("/zyplayer-doc-db/datasource")
|
||||
public class DbDatasourceController {
|
||||
|
||||
|
||||
@Resource
|
||||
DatabaseRegistrationBean databaseRegistrationBean;
|
||||
@Resource
|
||||
DbDatasourceService dbDatasourceService;
|
||||
|
||||
|
||||
@PostMapping(value = "/list")
|
||||
public ResponseJson list(Integer pageNum, Integer pageSize, String name, String groupName) {
|
||||
public DocDbResponseJson list(Integer pageNum, Integer pageSize, String name, String groupName) {
|
||||
QueryWrapper<DbDatasource> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("yn", 1);
|
||||
wrapper.eq(StringUtils.isNotBlank(groupName), "group_name", groupName);
|
||||
@@ -55,9 +54,9 @@ public class DbDatasourceController {
|
||||
}
|
||||
return DocDbResponseJson.ok(page);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/groups")
|
||||
public ResponseJson groups() {
|
||||
public DocDbResponseJson groups() {
|
||||
QueryWrapper<DbDatasource> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("yn", 1);
|
||||
wrapper.isNotNull("group_name");
|
||||
@@ -70,9 +69,9 @@ public class DbDatasourceController {
|
||||
Set<String> groupNameSet = datasourceList.stream().map(DbDatasource::getGroupName).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
|
||||
return DocDbResponseJson.ok(groupNameSet);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/test")
|
||||
public ResponseJson test(DbDatasource dbDatasource) {
|
||||
public DocDbResponseJson test(DbDatasource dbDatasource) {
|
||||
// 验证新的数据源
|
||||
try {
|
||||
// 获取原始密码
|
||||
@@ -92,9 +91,9 @@ public class DbDatasourceController {
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/update")
|
||||
public ResponseJson update(DbDatasource dbDatasource) {
|
||||
public DocDbResponseJson update(DbDatasource dbDatasource) {
|
||||
if (StringUtils.isBlank(dbDatasource.getName())) {
|
||||
return DocDbResponseJson.warn("名字必填");
|
||||
} else if (StringUtils.isBlank(dbDatasource.getDriverClassName())) {
|
||||
@@ -129,4 +128,3 @@ public class DbDatasourceController {
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbProcLog;
|
||||
@@ -42,12 +41,12 @@ import java.util.List;
|
||||
@RequestMapping("/zyplayer-doc-db/procedure")
|
||||
public class DbProcedureController {
|
||||
private static Logger logger = LoggerFactory.getLogger(DbProcedureController.class);
|
||||
|
||||
|
||||
@Resource
|
||||
DatabaseServiceFactory databaseServiceFactory;
|
||||
@Resource
|
||||
DbProcLogService dbProcLogService;
|
||||
|
||||
|
||||
/**
|
||||
* 存储过程列表
|
||||
*
|
||||
@@ -55,7 +54,7 @@ public class DbProcedureController {
|
||||
* @return 列表
|
||||
*/
|
||||
@PostMapping(value = "/list")
|
||||
public ResponseJson list(ProcedureListParam procedureParam) {
|
||||
public DocDbResponseJson list(ProcedureListParam procedureParam) {
|
||||
try {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(procedureParam.getSourceId());
|
||||
procedureParam.setOffset((procedureParam.getPageNum() - 1) * procedureParam.getPageSize());
|
||||
@@ -70,7 +69,7 @@ public class DbProcedureController {
|
||||
return DocDbResponseJson.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取函数详情
|
||||
*
|
||||
@@ -81,7 +80,7 @@ public class DbProcedureController {
|
||||
* @return 详情
|
||||
*/
|
||||
@PostMapping(value = "/detail")
|
||||
public ResponseJson detail(Long sourceId, String dbName, String typeName, String procName) {
|
||||
public DocDbResponseJson detail(Long sourceId, String dbName, String typeName, String procName) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(sourceId);
|
||||
try {
|
||||
ProcedureDto procedureDto = dbBaseService.getProcedureDetail(sourceId, dbName, typeName, procName);
|
||||
@@ -91,7 +90,7 @@ public class DbProcedureController {
|
||||
return DocDbResponseJson.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除函数
|
||||
*
|
||||
@@ -102,7 +101,7 @@ public class DbProcedureController {
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping(value = "/delete")
|
||||
public ResponseJson delete(Long sourceId, String dbName, String typeName, String procName) {
|
||||
public DocDbResponseJson delete(Long sourceId, String dbName, String typeName, String procName) {
|
||||
this.judgeAuth(sourceId, DbAuthType.PROC_EDIT.getName(), "没有修改该库函数的权限");
|
||||
DbProcLog dbProcLog = this.createDbProcLog(sourceId, dbName, typeName, procName, "删除函数操作");
|
||||
try {
|
||||
@@ -117,7 +116,7 @@ public class DbProcedureController {
|
||||
dbProcLogService.save(dbProcLog);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存函数
|
||||
*
|
||||
@@ -129,7 +128,7 @@ public class DbProcedureController {
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
public ResponseJson save(Long sourceId, String dbName, String typeName, String procName, String procSql) {
|
||||
public DocDbResponseJson save(Long sourceId, String dbName, String typeName, String procName, String procSql) {
|
||||
this.judgeAuth(sourceId, DbAuthType.PROC_EDIT.getName(), "没有修改该库函数的权限");
|
||||
DbProcLog dbProcLog = this.createDbProcLog(sourceId, dbName, typeName, procName, procSql);
|
||||
try {
|
||||
@@ -147,7 +146,7 @@ public class DbProcedureController {
|
||||
dbProcLogService.save(dbProcLog);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 存储过程修改日志列表
|
||||
*
|
||||
@@ -158,7 +157,7 @@ public class DbProcedureController {
|
||||
* @return 列表
|
||||
*/
|
||||
@PostMapping(value = "/log/list")
|
||||
public ResponseJson logList(Integer pageNum, Integer pageSize, Long sourceId, String dbName, String typeName, String procName) {
|
||||
public DocDbResponseJson logList(Integer pageNum, Integer pageSize, Long sourceId, String dbName, String typeName, String procName) {
|
||||
QueryWrapper<DbProcLog> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("datasource_id", sourceId);
|
||||
wrapper.eq("proc_db", dbName);
|
||||
@@ -170,7 +169,7 @@ public class DbProcedureController {
|
||||
dbProcLogService.page(page, wrapper);
|
||||
return DocDbResponseJson.ok(page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 存储过程修改日志详情
|
||||
*
|
||||
@@ -178,11 +177,11 @@ public class DbProcedureController {
|
||||
* @return 详情
|
||||
*/
|
||||
@PostMapping(value = "/log/detail")
|
||||
public ResponseJson logDetail(Long logId) {
|
||||
public DocDbResponseJson logDetail(Long logId) {
|
||||
DbProcLog dbProcLog = dbProcLogService.getById(logId);
|
||||
return DocDbResponseJson.ok(dbProcLog);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 权限判断
|
||||
*
|
||||
@@ -194,7 +193,7 @@ public class DbProcedureController {
|
||||
throw new ConfirmException(noAuthInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建日志对象
|
||||
*
|
||||
@@ -220,4 +219,3 @@ public class DbProcedureController {
|
||||
return dbProcLog;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
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;
|
||||
@@ -46,7 +45,7 @@ import java.util.*;
|
||||
@RequestMapping("/zyplayer-doc-db/executor")
|
||||
public class DbSqlExecutorController {
|
||||
private static Logger logger = LoggerFactory.getLogger(DbSqlExecutorController.class);
|
||||
|
||||
|
||||
@Resource
|
||||
SqlExecutor sqlExecutor;
|
||||
@Resource
|
||||
@@ -55,9 +54,9 @@ public class DbSqlExecutorController {
|
||||
DbFavoriteService dbFavoriteService;
|
||||
@Resource
|
||||
DatabaseServiceFactory databaseServiceFactory;
|
||||
|
||||
|
||||
@PostMapping(value = "/execute")
|
||||
public ResponseJson execute(Long sourceId, String executeId, String dbName, String sql, String params) {
|
||||
public DocDbResponseJson execute(Long sourceId, String executeId, String dbName, String sql, String params) {
|
||||
if (StringUtils.isBlank(sql)) {
|
||||
return DocDbResponseJson.warn("执行的SQL不能为空");
|
||||
}
|
||||
@@ -107,24 +106,24 @@ public class DbSqlExecutorController {
|
||||
}
|
||||
return DocDbResponseJson.ok(resultList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/cancel")
|
||||
public ResponseJson cancel(String executeId) {
|
||||
public DocDbResponseJson cancel(String executeId) {
|
||||
sqlExecutor.cancel(executeId);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/history/list")
|
||||
public ResponseJson historyList(Long sourceId) {
|
||||
public DocDbResponseJson 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);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/favorite/list")
|
||||
public ResponseJson favoriteList(Long sourceId) {
|
||||
public DocDbResponseJson favoriteList(Long sourceId) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
UpdateWrapper<DbFavorite> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq(sourceId != null, "datasource_id", sourceId);
|
||||
@@ -134,9 +133,9 @@ public class DbSqlExecutorController {
|
||||
List<DbFavorite> favoriteList = dbFavoriteService.list(wrapper);
|
||||
return DocDbResponseJson.ok(favoriteList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/favorite/add")
|
||||
public ResponseJson addFavorite(DbFavorite dbFavorite) {
|
||||
public DocDbResponseJson addFavorite(DbFavorite dbFavorite) {
|
||||
Integer yn = Optional.ofNullable(dbFavorite.getYn()).orElse(1);
|
||||
if (yn == 1) {
|
||||
if (StringUtils.isBlank(dbFavorite.getContent())) {
|
||||
@@ -156,6 +155,5 @@ public class DbSqlExecutorController {
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.zyplayer.doc.db.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbTableRelation;
|
||||
import com.zyplayer.doc.data.repository.manage.param.TableRelationParam;
|
||||
import com.zyplayer.doc.data.repository.manage.vo.TableRelationVo;
|
||||
@@ -34,22 +33,22 @@ import java.util.*;
|
||||
@RequestMapping("/zyplayer-doc-db/table-relation")
|
||||
public class DbTableRelationController {
|
||||
private static Logger logger = LoggerFactory.getLogger(DbTableRelationController.class);
|
||||
|
||||
|
||||
@Resource
|
||||
DatabaseServiceFactory databaseServiceFactory;
|
||||
@Resource
|
||||
DbTableRelationService dbTableRelationService;
|
||||
|
||||
|
||||
@PostMapping(value = "/update")
|
||||
public ResponseJson update(TableRelationParam param) {
|
||||
public DocDbResponseJson update(TableRelationParam param) {
|
||||
DbBaseService dbBaseService = databaseServiceFactory.getDbBaseService(param.getSourceId());
|
||||
dbBaseService.judgeAuth(param.getSourceId(), DbAuthType.UPDATE.getName(), "没有该库的执行权限");
|
||||
dbTableRelationService.update(param);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/getRelation")
|
||||
public ResponseJson getRelation(TableRelationParam param) {
|
||||
public DocDbResponseJson getRelation(TableRelationParam param) {
|
||||
TableRelationVo relationVo = new TableRelationVo();
|
||||
relationVo.setDbName(param.getDbName());
|
||||
relationVo.setName(param.getTableName());
|
||||
@@ -73,7 +72,7 @@ public class DbTableRelationController {
|
||||
}
|
||||
return DocDbResponseJson.ok(relationVo);
|
||||
}
|
||||
|
||||
|
||||
public List<TableRelationVo> getRelation(Long sourceId, String dbName, String tableName, String columnName, Set<String> drillPath, int recursion) {
|
||||
// 最大支持5层关系链展示
|
||||
if (recursion >= 5) {
|
||||
@@ -137,4 +136,3 @@ public class DbTableRelationController {
|
||||
return resultRelationList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.zyplayer.doc.db.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.DbTransferTask;
|
||||
@@ -28,26 +27,26 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/zyplayer-doc-db/transfer")
|
||||
public class DbTransferDataController {
|
||||
|
||||
|
||||
@Resource
|
||||
TransferDataServer transferDataServer;
|
||||
@Resource
|
||||
DbTransferTaskService dbTransferTaskService;
|
||||
|
||||
|
||||
@PostMapping(value = "/start")
|
||||
public ResponseJson doTransfer(Long id) {
|
||||
public DocDbResponseJson doTransfer(Long id) {
|
||||
transferDataServer.transferData(id);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/cancel")
|
||||
public ResponseJson cancel(Long id) {
|
||||
public DocDbResponseJson cancel(Long id) {
|
||||
transferDataServer.cancel(id);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/list")
|
||||
public ResponseJson list() {
|
||||
public DocDbResponseJson list() {
|
||||
QueryWrapper<DbTransferTask> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag", 0);
|
||||
queryWrapper.select(
|
||||
@@ -57,15 +56,15 @@ public class DbTransferDataController {
|
||||
List<DbTransferTask> taskList = dbTransferTaskService.list(queryWrapper);
|
||||
return DocDbResponseJson.ok(taskList);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/detail")
|
||||
public ResponseJson detail(Long id) {
|
||||
public DocDbResponseJson detail(Long id) {
|
||||
DbTransferTask transferTask = dbTransferTaskService.getById(id);
|
||||
return DocDbResponseJson.ok(transferTask);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/update")
|
||||
public ResponseJson update(DbTransferTask transferTask) {
|
||||
public DocDbResponseJson update(DbTransferTask transferTask) {
|
||||
DbTransferTask transferTaskUp = new DbTransferTask();
|
||||
if (transferTask.getId() == null) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
@@ -86,9 +85,9 @@ public class DbTransferDataController {
|
||||
dbTransferTaskService.saveOrUpdate(transferTaskUp);
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/sqlColumns")
|
||||
public ResponseJson sqlColumns(String sql) {
|
||||
public DocDbResponseJson sqlColumns(String sql) {
|
||||
List<String> selectNames = SqlParseUtil.getSelectNames(sql);
|
||||
return DocDbResponseJson.ok(selectNames);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -18,7 +17,7 @@ import java.util.Date;
|
||||
* @since 2018年8月8日
|
||||
*/
|
||||
@Data
|
||||
public class DocDbResponseJson implements ResponseJson {
|
||||
public class DocDbResponseJson {
|
||||
private static SerializeConfig mapping = new SerializeConfig();
|
||||
static {
|
||||
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
Reference in New Issue
Block a user