数据资产后台实现 试验1

etl-xin
xiaohuang 2024-04-23 08:42:29 +08:00
parent 70cb531906
commit d0e7ae8ba8
13 changed files with 338 additions and 4 deletions

View File

@ -0,0 +1,79 @@
package com.muyu.etl.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
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;
/**
* Structure
*
* @author xiaohuang
* on 2024/4/22
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class Structure extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 主键 */
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/** 表id */
@Excel(name = "表id")
private Long tableId;
/** 字段名称 */
@Excel(name = "字段名称")
private String columnName;
/** 字段注释 */
@Excel(name = "字段注释")
private String columnRemark;
/** 是否主键 'Y'是主键 'N'不是主键 */
@Excel(name = "是否主键 'Y'是主键 'N'不是主键")
private String isPrimary;
/** 数据类型 */
@Excel(name = "数据类型")
private String columnType;
/** 映射类型 */
@Excel(name = "映射类型")
private String javaType;
/** 字段长度 */
@Excel(name = "字段长度")
private String columnLength;
/** 小数位数 */
@Excel(name = "小数位数")
private String columnDecimals;
/** 是否为空 'Y'是 'N'不是 */
@Excel(name = "是否为空 'Y'是 'N'不是")
private String isNull;
/** 默认值 */
@Excel(name = "默认值")
private String defaultValue;
/** 是否字典 'Y'是 'N'不是 */
@Excel(name = "是否字典 'Y'是 'N'不是")
private String isDictionary;
/** 映射字典 */
@Excel(name = "映射字典")
private String dictionaryTable;
}

View File

@ -0,0 +1,61 @@
package com.muyu.etl.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.TreeEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* TableInfo
*
* @author xiaohuang
* on 2024/4/22
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class TableInfo extends TreeEntity {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId(value = "id",type = IdType.AUTO)
private Long id;
private Long basicId;
/**
* /
*/
@Excel(name = "表名称/数据库")
private String tableName;
/**
*
*/
@Excel(name = "表备注")
private String tableRemark;
/**
*
*/
@Excel(name = "数据量")
private Long dataNum;
/**
* 'Y' 'N'
*/
@Excel(name = "是否核心 ")
}

View File

@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.util.List;
/**
@ -41,6 +42,8 @@ public class BasicConfigInfoController extends BaseController
return getDataTable(list);
}
/**
*
*/
@ -106,4 +109,11 @@ public class BasicConfigInfoController extends BaseController
public Result connectionTest(@RequestBody BasicConfigInfo basicConfigInfo) throws ServletException {
return toAjax(basicConfigInfoService.connectionTest(basicConfigInfo));
}
@RequiresPermissions("etl:info:test")
@Log(title = "获取成功链接中的")
@GetMapping("/dataConstruct")
public Result<TableDataInfo<List>> getData(){
return getDataTable(basicConfigInfoService.getDataByEtl());
}
}

View File

@ -0,0 +1,44 @@
package com.muyu.etl.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.etl.domain.Structure;
/**
* StructureMapper
*
* @author xiaohuang
* on 2024/4/22
*/
public interface StructureMapper extends BaseMapper<Structure> {
/**
*
*/
public Structure selectStructureById(Long id);
/**
*
*/
public int insertStructure(Structure structure);
/**
*
* @param structure
* @return
*/
public int updateStructure(Structure structure);
/**
*
*/
public int deleteStructureById(Long id);
/**
*
*/
public int deleteStructureByIds(Long[] ids);
}

View File

@ -0,0 +1,36 @@
package com.muyu.etl.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import java.util.List;
/**
* TableInfoMapper
*
* @author xiaohuang
* on 2024/4/22
*/
public interface TableInfoMapper extends BaseMapper<TableInfo> {
/**
*
*/
public TableInfo selectTableInfoById(Long id);
public List<TableInfo> selectTableInfoList(TableInfo tableInfo);
public int insertTableInfo(TableInfo tableInfo);
public int updateTableInfo(TableInfo tableInfo);
public int deleteTableInfoById(Long id);
public int deleteTableInfoByIds(Long[] ids);
}

View File

@ -64,4 +64,8 @@ public interface BasicConfigInfoService extends IService<BasicConfigInfo> {
public int deleteBasicConfigInfoById(Long id);
boolean connectionTest(BasicConfigInfo basicConfigInfo) throws ServletException;
List<List> getDataByEtl();
}

View File

@ -0,0 +1,10 @@
package com.muyu.etl.service;
/**
* StructureService
*
* @author xiaohuang
* on 2024/4/22
*/
public interface StructureService {
}

View File

@ -0,0 +1,13 @@
package com.muyu.etl.service;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* TableInfoService
*
* @author xiaohuang
* on 2024/4/22
*/
public interface TableInfoService extends IService<TableInfo> {
}

View File

@ -1,18 +1,21 @@
package com.muyu.etl.service.impl;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.etl.domain.BasicConfigInfo;
import com.muyu.etl.mapper.BasicConfigInfoMapper;
import com.muyu.etl.service.BasicConfigInfoService;
import com.muyu.etl.service.StructureService;
import com.muyu.etl.service.TableInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.ServletException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* BasicConfigInfoServiceImpl
*
@ -26,6 +29,12 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
@Autowired
private BasicConfigInfoMapper basicConfigInfoMapper;
@Autowired
private StructureService structureService;
@Autowired
private TableInfoService tableInfoService;
@Override
public BasicConfigInfo selectBasicConfigInfoById(Long id) {
return basicConfigInfoMapper.selectBasicConfigInfoById(id);
@ -74,11 +83,47 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
try {
conn = DriverManager.getConnection(url, user, password);
System.out.println("Connected to the MySQL server successfully.");
//同步数据库信息
//树级结构 库,表
} catch (SQLException e) {
throw new ServletException("连接失败");
}
return true;
}
@Override
public List<List> getDataByEtl() {
List<BasicConfigInfo> list = this.list();
ArrayList<Map<String,List<String>>> mapList = new ArrayList<>();
for (BasicConfigInfo info : list) {
String url = "jdbc:" + info.getDatabaseType()
+ "://" + info.getHost()
+ ":" +info.getPort()
+ "/" +info.getDatabaseName() + "";
String user = info.getUsername();
String password = info.getPassword();
Connection conn = null;
try {
conn = DriverManager.getConnection(url,user,password);
DatabaseMetaData metaData = conn.getMetaData();
ResultSet resultSet = metaData.getCatalogs();
while (resultSet.next()){
//库名
String catalogs = resultSet.getString("TABLE_CAT");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}

View File

@ -0,0 +1,10 @@
package com.muyu.etl.service.impl;
/**
* StructureServiceImpl
*
* @author xiaohuang
* on 2024/4/22
*/
public class StructureServiceImpl {
}

View File

@ -0,0 +1,10 @@
package com.muyu.etl.service.impl;
/**
* TableInfoServiceImpl
*
* @author xiaohuang
* on 2024/4/22
*/
public class TableInfoServiceImpl {
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.etl.mapper.StructureMapper">
</mapper>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.etl.mapper.StructureMapper">
</mapper>