feat(): 数据资产展示

dev
chao 2024-05-01 11:25:32 +08:00
parent 4c6a93683d
commit 25da274496
3 changed files with 149 additions and 5 deletions

View File

@ -10,6 +10,8 @@ import com.etl.data.structure.service.IAssetTableDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static com.etl.common.core.domain.Result.success;
/**
@ -27,13 +29,12 @@ public class AssetTableDetailsController {
private IAssetTableDetailsService assetTableDetailsService;
/**
*
*/
@RequiresPermissions("data:details:query")
@GetMapping(value = "/{assetStructureTableId}")
public Result findByAssetStructureTableIdlist(@PathVariable("assetStructureTableId") Long assetStructureTableId) {
public Result findByAssetStructureTableIdList(@PathVariable("assetStructureTableId") Long assetStructureTableId) {
return success(assetTableDetailsService.list(
new LambdaQueryWrapper<AssetTableDetails>()
.eq(AssetTableDetails::getAssetStructureTableId, assetStructureTableId))
@ -44,7 +45,7 @@ public class AssetTableDetailsController {
*
*/
@RequiresPermissions("data:details:edit")
@Log(title = "数据详情", businessType = BusinessType.UPDATE)
@Log(title = "修改数据详情信息", businessType = BusinessType.UPDATE)
@PutMapping
public Result edit(@RequestBody AssetTableDetails assetTableDetails) {
return success(
@ -52,4 +53,15 @@ public class AssetTableDetailsController {
);
}
/**
* value
*/
@RequiresPermissions("data:details:tableDetailsValue")
@PostMapping(value = "tableDetailsValue/{tableId}")
public Result<Map<String, Object>> getTableDetailsValueList(@PathVariable("tableId") Long tableId) {
Map<String, Object> hashObjectMap = assetTableDetailsService.getTableDetailsValueList(tableId);
System.out.println(hashObjectMap);
return success(hashObjectMap);
}
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.etl.data.structure.domain.AssetTableDetails;
import java.util.List;
import java.util.Map;
/**
* Service
@ -28,4 +29,12 @@ public interface IAssetTableDetailsService extends IService<AssetTableDetails> {
* @return
*/
boolean updateAssetTableDetails(AssetTableDetails assetTableDetails);
/**
* value
*
* @param tableId
* @return
*/
Map<String, Object> getTableDetailsValueList(Long tableId);
}

View File

@ -1,14 +1,28 @@
package com.etl.data.structure.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.data.source.domain.DataSource;
import com.etl.data.source.service.IDataSourceService;
import com.etl.data.structure.domain.AssetStructure;
import com.etl.data.structure.domain.AssetStructureTable;
import com.etl.data.structure.domain.AssetTableDetails;
import com.etl.data.structure.mapper.AssetTableDetailsMapper;
import com.etl.data.structure.service.IAssetStructureService;
import com.etl.data.structure.service.IAssetStructureTableService;
import com.etl.data.structure.service.IAssetTableDetailsService;
import com.etl.data.type.domain.DataType;
import com.etl.data.type.service.IDataTypeService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.sql.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Service
@ -20,6 +34,20 @@ import java.util.List;
@Service
@Log4j2
public class AssetTableDetailsServiceImpl extends ServiceImpl<AssetTableDetailsMapper, AssetTableDetails> implements IAssetTableDetailsService {
@Autowired
private IAssetStructureTableService assetStructureTableService;
@Autowired
private IAssetStructureService assetStructureService;
@Lazy
@Autowired
private IDataSourceService dataSourceService;
@Autowired
private IDataTypeService dataTypeService;
/**
*
*
@ -33,14 +61,14 @@ public class AssetTableDetailsServiceImpl extends ServiceImpl<AssetTableDetailsM
@Override
public boolean updateAssetTableDetails(AssetTableDetails assetTableDetails) {
if ("Y".equals(assetTableDetails.getYesNoDictionary())){
if ("Y".equals(assetTableDetails.getYesNoDictionary())) {
return this.update(
new LambdaUpdateWrapper<AssetTableDetails>()
.eq(AssetTableDetails::getId, assetTableDetails.getId())
.set(AssetTableDetails::getYesNoDictionary, assetTableDetails.getYesNoDictionary())
.set(AssetTableDetails::getMappingDictionary, assetTableDetails.getMappingDictionary())
);
}else {
} else {
return this.update(
new LambdaUpdateWrapper<AssetTableDetails>()
.eq(AssetTableDetails::getId, assetTableDetails.getId())
@ -49,4 +77,99 @@ public class AssetTableDetailsServiceImpl extends ServiceImpl<AssetTableDetailsM
);
}
}
/**
* value
*
* @param tableId id
* @return value
*/
@Override
public Map<String, Object> getTableDetailsValueList(Long tableId) {
List<AssetTableDetails> assetTableDetailsList = this.list(
new LambdaQueryWrapper<AssetTableDetails>()
.eq(AssetTableDetails::getAssetStructureTableId, tableId)
);
Map<String, Object> stringObjectHashMap = new HashMap<>();
// 获取所有字段的名字
List<String> strings = assetTableDetailsList.stream().map(AssetTableDetails::getName).toList();
//获取表名
AssetStructureTable structureTable = assetStructureTableService.getOne(
new LambdaQueryWrapper<AssetStructureTable>()
.eq(AssetStructureTable::getId, tableId)
);
// 获取数据源
AssetStructure assetStructure = assetStructureService.getOne(
new LambdaQueryWrapper<AssetStructure>()
.eq(AssetStructure::getId, structureTable.getAssetStructureId())
);
// 获取数据信息
DataSource dataSource = dataSourceService.getOne(
new LambdaQueryWrapper<DataSource>()
.eq(DataSource::getId, assetStructure.getDataSourceSystemId())
);
DataType dataType = dataTypeService.getOne(
new LambdaQueryWrapper<DataType>()
.eq(DataType::getId, dataSource.getTypeId())
);
String driveClass = dataType.getDriverManager();
String jdbcUrl = dataType.getJdbcPre() + dataSource.getDataSourceIp() + ":" + dataSource.getDataSourcePort() + "/" + dataSource.getDataSourceDatabaseName() + "?" + dataSource.getAdditionalConfiguration();
if ("mysql".equals(dataType.getDataType())) {
log.info("MySQL");
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String tableDetails = "";
for (AssetTableDetails assetTableDetails : assetTableDetailsList) {
tableDetails += assetTableDetails.getName() + ",";
}
// 去掉最后一个逗号
tableDetails = tableDetails.substring(0, tableDetails.length() - 1);
String sql = "select " + tableDetails + " from " + structureTable.getTableName();
try {
Class.forName(driveClass);
conn = DriverManager.getConnection(jdbcUrl, dataSource.getDataSourceUsername(), dataSource.getDataSourcePassword());
st = conn.createStatement();
rs = st.executeQuery(sql);
while (rs.next()) {
for (String s : strings) {
String s1 = rs.getString(s);
stringObjectHashMap.put(s,s1);
}
}
System.out.println("----------------------------------分割线----------------------------------------");
} catch (Exception e) {
log.info("连接失败");
}finally {
try {
if (conn != null) {
conn.close();
}
if (st != null) {
st.close();
}
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
log.info("关闭资源失败");
throw new RuntimeException(e);
}
}
}
if ("oracle".equals(dataType.getDataType())) {
log.info("Oracle");
}
if ("sqlserver".equals(dataType.getDataType())) {
log.info("SQLServer");
}
return stringObjectHashMap;
}
}