feat: 新增资产展示功能
资产展示功能,会展示选中数据资产表的表信息,以及表资产信息(数据默认只展示表中第一条数据),表中没有数据,则展示的数据值为nullmaster
parent
cf644531f8
commit
a098a62a6b
|
@ -1,11 +1,21 @@
|
|||
package com.muyu.etl.domain;
|
||||
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】对象 asset_model
|
||||
|
@ -13,6 +23,11 @@ import java.util.List;
|
|||
* @author ruoyi
|
||||
* @date 2024-04-22
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AssetModel extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -86,149 +101,4 @@ public class AssetModel extends BaseEntity
|
|||
public List<DictionaryData> getDictionaryDatas() {
|
||||
return dictionaryDatas;
|
||||
}
|
||||
|
||||
public void setDictionaryDatas(List<DictionaryData> dictionaryDatas) {
|
||||
this.dictionaryDatas = dictionaryDatas;
|
||||
}
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public void setDataAssetId(Long dataAssetId)
|
||||
{
|
||||
this.dataAssetId = dataAssetId;
|
||||
}
|
||||
|
||||
public Long getDataAssetId()
|
||||
{
|
||||
return dataAssetId;
|
||||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
public void setComment(String comment)
|
||||
{
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getComment()
|
||||
{
|
||||
return comment;
|
||||
}
|
||||
public void setIsPrimaryKey(String isPrimaryKey)
|
||||
{
|
||||
this.isPrimaryKey = isPrimaryKey;
|
||||
}
|
||||
|
||||
public String getIsPrimaryKey()
|
||||
{
|
||||
return isPrimaryKey;
|
||||
}
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
public void setMappingType(String mappingType)
|
||||
{
|
||||
this.mappingType = mappingType;
|
||||
}
|
||||
|
||||
public String getMappingType()
|
||||
{
|
||||
return mappingType;
|
||||
}
|
||||
public void setLength(String length)
|
||||
{
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public String getLength()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
public void setDecimalPlaces(String decimalPlaces)
|
||||
{
|
||||
this.decimalPlaces = decimalPlaces;
|
||||
}
|
||||
|
||||
public String getDecimalPlaces()
|
||||
{
|
||||
return decimalPlaces;
|
||||
}
|
||||
public void setIsNull(String isNull)
|
||||
{
|
||||
this.isNull = isNull;
|
||||
}
|
||||
|
||||
public String getIsNull()
|
||||
{
|
||||
return isNull;
|
||||
}
|
||||
public void setIsDict(String isDict)
|
||||
{
|
||||
this.isDict = isDict;
|
||||
}
|
||||
|
||||
public String getIsDict()
|
||||
{
|
||||
return isDict;
|
||||
}
|
||||
public void setDictKey(String dictKey)
|
||||
{
|
||||
this.dictKey = dictKey;
|
||||
}
|
||||
|
||||
public String getDictKey()
|
||||
{
|
||||
return dictKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("dataAssetId", getDataAssetId())
|
||||
.append("name", getName())
|
||||
.append("comment", getComment())
|
||||
.append("isPrimaryKey", getIsPrimaryKey())
|
||||
.append("type", getType())
|
||||
.append("mappingType", getMappingType())
|
||||
.append("length", getLength())
|
||||
.append("decimalPlaces", getDecimalPlaces())
|
||||
.append("isNull", getIsNull())
|
||||
.append("isDict", getIsDict())
|
||||
.append("defaultValue", getDefaultValue())
|
||||
.append("dictKey", getDictKey())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,29 @@
|
|||
package com.muyu.etl.domain;
|
||||
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】对象 data_asset
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-04-22
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DataAsset extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -109,4 +122,21 @@ public class DataAsset extends BaseEntity
|
|||
.append("remark", getRemark())
|
||||
.toString();
|
||||
}
|
||||
|
||||
public DataAsset dataAssetBuilder(DataSource dataSource, ResultSet resultSet) {
|
||||
try {
|
||||
return DataAsset.builder()
|
||||
.tableName(resultSet.getString("t_name"))
|
||||
.tableComment(resultSet.getString("table_comment") == null ? "-":resultSet.getString("table_comment"))
|
||||
.tableCount(Long.valueOf(resultSet.getString("table_rows")))
|
||||
.fields(Long.valueOf(resultSet.getString("fields")))
|
||||
.dataSourceId(dataSource.getId())
|
||||
.createBy(SecurityUtils.getUsername())
|
||||
.createTime(new Date())
|
||||
.build();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.etl.domain.custom;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -15,6 +16,7 @@ import java.util.Map;
|
|||
* @Date 2024/4/21 9:54
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AssetsModule {
|
||||
|
@ -23,4 +25,11 @@ public class AssetsModule {
|
|||
|
||||
private List<TableAssets> tableAssets;
|
||||
private TableDetail tableDetail;
|
||||
|
||||
public AssetsModule assetsModuleBuilder(List<Map<String, VTClass>> kvtList, HashMap<String, String> map) {
|
||||
return AssetsModule.builder()
|
||||
.kvtList(kvtList)
|
||||
.structure(map)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -224,6 +224,7 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
List<Map<String, VTClass>> kvtList = new ArrayList<>();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
try {
|
||||
//进行jdbc驱动
|
||||
Class.forName(dataSource.getJdbcDriver());
|
||||
conn = DriverManager.getConnection(jdbcUrl, dataSource.getUsername(), dataSource.getPassword());
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
|
@ -233,9 +234,10 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
PreparedStatement pst = conn.prepareStatement(dataSource.getSql());
|
||||
ResultSet resultSet = pst.executeQuery();
|
||||
ResultSetMetaData rsd = resultSet.getMetaData();
|
||||
//循环查询到的每一列信息
|
||||
for(int i = 1; i <= rsd.getColumnCount(); i++) {
|
||||
String substring = rsd.getColumnClassName(i).substring(rsd.getColumnClassName(i).indexOf("java.lang.") + 10);
|
||||
map.put(rsd.getColumnName(i),substring);
|
||||
String[] split = rsd.getColumnClassName(i).split("\\.");
|
||||
map.put(rsd.getColumnName(i),split[split.length-1]);
|
||||
}
|
||||
int columnCount = rsd.getColumnCount();
|
||||
// 遍历每一行的数据
|
||||
|
@ -255,13 +257,13 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
kvtList.add(stringVTClassHashMap);
|
||||
}
|
||||
pst.close();
|
||||
conn.close();
|
||||
pst = null;
|
||||
conn = null;
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
AssetsModule assetsModule = new AssetsModule();
|
||||
assetsModule.setKvtList(kvtList);
|
||||
assetsModule.setStructure(map);
|
||||
return assetsModule;
|
||||
return new AssetsModule().assetsModuleBuilder(kvtList,map);
|
||||
}
|
||||
|
||||
public Map<String,String> getTypeMap(DataSource dataSource, String tableName){
|
||||
|
@ -276,9 +278,8 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
Connection conn = null;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
try {
|
||||
Class.forName(dataSource.getJdbcDriver());
|
||||
conn = DriverManager.getConnection(jdbcUrl, dataSource.getUsername(), dataSource.getPassword());
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
|
@ -294,7 +295,6 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
}else{
|
||||
substring = rsd.getColumnClassName(i);
|
||||
}
|
||||
|
||||
map.put(rsd.getColumnName(i),substring);
|
||||
}
|
||||
pst.close();
|
||||
|
@ -315,9 +315,8 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
long endTime = new Date().getTime();
|
||||
log.info("查询表字段类型信息耗时:"+(endTime-staTime)+"ms");
|
||||
try {
|
||||
Class.forName(dataSource.getJdbcDriver());
|
||||
conn = DriverManager.getConnection(jdbcUrl, dataSource.getUsername(), dataSource.getPassword());
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
|
@ -329,40 +328,22 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
primaryKeyColumnName = primaryKeyRS.getString("COLUMN_NAME");
|
||||
}
|
||||
while (columnsRS.next()) {
|
||||
AssetModel assetModel = new AssetModel();
|
||||
String columnName = columnsRS.getString("COLUMN_NAME");
|
||||
String typeName = columnsRS.getString("TYPE_NAME");
|
||||
int columnSize = columnsRS.getInt("COLUMN_SIZE");
|
||||
int decimalDigits = columnsRS.getInt("DECIMAL_DIGITS");
|
||||
String isNullable = columnsRS.getString("IS_NULLABLE");
|
||||
String columnDef = columnsRS.getString("COLUMN_DEF");
|
||||
String remarks = columnsRS.getString("REMARKS");
|
||||
assetModel.setCreateTime(new Date());
|
||||
assetModel.setCreateBy(SecurityUtils.getUsername());
|
||||
assetModel.setLength(String.valueOf(columnSize));
|
||||
assetModel.setDecimalPlaces(String.valueOf(decimalDigits));
|
||||
assetModel.setName(columnName);
|
||||
assetModel.setType(typeName);
|
||||
assetModel.setMappingType(typeMap.get(columnName));
|
||||
assetModel.setDictKey("");
|
||||
assetModel.setIsDict("");
|
||||
assetModel.setIsNull(isNullable.substring(0,1));
|
||||
if (columnName.equals(primaryKeyColumnName)){
|
||||
assetModel.setIsPrimaryKey("Y");
|
||||
}else{
|
||||
assetModel.setIsPrimaryKey("N");
|
||||
}
|
||||
if (remarks==null || remarks==""){
|
||||
assetModel.setComment("-");
|
||||
}else{
|
||||
assetModel.setComment(remarks);
|
||||
}
|
||||
if (columnDef==null || columnDef==""){
|
||||
assetModel.setDefaultValue("-");
|
||||
}else{
|
||||
assetModel.setDefaultValue(columnDef);
|
||||
}
|
||||
assetModels.add(assetModel);
|
||||
AssetModel build = AssetModel.builder()
|
||||
.createBy(SecurityUtils.getUsername())
|
||||
.createTime(new Date())
|
||||
.length(String.valueOf(columnsRS.getInt("COLUMN_SIZE")))
|
||||
.decimalPlaces(String.valueOf(columnsRS.getInt("DECIMAL_DIGITS")))
|
||||
.name(columnsRS.getString("COLUMN_NAME"))
|
||||
.type(columnsRS.getString("TYPE_NAME"))
|
||||
.mappingType(typeMap.get(columnsRS.getString("COLUMN_NAME")))
|
||||
.dictKey("")
|
||||
.isDict("")
|
||||
.isNull(columnsRS.getString("IS_NULLABLE").substring(0, 1))
|
||||
.isPrimaryKey(columnsRS.getString("COLUMN_NAME").equals(primaryKeyColumnName) ? "Y" : "N")
|
||||
.comment(columnsRS.getString("REMARKS")==null || columnsRS.getString("REMARKS")=="" ? "-" : columnsRS.getString("REMARKS"))
|
||||
.defaultValue(columnsRS.getString("COLUMN_DEF")==null || columnsRS.getString("COLUMN_DEF")=="" ? "-":columnsRS.getString("COLUMN_DEF"))
|
||||
.build();
|
||||
assetModels.add(build);
|
||||
}
|
||||
columnsRS.close();
|
||||
primaryKeyRS.close();
|
||||
|
@ -459,20 +440,7 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
ResultSet resultSet = ps.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
DataAsset dataAsset = new DataAsset();
|
||||
// ... (保留原方法中对dataAsset的设置逻辑)
|
||||
dataAsset.setTableName(resultSet.getString("t_name"));
|
||||
if (resultSet.getString("table_comment")==null || "".equals(resultSet.getString("table_comment"))){
|
||||
dataAsset.setTableComment("-");
|
||||
}else{
|
||||
dataAsset.setTableComment(resultSet.getString("table_comment"));
|
||||
}
|
||||
dataAsset.setTableCount(Long.valueOf(resultSet.getString("table_rows")));
|
||||
dataAsset.setFields(Long.valueOf(resultSet.getString("fields")));
|
||||
dataAsset.setDataSourceId(dataSource.getId());
|
||||
dataAsset.setCreateBy(SecurityUtils.getUsername());
|
||||
dataAsset.setCreateTime(new Date());
|
||||
dataAssets.add(dataAsset);
|
||||
dataAssets.add(new DataAsset().dataAssetBuilder(dataSource, resultSet));
|
||||
}
|
||||
return dataAssets;
|
||||
});
|
||||
|
@ -541,10 +509,10 @@ public class DataSourceServiceImpl implements IDataSourceService
|
|||
Result<List<Dictionary>> result = dictionaryService.getDictionaryDataList(strings);
|
||||
List<Dictionary> data = result.getData();
|
||||
assetModels.stream()
|
||||
.forEach(assetModel1 -> {
|
||||
.forEach(assetModelInfo -> {
|
||||
data.stream().forEach(dataInfo -> {
|
||||
if (assetModel1.getDictKey().equals(dataInfo.getDictionaryKey())){
|
||||
assetModel1.setDictionaryDatas(dataInfo.getDictionaryDataList());
|
||||
if (assetModelInfo.getDictKey().equals(dataInfo.getDictionaryKey())){
|
||||
assetModelInfo.setDictionaryDatas(dataInfo.getDictionaryDataList());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue