feat:增加了字典功能

master_dyf
Yunfei Du 2024-04-26 17:23:55 +08:00
parent e689771020
commit b4b3a54805
24 changed files with 525 additions and 41 deletions

View File

@ -0,0 +1,42 @@
package com.etl.data.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
*
* @author YunFei.Du
* @date 21:27 2024/4/25
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
@TableName("dictionary")
public class Dictionary {
/**
*
*/
private Long id;
/**
* id
*/
private Long dataSourceId;
/**
*
*/
private String dictionaryName;
@TableField(select = false)
private List< DictionaryInfo > dictionaryList;
}

View File

@ -0,0 +1,44 @@
package com.etl.data.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
* @author YunFei.Du
* @date 21:27 2024/4/25
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
@TableName("dictionary_info")
public class DictionaryInfo {
/**
*
*/
private Long id;
/**
* id
*/
private Long dictionaryId;
/**
*
*/
private String label;
/**
*
*/
private Integer value;
/**
* ( 0 )
*/
private Integer isEdit;
}

View File

@ -9,18 +9,26 @@ import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* @ClassName DataSourceDecoration
* @Description
* @Author YunFei.Du
* @Date 2024/4/23 14:39
*
* @author YunFei.Du
* @date 17:09 2024/4/25
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class DataSourceDecoration {
/**
*
*/
private DataSource dataSource;
/**
*
*/
private List<DataTableDecoration> dataTableList;
/**
*
*/
private String type;
public static DataSourceDecoration dataSourceBuild(DataSource dataSource, List<DataTableDecoration> dataTables){
return DataSourceDecoration.builder()

View File

@ -7,17 +7,22 @@ import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @ClassName DataTypeDecoration
* @Description
* @Author YunFei.Du
* @Date 2024/4/23 14:40
*
* @author YunFei.Du
* @date 17:09 2024/4/25
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class DataTableDecoration {
/**
*
*/
private DataTable dataTable;
/**
*
*/
private String type;
public static DataTableDecoration dataSourceBuild(DataTable dataTable){
return DataTableDecoration.builder()

View File

@ -10,16 +10,22 @@ import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* @ClassName DataSourceInfo
* @Description
* @Author YunFei.Du
* @Date 2024/4/23 14:30
*
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class DataSourceInfo {
/**
*
*/
private DataSource dataSource;
/**
*
*/
private List<DataTable> dataTableList;
}

View File

@ -0,0 +1,41 @@
package com.etl.data.domain.model;
import com.baomidou.mybatisplus.annotation.TableName;
import com.etl.data.domain.Dictionary;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
*
* @author YunFei.Du
* @date 21:27 2024/4/25
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public class DictionaryModel {
/**
*
*/
private Long id;
/**
* id
*/
private Long dataSourceId;
/**
*
*/
private String dictionaryName;
private List< Dictionary > dictionaries;
}

View File

@ -16,6 +16,9 @@ import lombok.experimental.SuperBuilder;
@NoArgsConstructor
@AllArgsConstructor
public class DataSourceQueryReq {
/**
*
*/
private String fromSystem;
private String name;
private String dataSourceDatabaseName;

View File

@ -20,8 +20,19 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
public class AssetsModelResp {
/**
*
*/
private DataTable dataTable;
private List<AssetsModel> assetsModelList;
/**
*
*
* @param dTable
* @param assetsModels
* @return
*/
public static AssetsModelResp dataTableAndAssetsModelBuild(DataTable dTable,List<AssetsModel> assetsModels){
return AssetsModelResp.builder()
.dataTable(dTable)

View File

@ -21,25 +21,91 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
public class DataSourceResp {
/**
*
*/
private Long id;
private Long typeId;
private String dataType;
private String dataSourceIp;
private String dataSourcePort;
private String dataSourceDatabaseName;
private String dataSourceUsername;
private String dataSourcePassword;
private String additionalConfiguration;
private String status;
private Integer initialNumberOfConnections;
private Integer maximumNumberOfConnections;
private Integer maximumWaitingTime;
private Integer maximumWaitingTimes;
/**
*
*/
private String name;
/**
*
*/
private String fromSystem;
/**
* id
*/
private Long typeId;
/**
*
*/
private String dataType;
/**
*ip
*/
private String dataSourceIp;
/**
*
*/
private String dataSourcePort;
/**
*
*/
private String dataSourceDatabaseName;
/**
* ip
*/
private String dataSourceUsername;
/**
*
*/
private String dataSourcePassword;
/**
*
*/
private String additionalConfiguration;
/**
*
*/
private String status;
/**
*
*/
private Integer initialNumberOfConnections;
/**
*
*/
private Integer maximumNumberOfConnections;
/**
*
*/
private Integer maximumWaitingTime;
/**
*
*/
private Integer maximumWaitingTimes;
/**
*
*/
private String remark;
/**
*
*/
private Integer isSync;
/**
*
*/
private List<DataSpliceParam> dataSpliceParamList;
/**
*
* @param dataSpliceParams
* @param dataSource
* @param dataType
* @return
*/
public static DataSourceResp buildDataSourceResp(List<DataSpliceParam> dataSpliceParams, DataSource dataSource, DataType dataType){
return DataSourceResp.builder()
.id(dataSource.getId())
@ -63,6 +129,12 @@ public class DataSourceResp {
.isSync(dataSource.getIsSync())
.build();
}
/**
*
* @param dataSource
* @return
*/
public static DataSourceResp tableStructureQueryReqBuild(TableStructureQueryReq dataSource){
return DataSourceResp.builder()
.id(dataSource.getId())

View File

@ -0,0 +1,36 @@
package com.etl.data.domain.resp;
import com.etl.data.domain.AssetsModel;
import com.etl.data.domain.DataTable;
import com.etl.data.domain.Dictionary;
import com.etl.data.domain.DictionaryInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
*
* @author YunFei.Du
* @date 21:33 2024/4/25
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DictionaryModelResp {
private String dictionaryName;
private List< DictionaryInfo > dictionaryList;
// public static AssetsModelResp dataTableAndAssetsModelBuild(DataTable dTable, List< AssetsModel > assetsModels){
// return AssetsModelResp.builder()
// .dataTable(dTable)
// .assetsModelList(assetsModels)
// .build();
// }
}

View File

@ -3,6 +3,7 @@ package com.etl.data;
import com.etl.common.security.annotation.EnableCustomConfig;
import com.etl.common.security.annotation.EnableMyFeignClients;
import com.etl.common.swagger.annotation.EnableCustomSwagger2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableCustomSwagger2
@EnableMyFeignClients
@SpringBootApplication
@MapperScan("com.etl.data.mapper")
public class ETLDataSourceApplication {
public static void main (String[] args) {
SpringApplication.run(ETLDataSourceApplication.class, args);

View File

@ -2,7 +2,11 @@ package com.etl.data.controller;
import com.etl.common.core.domain.Result;
import com.etl.common.core.web.controller.BaseController;
import com.etl.data.domain.Dictionary;
import com.etl.data.domain.model.DictionaryModel;
import com.etl.data.domain.resp.AssetsModelResp;
import com.etl.data.domain.resp.DictionaryModelResp;
import com.etl.data.service.AssetsModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -10,10 +14,9 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @ClassName AssetsModelController
* @Description
* @Author YunFei.Du
* @Date 2024/4/23 20:08
*
* @author YunFei.Du
* @date 21:46 2024/4/25
*/
@RestController
@RequestMapping("/assets")
@ -26,8 +29,11 @@ public class AssetsModelController extends BaseController {
public Result<List<AssetsModelResp>> getAssetsModelListByTableIds(@RequestBody List<Integer> tableIds){
return assetsModelService.getAssetsModelListByTableIds(tableIds);
}
@GetMapping("/getAssetsModelByDataTableId")
public Result<AssetsModelResp> getAssetsModelByDataTableId(@RequestParam Integer id){
return assetsModelService.getAssetsModelByDataTableId(id);
}
}

View File

@ -19,10 +19,9 @@ import java.util.Date;
import java.util.List;
/**
* @ClassName DataSourceController
* @Description
* @Author YunFei.Du
* @Date 2024/4/20 11:06
*
* @author YunFei.Du
* @date 21:47 2024/4/25
*/
@RestController
@RequestMapping("/source")
@ -30,11 +29,18 @@ public class DataSourceController extends BaseController {
@Autowired
private DataSourceService dataSourceService;
/**
*
* @param dataSourceQueryReq
* @return
*/
@PostMapping("/list")
public Result getDataSourceList (@RequestBody DataSourceQueryReq dataSourceQueryReq) {
List<DataSourceResp> list = dataSourceService.list(dataSourceQueryReq);
return success(list);
}
@PostMapping("/insertDataSource")
public Result insertDataSource(@RequestBody DataSource dataSource){
if (dataSource.getId() != null){

View File

@ -12,10 +12,9 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @ClassName DataTypeController
* @Description
* @Author YunFei.Du
* @Date 2024/4/20 12:55
*
* @author YunFei.Du
* @date 21:47 2024/4/25
*/
@RestController
@RequestMapping("/dataType")

View File

@ -0,0 +1,35 @@
package com.etl.data.controller;
import com.etl.common.core.domain.Result;
import com.etl.data.domain.Dictionary;
import com.etl.data.mapper.DictionaryMapper;
import com.etl.data.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @ClassName Dictionary
* @Description
* @Author YunFei.Du
* @Date 2024/4/26 15:41
*/
@RestController
@RequestMapping("dict")
public class DictionaryController {
@Autowired
private DictionaryService dictionaryService;
/**
* id
* @param dataSourceId
* @return
*/
@GetMapping("/getDictionaryByDataSourceId")
public Result< List< Dictionary > > getDictionaryByDataSourceId(@RequestParam Integer dataSourceId){
return dictionaryService.getDictionaryByDataSourceId(dataSourceId);
}
}

View File

@ -0,0 +1,15 @@
package com.etl.data.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.etl.data.domain.Dictionary;
import com.etl.data.domain.DictionaryInfo;
/**
* @ClassName DataSourceMapper
* @Description
* @Author YunFei.Du
* @Date 2024/4/20 11:46
*/
public interface DictionaryInfoMapper extends BaseMapper< DictionaryInfo > {
}

View File

@ -0,0 +1,15 @@
package com.etl.data.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.etl.data.domain.Dictionary;
/**
* @ClassName DataSourceMapper
* @Description
* @Author YunFei.Du
* @Date 2024/4/20 11:46
*/
public interface DictionaryMapper extends BaseMapper< Dictionary > {
}

View File

@ -3,7 +3,10 @@ package com.etl.data.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.common.core.domain.Result;
import com.etl.data.domain.AssetsModel;
import com.etl.data.domain.Dictionary;
import com.etl.data.domain.model.DictionaryModel;
import com.etl.data.domain.resp.AssetsModelResp;
import com.etl.data.domain.resp.DictionaryModelResp;
import java.util.List;
@ -17,4 +20,6 @@ public interface AssetsModelService extends IService<AssetsModel> {
Result<List<AssetsModelResp>> getAssetsModelListByTableIds(List<Integer> tableIds);
Result<AssetsModelResp> getAssetsModelByDataTableId(Integer id);
}

View File

@ -0,0 +1,14 @@
package com.etl.data.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.data.domain.Dictionary;
import com.etl.data.domain.DictionaryInfo;
/**
* @ClassName DataMansgerService
* @Description
* @Author YunFei.Du
* @Date 2024/4/20 11:48
*/
public interface DictionaryInfoService extends IService< DictionaryInfo > {
}

View File

@ -0,0 +1,18 @@
package com.etl.data.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.common.core.domain.Result;
import com.etl.data.domain.DataType;
import com.etl.data.domain.Dictionary;
import java.util.List;
/**
* @ClassName DataMansgerService
* @Description
* @Author YunFei.Du
* @Date 2024/4/20 11:48
*/
public interface DictionaryService extends IService< Dictionary > {
Result< List< Dictionary > > getDictionaryByDataSourceId(Integer dataSourceId);
}

View File

@ -5,15 +5,26 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.common.core.domain.Result;
import com.etl.data.domain.AssetsModel;
import com.etl.data.domain.DataTable;
import com.etl.data.domain.Dictionary;
import com.etl.data.domain.DictionaryInfo;
import com.etl.data.domain.model.DictionaryModel;
import com.etl.data.domain.resp.AssetsModelResp;
import com.etl.data.domain.resp.DictionaryModelResp;
import com.etl.data.mapper.AssetsModelMapper;
import com.etl.data.mapper.DictionaryInfoMapper;
import com.etl.data.mapper.DictionaryMapper;
import com.etl.data.service.AssetsModelService;
import com.etl.data.service.DataTableService;
import com.etl.data.service.DictionaryInfoService;
import com.etl.data.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @ClassName AssetsModelServiceImpl
@ -25,6 +36,17 @@ import java.util.List;
public class AssetsModelServiceImpl extends ServiceImpl<AssetsModelMapper, AssetsModel> implements AssetsModelService {
@Autowired
private DataTableService dataTableService;
@Autowired
private DictionaryService dictionaryService;
@Autowired
private DictionaryMapper dictionaryMapper;
@Autowired
private DictionaryInfoMapper dictionaryInfoMapper;
@Autowired
private DictionaryInfoService dictionaryInfoService;
@Override
public Result<List<AssetsModelResp>> getAssetsModelListByTableIds(List<Integer> tableId) {
ArrayList<AssetsModelResp> assetsModelRespArrayList = new ArrayList<>();
@ -51,4 +73,6 @@ public class AssetsModelServiceImpl extends ServiceImpl<AssetsModelMapper, Asset
AssetsModelResp assetsModelResp = AssetsModelResp.dataTableAndAssetsModelBuild(dataTable, assetsModelList);
return Result.success(assetsModelResp);
}
}

View File

@ -60,7 +60,10 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
dataSourceLambdaQueryWrapper.eq(DataSource::getName, dataSourceQueryReq.getName());
}
List<DataSource> list = this.list(dataSourceLambdaQueryWrapper);
ArrayList<DataSourceResp> dataSourceRespList = new ArrayList<>();
//切割参数数据
for (DataSource dataSource : list) {
//查询数据源类型表
@ -76,15 +79,19 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
DataSourceResp dataSourceResp = DataSourceResp.buildDataSourceResp(dataSpliceParams, dataSource, byId);
dataSourceRespList.add(dataSourceResp);
}
return dataSourceRespList;
}
@Override
public Result testConnect(DataSourceResp dataSourceResp) {
String username = dataSourceResp.getDataSourceUsername(); //用户名
String password = dataSourceResp.getDataSourcePassword();//密码
String dbName = dataSourceResp.getDataSourceDatabaseName(); //数据库名
System.out.println("数据库名:" + dbName);
Integer dbType = Math.toIntExact(dataSourceResp.getTypeId()); //数据库类型 1-mysql,2-oracle,3-postgressql
String dbIp = dataSourceResp.getDataSourceIp(); //数据库地址
String dbPort = dataSourceResp.getDataSourcePort(); //端口
@ -114,14 +121,16 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
boolean b = testDatasource(driveClass, jdbcUrl, username, password);
System.out.println(b);
if (!b) {
return Result.error("连接失败");
return Result.error();
}
} catch (Exception e) {
return Result.error("连接失败");
return Result.error();
}
return Result.success("连接成功", "连接成功");
return Result.success( );
}
public Connection queryStructure(DataSourceResp dataSourceResp, String infoDataBaseName) {
try {
//
@ -305,7 +314,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
for (int i = 0; i < resultSetCount.getMetaData().getColumnCount(); i++) {
String columnName = resultSetCount.getMetaData().getColumnName(i + 1);
if (columnName.equals(fieldsName)){
javaType = resultSetCount.getMetaData().getColumnClassName(i+1);
javaType = resultSetCount.getMetaData().getColumnClassName(i+1).substring ( 10 );
}
}
// 默认值

View File

@ -0,0 +1,21 @@
package com.etl.data.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.data.domain.Dictionary;
import com.etl.data.domain.DictionaryInfo;
import com.etl.data.mapper.DictionaryInfoMapper;
import com.etl.data.mapper.DictionaryMapper;
import com.etl.data.service.DictionaryInfoService;
import com.etl.data.service.DictionaryService;
import org.springframework.stereotype.Service;
/**
* @ClassName DictionaryServiceImpl
* @Description
* @Author YunFei.Du
* @Date 2024/4/26 9:40
*/
@Service
public class DictionaryInfoServiceImpl extends ServiceImpl< DictionaryInfoMapper, DictionaryInfo > implements DictionaryInfoService {
}

View File

@ -0,0 +1,47 @@
package com.etl.data.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.common.core.domain.Result;
import com.etl.common.security.utils.DictUtils;
import com.etl.data.domain.Dictionary;
import com.etl.data.domain.DictionaryInfo;
import com.etl.data.mapper.DictionaryInfoMapper;
import com.etl.data.mapper.DictionaryMapper;
import com.etl.data.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* @ClassName DictionaryServiceImpl
* @Description
* @Author YunFei.Du
* @Date 2024/4/26 9:40
*/
@Service
public class DictionaryServiceImpl extends ServiceImpl< DictionaryMapper, Dictionary > implements DictionaryService {
@Autowired
private DictionaryMapper dictionaryMapper;
@Autowired
private DictionaryInfoMapper dictionaryInfoMapper;
@Override
public Result< List< Dictionary > > getDictionaryByDataSourceId(Integer dataSourceId) {
List< Dictionary > dictionaryList = dictionaryMapper.selectList ( new LambdaQueryWrapper< Dictionary > ( ).eq ( Dictionary::getDataSourceId, dataSourceId ) );
if (!dictionaryList.isEmpty ()){
List< DictionaryInfo > dictionaryInfos = dictionaryInfoMapper.selectList ( new LambdaQueryWrapper< DictionaryInfo > ( ).in ( DictionaryInfo::getDictionaryId, dictionaryList.stream ().map ( Dictionary::getId ).collect ( Collectors.toList () ) ) );
dictionaryList.stream ()
.forEach ( dictionary -> {
List< DictionaryInfo > list = dictionaryInfos.stream ( ).filter ( dictionaryInfo -> dictionaryInfo.getDictionaryId ( ) == dictionary.getId ( ) ).toList ( );
dictionary.setDictionaryList ( list );
});
}
return Result.success (dictionaryList );
}
}