数据接入
parent
628688d189
commit
592dec16cc
|
@ -136,6 +136,12 @@
|
|||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-source</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-source-common</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-log</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,89 @@
|
|||
package com.muyu.data.source.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.data.source.domain.req.DatabaseTypeQueryReq;
|
||||
import com.muyu.data.source.domain.req.DatabaseTypeSaveReq;
|
||||
import com.muyu.data.source.domain.req.DatabaseTypeEditReq;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据源类型对象 database_type
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("database_type")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "DatabaseType", description = "数据源类型")
|
||||
public class DatabaseType extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键 */
|
||||
@TableId(value = "database_id",type = IdType.AUTO)
|
||||
@ApiModelProperty(name = "主键", value = "主键")
|
||||
private Long databaseId;
|
||||
|
||||
/** 名称 */
|
||||
@Excel(name = "名称")
|
||||
@ApiModelProperty(name = "名称", value = "名称")
|
||||
private String databaseName;
|
||||
|
||||
/** 注册驱动 */
|
||||
@Excel(name = "注册驱动")
|
||||
@ApiModelProperty(name = "注册驱动", value = "注册驱动")
|
||||
private String driverManager;
|
||||
|
||||
/** 前缀 */
|
||||
@Excel(name = "前缀")
|
||||
@ApiModelProperty(name = "前缀", value = "前缀")
|
||||
private String urlPre;
|
||||
|
||||
/**
|
||||
* 查询构造器
|
||||
*/
|
||||
public static DatabaseType queryBuild( DatabaseTypeQueryReq databaseTypeQueryReq){
|
||||
return DatabaseType.builder()
|
||||
.databaseName(databaseTypeQueryReq.getDatabaseName())
|
||||
.driverManager(databaseTypeQueryReq.getDriverManager())
|
||||
.urlPre(databaseTypeQueryReq.getUrlPre())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加构造器
|
||||
*/
|
||||
public static DatabaseType saveBuild(DatabaseTypeSaveReq databaseTypeSaveReq){
|
||||
return DatabaseType.builder()
|
||||
.databaseName(databaseTypeSaveReq.getDatabaseName())
|
||||
.driverManager(databaseTypeSaveReq.getDriverManager())
|
||||
.urlPre(databaseTypeSaveReq.getUrlPre())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改构造器
|
||||
*/
|
||||
public static DatabaseType editBuild(Long databaseId, DatabaseTypeEditReq databaseTypeEditReq){
|
||||
return DatabaseType.builder()
|
||||
.databaseId(databaseId)
|
||||
.databaseName(databaseTypeEditReq.getDatabaseName())
|
||||
.driverManager(databaseTypeEditReq.getDriverManager())
|
||||
.urlPre(databaseTypeEditReq.getUrlPre())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.data.source.domain.req;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据源类型对象 database_type
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "DatabaseTypeEditReq", description = "数据源类型")
|
||||
public class DatabaseTypeEditReq extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 名称 */
|
||||
@ApiModelProperty(name = "名称", value = "名称")
|
||||
private String databaseName;
|
||||
|
||||
/** 注册驱动 */
|
||||
@ApiModelProperty(name = "注册驱动", value = "注册驱动")
|
||||
private String driverManager;
|
||||
|
||||
/** 前缀 */
|
||||
@ApiModelProperty(name = "前缀", value = "前缀")
|
||||
private String urlPre;
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.data.source.domain.req;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据源类型对象 database_type
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "DatabaseTypeQueryReq", description = "数据源类型")
|
||||
public class DatabaseTypeQueryReq extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 名称 */
|
||||
@ApiModelProperty(name = "名称", value = "名称")
|
||||
private String databaseName;
|
||||
|
||||
/** 注册驱动 */
|
||||
@ApiModelProperty(name = "注册驱动", value = "注册驱动")
|
||||
private String driverManager;
|
||||
|
||||
/** 前缀 */
|
||||
@ApiModelProperty(name = "前缀", value = "前缀")
|
||||
private String urlPre;
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.data.source.domain.req;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据源类型对象 database_type
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel(value = "DatabaseTypeSaveReq", description = "数据源类型")
|
||||
public class DatabaseTypeSaveReq extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键 */
|
||||
|
||||
@ApiModelProperty(name = "主键", value = "主键")
|
||||
private Long databaseId;
|
||||
|
||||
/** 名称 */
|
||||
|
||||
@ApiModelProperty(name = "名称", value = "名称")
|
||||
private String databaseName;
|
||||
|
||||
/** 注册驱动 */
|
||||
|
||||
@ApiModelProperty(name = "注册驱动", value = "注册驱动")
|
||||
private String driverManager;
|
||||
|
||||
/** 前缀 */
|
||||
|
||||
@ApiModelProperty(name = "前缀", value = "前缀")
|
||||
private String urlPre;
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-source</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-source-remote</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-source</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-source-server</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-data-source-common</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger UI -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,121 @@
|
|||
package com.muyu.data.source.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
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.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
import com.muyu.data.source.domain.req.DataSourceQueryReq;
|
||||
import com.muyu.data.source.domain.req.DataSourceSaveReq;
|
||||
import com.muyu.data.source.domain.req.DataSourceEditReq;
|
||||
import com.muyu.data.source.service.DataSourceService;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 数据源Controller
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@Api(tags = "数据源")
|
||||
@RestController
|
||||
@RequestMapping("/source")
|
||||
public class DataSourceController extends BaseController {
|
||||
@Autowired
|
||||
private DataSourceService dataSourceService;
|
||||
|
||||
/**
|
||||
* 查询数据源列表
|
||||
*/
|
||||
@ApiOperation("获取数据源列表")
|
||||
@RequiresPermissions("data:source:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<DataSource>> list(DataSourceQueryReq dataSourceQueryReq) {
|
||||
startPage();
|
||||
List<DataSource> list = dataSourceService.list(DataSource.queryBuild(dataSourceQueryReq));
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据源列表
|
||||
*/
|
||||
@ApiOperation("导出数据源列表")
|
||||
@RequiresPermissions("data:source:export")
|
||||
@Log(title = "数据源", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DataSource dataSource) {
|
||||
List<DataSource> list = dataSourceService.list(dataSource);
|
||||
ExcelUtil<DataSource> util = new ExcelUtil<DataSource>(DataSource.class);
|
||||
util.exportExcel(response, list, "数据源数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据源详细信息
|
||||
*/
|
||||
@ApiOperation("获取数据源详细信息")
|
||||
@RequiresPermissions("data:source:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<DataSource> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(dataSourceService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据源
|
||||
*/
|
||||
@RequiresPermissions("data:source:add")
|
||||
@Log(title = "数据源", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增数据源")
|
||||
public Result<String> add(@RequestBody DataSourceSaveReq dataSourceSaveReq) {
|
||||
return toAjax(dataSourceService.save(DataSource.saveBuild(dataSourceSaveReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据源
|
||||
*/
|
||||
@RequiresPermissions("data:source:edit")
|
||||
@Log(title = "数据源", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@ApiOperation("修改数据源")
|
||||
public Result<String> edit(@PathVariable Long id, @RequestBody DataSourceEditReq dataSourceEditReq) {
|
||||
return toAjax(dataSourceService.updateById(DataSource.editBuild(id,dataSourceEditReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据源
|
||||
*/
|
||||
@RequiresPermissions("data:source:remove")
|
||||
@Log(title = "数据源", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除数据源")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
return toAjax(dataSourceService.removeBatchByIds(ids));
|
||||
}
|
||||
/**
|
||||
* 测试连接数据源
|
||||
*/
|
||||
@RequiresPermissions("data:source:jdbc")
|
||||
@Log(title = "数据源类型", businessType = BusinessType.DELETE)
|
||||
@PostMapping("/test/{databaseId}")
|
||||
@ApiOperation("测试数据源")
|
||||
public Result testConnection(@PathVariable("databaseId") Long id) {
|
||||
return Result.success(dataSourceService.testConnection(id));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package com.muyu.data.source.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
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.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.data.source.domain.DatabaseType;
|
||||
import com.muyu.data.source.domain.req.DatabaseTypeQueryReq;
|
||||
import com.muyu.data.source.domain.req.DatabaseTypeSaveReq;
|
||||
import com.muyu.data.source.domain.req.DatabaseTypeEditReq;
|
||||
import com.muyu.data.source.service.DatabaseTypeService;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 数据源类型Controller
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@Api(tags = "数据源类型")
|
||||
@RestController
|
||||
@RequestMapping("/source/type")
|
||||
public class DatabaseTypeController extends BaseController {
|
||||
@Autowired
|
||||
private DatabaseTypeService databaseTypeService;
|
||||
|
||||
/**
|
||||
* 查询数据源类型列表
|
||||
*/
|
||||
@ApiOperation("获取数据源类型列表")
|
||||
@RequiresPermissions("data:type:list")
|
||||
@GetMapping("/list")
|
||||
public Result<List<DatabaseType>> list(DatabaseTypeQueryReq databaseTypeQueryReq) {
|
||||
startPage();
|
||||
List<DatabaseType> list = databaseTypeService.list(DatabaseType.queryBuild(databaseTypeQueryReq));
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据源类型列表
|
||||
*/
|
||||
@ApiOperation("导出数据源类型列表")
|
||||
@RequiresPermissions("data:type:export")
|
||||
@Log(title = "数据源类型", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DatabaseType databaseType) {
|
||||
List<DatabaseType> list = databaseTypeService.list(databaseType);
|
||||
ExcelUtil<DatabaseType> util = new ExcelUtil<DatabaseType>(DatabaseType.class);
|
||||
util.exportExcel(response, list, "数据源类型数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据源类型详细信息
|
||||
*/
|
||||
@ApiOperation("获取数据源类型详细信息")
|
||||
@RequiresPermissions("data:type:query")
|
||||
@GetMapping(value = "/{databaseId}")
|
||||
@ApiImplicitParam(name = "databaseId", value = "databaseId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<DatabaseType> getInfo(@PathVariable("databaseId") Long databaseId) {
|
||||
return Result.success(databaseTypeService.getById(databaseId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据源类型
|
||||
*/
|
||||
@RequiresPermissions("data:type:add")
|
||||
@Log(title = "数据源类型", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增数据源类型")
|
||||
public Result<String> add(@RequestBody DatabaseTypeSaveReq databaseTypeSaveReq) {
|
||||
return toAjax(databaseTypeService.save(DatabaseType.saveBuild(databaseTypeSaveReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据源类型
|
||||
*/
|
||||
@RequiresPermissions("data:type:edit")
|
||||
@Log(title = "数据源类型", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{databaseId}")
|
||||
@ApiOperation("修改数据源类型")
|
||||
public Result<String> edit(@PathVariable Long databaseId, @RequestBody DatabaseTypeEditReq databaseTypeEditReq) {
|
||||
return toAjax(databaseTypeService.updateById(DatabaseType.editBuild(databaseId,databaseTypeEditReq)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据源类型
|
||||
*/
|
||||
@RequiresPermissions("data:type:remove")
|
||||
@Log(title = "数据源类型", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{databaseIds}")
|
||||
@ApiOperation("删除数据源类型")
|
||||
@ApiImplicitParam(name = "databaseId", value = "databaseId", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||
public Result<String> remove(@PathVariable List<Long> databaseIds) {
|
||||
return toAjax(databaseTypeService.removeBatchByIds(databaseIds));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.data.source.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
|
||||
/**
|
||||
* 数据源Mapper接口
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
public interface DataSourceMapper extends BaseMapper<DataSource> {
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.data.source.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.data.source.domain.DatabaseType;
|
||||
|
||||
/**
|
||||
* 数据源类型Mapper接口
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
public interface DatabaseTypeMapper extends BaseMapper<DatabaseType> {
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.data.source.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 数据源Service接口
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
public interface DataSourceService extends IService<DataSource> {
|
||||
/**
|
||||
* 查询数据源列表
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @return 数据源集合
|
||||
*/
|
||||
public List<DataSource> list(DataSource dataSource);
|
||||
|
||||
boolean testConnection(Long databaseId);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.data.source.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.muyu.data.source.domain.DatabaseType;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 数据源类型Service接口
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
public interface DatabaseTypeService extends IService<DatabaseType> {
|
||||
/**
|
||||
* 查询数据源类型列表
|
||||
*
|
||||
* @param databaseType 数据源类型
|
||||
* @return 数据源类型集合
|
||||
*/
|
||||
public List<DatabaseType> list(DatabaseType databaseType);
|
||||
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
package com.muyu.data.source.service.impl;
|
||||
|
||||
import com.muyu.data.source.domain.DatabaseType;
|
||||
import com.muyu.data.source.service.DatabaseTypeService;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.muyu.data.source.mapper.DataSourceMapper;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
import com.muyu.data.source.service.DataSourceService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
/**
|
||||
* 数据源Service业务层处理
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSource> implements DataSourceService {
|
||||
|
||||
@Autowired
|
||||
private DataSourceService dataSourceService;
|
||||
|
||||
@Autowired
|
||||
private DatabaseTypeService databaseTypeService;
|
||||
|
||||
/**
|
||||
* 查询数据源列表
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @return 数据源
|
||||
*/
|
||||
@Override
|
||||
public List<DataSource> list(DataSource dataSource) {
|
||||
LambdaQueryWrapper<DataSource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
if (ObjUtils.notNull(dataSource.getName())) {
|
||||
queryWrapper.like(DataSource::getName, dataSource.getName());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(dataSource.getSystemName())) {
|
||||
queryWrapper.like(DataSource::getSystemName, dataSource.getSystemName());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(dataSource.getDatabaseName())) {
|
||||
queryWrapper.like(DataSource::getDatabaseName, dataSource.getDatabaseName());
|
||||
}
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试连接
|
||||
*
|
||||
* @param id 数据源id
|
||||
*/
|
||||
@Override
|
||||
public boolean testConnection(Long id) {
|
||||
DataSource dataSource=null;
|
||||
List<DataSource> dataSourceList = this.list(
|
||||
new LambdaQueryWrapper<DataSource>()
|
||||
.eq(DataSource::getDatabaseType, id)
|
||||
);
|
||||
|
||||
// 使用Set进行去重,
|
||||
Set<DataSource> uniqueDataSources = new HashSet<>(dataSourceList);
|
||||
|
||||
Optional<DataSource> source = uniqueDataSources.stream().distinct().findFirst();
|
||||
if (source.isPresent()){
|
||||
dataSource = source.get();
|
||||
}
|
||||
|
||||
String jdbcUrl = "";
|
||||
String driveClass = "";
|
||||
boolean flag = false;
|
||||
DatabaseType dataType = databaseTypeService.getOne(
|
||||
new LambdaQueryWrapper<DatabaseType>()
|
||||
.eq(DatabaseType::getDatabaseId, dataSource.getDatabaseType())
|
||||
);
|
||||
|
||||
if (dataType.getDatabaseName().equals("mysql")||dataType.equals("MYSQL")){
|
||||
driveClass=dataType.getDriverManager();
|
||||
|
||||
}
|
||||
try {
|
||||
if (dataType.getDriverManager() != null && dataType.getUrlPre() != null){
|
||||
if ("mysql".equals(dataType.getDatabaseName())){
|
||||
driveClass = dataType.getDriverManager();
|
||||
jdbcUrl = dataType.getUrlPre() + dataSource.getHost() + ":" + dataSource.getPort() + "/" + dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
||||
}
|
||||
if ("oracle".equals(dataType.getDatabaseName())){
|
||||
driveClass = dataType.getDriverManager();
|
||||
jdbcUrl = dataType.getUrlPre() + dataSource.getHost() + ":" + dataSource.getPort() + ":" + dataSource.getDatabaseName();
|
||||
}
|
||||
if ("sqlserver".equals(dataType.getDatabaseName())){
|
||||
driveClass = dataType.getDriverManager();
|
||||
jdbcUrl = dataType.getUrlPre()+ dataSource.getHost() +":"+dataSource.getPort()+";databaseName="+dataSource.getDatabaseName();
|
||||
}
|
||||
flag = testDatasource(driveClass, jdbcUrl, dataSource.getUser(), dataSource.getPassword());
|
||||
}else if(dataType.getDriverManager()== null && dataType.getUrlPre() == null){
|
||||
// redis
|
||||
//连接指定的redis
|
||||
Jedis jedis = new Jedis(dataSource.getHost(), Integer.valueOf(dataSource.getPort()));
|
||||
//如果有密码则需要下面这一行
|
||||
if (dataSource.getPassword() != null && !dataSource.getPassword().equals("")){
|
||||
jedis.auth(dataSource.getPassword());
|
||||
}
|
||||
//查看服务是否运行,运行正常的话返回一个PONG,否则返回一个连接错误
|
||||
try {
|
||||
jedis.ping();
|
||||
flag = true;
|
||||
} catch (Exception e) {
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}catch (Exception e) {
|
||||
return flag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static boolean testDatasource(String driveClass, String url, String username, String password) {
|
||||
try {
|
||||
Class.forName(driveClass);
|
||||
DriverManager.getConnection(url, username, password);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package com.muyu.data.source.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.muyu.data.source.mapper.DatabaseTypeMapper;
|
||||
import com.muyu.data.source.domain.DatabaseType;
|
||||
import com.muyu.data.source.service.DatabaseTypeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
||||
/**
|
||||
* 数据源类型Service业务层处理
|
||||
*
|
||||
* @author hufangming
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DatabaseTypeServiceImpl extends ServiceImpl<DatabaseTypeMapper, DatabaseType> implements DatabaseTypeService {
|
||||
|
||||
/**
|
||||
* 查询数据源类型列表
|
||||
*
|
||||
* @param databaseType 数据源类型
|
||||
* @return 数据源类型
|
||||
*/
|
||||
@Override
|
||||
public List<DatabaseType> list(DatabaseType databaseType) {
|
||||
LambdaQueryWrapper<DatabaseType> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
|
||||
if (ObjUtils.notNull(databaseType.getDatabaseName())){
|
||||
queryWrapper.like(DatabaseType::getDatabaseName, databaseType.getDatabaseName());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(databaseType.getDriverManager())){
|
||||
queryWrapper.eq(DatabaseType::getDriverManager, databaseType.getDriverManager());
|
||||
}
|
||||
|
||||
if (ObjUtils.notNull(databaseType.getUrlPre())){
|
||||
queryWrapper.eq(DatabaseType::getUrlPre, databaseType.getUrlPre());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
/**
|
||||
* 将所有的大写转换成小写并清除中间所有的空格
|
||||
* @param str 需要转换的参数
|
||||
* @return 转换后的参数
|
||||
*/
|
||||
public static String lowerCase(String str){
|
||||
return str.toLowerCase().replaceAll(" ","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?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.muyu.data.source.mapper.DataSourceMapper">
|
||||
|
||||
<resultMap type="com.muyu.data.source.domain.DataSource" id="DataSourceResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="systemName" column="system_name" />
|
||||
<result property="databaseName" column="database_name" />
|
||||
<result property="databaseType" column="database_type" />
|
||||
<result property="host" column="host" />
|
||||
<result property="port" column="port" />
|
||||
<result property="user" column="user" />
|
||||
<result property="password" column="password" />
|
||||
<result property="type" column="type" />
|
||||
<result property="connectionParam" column="connection_param" />
|
||||
<result property="status" column="status" />
|
||||
<result property="initNum" column="init_num" />
|
||||
<result property="maxNum" column="max_num" />
|
||||
<result property="maxWaitTime" column="max_wait_time" />
|
||||
<result property="maxWaitSize" column="max_wait_size" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDataSourceVo">
|
||||
select id, name, system_name, database_name, database_type, host, port, user, password, type, connection_param, status, init_num, max_num, max_wait_time, max_wait_size, remark, create_by, create_time, update_by, update_time from data_source
|
||||
</sql>
|
||||
</mapper>
|
|
@ -0,0 +1,22 @@
|
|||
<?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.muyu.data.source.mapper.DatabaseTypeMapper">
|
||||
|
||||
<resultMap type="com.muyu.data.source.domain.DatabaseType" id="DatabaseTypeResult">
|
||||
<result property="databaseId" column="database_id" />
|
||||
<result property="databaseName" column="database_name" />
|
||||
<result property="driverManager" column="driver_manager" />
|
||||
<result property="urlPre" column="url_pre" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDatabaseTypeVo">
|
||||
select database_id, database_name, driver_manager, url_pre, remark, create_by, create_time, update_by, update_time from database_type
|
||||
</sql>
|
||||
</mapper>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-data-source</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<description>muyu-data-source数据源模块</description>
|
||||
<modules>
|
||||
<module>muyu-data-source-common</module>
|
||||
<module>muyu-data-source-remote</module>
|
||||
<module>muyu-data-source-server</module>
|
||||
</modules>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -13,6 +13,7 @@
|
|||
<module>muyu-gen</module>
|
||||
<module>muyu-job</module>
|
||||
<module>muyu-file</module>
|
||||
<module>muyu-data-source</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>muyu-modules</artifactId>
|
||||
|
|
7
pom.xml
7
pom.xml
|
@ -34,6 +34,7 @@
|
|||
<jjwt.version>0.9.1</jjwt.version>
|
||||
<minio.version>8.2.2</minio.version>
|
||||
<poi.version>4.1.2</poi.version>
|
||||
<jedis.version>2.9.0</jedis.version>
|
||||
<transmittable-thread-local.version>2.14.3</transmittable-thread-local.version>
|
||||
</properties>
|
||||
|
||||
|
@ -206,6 +207,12 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>${jedis.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
Loading…
Reference in New Issue