|
|
|
|
@ -4,11 +4,13 @@ package org.springblade.plugin.operation.database.controller; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
|
import io.swagger.models.auth.In; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.springblade.core.boot.ctrl.BladeController; |
|
|
|
|
import org.springblade.core.cache.utils.CacheUtil; |
|
|
|
|
@ -30,7 +32,10 @@ import org.springblade.plugin.operation.database.excel.DatabaseExcel; |
|
|
|
|
import org.springblade.plugin.operation.database.excel.UploadReturn; |
|
|
|
|
import org.springblade.plugin.operation.database.service.IDataBaseService; |
|
|
|
|
import org.springblade.plugin.operation.database.service.IDataTableService; |
|
|
|
|
import org.springblade.plugin.operation.database.vo.DataBaseVO; |
|
|
|
|
import org.springblade.plugin.operation.task.entity.TaskInfo; |
|
|
|
|
import org.springblade.system.cache.DictBizCache; |
|
|
|
|
import org.springblade.system.entity.Dept; |
|
|
|
|
import org.springblade.system.entity.DictBiz; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
@ -72,25 +77,32 @@ public class DataBaseController extends BladeController { |
|
|
|
|
* 分页 |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/list") |
|
|
|
|
@ApiOperationSupport(order = 2) |
|
|
|
|
@ApiOperation(value = "分页", notes = "传入dataScope") |
|
|
|
|
public R<IPage<DataTable>> list(DataTable dataTable, Query query) { |
|
|
|
|
IPage<DataTable> pages = dataTableService.page(Condition.getPage(query.setDescs("create_time")), Condition.getQueryWrapper(dataTable)); |
|
|
|
|
List<DataTable> dataTableList = pages.getRecords(); |
|
|
|
|
public R<IPage<DataBaseVO>> list(DataBase dataBase, Query query) { |
|
|
|
|
IPage<DataBaseVO> pages = dataTableService.pageVO(Condition.getPage(query), dataBase); |
|
|
|
|
List<DataBaseVO> dataTableList = pages.getRecords(); |
|
|
|
|
if (CollectionUtils.isNotEmpty(dataTableList)) { |
|
|
|
|
for (DataTable table : dataTableList) { |
|
|
|
|
DataBase dataBase = dataBaseService.getById(table.getDataBaseId()); |
|
|
|
|
table.setDataBaseName(dataBase.getDataBaseName()); |
|
|
|
|
table.setDataBaseAlias(dataBase.getDataBaseAlias()); |
|
|
|
|
table.setDataBaseType(dataBase.getDataBaseType()); |
|
|
|
|
table.setDataBaseIp(dataBase.getDataBaseIp()); |
|
|
|
|
table.setDataBasePort(dataBase.getDataBasePort()); |
|
|
|
|
table.setSystemName(dataBase.getSystemName()); |
|
|
|
|
for (DataBaseVO table : dataTableList) { |
|
|
|
|
table.setDeptName(sysClient.getDeptName(table.getDeptId()).getData()); |
|
|
|
|
table.setCompanyName(userClient.userInfoById(table.getCompany()).getData().getRealName()); |
|
|
|
|
table.setCompanyName(userClient.userInfoById(table.getCompany()).getData().getName()); |
|
|
|
|
} |
|
|
|
|
pages.setRecords(dataTableList); |
|
|
|
|
} |
|
|
|
|
// IPage<DataTable> pages = dataTableService.page(Condition.getPage(query.setDescs("create_time")), Condition.getQueryWrapper(dataTable));
|
|
|
|
|
// List<DataTable> dataTableList = pages.getRecords();
|
|
|
|
|
// if (CollectionUtils.isNotEmpty(dataTableList)) {
|
|
|
|
|
// for (DataTable table : dataTableList) {
|
|
|
|
|
// DataBase dataBase = dataBaseService.getById(table.getDataBaseId());
|
|
|
|
|
// table.setDataBaseName(dataBase.getDataBaseName());
|
|
|
|
|
// table.setDataBaseAlias(dataBase.getDataBaseAlias());
|
|
|
|
|
// table.setDataBaseType(dataBase.getDataBaseType());
|
|
|
|
|
// table.setDataBaseIp(dataBase.getDataBaseIp());
|
|
|
|
|
// table.setDataBasePort(dataBase.getDataBasePort());
|
|
|
|
|
// table.setSystemName(dataBase.getSystemName());
|
|
|
|
|
// table.setDeptName(sysClient.getDeptName(dataBase.getDeptId()).getData());
|
|
|
|
|
// table.setCompanyName(userClient.userInfoById(dataBase.getCompany()).getData().getName());
|
|
|
|
|
// }
|
|
|
|
|
// pages.setRecords(dataTableList);
|
|
|
|
|
// }
|
|
|
|
|
return R.data(pages); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -128,28 +140,8 @@ public class DataBaseController extends BladeController { |
|
|
|
|
* excel导入 |
|
|
|
|
*/ |
|
|
|
|
@PostMapping("/dataImport") |
|
|
|
|
public R importUser(MultipartFile file) { |
|
|
|
|
List<DatabaseExcel> excelList = ExcelUtil.read(file, DatabaseExcel.class); |
|
|
|
|
if (CollectionUtils.isNotEmpty(excelList)) { |
|
|
|
|
List<DataBase> dataBaseList = new ArrayList<>(); |
|
|
|
|
List<DataTable> dataTableList = new ArrayList<>(); |
|
|
|
|
excelList.forEach(item -> { |
|
|
|
|
// String data = sysClient.getDeptIds(AuthUtil.getTenantId(), item.getDeptId()).getData();
|
|
|
|
|
// User user = userClient.userInfoByName(AuthUtil.getTenantId(), item.getCompany()).getData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 数据库
|
|
|
|
|
DataBase dataBase = BeanUtil.copy(item, DataBase.class); |
|
|
|
|
dataBase.setDataBaseType(Integer.parseInt(DictBizCache.getKey("database_type", item.getDataBaseType()))); |
|
|
|
|
dataBaseList.add(dataBase); |
|
|
|
|
// 数据表
|
|
|
|
|
DataTable dataTable = BeanUtil.copy(item, DataTable.class); |
|
|
|
|
dataTableList.add(dataTable); |
|
|
|
|
}); |
|
|
|
|
dataBaseService.saveBatch(dataBaseList); |
|
|
|
|
dataTableService.saveBatch(dataTableList); |
|
|
|
|
} |
|
|
|
|
return R.success("操作成功"); |
|
|
|
|
public R dataImport(MultipartFile file) { |
|
|
|
|
return R.status(dataBaseService.dataImport(file)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -174,7 +166,10 @@ public class DataBaseController extends BladeController { |
|
|
|
|
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
|
|
|
|
|
EasyExcel.write(fileName, DatabaseExcel.class).registerWriteHandler(new CustomSheetWriteHandler()) |
|
|
|
|
.registerWriteHandler(new CustomCellWriteHandler()).sheet("模板").doWrite(excels); |
|
|
|
|
|
|
|
|
|
download(fileName, response); |
|
|
|
|
File file = new File(fileName); |
|
|
|
|
file.delete(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -212,7 +207,6 @@ public class DataBaseController extends BladeController { |
|
|
|
|
return R.data(uploadReturn); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查看文件 |
|
|
|
|
*/ |
|
|
|
|
@ -278,4 +272,42 @@ public class DataBaseController extends BladeController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 列表数据返回 |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/listData") |
|
|
|
|
public R listData() { |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
// 数据库实例名集合
|
|
|
|
|
QueryWrapper<DataBase> wrapper = new QueryWrapper<>(); |
|
|
|
|
wrapper.select("DISTINCT data_base_name"); |
|
|
|
|
map.put("dataBaseNames", dataBaseService.list(wrapper)); |
|
|
|
|
wrapper.clear(); |
|
|
|
|
|
|
|
|
|
// 运维公司集合
|
|
|
|
|
wrapper.select("DISTINCT company"); |
|
|
|
|
List<DataBase> dataBases = dataBaseService.list(wrapper); |
|
|
|
|
if (CollectionUtils.isNotEmpty(dataBases)) { |
|
|
|
|
List<User> users = new ArrayList<>(); |
|
|
|
|
for (DataBase dataBase : dataBases) { |
|
|
|
|
User user = userClient.userInfoById(dataBase.getCompany()).getData(); |
|
|
|
|
users.add(user); |
|
|
|
|
} |
|
|
|
|
map.put("companys", users); |
|
|
|
|
wrapper.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 部门集合
|
|
|
|
|
wrapper.select("DISTINCT dept_id"); |
|
|
|
|
List<DataBase> depts = dataBaseService.list(wrapper); |
|
|
|
|
if (CollectionUtils.isNotEmpty(depts)) { |
|
|
|
|
List<Dept> deptList = new ArrayList<>(); |
|
|
|
|
for (DataBase dataBase : depts) { |
|
|
|
|
Dept dept = sysClient.getDept(dataBase.getDeptId()).getData(); |
|
|
|
|
deptList.add(dept); |
|
|
|
|
} |
|
|
|
|
map.put("depts", deptList); |
|
|
|
|
} |
|
|
|
|
return R.data(map); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|