数据源的增删改查
parent
e06abd4e0e
commit
550c58dd02
|
@ -4,6 +4,9 @@ import com.dtflys.forest.springboot.annotation.ForestScannerRegister;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.source.domain.DataSource;
|
||||
import com.muyu.source.domain.req.DataSourceQueryReq;
|
||||
import com.muyu.source.service.DataSourceService;
|
||||
|
@ -12,9 +15,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.HttpRequestHandler;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -27,7 +32,7 @@ import java.util.List;
|
|||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/dataSource")
|
||||
@RequestMapping("/source")
|
||||
@Tag(name = "数据源控制层", description = "进行数据源管理,查看等相关操作")
|
||||
public class DataSourceController extends BaseController {
|
||||
public DataSourceController() {
|
||||
|
@ -40,6 +45,80 @@ public class DataSourceController extends BaseController {
|
|||
@Autowired
|
||||
private DataSourceService dataSourceService;
|
||||
|
||||
/**
|
||||
* 查询数据源列表
|
||||
*/
|
||||
@RequiresPermissions("Datasource:source:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<DataSource>> list(DataSource dataSource)
|
||||
{
|
||||
startPage();
|
||||
List<DataSource> list = dataSourceService.selectDataSourceList(dataSource);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据源列表
|
||||
*/
|
||||
@RequiresPermissions("Datasource:source:export")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DataSource dataSource)
|
||||
{
|
||||
List<DataSource> list = dataSourceService.selectDataSourceList(dataSource);
|
||||
ExcelUtil<DataSource> util = new ExcelUtil<DataSource>(DataSource.class);
|
||||
util.exportExcel(response, list, "数据源数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据源详细信息
|
||||
*/
|
||||
@RequiresPermissions("Datasource:source:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result<List<DataSource>> getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(dataSourceService.selectDataSourceById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据源
|
||||
*/
|
||||
@RequiresPermissions("Datasource:source:add")
|
||||
@PostMapping
|
||||
public Result<Integer> add(
|
||||
@Validated @RequestBody DataSource dataSource)
|
||||
{
|
||||
if (dataSourceService.checkIdUnique(dataSource)) {
|
||||
return error("新增 数据源 '" + dataSource + "'失败,数据源已存在");
|
||||
}
|
||||
dataSource.setCreateBy(SecurityUtils.getUsername());
|
||||
return toAjax(dataSourceService.save(dataSource));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据源
|
||||
*/
|
||||
@RequiresPermissions("Datasource:source:edit")
|
||||
@PutMapping
|
||||
public Result<Integer> edit(
|
||||
@Validated @RequestBody DataSource dataSource)
|
||||
{
|
||||
if (!dataSourceService.checkIdUnique(dataSource)) {
|
||||
return error("修改 数据源 '" + dataSource + "'失败,数据源不存在");
|
||||
}
|
||||
dataSource.setUpdateBy(SecurityUtils.getUsername());
|
||||
return toAjax(dataSourceService.updateById(dataSource));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据源
|
||||
*/
|
||||
@RequiresPermissions("Datasource:source:remove")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
|
||||
{
|
||||
dataSourceService.removeBatchByIds(Arrays.asList(ids));
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取数据
|
||||
|
@ -54,32 +133,8 @@ public class DataSourceController extends BaseController {
|
|||
return Result.success(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据源列表的全部数据
|
||||
*
|
||||
* @param dataSourceQueryReq 数据源
|
||||
* @return 数据源
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "查询数据源列表的全部数据", description = "根据数据源的接入名称,来源系统名称可以进行数据源的筛选")
|
||||
public Result<List<DataSource>> list(@RequestBody DataSourceQueryReq dataSourceQueryReq) {
|
||||
List<DataSource> list = dataSourceService.list(DataSource.queryBuild(dataSourceQueryReq));
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据源
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @param response response
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
@Operation(summary = "导出数据源", description = "导出数据源为Excel的格式")
|
||||
public void derive(DataSource dataSource, HttpServletResponse response) {
|
||||
List<DataSource> list = dataSourceService.list(dataSource);
|
||||
ExcelUtil<DataSource> excelUtil = new ExcelUtil<>(DataSource.class);
|
||||
excelUtil.exportExcel(response, list, "数据源数据");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据源详细信息
|
||||
|
@ -106,44 +161,7 @@ public class DataSourceController extends BaseController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加数据源
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @return 数据源
|
||||
*/
|
||||
@PostMapping("/insert")
|
||||
@Operation(summary = "数据源的添加", description = "数据源的添加")
|
||||
public Result insert(@RequestBody DataSource dataSource) {
|
||||
dataSourceService.save(dataSource);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据源
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @return 数据源
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "数据源的修改", description = "数据源的修改")
|
||||
public Result update(@RequestBody DataSource dataSource) {
|
||||
dataSourceService.updateById(dataSource);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据源
|
||||
*
|
||||
* @param id 数据源
|
||||
* @return 数据源
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@Operation(summary = "数据源的删除", description = "可以根据数据源的ID删除/批量删除")
|
||||
public Result delete(@PathVariable("id") List<Long> id) {
|
||||
dataSourceService.removeBatchByIds(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,11 +16,28 @@ import java.util.List;
|
|||
public interface DataSourceService extends IService<DataSource> {
|
||||
|
||||
/**
|
||||
* 查询数据源的列表
|
||||
* 精确查询数据源
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @param id 数据源主键
|
||||
* @return 数据源
|
||||
*/
|
||||
public DataSource selectDataSourceById(Long id);
|
||||
|
||||
/**
|
||||
* 查询数据源列表
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @return 数据源集合
|
||||
*/
|
||||
public List<DataSource> selectDataSourceList(DataSource dataSource);
|
||||
|
||||
/**
|
||||
* 判断 数据源 id是否唯一
|
||||
* @param dataSource 数据源
|
||||
* @return 结果
|
||||
*/
|
||||
Boolean checkIdUnique(DataSource dataSource);
|
||||
|
||||
|
||||
|
||||
List<DataSource> list(DataSource dataSource);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.muyu.source.service.Impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.source.domain.DataSource;
|
||||
|
@ -24,33 +24,60 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
|
||||
|
||||
/**
|
||||
* 查询数据源的列表
|
||||
* 精确查询数据源
|
||||
*
|
||||
* @param id 数据源主键
|
||||
* @return 数据源
|
||||
*/
|
||||
@Override
|
||||
public DataSource selectDataSourceById(Long id)
|
||||
{
|
||||
LambdaQueryWrapper<DataSource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
Assert.notNull(id, "id不可为空");
|
||||
queryWrapper.eq(DataSource::getId, id);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询数据源列表
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @return 数据源
|
||||
*/
|
||||
@Override
|
||||
public List<DataSource> list(DataSource dataSource) {
|
||||
LambdaQueryWrapper<DataSource> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
public List<DataSource> selectDataSourceList(DataSource dataSource)
|
||||
{
|
||||
LambdaQueryWrapper<DataSource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotEmpty(dataSource.getName())){
|
||||
lambdaQueryWrapper.like(DataSource::getName, dataSource.getName());
|
||||
queryWrapper.like(DataSource::getName, dataSource.getName());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dataSource.getSystemName())){
|
||||
lambdaQueryWrapper.like(DataSource::getSystemName, dataSource.getSystemName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(dataSource.getIp())){
|
||||
lambdaQueryWrapper.like(DataSource::getIp,dataSource.getIp());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(dataSource.getPort())){
|
||||
lambdaQueryWrapper.like(DataSource::getPort,dataSource.getPort());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(dataSource.getDatabaseName())){
|
||||
lambdaQueryWrapper.like(DataSource::getDatabaseName,dataSource.getDatabaseName());
|
||||
queryWrapper.like(DataSource::getSystemName, dataSource.getSystemName());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dataSource.getDataType())){
|
||||
lambdaQueryWrapper.eq(DataSource::getDataType,dataSource.getDataType());
|
||||
queryWrapper.eq(DataSource::getDataType, dataSource.getDataType());
|
||||
}
|
||||
return list(lambdaQueryWrapper);
|
||||
if (StringUtils.isNotEmpty(dataSource.getIp())){
|
||||
queryWrapper.like(DataSource::getIp, dataSource.getIp());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dataSource.getPort())){
|
||||
queryWrapper.like(DataSource::getPort, dataSource.getPort());
|
||||
}
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 唯一 判断
|
||||
* @param dataSource 数据源
|
||||
* @return 数据源
|
||||
*/
|
||||
@Override
|
||||
public Boolean checkIdUnique(DataSource dataSource) {
|
||||
LambdaQueryWrapper<DataSource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DataSource::getId, dataSource.getId());
|
||||
return this.count(queryWrapper) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue