parent
b4b3a54805
commit
a64eb808d6
|
@ -1,6 +1,8 @@
|
|||
package com.etl.data.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -11,9 +13,10 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典表
|
||||
* @author YunFei.Du
|
||||
* @date 21:27 2024/4/25
|
||||
* 字典表
|
||||
*
|
||||
* @author YunFei.Du
|
||||
* @date 21:27 2024/4/25
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -25,6 +28,7 @@ public class Dictionary {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.INPUT)
|
||||
private Long id;
|
||||
/**
|
||||
* 数据源id
|
||||
|
@ -36,7 +40,10 @@ public class Dictionary {
|
|||
*/
|
||||
private String dictionaryName;
|
||||
|
||||
@TableField(select = false)
|
||||
private List< DictionaryInfo > dictionaryList;
|
||||
/**
|
||||
* 字典值
|
||||
*/
|
||||
private String dictionaryValue;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.etl.data.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -22,6 +24,7 @@ public class DictionaryInfo {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id",type = IdType.INPUT)
|
||||
private Long id;
|
||||
/**
|
||||
* 字典表id
|
||||
|
@ -39,6 +42,6 @@ public class DictionaryInfo {
|
|||
/**
|
||||
* 是否编辑 (默认 0 不编辑)
|
||||
*/
|
||||
private Integer isEdit;
|
||||
// private Integer isEdit;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.etl.data.domain.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.etl.data.domain.Dictionary;
|
||||
import com.etl.data.domain.DictionaryInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -35,7 +37,24 @@ public class DictionaryModel {
|
|||
*/
|
||||
private String dictionaryName;
|
||||
|
||||
private List< Dictionary > dictionaries;
|
||||
/**
|
||||
* 字典值
|
||||
*/
|
||||
private String dictionaryValue;
|
||||
|
||||
|
||||
private String dictionaryNameAndValue;
|
||||
private List< DictionaryInfo > dictionaryList;
|
||||
|
||||
|
||||
public static DictionaryModel dictionaryInfoBuild(Dictionary dictionary, List< DictionaryInfo > dictionaryInfos) {
|
||||
return DictionaryModel.builder ( )
|
||||
.id ( dictionary.getId ( ) )
|
||||
.dataSourceId ( dictionary.getDataSourceId ())
|
||||
.dictionaryName ( dictionary.getDictionaryName ())
|
||||
.dictionaryValue ( dictionary.getDictionaryValue ())
|
||||
.dictionaryNameAndValue (dictionary.getDictionaryName ()+'('+dictionary.getDictionaryValue ()+')')
|
||||
.dictionaryList (dictionaryInfos )
|
||||
.build ( );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,6 +92,13 @@
|
|||
<artifactId>etl-data-source-remote</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 添加 PostgreSQL JDBC 驱动 -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.5.0</version> <!-- 使用当前最新稳定版本 -->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -55,7 +55,7 @@ public class DataSourceController extends BaseController {
|
|||
return success();
|
||||
}
|
||||
@PostMapping("/testConnect")
|
||||
public Result testConnect(@RequestBody DataSourceResp dataSourceResp){
|
||||
public Boolean testConnect(@RequestBody DataSourceResp dataSourceResp){
|
||||
return dataSourceService.testConnect(dataSourceResp);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,11 @@ package com.etl.data.controller;
|
|||
|
||||
import com.etl.common.core.domain.Result;
|
||||
import com.etl.data.domain.Dictionary;
|
||||
import com.etl.data.domain.DictionaryInfo;
|
||||
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 org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -29,7 +27,28 @@ public class DictionaryController {
|
|||
* @return
|
||||
*/
|
||||
@GetMapping("/getDictionaryByDataSourceId")
|
||||
public Result< List< Dictionary > > getDictionaryByDataSourceId(@RequestParam Integer dataSourceId){
|
||||
public Result getDictionaryByDataSourceId(@RequestParam Integer dataSourceId){
|
||||
return dictionaryService.getDictionaryByDataSourceId(dataSourceId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增字典表
|
||||
*/
|
||||
@PostMapping("insertDictionary")
|
||||
public Result insertDictionary(@RequestBody Dictionary dictionary){
|
||||
return dictionaryService.insertDictionary(dictionary);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字典选项
|
||||
*/
|
||||
@PostMapping("insertDictionarySelect")
|
||||
public Result insertDictionarySelect(@RequestBody DictionaryInfo dictionaryInfo){
|
||||
return dictionaryService.insertDictionarySelect(dictionaryInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
public interface DataSourceService extends IService<DataSource> {
|
||||
List<DataSourceResp> list(DataSourceQueryReq dataSourceQueryReq);
|
||||
|
||||
Result testConnect(DataSourceResp dataSourceResp);
|
||||
Boolean testConnect(DataSourceResp dataSourceResp);
|
||||
|
||||
|
||||
Result queryTableStructure(TableStructureQueryReq tableStructureQueryReq);
|
||||
|
|
|
@ -4,6 +4,7 @@ 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 com.etl.data.domain.DictionaryInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -14,5 +15,14 @@ import java.util.List;
|
|||
* @Date 2024/4/20 11:48
|
||||
*/
|
||||
public interface DictionaryService extends IService< Dictionary > {
|
||||
Result< List< Dictionary > > getDictionaryByDataSourceId(Integer dataSourceId);
|
||||
Result getDictionaryByDataSourceId(Integer dataSourceId);
|
||||
/**
|
||||
* 新增字典表
|
||||
*/
|
||||
Result insertDictionary(Dictionary dictionary);
|
||||
|
||||
/**
|
||||
* 新增字典选项
|
||||
*/
|
||||
Result insertDictionarySelect(DictionaryInfo dictionaryInfo);
|
||||
}
|
||||
|
|
|
@ -84,10 +84,8 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result testConnect(DataSourceResp dataSourceResp) {
|
||||
public Boolean testConnect(DataSourceResp dataSourceResp) {
|
||||
|
||||
String username = dataSourceResp.getDataSourceUsername(); //用户名
|
||||
String password = dataSourceResp.getDataSourcePassword();//密码
|
||||
String dbName = dataSourceResp.getDataSourceDatabaseName(); //数据库名
|
||||
System.out.println("数据库名:" + dbName);
|
||||
|
||||
|
@ -118,15 +116,15 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
driveClass = "org.postgresql.Driver";
|
||||
jdbcUrl = "jdbc:postgresql://" + dbIpPort + "/" + dbName;
|
||||
}
|
||||
boolean b = testDatasource(driveClass, jdbcUrl, username, password);
|
||||
boolean b = testDatasource(driveClass, jdbcUrl, dataSourceResp.getDataSourceUsername (), dataSourceResp.getDataSourcePassword ());
|
||||
System.out.println(b);
|
||||
if (!b) {
|
||||
return Result.error();
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
return false;
|
||||
}
|
||||
return Result.success( );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -175,7 +173,6 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
System.out.print("类型:" + pkInfo.getString("PK_NAME") + " ");
|
||||
System.out.println("");
|
||||
}
|
||||
System.out.println("------------------------------分隔符--------------------------------------------");
|
||||
// 获取表的相对应的列的名字
|
||||
ResultSet tableInfo = metaData.getColumns(tableStructureQueryReq.getDataSourceDatabaseName(), "%", tableStructureQueryReq.getTableName(), "%");
|
||||
while (tableInfo.next()) {
|
||||
|
@ -235,6 +232,28 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
|
||||
@Override
|
||||
public Result dataSynchronization(DataSourceResp dataSourceResp) {
|
||||
|
||||
|
||||
|
||||
if (this.testConnect ( dataSourceResp)==!true){
|
||||
return Result.error ( "连接失败" );
|
||||
}
|
||||
|
||||
// deleteOldDate(dataSourceResp);
|
||||
|
||||
|
||||
|
||||
LambdaQueryWrapper< DataTable > dataTableLambdaQueryWrapper1 = new LambdaQueryWrapper<> ( );
|
||||
dataTableLambdaQueryWrapper1.eq ( DataTable::getDataSourceId,dataSourceResp.getId () );
|
||||
List< DataTable > list = dataTableService.list ( dataTableLambdaQueryWrapper1 );
|
||||
list.stream ().map ( DataTable::getId ).toList ();
|
||||
|
||||
if (list != null &&list.size ()!=0) {
|
||||
LambdaQueryWrapper< AssetsModel > assetsModelLambdaQueryWrapper = new LambdaQueryWrapper<> ( );
|
||||
assetsModelLambdaQueryWrapper.in ( AssetsModel::getDataTableId, list );
|
||||
|
||||
}
|
||||
|
||||
//获取所有表,根据数据源id'
|
||||
LambdaQueryWrapper<DataTable> dataTableLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
dataTableLambdaQueryWrapper.eq(DataTable::getDataSourceId,dataSourceResp.getId());
|
||||
|
@ -297,7 +316,6 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
while (pkInfo.next()) {
|
||||
primaryString = pkInfo.getString("COLUMN_NAME");
|
||||
}
|
||||
System.out.println("------------------------------分隔符--------------------------------------------");
|
||||
// 获取表的相对应的列的名字
|
||||
ResultSet assetsInfo = metaData.getColumns(dataSourceResp.getDataSourceDatabaseName(), "%", tableInfo.getTableName(), "%");
|
||||
|
||||
|
|
|
@ -6,12 +6,16 @@ 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.domain.model.DictionaryModel;
|
||||
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.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -29,19 +33,50 @@ public class DictionaryServiceImpl extends ServiceImpl< DictionaryMapper, Dictio
|
|||
@Autowired
|
||||
private DictionaryInfoMapper dictionaryInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private DictionaryInfoService dictionaryInfoService;
|
||||
|
||||
@Override
|
||||
public Result< List< Dictionary > > getDictionaryByDataSourceId(Integer dataSourceId) {
|
||||
public Result<List< DictionaryModel >> 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 );
|
||||
List< DictionaryModel > dictionaryModels = new ArrayList<> ( );
|
||||
|
||||
});
|
||||
List< Dictionary > dictionaryList = this.list ( new LambdaQueryWrapper< Dictionary > ( ).eq ( Dictionary::getDataSourceId, dataSourceId ) );
|
||||
|
||||
for (Dictionary dictionary : dictionaryList) {
|
||||
List< DictionaryInfo > dictionaryInfoList = dictionaryInfoService.list ( new LambdaQueryWrapper< DictionaryInfo > ( ).eq (
|
||||
DictionaryInfo::getDictionaryId, dictionary.getId ( ) ));
|
||||
|
||||
dictionaryModels.add ( DictionaryModel.dictionaryInfoBuild (dictionary, dictionaryInfoList ));
|
||||
}
|
||||
return Result.success (dictionaryList );
|
||||
|
||||
return Result.success (dictionaryModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result insertDictionary(Dictionary dictionary) {
|
||||
|
||||
boolean save = this.save ( dictionary );
|
||||
if (!save) {
|
||||
return Result.error ( "添加失败" );
|
||||
}
|
||||
return Result.success ( "添加成功" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result insertDictionarySelect(DictionaryInfo dictionaryInfo) {
|
||||
String returnString = "";
|
||||
boolean save;
|
||||
if (dictionaryInfo.getId ( ) == null) {
|
||||
save = dictionaryInfoService.save ( dictionaryInfo );
|
||||
returnString = save ? "添加字典标签成功" : "添加字典标签失败";
|
||||
} else {
|
||||
save = dictionaryInfoService.updateById ( dictionaryInfo );
|
||||
returnString = save ? "修改字典标签成功" : "修改字典标签失败";
|
||||
}
|
||||
if (save) {
|
||||
return Result.success ( null, returnString );
|
||||
}
|
||||
return Result.error ( returnString );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue