重构项目5.12

master
xiaohuang 2024-05-12 22:38:19 +08:00
parent d7fd3e9135
commit d1e233042d
10 changed files with 433 additions and 6 deletions

View File

@ -30,6 +30,8 @@ public class TableInfo extends TreeEntity {
@TableId(value = "id",type = IdType.AUTO)
private Long id;
private Long basicId;
/**
* //

View File

@ -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;
}

View File

@ -7,9 +7,14 @@ import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.etl.domain.AssetDataDict;
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.service.BasicConfigInfoService;
import com.muyu.etl.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -31,6 +36,16 @@ public class BasicConfigInfoController extends BaseController {
@Autowired
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")
@Log(title = "获取已成功链接的树级结构")
@GetMapping("/getTableTree")
public Result<List<TableTreeResp>> getTableTree(){
public Result<List<TableTreeResp>> 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), "修改成功");
}
}

View File

@ -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);
}

View File

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

View File

@ -2,6 +2,7 @@ package com.muyu.etl.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.etl.domain.BasicConfigInfo;
import com.muyu.etl.domain.resp.TableInfoStructureResp;
import com.muyu.etl.domain.resp.TableTreeResp;
import javax.servlet.ServletException;
@ -34,4 +35,8 @@ public interface BasicConfigInfoService extends IService<BasicConfigInfo> {
boolean connectionTest(BasicConfigInfo basicConfigInfo) throws ServletException;
List<TableTreeResp> getTableTree();
TableInfoStructureResp getTableInfo(Long tableId);
Object getBasicTableInfo(Long tableId);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -1,11 +1,16 @@
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.muyu.common.security.utils.SecurityUtils;
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.mapper.BasicConfigInfoMapper;
import com.muyu.etl.service.BasicConfigInfoService;
import com.muyu.etl.service.StructureService;
import com.muyu.etl.service.TableInfoService;
import lombok.extern.log4j.Log4j2;
import net.sf.jsqlparser.schema.Table;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,10 +19,11 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.ServletException;
import javax.sql.rowset.serial.SerialException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* BasicConfigInfoServiceImpl
@ -32,6 +38,15 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMappe
@Autowired
private BasicConfigInfoMapper basicConfigInfoMapper;
@Autowired
private StructureService structureService;
@Autowired
private TableInfoService tableInfoService;
@Autowired
/**
*
* @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
*/
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
public List<TableTreeResp> getTableTree() {