diff --git a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/controller/DataSourceController.java b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/controller/DataSourceController.java index 9c9d492..f83f0e5 100644 --- a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/controller/DataSourceController.java +++ b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/controller/DataSourceController.java @@ -66,6 +66,11 @@ public class DataSourceController extends BaseController return dataSourceService.dataAssetList(dataSource); } + @GetMapping("/Statistics") + public Result statistics(){ + return dataSourceService.statistics(); + } + @PostMapping("/AssetModelList") public Result assetModelList(@RequestBody DataAsset dataAsset) { diff --git a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/domain/DataSource.java b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/domain/DataSource.java index cb92b97..4dd57b2 100644 --- a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/domain/DataSource.java +++ b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/domain/DataSource.java @@ -93,11 +93,22 @@ public class DataSource extends BaseEntity /** 数据来源名称 */ @Excel(name = "数据来源名称") private String systemName; + /** 连接驱动名称 */ + @Excel(name = "连接驱动名称") + private String jdbcDriver; /** 模式名称 */ @Excel(name = "数据来源名称") private String modeName; + public String getJdbcDriver() { + return jdbcDriver; + } + + public void setJdbcDriver(String jdbcDriver) { + this.jdbcDriver = jdbcDriver; + } + public String getModeName() { return modeName; } diff --git a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/domain/custom/Statistics.java b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/domain/custom/Statistics.java new file mode 100644 index 0000000..4357a08 --- /dev/null +++ b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/domain/custom/Statistics.java @@ -0,0 +1,20 @@ +package com.muyu.etl.domain.custom; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @ClassName Statistics + * @Description 描述 + * @Author Xin.Yao + * @Date 2024/4/23 20:43 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Statistics { + private Long dataAsset; + private Long assetModel; + private Long dataModel; +} diff --git a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/mapper/DataAssetMapper.java b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/mapper/DataAssetMapper.java index 7db7261..25e626c 100644 --- a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/mapper/DataAssetMapper.java +++ b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/mapper/DataAssetMapper.java @@ -62,4 +62,6 @@ public interface DataAssetMapper public int deleteDataAssetByIds(Long[] ids); void batchInsert(@Param("dataAssets") ArrayList dataAssets); + + List selectDataAssetBatchId(@Param("longs") List longs); } diff --git a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/service/IDataSourceService.java b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/service/IDataSourceService.java index 90ad081..f44b5e5 100644 --- a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/service/IDataSourceService.java +++ b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/service/IDataSourceService.java @@ -73,4 +73,6 @@ public interface IDataSourceService Result dataAssetList(DataSource dataSource); Result assetModelList(DataAsset dataAsset); + + Result statistics(); } diff --git a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/service/impl/DataSourceServiceImpl.java b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/service/impl/DataSourceServiceImpl.java index 631c41b..9cce0f9 100644 --- a/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/service/impl/DataSourceServiceImpl.java +++ b/muyu-modules/muyu-etl/src/main/java/com/muyu/etl/service/impl/DataSourceServiceImpl.java @@ -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(); - 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("连接失败"); - } - }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("连接失败"); - } + 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(dataSource.getJdbcDriver()); + } catch (ClassNotFoundException e) { + return Result.error("连接失败"); + } + try { + conn = DriverManager.getConnection(jdbcUrl, dataSource.getUsername(), dataSource.getPassword()); + conn.close(); + }catch (Exception e){ + return Result.error("连接失败"); } return Result.success("连接成功"); } public AssetsModule getStructure(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(); + if (dataSource.getConnectionParam()!=null && dataSource.getConnectionParam()!=""){ + jdbcUrl = jdbcUrl+"?"+dataSource.getConnectionParam(); + } Connection conn = null; List> kvtList = new ArrayList<>(); HashMap 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 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 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 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 assetModels = new ArrayList<>(); Map 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); - } - try { - PreparedStatement pst = conn.prepareStatement(sql); - ResultSet resultSet = pst.executeQuery(); - ResultSetMetaData rsd = resultSet.getMetaData(); - while (resultSet.next()) { + 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"); + } + 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 map = new HashMap<>(); List 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 map = new HashMap<>(); ArrayList 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")); - dataAsset.setTableComment(resultSet.getString("table_comment")); + 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 assetModels = assetModelMapper.selectAssetModelList(assetModel); return Result.success(assetModels); } + + @Override + public Result statistics() { + //查询所有数据源 + List dataSources = dataSourceMapper.selectDataSourceList(new DataSource()); + //获取所有数据源的主键 + List longs = dataSources.stream().map(dataSource -> dataSource.getId()).toList(); + List 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); + } } diff --git a/muyu-modules/muyu-etl/src/main/resources/mapper/system/DataAssetMapper.xml b/muyu-modules/muyu-etl/src/main/resources/mapper/system/DataAssetMapper.xml index 203ec50..d6dc5b5 100644 --- a/muyu-modules/muyu-etl/src/main/resources/mapper/system/DataAssetMapper.xml +++ b/muyu-modules/muyu-etl/src/main/resources/mapper/system/DataAssetMapper.xml @@ -37,7 +37,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} - + + insert into data_asset diff --git a/muyu-modules/muyu-etl/src/main/resources/mapper/system/DataSourceMapper.xml b/muyu-modules/muyu-etl/src/main/resources/mapper/system/DataSourceMapper.xml index e336703..ace093e 100644 --- a/muyu-modules/muyu-etl/src/main/resources/mapper/system/DataSourceMapper.xml +++ b/muyu-modules/muyu-etl/src/main/resources/mapper/system/DataSourceMapper.xml @@ -25,10 +25,11 @@ + - select id, data_source_name, link_address, port, database_name, username, password, connection_param, init_num, max_num, max_wait_time, max_wait_size, create_by, create_time, update_by, update_time, remark, type, system_name,mode_name from data_source + select id, data_source_name, link_address, port, database_name, username, password, connection_param, init_num, max_num, max_wait_time, max_wait_size, create_by, create_time, update_by, update_time, remark, type, system_name,mode_name,jdbc_driver from data_source @@ -78,6 +80,7 @@ type, system_name, mode_name, + jdbc_driver, #{dataSourceName}, @@ -99,6 +102,7 @@ #{type}, #{systemName}, #{modeName}, + #{jdbcDriver}, @@ -124,6 +128,7 @@ type = #{type}, system_name = #{systemName}, mode_name = #{modeName}, + jdbc_driver = #{jdbcDriver}, where id = #{id}