@ -11,10 +11,7 @@ import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.DateUtils ;
import com.muyu.common.security.utils.SecurityUtils ;
import com.muyu.etl.domain.* ;
import com.muyu.etl.domain.custom.AssetsModule ;
import com.muyu.etl.domain.custom.TableAssets ;
import com.muyu.etl.domain.custom.TableDetail ;
import com.muyu.etl.domain.custom.VTClass ;
import com.muyu.etl.domain.custom.* ;
import com.muyu.etl.mapper.AssetModelMapper ;
import com.muyu.etl.mapper.DataAssetMapper ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -116,6 +113,11 @@ public class DataSourceServiceImpl implements IDataSourceService
{
dataSource . setCreateTime ( DateUtils . getNowDate ( ) ) ;
dataSource . setCreateBy ( SecurityUtils . getUsername ( ) ) ;
if ( "MySql" . equals ( dataSource . getType ( ) ) ) {
dataSource . setJdbcDriver ( "com.mysql.cj.jdbc.Driver" ) ;
} else {
dataSource . setJdbcDriver ( "org.postgresql.Driver" ) ;
}
return dataSourceMapper . insertDataSource ( dataSource ) ;
}
@ -130,6 +132,11 @@ public class DataSourceServiceImpl implements IDataSourceService
{
dataSource . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
dataSource . setUpdateBy ( SecurityUtils . getUsername ( ) ) ;
if ( "MySql" . equals ( dataSource . getType ( ) ) ) {
dataSource . setJdbcDriver ( "com.mysql.cj.jdbc.Driver" ) ;
} else {
dataSource . setJdbcDriver ( "org.postgresql.Driver" ) ;
}
return dataSourceMapper . updateDataSource ( dataSource ) ;
}
@ -159,62 +166,37 @@ public class DataSourceServiceImpl implements IDataSourceService
@Override
public Result testConnection ( DataSource dataSource ) {
if ( dataSource . getType ( ) . equals ( "MySql" ) ) {
String user = dataSource . getUsername ( ) ;
String password = dataSource . getPassword ( ) ;
String jdbcDriver = "com.mysql.cj.jdbc.Driver" ;
String jdbcUrl = "jdbc:mysql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
String jdbcUrl = "jdbc:" + dataSource . getType ( ) . toLowerCase ( ) + "://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
if ( dataSource . getConnectionParam ( ) ! = null & & dataSource . getConnectionParam ( ) ! = "" ) {
jdbcUrl = jdbcUrl + "?" + dataSource . getConnectionParam ( ) ;
}
Connection conn = null ;
try {
Class . forName ( jdbcDriver ) ;
Class . forName ( dataSource. getJdbcDriver ( ) ) ;
} catch ( ClassNotFoundException e ) {
return Result . error ( "连接失败" ) ;
}
try {
conn = DriverManager . getConnection ( jdbcUrl , user, password ) ;
conn = DriverManager . getConnection ( jdbcUrl , dataSource. getUsername ( ) , dataSource . getPassword ( ) ) ;
conn . close ( ) ;
} catch ( Exception e ) {
return Result . error ( "连接失败" ) ;
}
} else {
String user = dataSource . getUsername ( ) ;
String password = dataSource . getPassword ( ) ;
String jdbcDriver = "org.postgresql.Driver" ;
String jdbcUrl = "jdbc:postgresql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
if ( dataSource . getConnectionParam ( ) ! = null & & dataSource . getConnectionParam ( ) ! = "" ) {
jdbcUrl = jdbcUrl + "?" + dataSource . getConnectionParam ( ) ;
}
Connection conn = null ;
try {
Class . forName ( jdbcDriver ) ;
} catch ( ClassNotFoundException e ) {
return Result . error ( "连接失败" ) ;
}
try {
conn = DriverManager . getConnection ( jdbcUrl , user , password ) ;
conn . close ( ) ;
} catch ( Exception e ) {
return Result . error ( "连接失败" ) ;
}
}
return Result . success ( "连接成功" ) ;
}
public AssetsModule getStructure ( DataSource dataSource ) {
String user = dataSource . getUsern ame( ) ;
String password = dataSource . getPassword ( ) ;
String jdbcDriver = "com.mysql.cj.jdbc.Driver" ;
String jdbcUrl = "jdbc:mysql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
String jdbcUrl = "jdbc:" + dataSource . getType ( ) . toLowerCase ( ) + "://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
if ( dataSource . getConnectionParam ( ) ! = null & & dataSource . getConnectionParam ( ) ! = "" ) {
jdbcUrl = jdbcUrl + "?" + dataSource . getConnectionParam ( ) ;
}
Connection conn = null ;
List < Map < String , VTClass > > kvtList = new ArrayList < > ( ) ;
HashMap < String , String > map = new HashMap < > ( ) ;
try {
Class . forName ( jdbcDriver ) ;
conn = DriverManager . getConnection ( jdbcUrl , user, password ) ;
Class . forName ( dataSource . getJdbcDriver ( ) ) ;
conn = DriverManager . getConnection ( jdbcUrl , dataSource . getUsername ( ) , dataSource . getPassword ( ) ) ;
} catch ( SQLException | ClassNotFoundException e ) {
throw new RuntimeException ( e ) ;
}
@ -224,10 +206,6 @@ public class DataSourceServiceImpl implements IDataSourceService
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 ) ;
System . out . print ( "java类型: " + substring ) ;
System . out . print ( " 数据库类型:" + rsd . getColumnTypeName ( i ) ) ;
System . out . print ( " 字段名称:" + rsd . getColumnName ( i ) ) ;
System . out . println ( ) ;
map . put ( rsd . getColumnName ( i ) , substring ) ;
}
int columnCount = rsd . getColumnCount ( ) ;
@ -258,25 +236,19 @@ public class DataSourceServiceImpl implements IDataSourceService
}
public Map < String , String > getTypeMap ( DataSource dataSource , String tableName ) {
String user = dataSource . getUsername ( ) ;
String password = dataSource . getPassword ( ) ;
String jdbcDriver = "" ;
String jdbcUrl = "" ;
String sql = "" ;
jdbcUrl = "jdbc:" + dataSource . getType ( ) . toLowerCase ( ) + "://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
if ( dataSource . getType ( ) . equals ( "MySql" ) ) {
jdbcDriver = "com.mysql.cj.jdbc.Driver" ;
jdbcUrl = "jdbc:mysql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
sql = "select * from " + tableName ;
} else {
jdbcDriver = "org.postgresql.Driver" ;
jdbcUrl = "jdbc:postgresql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
sql = "select * from " + dataSource . getModeName ( ) + "." + tableName ;
}
Connection conn = null ;
Map < String , String > map = new HashMap < > ( ) ;
try {
Class . forName ( jdbcDriver ) ;
conn = DriverManager . getConnection ( jdbcUrl , user, password ) ;
Class . forName ( dataSource. getJdbcDriver ( ) ) ;
conn = DriverManager . getConnection ( jdbcUrl , dataSource. getUsername ( ) , dataSource . getPassword ( ) ) ;
} catch ( SQLException | ClassNotFoundException e ) {
throw new RuntimeException ( e ) ;
}
@ -294,7 +266,7 @@ public class DataSourceServiceImpl implements IDataSourceService
substring = rsd . getColumnClassName ( i ) ;
}
map . put ( rsd . getColumnName ( i ) .toUpperCase ( ) ,substring ) ;
map . put ( rsd . getColumnName ( i ) ,substring ) ;
}
pst . close ( ) ;
pst = null ;
@ -305,153 +277,64 @@ public class DataSourceServiceImpl implements IDataSourceService
}
public List < AssetModel > getTableAssets ( DataSource dataSource , String tableName ) {
String user = dataSource . getUsername ( ) ;
String password = dataSource . getPassword ( ) ;
String jdbcDriver = "" ;
String jdbcUrl = "" ;
String sql = "" ;
if ( dataSource . getType ( ) . equals ( "MySql" ) ) {
jdbcDriver = "com.mysql.cj.jdbc.Driver" ;
jdbcUrl = "jdbc:mysql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
sql = "SELECT COLUMN_NAME,DATA_TYPE,IS_NULLABLE,COLUMN_KEY,COLUMN_DEFAULT,COLUMN_COMMENT,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" + dataSource . getDatabaseName ( ) + "' AND TABLE_NAME = '" + tableName + "'" ;
} else {
jdbcDriver = "org.postgresql.Driver" ;
jdbcUrl = "jdbc:postgresql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
sql = "SELECT \n" +
" a.attname AS \"COLUMN_NAME\",\n" +
" coalesce(cc.description, '') AS \"COLUMN_COMMENT\",\n" +
" EXISTS (\n" +
" SELECT 1\n" +
" FROM pg_index i\n" +
" JOIN pg_attribute ia ON ia.attrelid = i.indrelid AND ia.attnum = ANY(i.indkey)\n" +
" WHERE i.indrelid = a.attrelid AND ia.attname = a.attname AND i.indisprimary\n" +
" ) AS \"COLUMN_KEY\",\n" +
" format_type(a.atttypid, a.atttypmod) AS \"DATA_TYPE\",\n" +
" CASE \n" +
" WHEN strpos(format_type(a.atttypid, a.atttypmod), '(') > 0 THEN \n" +
" split_part(substring(format_type(a.atttypid, a.atttypmod) FROM '\\((.*)\\)')::text, ',', 1)::int\n" +
" ELSE \n" +
" NULL\n" +
" END AS \"NUMERIC_PRECISION\",\n" +
" CASE \n" +
" WHEN strpos(format_type(a.atttypid, a.atttypmod), ',') > 0 THEN \n" +
" split_part(substring(format_type(a.atttypid, a.atttypmod) FROM '\\((.*)\\)')::text, ',', 2)::int\n" +
" ELSE \n" +
" NULL\n" +
" END AS \"NUMERIC_SCALE\",\n" +
" COALESCE(pg_get_expr(ad.adbin, ad.adrelid), '') AS \"COLUMN_DEFAULT\",\n" +
" NOT a.attnotnull AS \"IS_NULLABLE\"\n" +
"FROM \n" +
" pg_catalog.pg_attribute a\n" +
"JOIN \n" +
" pg_catalog.pg_class c ON a.attrelid = c.oid\n" +
"JOIN \n" +
" pg_catalog.pg_namespace n ON c.relnamespace = n.oid\n" +
"LEFT JOIN \n" +
" pg_catalog.pg_description cc ON cc.objoid = a.attrelid AND cc.objsubid = a.attnum\n" +
"LEFT JOIN \n" +
" pg_catalog.pg_attrdef ad ON ad.adrelid = a.attrelid AND ad.adnum = a.attnum\n" +
"WHERE \n" +
" n.nspname = '" + dataSource . getModeName ( ) + "' \n" +
" AND c.relname = '" + tableName + "' \n" +
" AND a.attnum > 0 \n" +
" AND NOT a.attisdropped \n" +
"ORDER BY \n" +
" a.attnum " ;
}
jdbcUrl = "jdbc:" + dataSource . getType ( ) . toLowerCase ( ) + "://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
Connection conn = null ;
List < AssetModel > assetModels = new ArrayList < > ( ) ;
Map < String , String > typeMap = getTypeMap ( dataSource , tableName ) ;
try {
Class . forName ( jdbcDriver ) ;
conn = DriverManager . getConnection ( jdbcUrl , user, password ) ;
Class . forName ( dataSource . getJdbcDriver ( ) ) ;
conn = DriverManager . getConnection ( jdbcUrl , dataSource . getUsername ( ) , dataSource . getPassword ( ) ) ;
} catch ( SQLException | ClassNotFoundException e ) {
throw new RuntimeException ( e ) ;
}
try {
Class . forName ( jdbcDriver ) ;
conn = DriverManager . getConnection ( jdbcUrl , user , password ) ;
} catch ( SQLException | ClassNotFoundException e ) {
throw new RuntimeException ( e ) ;
DatabaseMetaData metaData = conn . getMetaData ( ) ;
ResultSet columnsRS = metaData . getColumns ( dataSource . getDatabaseName ( ) , dataSource . getModeName ( ) , tableName , "%" ) ;
ResultSet primaryKeyRS = metaData . getPrimaryKeys ( dataSource . getDatabaseName ( ) , dataSource . getModeName ( ) , tableName ) ;
String primaryKeyColumnName = "" ;
while ( primaryKeyRS . next ( ) ) {
primaryKeyColumnName = primaryKeyRS . getString ( "COLUMN_NAME" ) ;
}
try {
PreparedStatement pst = conn . prepareStatement ( sql ) ;
ResultSet resultSet = pst . executeQuery ( ) ;
ResultSetMetaData rsd = resultSet . getMetaData ( ) ;
while ( resultSet . next ( ) ) {
while ( columnsRS . next ( ) ) {
AssetModel assetModel = new AssetModel ( ) ;
assetModel . setComment ( resultSet . getString ( "COLUMN_COMMENT" ) ) ;
assetModel . setName ( resultSet . getString ( "COLUMN_NAME" ) ) ;
assetModel . setType ( resultSet . getString ( "DATA_TYPE" ) ) ;
if ( dataSource . getType ( ) . equals ( "MySql" ) ) {
if ( resultSet . getString ( "CHARACTER_MAXIMUM_LENGTH" ) ! = null ) {
assetModel . setLength ( resultSet . getString ( "CHARACTER_MAXIMUM_LENGTH" ) ) ;
} else if ( resultSet . getString ( "NUMERIC_PRECISION" ) ! = null ) {
assetModel . setLength ( resultSet . getString ( "NUMERIC_PRECISION" ) ) ;
} else {
assetModel . setLength ( "-" ) ;
}
//是否主键
if ( "PRI" . equals ( resultSet . getString ( "COLUMN_KEY" ) ) ) {
assetModel . setIsPrimaryKey ( "Y" ) ;
} else {
assetModel . setIsPrimaryKey ( "N" ) ;
}
//是否不可为空
if ( resultSet . getString ( "IS_NULLABLE" ) . equals ( "NO" ) ) {
assetModel . setIsNull ( "N" ) ;
} else {
assetModel . setIsNull ( "Y" ) ;
}
} else {
if ( resultSet . getString ( "NUMERIC_PRECISION" ) ! = null ) {
assetModel . setLength ( resultSet . getString ( "NUMERIC_PRECISION" ) ) ;
} else {
if ( ! assetModel . getType ( ) . contains ( "time" ) & & ! assetModel . getType ( ) . contains ( "date" ) ) {
assetModel . setLength ( "10" ) ;
} else {
assetModel . setLength ( "-" ) ;
}
}
//是否主键
if ( "t" . equals ( resultSet . getString ( "COLUMN_KEY" ) ) ) {
assetModel . setIsPrimaryKey ( "Y" ) ;
} else {
assetModel . setIsPrimaryKey ( "N" ) ;
}
//是否不可为空
if ( resultSet . getString ( "IS_NULLABLE" ) . equals ( "t" ) ) {
assetModel . setIsNull ( "N" ) ;
} else {
assetModel . setIsNull ( "Y" ) ;
}
}
if ( resultSet . getString ( "NUMERIC_SCALE" ) ! = null ) {
assetModel . setDecimalPlaces ( resultSet . getString ( "NUMERIC_SCALE" ) ) ;
} else {
assetModel . setDecimalPlaces ( "-" ) ;
}
//是否有默认值
if ( resultSet . getString ( "COLUMN_DEFAULT" ) ! = null ) {
assetModel . setDefaultValue ( resultSet . getString ( "COLUMN_DEFAULT" ) ) ;
} else {
assetModel . setDefaultValue ( "-" ) ;
}
assetModel . setIsDict ( "" ) ;
assetModel . setDictKey ( "" ) ;
assetModel . setCreateBy ( SecurityUtils . getUsername ( ) ) ;
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 . setMappingType ( typeMap . get ( assetModel . getName ( ) . toUpperCase ( ) ) ) ;
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 ) ;
}
pst . close ( ) ;
columnsRS . close ( ) ;
primaryKeyRS . close ( ) ;
conn . close ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
@ -459,16 +342,13 @@ public class DataSourceServiceImpl implements IDataSourceService
}
public AssetsModule getAssets ( DataSource dataSource ) {
String user = dataSource . getUsername ( ) ;
String password = dataSource . getPassword ( ) ;
String jdbcDriver = "com.mysql.cj.jdbc.Driver" ;
String jdbcUrl = "jdbc:mysql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
String jdbcUrl = "jdbc:" + dataSource . getType ( ) . toLowerCase ( ) + "://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
Connection conn = null ;
HashMap < String , String > map = new HashMap < > ( ) ;
List < AssetModel > assetModels = getTableAssets ( dataSource , dataSource . getTableName ( ) ) ;
try {
Class . forName ( jdbcDriver ) ;
conn = DriverManager . getConnection ( jdbcUrl , user, password ) ;
Class . forName ( dataSource. getJdbcDriver ( ) ) ;
conn = DriverManager . getConnection ( jdbcUrl , dataSource. getUsername ( ) , dataSource . getPassword ( ) ) ;
} catch ( SQLException | ClassNotFoundException e ) {
throw new RuntimeException ( e ) ;
}
@ -507,18 +387,12 @@ public class DataSourceServiceImpl implements IDataSourceService
@Override
public Result synchronousData ( DataSource dataSource ) {
String user = dataSource . getUsername ( ) ;
String password = dataSource . getPassword ( ) ;
String jdbcDriver = "" ;
String jdbcUrl = "" ;
String sql = "" ;
jdbcUrl = "jdbc:" + dataSource . getType ( ) . toLowerCase ( ) + "://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
if ( dataSource . getType ( ) . equals ( "MySql" ) ) {
jdbcDriver = "com.mysql.cj.jdbc.Driver" ;
jdbcUrl = "jdbc:mysql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
sql = "SELECT TABLE_NAME t_name,TABLE_COMMENT table_comment,TABLE_ROWS table_rows,(SELECT count(*) FROM INFORMATION_SCHEMA.columns WHERE TABLE_SCHEMA = '" + dataSource . getDatabaseName ( ) + "' and TABLE_NAME=t_name) fields FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='" + dataSource . getDatabaseName ( ) + "'" ;
} else {
jdbcDriver = "org.postgresql.Driver" ;
jdbcUrl = "jdbc:postgresql://" + dataSource . getLinkAddress ( ) + ":" + dataSource . getPort ( ) + "/" + dataSource . getDatabaseName ( ) ;
sql = "SELECT \n" +
" c.relname AS t_name,\n" +
" pgd.description AS table_comment,\n" +
@ -543,14 +417,18 @@ public class DataSourceServiceImpl implements IDataSourceService
HashMap < String , String > map = new HashMap < > ( ) ;
ArrayList < DataAsset > dataAssets = new ArrayList < > ( ) ;
try {
Class . forName ( jdbcDriver ) ;
conn = DriverManager . getConnection ( jdbcUrl , user, password ) ;
Class . forName ( dataSource. getJdbcDriver ( ) ) ;
conn = DriverManager . getConnection ( jdbcUrl , dataSource. getUsername ( ) , dataSource . getPassword ( ) ) ;
PreparedStatement ps = conn . prepareStatement ( sql ) ;
ResultSet resultSet = ps . executeQuery ( ) ;
while ( resultSet . next ( ) ) {
DataAsset dataAsset = new 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 ( ) ) ;
@ -585,4 +463,22 @@ public class DataSourceServiceImpl implements IDataSourceService
List < AssetModel > assetModels = assetModelMapper . selectAssetModelList ( assetModel ) ;
return Result . success ( assetModels ) ;
}
@Override
public Result statistics ( ) {
//查询所有数据源
List < DataSource > dataSources = dataSourceMapper . selectDataSourceList ( new DataSource ( ) ) ;
//获取所有数据源的主键
List < Long > longs = dataSources . stream ( ) . map ( dataSource - > dataSource . getId ( ) ) . toList ( ) ;
List < DataAsset > dataAssetList = dataAssetMapper . selectDataAssetBatchId ( longs ) ;
Statistics statistics = new Statistics ( ) ;
statistics . setDataAsset ( Long . valueOf ( dataSources . size ( ) ) ) ;
long sum1 ;
long sum2 = 0 ;
sum1 = dataAssetList . stream ( ) . mapToLong ( dataAsset - > Long . valueOf ( dataAsset . getFields ( ) ) ) . sum ( ) ;
sum2 = dataAssetList . stream ( ) . mapToLong ( dataAsset - > Long . valueOf ( dataAsset . getTableCount ( ) ) ) . sum ( ) ;
statistics . setAssetModel ( sum1 ) ;
statistics . setDataModel ( sum2 ) ;
return Result . success ( statistics ) ;
}
}