fix: 数据接入
parent
63eed1d18e
commit
a46e405889
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.kvt.dictionary;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 前台接受字典 Diction
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/4/25
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Diction {
|
||||
/**
|
||||
* 主鍵
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 名稱
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 類型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 狀態
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
private List<Dictionaryy> dictionaryTypes;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.muyu.kvt.dictionary;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 字典類型 DictionaryType
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/4/24
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class DictionaryType {
|
||||
|
||||
/**
|
||||
* 主鍵
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 名稱
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 類型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 狀態
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.muyu.kvt.dictionary;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 字典 Dictionary
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/4/24
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
||||
public class Dictionaryy extends BaseEntity {
|
||||
/**
|
||||
* 主鍵
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 接口注入
|
||||
*/
|
||||
private String dataAccess;
|
||||
/**
|
||||
* 字典名稱
|
||||
*/
|
||||
private String dictionaryName;
|
||||
/**
|
||||
* 字典值
|
||||
*/
|
||||
private Integer dictionaryValue;
|
||||
/**
|
||||
* 字典類型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 狀態
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.kvt.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 授权 Authorization
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/4/24
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Authorization {
|
||||
private Integer id;
|
||||
private Long uid;
|
||||
private Long kvtId;
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.muyu.kvt.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 数据授权基本信息 DataAuthorization
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/4/24
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class DataAuthorization {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 接口接入名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 系统名称
|
||||
*/
|
||||
private String systemName;
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String databaseName;
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表备注
|
||||
*/
|
||||
private String as;
|
||||
|
||||
/**
|
||||
* 总数量
|
||||
*/
|
||||
private Integer dataTotal;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.kvt.controller;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Dictionary;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -11,15 +12,19 @@ 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.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.kvt.dictionary.Diction;
|
||||
import com.muyu.kvt.dictionary.Dictionaryy;
|
||||
import com.muyu.kvt.domain.*;
|
||||
import com.muyu.kvt.domain.req.AssetStructureResponse;
|
||||
import com.muyu.kvt.domain.req.KvtEditReq;
|
||||
import com.muyu.kvt.domain.req.KvtQueryReq;
|
||||
import com.muyu.kvt.domain.req.KvtSaveReq;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.muyu.kvt.service.KvtService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -134,10 +139,21 @@ public class KvtController extends BaseController {
|
|||
|
||||
}
|
||||
|
||||
@PostMapping("/synchronizationAdd")
|
||||
public Result synchronizationAdd (@RequestBody Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
kvtService.synchronizationAdd(kvt);
|
||||
return Result.success("同步成功");
|
||||
// @PostMapping("/synchronizationAdd")
|
||||
// public Result synchronizationAdd (@RequestBody Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
//
|
||||
//// //构建当前授权
|
||||
//// Authorization.builder()
|
||||
//// .kvtId(kvt.getId())
|
||||
//// .uid(SecurityUtils.getUserId());
|
||||
// return kvtService.synchronizationAdd(kvt);
|
||||
//
|
||||
// }
|
||||
|
||||
@PostMapping("/selectDataAuthorization")
|
||||
public Result selectDataAuthorization (@RequestParam String databaseName){
|
||||
kvtService.selectDataAuthorization(databaseName);
|
||||
return Result.success();
|
||||
|
||||
}
|
||||
|
||||
|
@ -190,4 +206,28 @@ public class KvtController extends BaseController {
|
|||
List<DataStructure> childList=kvtService.selectChildAll();
|
||||
return Result.success(childList);
|
||||
}
|
||||
|
||||
//查询所有部门
|
||||
@PostMapping("/selectDept")
|
||||
public Result<List<SysDept>> deptList(){
|
||||
List<SysDept> list= kvtService.deptList();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
//查询字典
|
||||
@PostMapping("/selectDictionaryy")
|
||||
public Result<List<Diction>> selectDictionaryy(@RequestParam String databaseName){
|
||||
List<Diction> list= kvtService.selectDictionaryy(databaseName);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//同步数据添加到数据库
|
||||
@PostMapping("/synchronizationAdd")
|
||||
public Result synchronizationAdd(@RequestBody Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
|
||||
return kvtService.synchronizationAdd(kvt);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.muyu.kvt.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.kvt.dictionary.DictionaryType;
|
||||
import com.muyu.kvt.dictionary.Dictionaryy;
|
||||
import com.muyu.kvt.domain.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -43,4 +46,20 @@ public interface KvtMapper extends BaseMapper<Kvt> {
|
|||
|
||||
List<DataStructure> selectChildAll();
|
||||
|
||||
void DataAuthorizationAdd(DataAuthorization build);
|
||||
|
||||
List<SysDept> deptList();
|
||||
|
||||
|
||||
|
||||
|
||||
void del(String tableName);
|
||||
|
||||
List<String> selectTable(String databaseName);
|
||||
|
||||
List<Dictionaryy> selectDictionaryy(String databaseName);
|
||||
|
||||
DictionaryType selectDictionaryType(String type);
|
||||
|
||||
void childAdd(Child build1);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package com.muyu.kvt.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.kvt.dictionary.Diction;
|
||||
import com.muyu.kvt.dictionary.Dictionaryy;
|
||||
import com.muyu.kvt.domain.*;
|
||||
import com.muyu.kvt.domain.req.AssetStructureResponse;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
@ -38,7 +42,7 @@ public interface KvtService extends IService<Kvt> {
|
|||
|
||||
List<AssetStructureResponse> assetStructureResponse() throws ClassNotFoundException, SQLException;
|
||||
|
||||
void synchronizationAdd(Kvt kvt) throws SQLException, ClassNotFoundException;
|
||||
// Result synchronizationAdd(Kvt kvt) throws SQLException, ClassNotFoundException;
|
||||
|
||||
|
||||
|
||||
|
@ -56,6 +60,13 @@ public interface KvtService extends IService<Kvt> {
|
|||
|
||||
List<DataStructure> selectChildAll();
|
||||
|
||||
List<SysDept> deptList();
|
||||
|
||||
List<Diction> selectDictionaryy(String databaseName);
|
||||
|
||||
List<DataAuthorization> selectDataAuthorization(String databaseName);
|
||||
|
||||
Result synchronizationAdd(Kvt kvt) throws SQLException, ClassNotFoundException;
|
||||
|
||||
|
||||
// List<String> kvtList(Kvt kvt) throws ClassNotFoundException, SQLException;
|
||||
|
|
|
@ -4,9 +4,14 @@ import java.sql.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.kvt.dictionary.Diction;
|
||||
import com.muyu.kvt.dictionary.DictionaryType;
|
||||
import com.muyu.kvt.dictionary.Dictionaryy;
|
||||
import com.muyu.kvt.domain.*;
|
||||
import com.muyu.kvt.domain.req.AssetStructureResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -89,11 +94,16 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
|
||||
@Override
|
||||
public boolean connectionTest(Kvt kvt) throws ClassNotFoundException, SQLException {
|
||||
if (kvt.getType() ==1){
|
||||
return Mysql(kvt);
|
||||
}
|
||||
|
||||
return PostgreSQL(kvt);
|
||||
try {
|
||||
if (kvt.getType() == 1){
|
||||
return Mysql(kvt);
|
||||
}else {
|
||||
return PostgreSQL(kvt);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public boolean Mysql(Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
String user = kvt.getUsername();
|
||||
|
@ -232,29 +242,52 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
return assetStructureResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void synchronizationAdd(Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
boolean b = this.connectionTest(kvt);
|
||||
if (b){
|
||||
baseMapper.synchronizationAdd(kvt);
|
||||
List<ChildrenList> assetStructureLists= baseMapper.selectDepartment(kvt.getDatabaseName());
|
||||
baseMapper.ChildAdd(assetStructureLists);
|
||||
for (ChildrenList assetStructureList : assetStructureLists) {
|
||||
List<DataStructure>dataStructure= baseMapper.selectDataStructure(kvt.getDatabaseName(),assetStructureList.getName());
|
||||
for (DataStructure structure : dataStructure) {
|
||||
structure.setTableName(assetStructureList.getName());
|
||||
structure.setWarName(kvt.getDatabaseName());
|
||||
baseMapper.add(structure);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}else {
|
||||
|
||||
throw new RuntimeException("同步失败");
|
||||
}
|
||||
|
||||
}
|
||||
// @Override
|
||||
// public Result synchronizationAdd(Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
// boolean b = this.connectionTest(kvt);
|
||||
//
|
||||
// if (b){
|
||||
// //删除之前已经存在的数据
|
||||
// List<String> stringList= baseMapper.selectTable(kvt.getDatabaseName());
|
||||
//// for (String s : stringList) {
|
||||
//// baseMapper.del(s);
|
||||
//// }
|
||||
// baseMapper.synchronizationAdd(kvt);
|
||||
//
|
||||
// for (String s : stringList) {
|
||||
// List<DataStructure> dataStructure= baseMapper.selectDataStructure(kvt.getDatabaseName(),s);
|
||||
// for (DataStructure structure : dataStructure) {
|
||||
// structure.setTableName(s);
|
||||
// structure.setWarName(kvt.getDatabaseName());
|
||||
// baseMapper.add(structure);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// //查询库下的所有表以及数量 备注等
|
||||
// List<ChildrenList> assetStructureLists= baseMapper.selectDepartment(kvt.getDatabaseName());
|
||||
//
|
||||
// for (ChildrenList assetStructureList : assetStructureLists) {
|
||||
//
|
||||
// DataAuthorization build = DataAuthorization.builder()
|
||||
// .name(kvt.getName())
|
||||
// .as(assetStructureList.getAs())
|
||||
// .dataTotal(assetStructureList.getDataTotal())
|
||||
// .systemName(kvt.getSystemName())
|
||||
// .tableName(assetStructureList.getName())
|
||||
// .databaseName(kvt.getDatabaseName()).build();
|
||||
// baseMapper.DataAuthorizationAdd(build);
|
||||
//
|
||||
// baseMapper.ChildAdd(assetStructureLists);
|
||||
// }
|
||||
//
|
||||
// return Result.success(kvt, "同步成功");
|
||||
// }else {
|
||||
//
|
||||
// throw new RuntimeException("同步失败");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<AssetStructureList> assetStructureList() {
|
||||
|
@ -305,6 +338,201 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
return baseMapper.selectChildAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDept> deptList() {
|
||||
return baseMapper.deptList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Diction> selectDictionaryy(String databaseName) {
|
||||
List<Dictionaryy> list = baseMapper.selectDictionaryy(databaseName);
|
||||
List<Diction> dictions = new ArrayList<>();
|
||||
for (Dictionaryy dictionaryy : list) {
|
||||
DictionaryType dictionaryType= baseMapper.selectDictionaryType(dictionaryy.getType());
|
||||
Diction build = Diction.builder()
|
||||
.dictionaryTypes(list)
|
||||
.type(dictionaryType.getType())
|
||||
.status(0)
|
||||
.name(dictionaryType.getName())
|
||||
.id(dictionaryType.getId())
|
||||
.build();
|
||||
|
||||
boolean exists = dictions.stream()
|
||||
.anyMatch(d -> d.getType().equals(build.getType()) &&
|
||||
d.getStatus().equals(build.getStatus()) &&
|
||||
d.getName().equals(build.getName()) &&
|
||||
d.getId().equals(build.getId()));
|
||||
|
||||
// 如果不存在,则添加到列表中
|
||||
if (!exists) {
|
||||
dictions.add(build);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return dictions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataAuthorization> selectDataAuthorization(String databaseName) {
|
||||
|
||||
List<ChildrenList> list= baseMapper.selectDepartment(databaseName);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步数据
|
||||
* @param kvt
|
||||
*/
|
||||
@Override
|
||||
public Result synchronizationAdd(Kvt kvt){
|
||||
int count =0;
|
||||
//用户名
|
||||
String user =kvt.getUsername();
|
||||
//密码
|
||||
String password = kvt.getPassword();
|
||||
String jdbcDriver = "com.mysql.cj.jdbc.Driver";
|
||||
String jdbcUrl = "jdbc:mysql://" + kvt.getHost() + ":" + kvt.getPort() + "/" + kvt.getDatabaseName() + "?" + kvt.getConnectionParam();
|
||||
Connection connection=null;
|
||||
String sql =" ";
|
||||
try {
|
||||
Class.forName(jdbcDriver);
|
||||
|
||||
connection = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
String sql1="SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='"+kvt.getDatabaseName()+"'";
|
||||
baseMapper.synchronizationAdd(kvt);
|
||||
sql ="SELECT\n" +
|
||||
" TABLE_NAME AS 'tableName',\n" +
|
||||
" COLUMN_NAME AS 'name',\n" +
|
||||
" COLUMN_COMMENT AS 'comment',\n" +
|
||||
" CASE WHEN COLUMN_KEY = 'PRI' THEN '是' ELSE '否' END AS 'isPrimaryKey',\n" +
|
||||
"\n" +
|
||||
" CASE\n" +
|
||||
" WHEN DATA_TYPE = 'int' THEN 'Integer'\n" +
|
||||
" WHEN DATA_TYPE = 'varchar' THEN 'String'\n" +
|
||||
" WHEN DATA_TYPE = 'decimal' THEN 'BigDecimal'\n" +
|
||||
" WHEN DATA_TYPE = 'tinyint' AND COLUMN_TYPE = 'tinyint(1)' THEN 'Boolean'\n" +
|
||||
"\n" +
|
||||
" ELSE DATA_TYPE\n" +
|
||||
" END AS 'type',\n" +
|
||||
" DATA_TYPE AS 'mappingType',\n" +
|
||||
" COLUMN_TYPE AS 'detailType',\n" +
|
||||
" CHARACTER_MAXIMUM_LENGTH AS 'length',\n" +
|
||||
" NUMERIC_SCALE AS 'decimalPlaces',\n" +
|
||||
" IS_NULLABLE AS 'isNull',\n" +
|
||||
" COLUMN_DEFAULT AS 'defaultValue'\n" +
|
||||
" FROM\n" +
|
||||
" INFORMATION_SCHEMA.COLUMNS\n" +
|
||||
" WHERE\n" +
|
||||
" TABLE_SCHEMA = ?\n" +
|
||||
" AND TABLE_NAME = ?";
|
||||
|
||||
String sql2 ="SELECT\n" +
|
||||
" TABLE_NAME as 'name',\n" +
|
||||
" TABLE_COMMENT as 'as',\n" +
|
||||
" TABLE_ROWS as 'dataTotal'\n" +
|
||||
" FROM INFORMATION_SCHEMA.TABLES\n" +
|
||||
" WHERE\n" +
|
||||
" TABLE_SCHEMA = ?";
|
||||
ResultSet resultSet = statement.executeQuery(sql1);
|
||||
|
||||
while (resultSet.next()){
|
||||
|
||||
String tableName = resultSet.getString("table_name");
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.setString(1, kvt.getDatabaseName()); // 设置第一个参数的值
|
||||
preparedStatement.setString(2, tableName); // 设置第二个参数的值
|
||||
ResultSet executeQuery = preparedStatement.executeQuery();
|
||||
while (executeQuery.next()){
|
||||
String name = executeQuery.getString("name");
|
||||
/**
|
||||
* 注释
|
||||
*/
|
||||
String comment = executeQuery.getString("comment");
|
||||
/**
|
||||
* 是否主键
|
||||
*/
|
||||
String isPrimaryKey = executeQuery.getString("isPrimaryKey");
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
String type = executeQuery.getString("type");
|
||||
/**
|
||||
* 映射类型
|
||||
*/
|
||||
String mappingType = executeQuery.getString("mappingType");
|
||||
/**
|
||||
* 长度
|
||||
*/
|
||||
String length = executeQuery.getString("length");
|
||||
/**
|
||||
* 小数位
|
||||
*/
|
||||
String decimalPlaces = executeQuery.getString("decimalPlaces");
|
||||
/**
|
||||
* 是否为空
|
||||
*/
|
||||
String isNull = executeQuery.getString("isNull");
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
String defaultValue = executeQuery.getString("defaultValue");
|
||||
// String isDict = executeQuery.getString("isDict");
|
||||
// String dictKey = executeQuery.getString("dictKey");
|
||||
DataStructure build = DataStructure.builder()
|
||||
.tableName(tableName)
|
||||
.warName(kvt.getDatabaseName())
|
||||
.name(name)
|
||||
.comment(comment)
|
||||
.isPrimaryKey(isPrimaryKey)
|
||||
.type(type)
|
||||
.mappingType(mappingType)
|
||||
.length(length)
|
||||
.decimalPlaces(decimalPlaces)
|
||||
.isNull(isNull)
|
||||
.defaultValue(defaultValue)
|
||||
.isDict(null)
|
||||
.dictKey(null)
|
||||
.build();
|
||||
baseMapper.add(build);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
PreparedStatement preparedStatement2 = connection.prepareStatement(sql2);
|
||||
preparedStatement2.setString(1, kvt.getDatabaseName()); // 设置第一个参数的值
|
||||
ResultSet query = preparedStatement2.executeQuery();
|
||||
while (query.next()){
|
||||
count++;
|
||||
String name2 = query.getString("name");
|
||||
String as = query.getString("as");
|
||||
String dataTotal = query.getString("dataTotal");
|
||||
Child build1 = Child.builder()
|
||||
.dataTotal(Integer.valueOf(dataTotal))
|
||||
.name(name2)
|
||||
.as(as)
|
||||
.isPrimaryKey(null)
|
||||
.build();
|
||||
baseMapper.childAdd(build1);
|
||||
}
|
||||
|
||||
resultSet.close();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
return Result.success(kvt,"同步成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public List<String> kvtList(Kvt kvt) {
|
||||
|
@ -350,4 +578,104 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
//
|
||||
// return tables;
|
||||
// }
|
||||
|
||||
// sql = "show tables";
|
||||
// ResultSet resultSet = statement.executeQuery(sql);
|
||||
// while (resultSet.next()) {
|
||||
// String tableName = resultSet.getString("Tables_in_data_basete");//表名称
|
||||
// ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
|
||||
// //遍历表所有元数据信息
|
||||
// for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
|
||||
// System.out.println(resultSet.getString(i) + "-==-" + resultSetMetaData.getColumnName(i));
|
||||
// }
|
||||
// ResultSet resultSet1 = metaData.getColumns(connection.getCatalog(), metaData.getUserName(), tableName, null);
|
||||
// // /**
|
||||
// // * 主键
|
||||
// // */
|
||||
// // private Integer id;
|
||||
// //
|
||||
// //
|
||||
// // private String tableName;
|
||||
// // private String warName;
|
||||
// //
|
||||
// // /**
|
||||
// // * 名称
|
||||
// // */
|
||||
// // private String name;
|
||||
// // /**
|
||||
// // * 注释
|
||||
// // */
|
||||
// // private String comment;
|
||||
// // /**
|
||||
// // * 是否主键
|
||||
// // */
|
||||
// // private String isPrimaryKey;
|
||||
// // /**
|
||||
// // * 类型
|
||||
// // */
|
||||
// // private String type;
|
||||
// // /**
|
||||
// // * 映射类型
|
||||
// // */
|
||||
// // private String mappingType;
|
||||
// // /**
|
||||
// // * 长度
|
||||
// // */
|
||||
// // private String length;
|
||||
// // /**
|
||||
// // * 小数位
|
||||
// // */
|
||||
// // private String decimalPlaces;
|
||||
// // /**
|
||||
// // * 是否为空
|
||||
// // */
|
||||
// // private String isNull;
|
||||
// // /**
|
||||
// // * 默认值
|
||||
// // */
|
||||
// // private String defaultValue;
|
||||
// // /**
|
||||
// // * 是否字典
|
||||
// // */
|
||||
// // private String isDict;
|
||||
// // /**
|
||||
// // * 映射字典
|
||||
// // */
|
||||
// // private String dictKey;
|
||||
//
|
||||
// while (resultSet1.next()) {
|
||||
// String table_name = resultSet.getString("Tables_in_data_basete");//表名
|
||||
// String columnName = resultSet.getString("name");//字段名
|
||||
// String typeName = resultSet.getString("type");//字段类型
|
||||
// String dataType = resultSet.getString("mappingType");//字段类型
|
||||
// String columnSize = resultSet.getString("length");//长度
|
||||
//// String decimalDigits = resultSet.getString("DECIMAL_DIGITS");//长度
|
||||
// String columnDef = resultSet.getString("defaultValue");//默认值
|
||||
// String remarks = resultSet.getString("comment");//注释
|
||||
// String decimalPlaces = resultSet.getString("decimalPlaces");//小数值
|
||||
// String isNull = resultSet.getString("isNull");//是否为空
|
||||
// String isDict = resultSet.getString("isDict");//是否字典
|
||||
// String dictKey = resultSet.getString("dictKey");//映射字典
|
||||
// ResultSet rs2 = connection.getMetaData().getPrimaryKeys(connection.getCatalog(), null, tableName);
|
||||
// ResultSetMetaData resultSetMetaData2 = rs2.getMetaData();
|
||||
// while (rs2.next()) {
|
||||
// String columnName1 = rs2.getString("isPrimaryKey");//主键
|
||||
// sql = "select count(*) from " + table_name;
|
||||
// ResultSet resultSet2 = statement.executeQuery(sql);
|
||||
// resultSet2.next();
|
||||
// int row = resultSet2.getInt(1);//总数量
|
||||
// baseMapper.synchronizationAdd(kvt);
|
||||
// DataAuthorization build = DataAuthorization.builder()
|
||||
// .name(kvt.getName())
|
||||
// .systemName(kvt.getSystemName())
|
||||
// .databaseName(kvt.getDatabaseName())
|
||||
// .tableName(table_name)
|
||||
// .dataTotal(row)
|
||||
// .as(remarks)
|
||||
// .build();
|
||||
// baseMapper.DataAuthorizationAdd(build);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return Result.success(kvt, "同步成功");
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
select id, name, system_name, type, host, port, database_name, connection_param, init_num, max_num, max_wait_time, max_wait_size, remark, create_by, create_time, update_by, update_time
|
||||
from kvt
|
||||
</sql>
|
||||
<delete id="del">
|
||||
truncate table #{tableName}
|
||||
</delete>
|
||||
|
||||
<select id="dataTypeList" resultType="com.muyu.kvt.domain.DataType">
|
||||
select * from data_type
|
||||
|
@ -85,12 +88,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="selectDataStur" resultType="com.muyu.kvt.domain.DataStructure">
|
||||
select * from data_structure where table_name =#{tableName}
|
||||
</select>
|
||||
|
||||
<select id="selectChild" resultType="com.muyu.kvt.domain.Child">
|
||||
select * from child where name =#{tableName}
|
||||
</select>
|
||||
<select id="selectChildAll" resultType="com.muyu.kvt.domain.Child">
|
||||
select * from child
|
||||
</select>
|
||||
<select id="deptList" resultType="com.muyu.common.system.domain.SysDept">
|
||||
select * from dept
|
||||
</select>
|
||||
|
||||
<select id="selectTable" resultType="java.lang.String">
|
||||
SELECT
|
||||
TABLE_NAME as 'name'
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE
|
||||
TABLE_SCHEMA = #{databaseName}
|
||||
</select>
|
||||
<select id="selectDictionaryy" resultType="com.muyu.kvt.dictionary.Dictionaryy">
|
||||
select * from dictionary where data_access =#{databaseName}
|
||||
</select>
|
||||
<select id="selectDictionaryType" resultType="com.muyu.kvt.dictionary.DictionaryType">
|
||||
select * from dictionary_type where type =#{type}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="synchronizationAdd">
|
||||
|
@ -127,5 +148,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
|
||||
|
||||
</insert>
|
||||
<insert id="DataAuthorizationAdd">
|
||||
INSERT INTO `data_basete`.`data_authorization` ( `name`, `system_name`, `database_name`, `table_name`,
|
||||
`as`, `data_total`)
|
||||
VALUES (#{name}, #{systemName}, #{databaseName}, #{tableName}, #{as}, #{dataTotal});
|
||||
|
||||
|
||||
</insert>
|
||||
<insert id="childAdd">
|
||||
INSERT INTO `data_basete`.`child` (`name`, `as`, `data_total`, `is_primary_key`)
|
||||
VALUES ( #{name}, #{as}, #{dataTotal}
|
||||
, #{isPrimaryKey})
|
||||
</insert>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue