添加数据源参数类
parent
17f1ec6357
commit
e62a81aca2
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/etl-cleaning/src/main/java/com/etl/cleaning/server/ServerTest.java" dialect="GenericSQL" />
|
||||
</component>
|
||||
</project>
|
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,6 @@ package com.etl.cleaning.config;
|
|||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
@ -12,7 +11,6 @@ import org.springframework.context.annotation.Configuration;
|
|||
*/
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 添加分页插件
|
||||
*/
|
||||
|
@ -23,4 +21,5 @@ public class MybatisPlusConfig {
|
|||
// 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package com.etl.cleaning.controller;
|
||||
|
||||
import com.etl.cleaning.domian.request.InsertItemRequest;
|
||||
import com.etl.cleaning.service.ItemService;
|
||||
import com.etl.common.result.Result;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 数据源详情
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/item")
|
||||
public class ItemController {
|
||||
private final ItemService itemService;
|
||||
|
||||
public ItemController(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据源详情
|
||||
* @param insertItemRequest
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/insertItem")
|
||||
public Result insertItem(@RequestBody InsertItemRequest insertItemRequest) {
|
||||
itemService.insertItem(insertItemRequest);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -1,13 +1,12 @@
|
|||
package com.etl.cleaning.controller;
|
||||
|
||||
import com.etl.cleaning.domian.pojo.DataPlace;
|
||||
import com.etl.cleaning.domian.request.InsertPlaceRequest;
|
||||
import com.etl.cleaning.domian.request.PlaceRequest;
|
||||
import com.etl.cleaning.service.PlaceService;
|
||||
import com.etl.common.result.Result;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -45,4 +44,26 @@ public class PlaceController {
|
|||
boolean b = placeService.removeBatchByIds(ids);
|
||||
return Result.success(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试连接
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/testMysql/{id}")
|
||||
public Result testMysql(@PathVariable Long id){
|
||||
String s = placeService.dataTest(id);
|
||||
return Result.success(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据源
|
||||
* @param insertPlaceRequest
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/insertData")
|
||||
public Result insertData(@RequestBody @Validated InsertPlaceRequest insertPlaceRequest){
|
||||
Boolean b = placeService.insertDataPlace(insertPlaceRequest);
|
||||
return Result.success(b);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package com.etl.cleaning.domian.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 数据源类型详情
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@TableName("data_item")
|
||||
public class DataItem {
|
||||
/**
|
||||
* 主键ID自增
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long itemId;
|
||||
/**
|
||||
* 数据源藐视
|
||||
*/
|
||||
private String itemDesc;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String itemUsername;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String itemPass;
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private String itemPort;
|
||||
/**
|
||||
* 连接数据库名称
|
||||
*/
|
||||
private String itemName;
|
||||
/**
|
||||
* 额外配置
|
||||
*/
|
||||
private String itemYaml;
|
||||
/**
|
||||
* 连接状态
|
||||
*/
|
||||
private Long itemStatue;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String itemBank;
|
||||
/**
|
||||
* 连接地址
|
||||
*/
|
||||
private String itemPlace;
|
||||
}
|
|
@ -50,4 +50,28 @@ public class DataPlace {
|
|||
*/
|
||||
@TableField(exist = false)
|
||||
private String typeName;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private String port;
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String dataName;
|
||||
/**
|
||||
* 额外配置
|
||||
*/
|
||||
private String yaml;
|
||||
/**
|
||||
* 链接路径
|
||||
*/
|
||||
private String dataUrl;
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package com.etl.cleaning.domian.request;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 添加数据源参数
|
||||
*/
|
||||
@Data
|
||||
public class InsertItemRequest {
|
||||
/**
|
||||
* 数据源藐视
|
||||
*/
|
||||
private String itemDesc;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String itemUsername;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String itemPass;
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private String itemPort;
|
||||
/**
|
||||
* 连接数据库名称
|
||||
*/
|
||||
private String itemName;
|
||||
/**
|
||||
* 额外配置
|
||||
*/
|
||||
private String itemYaml;
|
||||
/**
|
||||
* 连接状态
|
||||
*/
|
||||
private Long itemStatue;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String itemBank;
|
||||
/**
|
||||
* 连接地址
|
||||
*/
|
||||
private String place;
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.etl.cleaning.domian.request;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 添加数据源参数
|
||||
*/
|
||||
@Data
|
||||
public class InsertPlaceRequest {
|
||||
/**
|
||||
* 数据源描述
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String bank;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 类型ID
|
||||
*/
|
||||
@NotNull(message = "连接类型不能为空")
|
||||
private Long typeId;
|
||||
/**
|
||||
* 链接状态
|
||||
*/
|
||||
private Boolean statue;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
private String username;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
@NotBlank(message = "端口不能为空")
|
||||
private String port;
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
@NotBlank(message = "数据库不能为空")
|
||||
private String dataName;
|
||||
/**
|
||||
* 额外配置
|
||||
*/
|
||||
private String yaml;
|
||||
/**
|
||||
* 链接路径
|
||||
*/
|
||||
@NotBlank(message = "连接地址不能为空")
|
||||
private String dataUrl;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.etl.cleaning.domian.request;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* mysql链接参数
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class MysqlRequest {
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
private String itemUsername;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String itemPass;
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
@NotBlank(message = "端口号不能为空")
|
||||
private String itemPort;
|
||||
/**
|
||||
* 连接数据库名称
|
||||
*/
|
||||
@NotBlank(message = "数据库名称不能为空")
|
||||
private String itemName;
|
||||
/**
|
||||
* 连接地址
|
||||
*/
|
||||
@NotBlank(message = "链接地址不能为空")
|
||||
private String place;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.etl.cleaning.domian.response;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据源管理返回列表
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class PlaceResponse {
|
||||
/**
|
||||
* 数据源描述
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String bank;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 链接状态
|
||||
*/
|
||||
private Boolean statue;
|
||||
/**
|
||||
* 连接类型
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String typeName;
|
||||
}
|
|
@ -10,7 +10,8 @@ import lombok.Getter;
|
|||
public enum EnumMsg {
|
||||
// 定义一个带有错误码和描述性字符串的枚举常量
|
||||
NO_TYPE(401, "暂无类型"),
|
||||
DRIVER_CLASS_NAME(402,"com.mysql.cj.jdbc.Driver");
|
||||
DRIVER_CLASS_NAME(402,"com.mysql.cj.jdbc.Driver"),
|
||||
URL_PRE(403,"jdbc:mysql");
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package com.etl.cleaning.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.etl.cleaning.domian.pojo.DataItem;
|
||||
|
||||
/**
|
||||
* 数据源详情
|
||||
*/
|
||||
public interface ItemMapper extends BaseMapper<DataItem> {
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.etl.cleaning.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.etl.cleaning.domian.pojo.DataItem;
|
||||
import com.etl.cleaning.domian.request.InsertItemRequest;
|
||||
|
||||
/**
|
||||
* 数据源详情
|
||||
*/
|
||||
public interface ItemService extends IService<DataItem> {
|
||||
void insertItem(InsertItemRequest insertItemRequest);
|
||||
}
|
|
@ -2,14 +2,33 @@ package com.etl.cleaning.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.etl.cleaning.domian.pojo.DataPlace;
|
||||
import com.etl.cleaning.domian.request.InsertPlaceRequest;
|
||||
import com.etl.cleaning.domian.request.PlaceRequest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据源管理
|
||||
*/
|
||||
public interface PlaceService extends IService<DataPlace> {
|
||||
/**
|
||||
* 展示数据源管理列表
|
||||
* @param placeRequest
|
||||
* @return
|
||||
*/
|
||||
Map<String,Object> showPlacePage(PlaceRequest placeRequest);
|
||||
|
||||
|
||||
/**
|
||||
* 链接测试
|
||||
* @param id
|
||||
*/
|
||||
String dataTest(Long id);
|
||||
|
||||
/**
|
||||
* 添加数据源
|
||||
* @param insertItemRequest
|
||||
* @return
|
||||
*/
|
||||
Boolean insertDataPlace(InsertPlaceRequest insertItemRequest);
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package com.etl.cleaning.serviceimpl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.etl.cleaning.config.DatabaseConfig;
|
||||
import com.etl.cleaning.domian.pojo.DataItem;
|
||||
import com.etl.cleaning.domian.request.InsertItemRequest;
|
||||
import com.etl.cleaning.mapper.ItemMapper;
|
||||
import com.etl.cleaning.server.ServerTest;
|
||||
import com.etl.cleaning.service.ItemService;
|
||||
import org.springframework.stereotype.Service;
|
||||
/**
|
||||
* 数据源详情
|
||||
*/
|
||||
@Service
|
||||
public class ItemServiceImpl extends ServiceImpl<ItemMapper, DataItem> implements ItemService {
|
||||
@Override
|
||||
public void insertItem(InsertItemRequest insertItemRequest) {
|
||||
//拼接路径
|
||||
String url = insertItemRequest.getPlace() + "/" +insertItemRequest.getItemName();
|
||||
DatabaseConfig databaseConfig = DatabaseConfig.builder()
|
||||
.url(url)
|
||||
.port(insertItemRequest.getItemPort())
|
||||
.username(insertItemRequest.getItemUsername())
|
||||
.password(insertItemRequest.getItemPass())
|
||||
.build();
|
||||
String result = ServerTest.testDatabaseConnection(databaseConfig);
|
||||
System.out.println("测试结果"+result);
|
||||
}
|
||||
}
|
|
@ -3,11 +3,16 @@ package com.etl.cleaning.serviceimpl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.etl.cleaning.config.DatabaseConfig;
|
||||
import com.etl.cleaning.domian.pojo.DataPlace;
|
||||
import com.etl.cleaning.domian.pojo.DateType;
|
||||
import com.etl.cleaning.domian.request.InsertPlaceRequest;
|
||||
import com.etl.cleaning.domian.request.MysqlRequest;
|
||||
import com.etl.cleaning.domian.request.PlaceRequest;
|
||||
import com.etl.cleaning.domian.response.PlaceResponse;
|
||||
import com.etl.cleaning.enums.EnumMsg;
|
||||
import com.etl.cleaning.mapper.PlaceMapper;
|
||||
import com.etl.cleaning.server.ServerTest;
|
||||
import com.etl.cleaning.service.PlaceService;
|
||||
import com.etl.cleaning.service.TypeService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -41,7 +46,9 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
|
|||
lambdaQueryWrapper.eq(DataPlace::getTypeId,placeRequest.getTypeId());
|
||||
}
|
||||
Page<DataPlace> page = new Page<>(placeRequest.getPageNum(), placeRequest.getPageSize());
|
||||
|
||||
Page<DataPlace> dataPlacePage = placeMapper.selectPage(page, lambdaQueryWrapper);
|
||||
|
||||
List<DataPlace> records = dataPlacePage.getRecords();
|
||||
if(CollectionUtils.isEmpty(records)){
|
||||
return Collections.emptyMap();
|
||||
|
@ -49,15 +56,15 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
|
|||
List<Long> typeIds = records.stream().map(DataPlace::getTypeId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
List<DateType> dateTypes = typeService.listByIds(typeIds);
|
||||
Map<Long, DateType> typeMap = dateTypes.stream().collect(Collectors.toMap(DateType::getId, Function.identity()));
|
||||
List<DataPlace> dataPlaceList = records.stream().map(item -> {
|
||||
List<PlaceResponse> dataPlaceList = records.stream().map(item -> {
|
||||
Long typeId = item.getTypeId();
|
||||
DateType dateType = typeMap.get(typeId);
|
||||
if (dateType == null) {
|
||||
item.setTypeName(EnumMsg.NO_TYPE.getMessage());
|
||||
PlaceResponse.builder().typeName(EnumMsg.NO_TYPE.getMessage());
|
||||
}else{
|
||||
item.setTypeName(dateType.getName());
|
||||
PlaceResponse.builder().typeName(dateType.getName());
|
||||
}
|
||||
return item;
|
||||
return PlaceResponse.builder().name(item.getName()).bank(item.getBank()).statue(item.getStatue()).updateTime(item.getUpdateTime()).build();
|
||||
}).collect(Collectors.toList());
|
||||
//查询总条数
|
||||
long total = dataPlacePage.getTotal();
|
||||
|
@ -76,4 +83,51 @@ public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, DataPlace> implem
|
|||
map.put("data", dataPlaceList);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dataTest(Long id) {
|
||||
DataPlace dataPlace = this.getOne(new LambdaQueryWrapper<DataPlace>().eq(DataPlace::getId, id));
|
||||
if(dataPlace.getTypeId() == 1){
|
||||
MysqlRequest mysqlRequest = MysqlRequest.builder()
|
||||
.place(dataPlace.getDataUrl())
|
||||
.itemPass(dataPlace.getPassword())
|
||||
.itemUsername(dataPlace.getUsername())
|
||||
.itemPort(dataPlace.getPort())
|
||||
.itemName(dataPlace.getDataName())
|
||||
.build();
|
||||
return this.insertItem(mysqlRequest);
|
||||
}
|
||||
return "redis连接数据源失败";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertDataPlace(InsertPlaceRequest insertItemRequest) {
|
||||
DataPlace dataPlace = DataPlace.builder()
|
||||
.dataName(insertItemRequest.getDataName())
|
||||
.password(insertItemRequest.getPassword())
|
||||
.bank(insertItemRequest.getBank())
|
||||
.dataUrl(insertItemRequest.getDataUrl())
|
||||
.port(insertItemRequest.getPort())
|
||||
.username(insertItemRequest.getUsername())
|
||||
.yaml(insertItemRequest.getYaml())
|
||||
.typeId(insertItemRequest.getTypeId())
|
||||
.name(insertItemRequest.getName())
|
||||
.statue(insertItemRequest.getStatue())
|
||||
.updateTime(new Date())
|
||||
.build();
|
||||
return this.save(dataPlace);
|
||||
}
|
||||
|
||||
|
||||
private String insertItem(MysqlRequest mysqlRequest) {
|
||||
//拼接路径 测试mysql数据库连接
|
||||
String url =EnumMsg.URL_PRE + "://" + mysqlRequest.getPlace() + "/" +mysqlRequest.getItemName();
|
||||
DatabaseConfig databaseConfig = DatabaseConfig.builder()
|
||||
.url(url)
|
||||
.port(mysqlRequest.getItemPort())
|
||||
.username(mysqlRequest.getItemUsername())
|
||||
.password(mysqlRequest.getItemPass())
|
||||
.build();
|
||||
return ServerTest.testDatabaseConnection(databaseConfig);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,5 @@ import org.springframework.stereotype.Service;
|
|||
*/
|
||||
@Service
|
||||
public class TypeServiceImpl extends ServiceImpl<TypeMapper, DateType> implements TypeService {
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue