重构项目5.12
parent
d7fd3e9135
commit
d1e233042d
|
@ -30,6 +30,8 @@ public class TableInfo extends TreeEntity {
|
||||||
@TableId(value = "id",type = IdType.AUTO)
|
@TableId(value = "id",type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
private Long basicId;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表名称/数据库/
|
* 表名称/数据库/
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.muyu.etl.controller;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
|
import com.muyu.etl.domain.AssetImpower;
|
||||||
|
import com.muyu.etl.domain.TableInfo;
|
||||||
|
import com.muyu.etl.service.AssetImpowerService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资产赋权 AssetImpowerController
|
||||||
|
*
|
||||||
|
* @author xiaohuang
|
||||||
|
* on 2024/5/12
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/impower")
|
||||||
|
public class AssetImpowerController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AssetImpowerService assetImpowerService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -7,9 +7,14 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
import com.muyu.common.log.annotation.Log;
|
import com.muyu.common.log.annotation.Log;
|
||||||
import com.muyu.common.log.enums.BusinessType;
|
import com.muyu.common.log.enums.BusinessType;
|
||||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
|
import com.muyu.etl.domain.AssetDataDict;
|
||||||
import com.muyu.etl.domain.BasicConfigInfo;
|
import com.muyu.etl.domain.BasicConfigInfo;
|
||||||
|
import com.muyu.etl.domain.DictInfo;
|
||||||
|
import com.muyu.etl.domain.Structure;
|
||||||
|
import com.muyu.etl.domain.resp.BasicDictResp;
|
||||||
|
import com.muyu.etl.domain.resp.TableInfoStructureResp;
|
||||||
import com.muyu.etl.domain.resp.TableTreeResp;
|
import com.muyu.etl.domain.resp.TableTreeResp;
|
||||||
import com.muyu.etl.service.BasicConfigInfoService;
|
import com.muyu.etl.service.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -31,6 +36,16 @@ public class BasicConfigInfoController extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private BasicConfigInfoService basicConfigInfoService;
|
private BasicConfigInfoService basicConfigInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BasicConfigInfoService basicConfigInfoService;
|
||||||
|
@Autowired
|
||||||
|
private AssetDataDictService assetDataDictService;
|
||||||
|
@Autowired
|
||||||
|
private TableInfoService tableInfoService;
|
||||||
|
@Autowired
|
||||||
|
private DictInfoService dictInfoService;
|
||||||
|
@Autowired
|
||||||
|
private StructureService structureService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询基础信息列表
|
* 查询基础信息列表
|
||||||
|
@ -107,13 +122,93 @@ public class BasicConfigInfoController extends BaseController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 树级结构数据
|
* 树级结构数据
|
||||||
|
*
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("etl:table:list")
|
@RequiresPermissions("etl:table:list")
|
||||||
@Log(title = "获取已成功链接的树级结构")
|
@Log(title = "获取已成功链接的树级结构")
|
||||||
@GetMapping("/getTableTree")
|
@GetMapping("/getTableTree")
|
||||||
public Result<List<TableTreeResp>> getTableTree(){
|
public Result<List<TableTreeResp>> getTableTree() {
|
||||||
return Result.success(basicConfigInfoService.getTableTree());
|
return Result.success(basicConfigInfoService.getTableTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过接入id查询数据库所属字典
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("etl:table:dictList")
|
||||||
|
@Log(title = "描述")
|
||||||
|
@GetMapping("/getDict/{basicId}")
|
||||||
|
public Result<List<BasicDictResp>>
|
||||||
|
getDict(@PathVariable Long basicId) {
|
||||||
|
return Result.success(assetDataDictService.getDict(basicId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过tableId查询表信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Log(title = "描述")
|
||||||
|
@GetMapping("/getTableInfo/{tableId}")
|
||||||
|
public Result<TableInfoStructureResp>
|
||||||
|
getTableInfo(@PathVariable Long tableId) {
|
||||||
|
return Result.success(basicConfigInfoService.getTableInfo(tableId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加字典表
|
||||||
|
*
|
||||||
|
* @param assetDataDict
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("etl:table:list")
|
||||||
|
@Log(title = "添加字典内容")
|
||||||
|
@PostMapping("/insertDict")
|
||||||
|
public Result insertDictInfo(@RequestBody AssetDataDict assetDataDict) throws ServletException {
|
||||||
|
return Result.success(assetDataDictService.insertAssetDataDict(assetDataDict));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加字典详细信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("etl:table:add")
|
||||||
|
@Log(title = "添加字典表")
|
||||||
|
@PostMapping("/insertDictInfo")
|
||||||
|
public Result insertDict(@RequestBody DictInfo dictInfo)
|
||||||
|
throws ServletException {
|
||||||
|
return Result.success(dictInfoService.insertDictInfo(dictInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取具体表的所有基础信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("etl:table:list")
|
||||||
|
@Log(title = "获取具体表的所有基础信息")
|
||||||
|
@GetMapping("/getBasicTableInfo/{tableId}")
|
||||||
|
public Result getBasicTableInfo(@PathVariable Long tableId)
|
||||||
|
throws ServletException {
|
||||||
|
return Result.success(basicConfigInfoService.getBasicTableInfo(tableId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改资产结构中字典信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("etl:table:update")
|
||||||
|
@Log(title = "修改资产结构中字典信息")
|
||||||
|
@PutMapping("/updateStructureInfo")
|
||||||
|
public Result updateStructureInfo
|
||||||
|
(@RequestBody Structure structure) {
|
||||||
|
return Result.success(structureService.updateStructureInfoDict(structure), "修改成功");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.muyu.etl.service;
|
||||||
|
|
||||||
|
import com.muyu.etl.domain.AssetDataDict;
|
||||||
|
import com.muyu.etl.domain.resp.BasicDictResp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资产数据字典 AssetDataDictService
|
||||||
|
*
|
||||||
|
* @author xiaohuang
|
||||||
|
* on 2024/5/12
|
||||||
|
*/
|
||||||
|
public interface AssetDataDictService {
|
||||||
|
List<BasicDictResp> getDict(Long basicId);
|
||||||
|
|
||||||
|
Object insertAssetDataDict(AssetDataDict assetDataDict);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.muyu.etl.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资产赋权 AssetImpowerService
|
||||||
|
*
|
||||||
|
* @author xiaohuang
|
||||||
|
* on 2024/5/12
|
||||||
|
*/
|
||||||
|
public interface AssetImpowerService {
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package com.muyu.etl.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.etl.domain.BasicConfigInfo;
|
import com.muyu.etl.domain.BasicConfigInfo;
|
||||||
|
import com.muyu.etl.domain.resp.TableInfoStructureResp;
|
||||||
import com.muyu.etl.domain.resp.TableTreeResp;
|
import com.muyu.etl.domain.resp.TableTreeResp;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -34,4 +35,8 @@ public interface BasicConfigInfoService extends IService<BasicConfigInfo> {
|
||||||
boolean connectionTest(BasicConfigInfo basicConfigInfo) throws ServletException;
|
boolean connectionTest(BasicConfigInfo basicConfigInfo) throws ServletException;
|
||||||
|
|
||||||
List<TableTreeResp> getTableTree();
|
List<TableTreeResp> getTableTree();
|
||||||
|
|
||||||
|
TableInfoStructureResp getTableInfo(Long tableId);
|
||||||
|
|
||||||
|
Object getBasicTableInfo(Long tableId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.muyu.etl.service;
|
||||||
|
|
||||||
|
import com.muyu.etl.domain.DictInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DictInfoService
|
||||||
|
*
|
||||||
|
* @author xiaohuang
|
||||||
|
* on 2024/5/12
|
||||||
|
*/
|
||||||
|
public interface DictInfoService {
|
||||||
|
Object insertDictInfo(DictInfo dictInfo);
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.muyu.etl.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.etl.domain.Structure;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结构 StructureService
|
||||||
|
*
|
||||||
|
* @author xiaohuang
|
||||||
|
* on 2024/5/12
|
||||||
|
*/
|
||||||
|
public interface StructureService extends IService<Structure> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询结构
|
||||||
|
*/
|
||||||
|
public Structure selectStructureById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询结构列表
|
||||||
|
*/
|
||||||
|
public List<Structure> selectStructureList(Structure structure);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增结构
|
||||||
|
*/
|
||||||
|
public int insertStructure(Structure structure);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改结构
|
||||||
|
*/
|
||||||
|
public int updateStructure(Structure structure);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除结构
|
||||||
|
*/
|
||||||
|
public int deleteStructureByIds(Long[] ids);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除结构信息
|
||||||
|
*/
|
||||||
|
public int deleteStructureById(Long id);
|
||||||
|
|
||||||
|
boolean updateStructureInfoDict(Structure structure);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.muyu.etl.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.etl.domain.TableInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 库表基础信息 TableInfoService
|
||||||
|
*
|
||||||
|
* @author xiaohuang
|
||||||
|
* on 2024/5/12
|
||||||
|
*/
|
||||||
|
public interface TableInfoService extends IService<TableInfo> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询库表基础信息
|
||||||
|
*/
|
||||||
|
public TableInfo selectTableInfoById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询库表基础信息列表
|
||||||
|
*/
|
||||||
|
public List<TableInfo> selectTableInfoList(TableInfo tableInfo);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增库表基础信息
|
||||||
|
*/
|
||||||
|
public int insertTableInfo(TableInfo tableInfo);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改库表基础信息
|
||||||
|
*/
|
||||||
|
public int updateTableInfo(TableInfo tableInfo);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除库表基础信息
|
||||||
|
*/
|
||||||
|
public int deleteTableInfoByIds(Long[] ids);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除库表基础信息
|
||||||
|
*/
|
||||||
|
public int deleteTableInfoById(Long id);
|
||||||
|
|
||||||
|
TableInfo selectTableInfoByName(TableInfo build);
|
||||||
|
}
|
|
@ -1,11 +1,16 @@
|
||||||
package com.muyu.etl.service.impl;
|
package com.muyu.etl.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.etl.domain.BasicConfigInfo;
|
import com.muyu.etl.domain.BasicConfigInfo;
|
||||||
|
import com.muyu.etl.domain.Structure;
|
||||||
|
import com.muyu.etl.domain.TableInfo;
|
||||||
import com.muyu.etl.domain.resp.TableTreeResp;
|
import com.muyu.etl.domain.resp.TableTreeResp;
|
||||||
import com.muyu.etl.mapper.BasicConfigInfoMapper;
|
import com.muyu.etl.mapper.BasicConfigInfoMapper;
|
||||||
import com.muyu.etl.service.BasicConfigInfoService;
|
import com.muyu.etl.service.BasicConfigInfoService;
|
||||||
|
import com.muyu.etl.service.StructureService;
|
||||||
|
import com.muyu.etl.service.TableInfoService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import net.sf.jsqlparser.schema.Table;
|
import net.sf.jsqlparser.schema.Table;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -14,10 +19,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.sql.rowset.serial.SerialException;
|
import javax.sql.rowset.serial.SerialException;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
import java.util.Date;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据接入 BasicConfigInfoServiceImpl
|
* 数据接入 BasicConfigInfoServiceImpl
|
||||||
|
@ -32,6 +38,15 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
|
||||||
@Autowired
|
@Autowired
|
||||||
private BasicConfigInfoMapper basicConfigInfoMapper;
|
private BasicConfigInfoMapper basicConfigInfoMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StructureService structureService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TableInfoService tableInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询列表
|
* 查询列表
|
||||||
* @param basicConfigInfo
|
* @param basicConfigInfo
|
||||||
|
@ -91,6 +106,66 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
|
||||||
|
|
||||||
//同步数据库信息
|
//同步数据库信息
|
||||||
//树级结构 库 表
|
//树级结构 库 表
|
||||||
|
TableInfo tableInfoInsert = TableInfo.builder()
|
||||||
|
.basicId(basicConfigInfo.getId())
|
||||||
|
.parentId(0L)
|
||||||
|
.tableRemark("")
|
||||||
|
.center("Y")
|
||||||
|
.type("dataSource")
|
||||||
|
.tableName(basicConfigInfo.getDataSourcesSystemName() + "(" + databaseName + ")")
|
||||||
|
.createBy(SecurityUtils.getUsername())
|
||||||
|
.createTime(new Date())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
tableInfoService.saveOrUpdate(tableInfoInsert,new LambdaUpdateWrapper<>(TableInfo.class) {{
|
||||||
|
eq(TableInfo::getTableName,tableInfoInsert.getTableName());
|
||||||
|
eq(TableInfo::getBasicId,basicConfigInfo.getId());
|
||||||
|
}});
|
||||||
|
|
||||||
|
//查询列表中的所有tableinfo basiac_id 不存在删除
|
||||||
|
//通过查询获取当前tableinfo对象的id
|
||||||
|
|
||||||
|
TableInfo tableInfo = tableInfoService.selectTableInfoByName(tableInfoInsert);
|
||||||
|
DatabaseMetaData metaData = conn.getMetaData();
|
||||||
|
ResultSet rs = metaData.getTables(databaseName, null, "%", new String[]{"TABLE", "VIEW"});
|
||||||
|
while (rs.next()){
|
||||||
|
//表名
|
||||||
|
String tableName = rs.getString("TABLE_NAME");
|
||||||
|
String tableRemark = rs.getString("REMARKS");
|
||||||
|
Connection finalConn = conn;
|
||||||
|
PreparedStatement ps = conn.prepareStatement("select * from " + tableName);
|
||||||
|
ResultSet rset = ps.executeQuery();
|
||||||
|
Long rowCount = 0L;
|
||||||
|
while (rset.next()){
|
||||||
|
rowCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
TableInfo build = TableInfo.builder()
|
||||||
|
.basicId(basicConfigInfo.getId())
|
||||||
|
.tableName(tableName)
|
||||||
|
.tableRemark(tableRemark == null ? "" : tableRemark)
|
||||||
|
.parentId(tableInfo.getId())
|
||||||
|
.type("dataTable")
|
||||||
|
.center("Y")
|
||||||
|
.updateBy(SecurityUtils.getUsername())
|
||||||
|
.dataNum(rowCount)
|
||||||
|
.updateTime(new Date())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
tableInfoService.saveOrUpdate(build,new LambdaUpdateWrapper<>(TableInfo.class) {{
|
||||||
|
eq(TableInfo::getTableName, build.getTableName());
|
||||||
|
eq(TableInfo::getBasicId, basicConfigInfo.getId());
|
||||||
|
}});
|
||||||
|
|
||||||
|
TableInfo table = tableInfoService.selectTableInfoByName(build);
|
||||||
|
//线程池
|
||||||
|
ExecutorService threadPool = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
|
threadPool.submit(() ->{
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,6 +177,78 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void syncData(Connection conn,String databaseName,TableInfo table) throws SQLException{
|
||||||
|
ExecutorService threadPool = Executors.newCachedThreadPool();
|
||||||
|
PreparedStatement ps = conn.prepareStatement(
|
||||||
|
" SELECT " +
|
||||||
|
" COLUMN_NAME , " +
|
||||||
|
" COLUMN_COMMENT ," +
|
||||||
|
" CASE WHEN COLUMN_KEY = 'PRI' THEN '是' ELSE '否' END ," +
|
||||||
|
" CASE \n" +
|
||||||
|
" WHEN DATA_TYPE = 'int' THEN 'Integer' " +
|
||||||
|
" WHEN DATA_TYPE = 'bigint' THEN 'Long' " +
|
||||||
|
" WHEN DATA_TYPE = 'varchar' THEN 'String' " +
|
||||||
|
" WHEN DATA_TYPE = 'decimal' THEN 'BigDecimal' " +
|
||||||
|
" WHEN DATA_TYPE = 'tinyint' AND COLUMN_TYPE = 'tinyint(1)' THEN 'Boolean'" +
|
||||||
|
" ELSE DATA_TYPE -- 如果无法映射,则返回原始数据库类型 \n" +
|
||||||
|
" END , " +
|
||||||
|
" DATA_TYPE , -- 原始的数据库类型 \n" +
|
||||||
|
" COLUMN_TYPE , -- 更详细的数据库类型,可能包含长度、精度等 \n" +
|
||||||
|
" CHARACTER_MAXIMUM_LENGTH , \n" +
|
||||||
|
" NUMERIC_SCALE , \n" +
|
||||||
|
" IS_NULLABLE , \n" +
|
||||||
|
" COLUMN_DEFAULT \n" +
|
||||||
|
"FROM INFORMATION_SCHEMA.COLUMNS WHERE \n" +
|
||||||
|
"TABLE_SCHEMA = '" + databaseName + "' -- 替换为你的数据库名称 \n" +
|
||||||
|
"AND TABLE_NAME = '" + table.getTableName() + "'");
|
||||||
|
|
||||||
|
ResultSet resultSet = ps.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()){
|
||||||
|
String columnName = String.valueOf(resultSet.getString(1));
|
||||||
|
String columnComment = String.valueOf(resultSet.getObject(2));
|
||||||
|
String columnKey = String.valueOf(resultSet.getObject(3));
|
||||||
|
String end = String.valueOf(resultSet.getObject(4));
|
||||||
|
String dataType = String.valueOf(resultSet.getObject(5));
|
||||||
|
String columnType = String.valueOf(resultSet.getObject(6));
|
||||||
|
String characterMaximumLength = String.valueOf(resultSet.getInt(7));
|
||||||
|
String NumericScale = String.valueOf(resultSet.getInt(8));
|
||||||
|
String isNullable = String.valueOf(resultSet.getObject(9));
|
||||||
|
String columnDefault = String.valueOf(resultSet.getObject(10));
|
||||||
|
Structure build = Structure.builder()
|
||||||
|
.tableId(table.getId())
|
||||||
|
.columnName(String.valueOf(columnName))
|
||||||
|
.columnRemark(columnComment)
|
||||||
|
.isPrimary("是".equals(columnKey) ? "Y" : "N")
|
||||||
|
.javaType(end)
|
||||||
|
.columnType(dataType)
|
||||||
|
.columnType(columnType)
|
||||||
|
.columnLength(characterMaximumLength)
|
||||||
|
.columnDecimals(NumericScale)
|
||||||
|
.isNull("YES".equals(isNullable) ? "Y" : "N")
|
||||||
|
.defaultValue(columnDefault)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
threadPool.submit(() -> {
|
||||||
|
structureService.saveOrUpdate(build,new LambdaUpdateWrapper<>(){{
|
||||||
|
eq(Structure::getTableId,build.getTableId());
|
||||||
|
eq(Structure::getColumnName,build.getColumnName());
|
||||||
|
eq(Structure::getColumnDecimals,build.getColumnRemark());
|
||||||
|
}});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
threadPool.shutdown();
|
||||||
|
ps.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TableTreeResp> getTableTree() {
|
public List<TableTreeResp> getTableTree() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue