find:()修改接口名称 优化方法
parent
0ef04a83a0
commit
c3c6606b02
|
@ -0,0 +1,12 @@
|
|||
package com.muyu;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu
|
||||
* @Project:cloud-property
|
||||
* @name:fusingRemote
|
||||
* @Date:2024/9/8 20:43
|
||||
*/
|
||||
|
||||
public interface fusingRemote extends Runnable{
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
</parent>
|
||||
|
||||
<artifactId>cloud-property-server</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
|
@ -97,15 +98,15 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- 加入maven deploy插件,当在deploy时,忽略些model-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <!– 加入maven deploy插件,当在deploy时,忽略些model–>-->
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-deploy-plugin</artifactId>-->
|
||||
<!-- <version>3.1.1</version>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <skip>true</skip>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.muyu.common.domain.DataName;
|
|||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.common.domain.TableFie;
|
||||
import com.muyu.common.domain.TableNames;
|
||||
import com.muyu.common.domain.enums.DataType;
|
||||
import com.muyu.server.mapper.DataRunNameMapper;
|
||||
import com.muyu.server.mysql.MySqlDataSource;
|
||||
import com.muyu.server.mysql.MySqlQuery;
|
||||
|
@ -14,15 +15,15 @@ import com.muyu.server.service.*;
|
|||
import com.muyu.server.util.JdbcHelper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.*;
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -41,6 +42,8 @@ public class DataLinkServiceImpl implements DataLinkService {
|
|||
private TableRunNameService tableRunNameService;
|
||||
@Autowired
|
||||
private DataRunNameService dataRunNameService;
|
||||
@Autowired
|
||||
private TableFieldService tableFieldService;
|
||||
/**
|
||||
* 查询表数据count
|
||||
* @param dataName 数据库名称
|
||||
|
@ -81,15 +84,15 @@ public class DataLinkServiceImpl implements DataLinkService {
|
|||
|
||||
@Override
|
||||
public List<DataName> findSelectDataShow(String dataName) {
|
||||
ArrayList<DataName> dataNames = new ArrayList<>();
|
||||
DataName dataName1 = new DataName();
|
||||
dataName1.setName(dataName);
|
||||
|
||||
List<DataName> dataNameList = dataNameService.list(new LambdaQueryWrapper<DataName>()
|
||||
.eq(DataName::getName, dataNames))
|
||||
.eq(DataName::getName, dataName))
|
||||
.stream()
|
||||
.map(DataName::dataNameBuild)
|
||||
.toList();
|
||||
if (CollectionUtils.isEmpty(dataNameList)){
|
||||
return null;
|
||||
}
|
||||
dataNameList.forEach(dataName2 -> {
|
||||
//在取数据数据遍历里获取表名称查询方法
|
||||
List<TableNames> tableNamesList = tableRunNameService.list(new LambdaQueryWrapper<TableNames>()
|
||||
|
@ -128,10 +131,164 @@ public class DataLinkServiceImpl implements DataLinkService {
|
|||
.stream()
|
||||
.map(TableNames::tableNamesBuild)
|
||||
.toList();
|
||||
if (CollectionUtils.isEmpty(tableNamesList)){
|
||||
return null;
|
||||
}
|
||||
tableNamesList.forEach(tableNames -> {
|
||||
List<TableFie> tableFies = dataRunNameService.tableStructureShow(tableNames);
|
||||
List<TableFie> tableFies = this.tableStructureShow(tableNames);
|
||||
tableNames.setTableFie(tableFies);
|
||||
});
|
||||
return tableNamesList;
|
||||
}
|
||||
|
||||
|
||||
public List<TableFie> tableStructureShow(TableNames tableNames) {
|
||||
|
||||
List<TableFie> tableFieList = null;
|
||||
if (StringUtils.isNotBlank(String.valueOf(tableNames.getId()))) {
|
||||
tableFieList = tableFieldService.list(new LambdaQueryWrapper<TableFie>()
|
||||
.eq(TableFie::getTableId, tableNames.getId()))
|
||||
.stream()
|
||||
.map(TableFie::tableFieBuild).toList();
|
||||
log.info("字段类型名称集合:{}", tableFieList);
|
||||
DataName dataName = dataNameService.getById(tableNames.getDataId());
|
||||
|
||||
List<DataValue> tableValue = this.findTableValue(String.valueOf(dataName.getId()), tableNames.getName());
|
||||
|
||||
tableFieList.forEach(tableFy -> {
|
||||
//查询字段映射信息
|
||||
String str = this.tableFySelect(dataName.getName(), tableNames.getName(), tableFy.getField());
|
||||
tableFy.setDataValue(str);
|
||||
|
||||
log.info("字段数据对象:{}", tableFy);
|
||||
|
||||
for (DataValue dataValue : tableValue) {
|
||||
if (tableFy.getField().equals(dataValue.getKey())) {
|
||||
tableFy.setDataMapping(dataValue.getType().getJavaType());
|
||||
}
|
||||
}
|
||||
});
|
||||
log.info("字段数据信息:{}", tableFieList);
|
||||
}
|
||||
return tableFieList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据类型转换
|
||||
* @para 数据类型转换ID
|
||||
* @return 返回结果
|
||||
*/
|
||||
public List<DataValue> findTableValue( String dataId,String tableName) {
|
||||
DataName byId = dataNameService.getById(dataId);
|
||||
MySqlQuery mySqlQuery = new MySqlQuery();
|
||||
// 设置数据源ID
|
||||
mySqlQuery.setDataSourceId(String.valueOf(dataId));
|
||||
|
||||
DruidDataSource connRs1 = JdbcHelper.getConnRs(byId.getName());
|
||||
DruidPooledConnection conn = null;
|
||||
try {
|
||||
conn = connRs1.getConnection();
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
List<DataValue> list = new ArrayList<>();
|
||||
|
||||
try {
|
||||
PreparedStatement preparedStatement = conn.prepareStatement("select * FROM " + tableName + " LIMIT 5");
|
||||
|
||||
this.getDataResult(conn, list, preparedStatement);
|
||||
JdbcHelper.close(conn,null,null);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询值
|
||||
*
|
||||
* @param dataDame
|
||||
* @param tableName
|
||||
* @param field
|
||||
* @return
|
||||
*/
|
||||
private String tableFySelect(String dataDame, String tableName, String field) {
|
||||
|
||||
// 从连接池获取数据库连接
|
||||
DruidDataSource conn = JdbcHelper.getConnRs(dataDame);
|
||||
// 初始化一个列表,用于存储数据值对象
|
||||
try {
|
||||
DruidPooledConnection connection = conn.getConnection();
|
||||
// 准备SQL查询语句
|
||||
|
||||
PreparedStatement ps = connection.prepareStatement("select " + field + " FROM " + tableName +" LIMIT 5");
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
String fields = resultSet.getString(field);
|
||||
// 返回包含数据值的列表
|
||||
return fields;
|
||||
}
|
||||
|
||||
// 释放数据库连接
|
||||
} catch (SQLException e) {
|
||||
// 如果发生SQL异常,抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权后资产展示
|
||||
* @param conn
|
||||
* @param list
|
||||
* @param preparedStatement
|
||||
* @throws SQLException
|
||||
*/
|
||||
private void getDataResult(DruidPooledConnection conn, List<DataValue> list, PreparedStatement preparedStatement) {
|
||||
try {
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
|
||||
HashMap<Integer, DataValue> map = new HashMap<>();
|
||||
while (resultSet.next()){
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
|
||||
if (resultSet.isFirst()){
|
||||
String columnTypeName = metaData.getColumnTypeName(i);
|
||||
|
||||
DatabaseMetaData metaData1 = conn.getMetaData();
|
||||
ResultSet columns = metaData1.getColumns(null, null, metaData.getTableName(i), metaData.getColumnName(i));
|
||||
String remarks =null;
|
||||
while (columns.next()){
|
||||
remarks = columns.getString("REMARKS");
|
||||
log.info("字段备注:{}", remarks);
|
||||
}
|
||||
DataValue build = DataValue.builder()
|
||||
.key(metaData.getColumnName(i))
|
||||
.label(remarks)
|
||||
.value(resultSet.getObject(i, DataType.convertType(columnTypeName)))
|
||||
.type(DataType.findBySqlType(columnTypeName))
|
||||
.build();
|
||||
list.add(build);
|
||||
map.put(i, build);
|
||||
}else {
|
||||
DataValue build = DataValue.builder()
|
||||
.key(metaData.getColumnName(i))
|
||||
.label(map.get(i).getLabel())
|
||||
.value(resultSet.getObject(i, map.get(i).getType().getTargetType()))
|
||||
.type(map.get(i).getType())
|
||||
.build();
|
||||
list.add(build);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
JdbcHelper.close(null,preparedStatement,null);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class DataNameServiceImpl
|
|||
String sql = null;
|
||||
String dataName= "core_data_warehouse";
|
||||
DruidDataSource druidDataSource = JdbcHelper.getConnRs(dataName);
|
||||
sql = "SHOW DATABASES;";
|
||||
sql = "SELECT * FROM data_name";
|
||||
try {
|
||||
assert druidDataSource != null;
|
||||
try (Connection conn = druidDataSource.getConnection()) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue