feat: 资产展示
parent
8a1ffb7da2
commit
fb2cb32004
|
@ -37,4 +37,5 @@ public interface RemoteUserService {
|
|||
*/
|
||||
@PostMapping("/user/register")
|
||||
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
<artifactId>muyu-common</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<description>
|
||||
muyu-common通用模块
|
||||
</description>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.Date;
|
|||
@NoArgsConstructor
|
||||
@Builder
|
||||
|
||||
public class DictionaryType extends BaseEntity{
|
||||
public class DictionaryType{
|
||||
|
||||
/**
|
||||
* 主鍵
|
||||
|
|
|
@ -21,6 +21,19 @@ public class AssetStructureList {
|
|||
private String databaseName;
|
||||
private Long type;
|
||||
|
||||
/**
|
||||
* 总接口
|
||||
*/
|
||||
private Integer kvtNumber;
|
||||
/**
|
||||
* 总表数
|
||||
*/
|
||||
private Integer tableSum;
|
||||
/**
|
||||
* 总表数中的总数量
|
||||
*/
|
||||
private Integer sum;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
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;
|
||||
}
|
|
@ -20,6 +20,7 @@ import lombok.experimental.SuperBuilder;
|
|||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class ChildrenList {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String as;
|
||||
private Integer dataTotal;
|
||||
|
|
|
@ -65,11 +65,12 @@ public class DataStructure {
|
|||
* 是否字典
|
||||
*/
|
||||
private String isDict;
|
||||
|
||||
/**
|
||||
* 映射字典
|
||||
*/
|
||||
private String dictKey;
|
||||
|
||||
|
||||
private String value;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package com.muyu.kvt.domain.req;
|
||||
|
||||
import com.muyu.kvt.domain.AssetStructureList;
|
||||
import com.muyu.kvt.domain.ChildrenList;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AssetStructureResponse
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/4/21
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
public class AssetStructureResponse {
|
||||
private List<AssetStructureList> assetStructureLists;
|
||||
private List<ChildrenList> childrenLists;
|
||||
}
|
|
@ -16,5 +16,12 @@
|
|||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-system</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -89,6 +89,12 @@
|
|||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-kvt-remote</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.muyu.common.security.annotation.EnableMyFeignClients;
|
|||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
|
@ -22,30 +23,5 @@ public class MuyuApplication {
|
|||
public static void main(String[] args) {
|
||||
SpringApplication.run(MuyuApplication.class);
|
||||
|
||||
// Connection connection=null;
|
||||
// Statement statement=null;
|
||||
// try {
|
||||
// Class.forName("org.postgresql.Driver");
|
||||
//
|
||||
// String url = "jdbc:postgresql://localhost:5432/postgres";
|
||||
// String user = "postgres";
|
||||
// String password = "root";
|
||||
// connection = DriverManager.getConnection(url,user,password);
|
||||
// statement= connection.createStatement();
|
||||
// String sql =" select * from user";
|
||||
// ResultSet resultSet = statement.executeQuery(sql);
|
||||
// while (resultSet.next()){
|
||||
// System.out.println("wfegrth"+resultSet);
|
||||
// }
|
||||
// resultSet.close();
|
||||
// statement.close();
|
||||
// connection.close();
|
||||
//
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } catch (SQLException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.muyu.kvt.controller;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Dictionary;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -12,9 +11,9 @@ 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.dataStructure.OverallDataStructure;
|
||||
import com.muyu.kvt.datadisplay.DataDisplay;
|
||||
import com.muyu.kvt.dictionary.Diction;
|
||||
import com.muyu.kvt.dictionary.DictionaryType;
|
||||
import com.muyu.kvt.dictionary.Dictionaryy;
|
||||
|
@ -25,7 +24,6 @@ import com.muyu.kvt.domain.req.KvtSaveReq;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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.*;
|
||||
|
@ -84,7 +82,6 @@ public class KvtController extends BaseController {
|
|||
|
||||
/**
|
||||
* 新增kvt
|
||||
|
||||
*/
|
||||
@RequiresPermissions("kvt:kvt:add")
|
||||
@Log(title = "kvt ", businessType = BusinessType.INSERT)
|
||||
|
@ -133,6 +130,10 @@ public class KvtController extends BaseController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/dataTypeList")
|
||||
public Result<List<DataType>> dataTypeList(){
|
||||
List<DataType> dataTypeList=kvtService.dataTypeList();
|
||||
|
@ -140,16 +141,11 @@ public class KvtController extends BaseController {
|
|||
|
||||
}
|
||||
|
||||
// @PostMapping("/synchronizationAdd")
|
||||
// public Result synchronizationAdd (@RequestBody Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
//
|
||||
//// //构建当前授权
|
||||
//// Authorization.builder()
|
||||
//// .kvtId(kvt.getId())
|
||||
//// .uid(SecurityUtils.getUserId());
|
||||
// return kvtService.synchronizationAdd(kvt);
|
||||
//
|
||||
// }
|
||||
/**
|
||||
*
|
||||
* @param databaseName 数据库名称
|
||||
* @return
|
||||
*/
|
||||
|
||||
@PostMapping("/selectDataAuthorization")
|
||||
public Result selectDataAuthorization (@RequestParam String databaseName){
|
||||
|
@ -182,26 +178,12 @@ public class KvtController extends BaseController {
|
|||
return Result.success(structureList);
|
||||
}
|
||||
|
||||
// @PostMapping("/selectName")
|
||||
// public Result<List<String>> listResult(@RequestParam String name) throws SQLException, ClassNotFoundException {
|
||||
// Kvt kvt= kvtService.listResult(name);
|
||||
// List<String> list= kvtService.kvtList(kvt);
|
||||
// return Result.success(list);
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/assetStructureResponse")
|
||||
// public Result<List<AssetStructureResponse>> assetStructureResponse( ) throws SQLException, ClassNotFoundException {
|
||||
// List<AssetStructureResponse> assetStructureList= kvtService.assetStructureResponse();
|
||||
//
|
||||
// return Result.success(assetStructureList) ;
|
||||
// }
|
||||
|
||||
@PostMapping("/selectChild")
|
||||
public Result<Child> selectChild(@RequestParam String tableName){
|
||||
Child child= kvtService.selectChild(tableName);
|
||||
return Result.success(child);
|
||||
}
|
||||
|
||||
//查询数据结构
|
||||
@PostMapping("/selectChildAll")
|
||||
public Result<List<DataStructure>> selectChildAll(){
|
||||
List<DataStructure> childList=kvtService.selectChildAll();
|
||||
|
@ -224,12 +206,9 @@ public class KvtController extends BaseController {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
//同步数据添加到数据库
|
||||
@PostMapping("/synchronizationAdd")
|
||||
public Result synchronizationAdd(@RequestBody Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
|
||||
return kvtService.synchronizationAdd(kvt);
|
||||
}
|
||||
//添加字典
|
||||
|
@ -250,12 +229,34 @@ public class KvtController extends BaseController {
|
|||
@PostMapping("/selectDictionaryTypeId")
|
||||
public Result selectDictionaryTypeId(@RequestBody Dictionaryy dictionaryy) {
|
||||
Dictionaryy dictionaryType = kvtService.selectDictionaryTypeId(dictionaryy.getId());
|
||||
if (dictionaryy !=null ){
|
||||
if (dictionaryType !=null ){
|
||||
kvtService.delDictionaryTypeId(dictionaryy);
|
||||
return Result.success("修改成功");
|
||||
}
|
||||
kvtService.dictionaryTypeAdd(dictionaryy);
|
||||
return Result.success("添加成功");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据模型(字典)
|
||||
*/
|
||||
@PostMapping("utilAssetModel")
|
||||
public Result utilAssetModel(@RequestBody DataStructure dataStructure){
|
||||
kvtService.utilAssetModel(dataStructure);
|
||||
return Result.success("修改成功");
|
||||
}
|
||||
|
||||
//查询数据结构数量
|
||||
@PostMapping("/OverallDataStructure")
|
||||
public Result<OverallDataStructure> selectOver(){
|
||||
return kvtService.OverallDataStructure();
|
||||
}
|
||||
|
||||
|
||||
//查询资产展示
|
||||
@PostMapping("/selectDataDisplay")
|
||||
public Result<List<DataDisplay>> listResult(){
|
||||
List<DataDisplay> list= kvtService.listResult();
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.muyu.kvt.mapper;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.kvt.datadisplay.DataDisplay;
|
||||
import com.muyu.kvt.dept.DataSource;
|
||||
import com.muyu.kvt.dept.DeptUserKvt;
|
||||
import com.muyu.kvt.dictionary.Diction;
|
||||
import com.muyu.kvt.dictionary.DictionaryType;
|
||||
import com.muyu.kvt.dictionary.Dictionaryy;
|
||||
|
@ -75,4 +78,19 @@ public interface KvtMapper extends BaseMapper<Kvt> {
|
|||
Dictionaryy selectDictionaryTypeId(Integer id);
|
||||
|
||||
void updateDictionaryTypeId(Dictionaryy dictionaryy);
|
||||
|
||||
void DeptUserKvtAdd(DeptUserKvt build);
|
||||
|
||||
List<DataSource> selectDataSource(String tableName);
|
||||
|
||||
void utilAssetModel(DataStructure dataStructure);
|
||||
|
||||
List<Synchronization> selectSyn();
|
||||
|
||||
List<Child> list();
|
||||
|
||||
void dataDisplayAdd(@Param("dataDisplays") List<DataDisplay> dataDisplays);
|
||||
|
||||
List<DataDisplay> listResult();
|
||||
|
||||
}
|
||||
|
|
|
@ -3,11 +3,12 @@ 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.dataStructure.OverallDataStructure;
|
||||
import com.muyu.kvt.datadisplay.DataDisplay;
|
||||
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 org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
@ -21,15 +22,7 @@ Service接口
|
|||
* @date 2024-04-20
|
||||
*/
|
||||
public interface KvtService extends IService<Kvt> {
|
||||
/**
|
||||
* 查询kvt
|
||||
列表
|
||||
*
|
||||
* @param kvt kvt
|
||||
|
||||
* @return kvt
|
||||
集合
|
||||
*/
|
||||
public List<Kvt> list(Kvt kvt);
|
||||
|
||||
boolean connectionTest(Kvt kvt) throws ClassNotFoundException, SQLException;
|
||||
|
@ -37,16 +30,6 @@ public interface KvtService extends IService<Kvt> {
|
|||
List<DataType> dataTypeList();
|
||||
|
||||
|
||||
Kvt listResult(String name);
|
||||
|
||||
// List<AssetStructureList> assetStructureList() throws ClassNotFoundException, SQLException;
|
||||
|
||||
List<AssetStructureResponse> assetStructureResponse() throws ClassNotFoundException, SQLException;
|
||||
|
||||
// Result synchronizationAdd(Kvt kvt) throws SQLException, ClassNotFoundException;
|
||||
|
||||
|
||||
|
||||
List<AssetStructureList> assetStructureList();
|
||||
|
||||
List<ChildrenList> selectDepartment(String databaseName);
|
||||
|
@ -77,7 +60,11 @@ public interface KvtService extends IService<Kvt> {
|
|||
|
||||
void delDictionaryTypeId(Dictionaryy dictionaryy);
|
||||
|
||||
void utilAssetModel(DataStructure dataStructure);
|
||||
|
||||
// List<String> kvtList(Kvt kvt) throws ClassNotFoundException, SQLException;
|
||||
Result<OverallDataStructure> OverallDataStructure();
|
||||
|
||||
|
||||
List<DataDisplay> listResult();
|
||||
|
||||
}
|
||||
|
|
|
@ -3,24 +3,36 @@ package com.muyu.kvt.service.impl;
|
|||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
|
||||
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.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.kvt.dataStructure.OverallDataStructure;
|
||||
import com.muyu.kvt.datadisplay.DataDisplay;
|
||||
import com.muyu.kvt.dept.DeptUserKvt;
|
||||
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 com.muyu.kvt.remote.RemoteUserSer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.muyu.kvt.mapper.KvtMapper;
|
||||
import com.muyu.kvt.service.KvtService;
|
||||
|
||||
|
||||
/**
|
||||
* kvt
|
||||
Service业务层处理
|
||||
* Service业务层处理
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-04-20
|
||||
|
@ -34,7 +46,6 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
*
|
||||
* @param kvt kvt
|
||||
* @return kvt
|
||||
|
||||
*/
|
||||
@Override
|
||||
public List<Kvt> list(Kvt kvt) {
|
||||
|
@ -86,9 +97,6 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
|
@ -105,6 +113,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean Mysql(Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
String user = kvt.getUsername();
|
||||
String password = kvt.getPassword();
|
||||
|
@ -117,6 +126,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean PostgreSQL(Kvt kvt) throws SQLException, ClassNotFoundException {
|
||||
String user = kvt.getUsername();
|
||||
String password = kvt.getPassword();
|
||||
|
@ -129,176 +139,32 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataType> dataTypeList() {
|
||||
return baseMapper.dataTypeList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kvt listResult(String name) {
|
||||
return baseMapper.findName(name);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<AssetStructureList> assetStructureList() throws ClassNotFoundException, SQLException {
|
||||
// List<Kvt> list = list();
|
||||
// for (Kvt kvt : list) {
|
||||
// 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();
|
||||
// Class.forName(jdbcDriver);
|
||||
// Connection connection = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
// if (connection == null) {
|
||||
// throw new RuntimeException("连接失败");
|
||||
// }
|
||||
//
|
||||
// AssetStructureList assetStructureList = new AssetStructureList();
|
||||
// assetStructureList.setName(kvt.getName());
|
||||
// assetStructureList.setType(kvt.getType());
|
||||
// assetStructureList.setSystemName(kvt.getSystemName());
|
||||
// assetStructureList.setDatabaseName(kvt.getDatabaseName());
|
||||
//
|
||||
//
|
||||
// }
|
||||
// AssetStructureList assetStructureList = new AssetStructureList();
|
||||
// return assetStructureList;
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<AssetStructureResponse> assetStructureResponse() throws ClassNotFoundException, SQLException {
|
||||
List<Kvt> list = list();
|
||||
for (Kvt kvt : list) {
|
||||
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();
|
||||
Class.forName(jdbcDriver);
|
||||
Connection connection = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
if (connection==null){
|
||||
throw new RuntimeException("连接失败");
|
||||
}
|
||||
|
||||
AssetStructureList assetStructureList = new AssetStructureList();
|
||||
assetStructureList.setName(kvt.getName());
|
||||
assetStructureList.setType(kvt.getType());
|
||||
assetStructureList.setSystemName(kvt.getSystemName());
|
||||
assetStructureList.setDatabaseName(kvt.getDatabaseName());
|
||||
ArrayList<AssetStructureList> assetStructureLists = new ArrayList<>();
|
||||
assetStructureLists.add(assetStructureList);
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
String sql = "SHOW TABLES FROM "+kvt.getDatabaseName(); // 查询数据库中的所有表
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
|
||||
|
||||
List<ChildrenList> childrenLists = new ArrayList<>();
|
||||
List<AssetStructureResponse> assetStructureResponses = new ArrayList<>();
|
||||
|
||||
// 遍历结果集的列,获取表名
|
||||
while (resultSet.next()) {
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
ChildrenList childrenList = new ChildrenList();
|
||||
String tableName = resultSet.getString(i);
|
||||
|
||||
|
||||
|
||||
String remark = "SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = '" + kvt.getDatabaseName() + "' AND table_name = '" + tableName + "'";
|
||||
System.out.println(remark);
|
||||
ResultSet resultSet22 = statement.executeQuery(remark);
|
||||
if (resultSet22.next()) {
|
||||
String tableComment = resultSet22.getString(tableName);
|
||||
System.out.println("表备注:" + tableComment);
|
||||
System.out.println("seggredhjrdfg"+tableComment);
|
||||
childrenList.setName(tableComment);
|
||||
}
|
||||
|
||||
|
||||
String count = "SELECT COUNT(*) AS total_records FROM "+tableName; // 查询数据库中的所有表
|
||||
ResultSet resultSet11 = statement.executeQuery(count);
|
||||
if (resultSet11.next()){
|
||||
int totalRecords = resultSet11.getInt(tableName);
|
||||
childrenList.setDataTotal(totalRecords);
|
||||
}
|
||||
|
||||
|
||||
childrenList.setAs(tableName);
|
||||
|
||||
|
||||
// childrenList.setType(kvt.getType());
|
||||
childrenLists.add(childrenList);
|
||||
}
|
||||
}
|
||||
AssetStructureResponse build = AssetStructureResponse.builder()
|
||||
.assetStructureLists(assetStructureLists)
|
||||
.childrenLists(childrenLists)
|
||||
.build();
|
||||
assetStructureResponses.add(build );
|
||||
}
|
||||
|
||||
return assetStructureResponse();
|
||||
}
|
||||
|
||||
// @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() {
|
||||
List<AssetStructureList> assetStructureListList = baseMapper.assetStructureList();
|
||||
|
||||
return baseMapper.assetStructureList();
|
||||
// private Integer kvtNumber;
|
||||
// private Integer tableSum;
|
||||
// private Integer sum;
|
||||
int kvtNumber = assetStructureListList.size();
|
||||
int tableSum = 0;
|
||||
int sum = 0;
|
||||
int count = 0;
|
||||
|
||||
return assetStructureListList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChildrenList> selectDepartment(String databaseName) {
|
||||
List<ChildrenList> list = baseMapper.selectDepartment(databaseName);
|
||||
Kvt kvt = baseMapper.selectType(databaseName);
|
||||
// Kvt kvt = baseMapper.selectType(databaseName);
|
||||
List<ChildrenList> childrenLists = new ArrayList<>();
|
||||
for (ChildrenList childrenList : list) {
|
||||
ChildrenList build = ChildrenList.builder()
|
||||
|
@ -361,16 +227,6 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
return build;
|
||||
}).toList();
|
||||
return dictions1;
|
||||
// List<DictionaryType> dictTypeList = list(new LambdaQueryWrapper<>() {{
|
||||
// eq(Dictionaryy::get, id);
|
||||
// }});
|
||||
//
|
||||
// List<Diction> dictDataRespList = dictTypeList.stream().map(dictType -> {
|
||||
// List<DictData> dictDataList = dictDataService.list(new LambdaQueryWrapper<>() {{
|
||||
// eq(DictData::getDictTypeId, dictType.getId());
|
||||
// }});
|
||||
// return dictType.toDataDictResp(dictDataList);
|
||||
// }).toList();
|
||||
|
||||
}
|
||||
|
||||
|
@ -381,18 +237,18 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步数据
|
||||
* @param kvt
|
||||
*/
|
||||
@Override
|
||||
public Result synchronizationAdd(Kvt kvt){
|
||||
int count =0;
|
||||
@Autowired
|
||||
private RemoteUserSer remoteUserSer;
|
||||
|
||||
public Result mysql(Kvt kvt) {
|
||||
|
||||
//用户名
|
||||
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 = " ";
|
||||
|
@ -400,54 +256,115 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
Class.forName(jdbcDriver);
|
||||
|
||||
connection = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
|
||||
if (connection == null){
|
||||
return Result.error("连接失败");
|
||||
}
|
||||
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 = ?";
|
||||
// 根据 库名查询所有的表名
|
||||
String sql1 = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='" + kvt.getDatabaseName() + "'";
|
||||
ResultSet resultSet = statement.executeQuery(sql1);
|
||||
|
||||
//处理数据库查询结果的循环结构
|
||||
while (resultSet.next()) {
|
||||
|
||||
//获取表名
|
||||
String tableName = resultSet.getString("table_name");
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
||||
|
||||
//添加资产展示数据
|
||||
this.dataDisplayAdd(tableName,connection,kvt);
|
||||
//添加数据结构
|
||||
this.dataStructureAdd(connection,kvt,tableName);
|
||||
|
||||
}
|
||||
|
||||
this.selectDatabaseName(connection, kvt);
|
||||
|
||||
|
||||
Result<SysUser> sysUserResult = remoteUserSer.selectUserId(SecurityUtils.getUserId());
|
||||
SysUser data = sysUserResult.getData();
|
||||
DeptUserKvt build = DeptUserKvt.builder()
|
||||
.userId(SecurityUtils.getUserId())
|
||||
.kvtId(kvt.getId())
|
||||
.deptId(data.getDeptId()).build();
|
||||
baseMapper.DeptUserKvtAdd(build);
|
||||
|
||||
resultSet.close();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return Result.success("mysql同步成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步添加资产展示
|
||||
* @param tableName
|
||||
* @param connection
|
||||
* @param kvt
|
||||
*/
|
||||
public void dataDisplayAdd(String tableName,Connection connection,Kvt kvt) {
|
||||
try {
|
||||
//查询表中的数据
|
||||
String selectSql = "SELECT * FROM " + tableName;
|
||||
|
||||
Statement stmt = connection.createStatement();
|
||||
|
||||
//执行查询sql语句
|
||||
ResultSet resultSet2 = stmt.executeQuery(selectSql);
|
||||
|
||||
ResultSetMetaData metaDataTest = resultSet2.getMetaData();
|
||||
|
||||
int columnCount = metaDataTest.getColumnCount();
|
||||
|
||||
|
||||
List<DataDisplay> dataDisplays = new ArrayList<>();
|
||||
|
||||
while (resultSet2.next()) {
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
DataDisplay dataDisplay = new DataDisplay();
|
||||
String columnName = metaDataTest.getColumnName(i);
|
||||
//资产展示类型
|
||||
String typeName = metaDataTest.getColumnTypeName(i);
|
||||
dataDisplay.setValue(resultSet2.getObject(i));
|
||||
dataDisplay.setType(typeName);
|
||||
dataDisplay.setWarName(kvt.getDatabaseName() + "-" + tableName + "-" + columnName);
|
||||
dataDisplays.add(dataDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(dataDisplays);
|
||||
if(dataDisplays!=null && dataDisplays.size()!=0){
|
||||
baseMapper.dataDisplayAdd(dataDisplays);
|
||||
}
|
||||
resultSet2.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("添加资产展示数据有误",e);
|
||||
}
|
||||
log.info("资产展示添加成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*添加数据结构
|
||||
* @param connection
|
||||
* @param kvt
|
||||
* @param tableName
|
||||
*/
|
||||
private void dataStructureAdd(Connection connection,Kvt kvt,String tableName){
|
||||
try{
|
||||
//执行一个预编译的 SQL 查询
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(this.sql()
|
||||
+ " TABLE_SCHEMA = ?\n"
|
||||
+ " AND TABLE_NAME = ?");
|
||||
preparedStatement.setString(1, kvt.getDatabaseName()); // 设置第一个参数的值
|
||||
preparedStatement.setString(2, tableName); // 设置第二个参数的值
|
||||
ResultSet executeQuery = preparedStatement.executeQuery();
|
||||
while (executeQuery.next()) {
|
||||
|
||||
String name = executeQuery.getString("name");
|
||||
/**
|
||||
* 注释
|
||||
|
@ -481,8 +398,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
* 默认值
|
||||
*/
|
||||
String defaultValue = executeQuery.getString("defaultValue");
|
||||
// String isDict = executeQuery.getString("isDict");
|
||||
// String dictKey = executeQuery.getString("dictKey");
|
||||
|
||||
DataStructure build = DataStructure.builder()
|
||||
.tableName(tableName)
|
||||
.warName(kvt.getDatabaseName())
|
||||
|
@ -499,35 +415,106 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
.dictKey(null)
|
||||
.build();
|
||||
baseMapper.add(build);
|
||||
}
|
||||
executeQuery.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("添加数据结构失败");
|
||||
}
|
||||
log.info("添加数据结构成功");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 查询数据库中表的总条数 以及备注 名称
|
||||
* @param connection
|
||||
* @param kvt
|
||||
*/
|
||||
public void selectDatabaseName(Connection connection,Kvt kvt){
|
||||
try {
|
||||
//查询总条数
|
||||
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 = ?";
|
||||
PreparedStatement preparedStatement2 = connection.prepareStatement(sql2);
|
||||
preparedStatement2.setString(1, kvt.getDatabaseName()); // 设置第一个参数的值
|
||||
ResultSet query = preparedStatement2.executeQuery();
|
||||
while (query.next()) {
|
||||
count++;
|
||||
String name2 = query.getString("name");
|
||||
//表名
|
||||
String name = query.getString("name");
|
||||
//备注
|
||||
String as = query.getString("as");
|
||||
//总数量
|
||||
String dataTotal = query.getString("dataTotal");
|
||||
|
||||
Child build1 = Child.builder()
|
||||
.dataTotal(Integer.valueOf(dataTotal))
|
||||
.name(name2)
|
||||
.name(name)
|
||||
.as(as)
|
||||
.isPrimaryKey(null)
|
||||
.build();
|
||||
baseMapper.childAdd(build1);
|
||||
}
|
||||
|
||||
resultSet.close();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
log.info("查询总条数成功");
|
||||
}
|
||||
|
||||
public Result postgres(Kvt kvt) {
|
||||
Connection connection = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
// 加载 PostgreSQL 驱动类
|
||||
Class.forName("org.postgresql.Driver");
|
||||
|
||||
// 创建数据库连接
|
||||
String url = "jdbc:postgresql://" + kvt.getHost() + ":" + kvt.getPort() + "/" + kvt.getDatabaseName();
|
||||
String user = kvt.getUsername();
|
||||
String password = kvt.getPassword();
|
||||
connection = DriverManager.getConnection(url, user, password);
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';");
|
||||
|
||||
while (resultSet.next()) {
|
||||
String name = resultSet.getString("name");
|
||||
System.out.println("name" + name);
|
||||
}
|
||||
resultSet.close();
|
||||
statement.close();
|
||||
connection.close();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return Result.success("postgres同步成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步数据
|
||||
*
|
||||
* @param kvt
|
||||
*/
|
||||
@Override
|
||||
public Result synchronizationAdd(Kvt kvt) {
|
||||
//先判断哪种数据库
|
||||
if (kvt.getType() == 1) {
|
||||
mysql(kvt);
|
||||
} else {
|
||||
postgres(kvt);
|
||||
}
|
||||
return Result.success("同步成功");
|
||||
}
|
||||
|
||||
|
@ -551,149 +538,58 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
baseMapper.updateDictionaryTypeId(dictionaryy);
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public List<String> kvtList(Kvt kvt) {
|
||||
// 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;
|
||||
// List<String> tables = new ArrayList<>();
|
||||
//
|
||||
// try {
|
||||
// Class.forName(jdbcDriver);
|
||||
// connection = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
// Statement statement = connection.createStatement();
|
||||
// String sql = "SHOW TABLES"; // 查询数据库中的所有表
|
||||
// ResultSet resultSet = statement.executeQuery(sql);
|
||||
// ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
// int columnCount = metaData.getColumnCount();
|
||||
//
|
||||
// // 遍历结果集的列,获取表名
|
||||
// while (resultSet.next()) {
|
||||
// for (int i = 1; i <= columnCount; i++) {
|
||||
// String tableName = resultSet.getString(i);
|
||||
// tables.add(tableName);
|
||||
// System.out.println("表名:" + tableName);
|
||||
// }
|
||||
// }
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (SQLException e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// // 关闭连接
|
||||
// if (connection != null) {
|
||||
// try {
|
||||
// connection.close();
|
||||
// } catch (SQLException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// 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, "同步成功");
|
||||
@Override
|
||||
public void utilAssetModel(DataStructure dataStructure) {
|
||||
baseMapper.utilAssetModel(dataStructure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<OverallDataStructure> OverallDataStructure() {
|
||||
List<Synchronization> synchronizationList = baseMapper.selectSyn();
|
||||
List<Child> list = baseMapper.list();
|
||||
IntStream intStream = list.stream().mapToInt(Child::getDataTotal);
|
||||
OverallDataStructure build = OverallDataStructure.builder()
|
||||
.table(list.size())
|
||||
.datas(intStream.sum() + list.size())
|
||||
.kvt(synchronizationList.size())
|
||||
.build();
|
||||
|
||||
return Result.success(build);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDisplay> listResult() {
|
||||
return baseMapper.listResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 根据库名跟表名查询字段信息
|
||||
* @return
|
||||
*/
|
||||
private String sql () {
|
||||
//查询 根据库名跟表名查询字段信息
|
||||
return "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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
WHERE `id` = #{id}
|
||||
|
||||
|
||||
</update>
|
||||
<update id="utilAssetModel">
|
||||
UPDATE `data_basete`.`data_structure`
|
||||
SET `war_name` = #{warName},
|
||||
`table_name` = #{tableName},
|
||||
`name` = #{name},
|
||||
`comment` = #{comment},
|
||||
`isPrimaryKey` = #{isPrimaryKey},
|
||||
`type` = #{type},
|
||||
`mappingType` = #{mappingType},
|
||||
`length` = #{length},
|
||||
`decimalPlaces` = #{decimalPlaces},
|
||||
`isNull` = #{isNull},
|
||||
`defaultValue` = #{defaultValue},
|
||||
`isDict` = #{isDict},
|
||||
`dictKey` = #{dictKey},
|
||||
`value` = #{value}
|
||||
WHERE `id` = #{id};
|
||||
|
||||
|
||||
</update>
|
||||
<delete id="del">
|
||||
truncate table #{tableName}
|
||||
|
@ -104,9 +124,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<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>
|
||||
|
@ -138,6 +156,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="selectDictionaryTypeId" resultType="com.muyu.kvt.dictionary.Dictionaryy">
|
||||
select * from dictionary where id =#{id}
|
||||
</select>
|
||||
<select id="selectDataSource" resultType="com.muyu.kvt.dept.DataSource">
|
||||
select * from data_structure where table_name =#{tableName}
|
||||
</select>
|
||||
<select id="selectChildAll" resultType="com.muyu.kvt.domain.DataStructure">
|
||||
select * from child
|
||||
</select>
|
||||
<select id="selectSyn" resultType="com.muyu.kvt.domain.Synchronization">
|
||||
select * from synchronization
|
||||
</select>
|
||||
<select id="list" resultType="com.muyu.kvt.domain.Child">
|
||||
select * from child
|
||||
</select>
|
||||
<select id="listResult" resultType="com.muyu.kvt.datadisplay.DataDisplay">
|
||||
select * from data_display
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="synchronizationAdd">
|
||||
|
@ -197,9 +230,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</insert>
|
||||
<insert id="dictionTypeAdd">
|
||||
INSERT INTO `data_basete`.`dictionary_type`
|
||||
( `name`, `type`, `status`)
|
||||
VALUES (#{name}, #{type}, #{status});
|
||||
(`data_access`, `name`, `type`, `status`)
|
||||
VALUES (#{dataAccess},#{name}, #{type}, #{status});
|
||||
|
||||
|
||||
</insert>
|
||||
<insert id="DeptUserKvtAdd">
|
||||
INSERT INTO `data_basete`.`detp_user_kvt`
|
||||
( `user_id`, `kvt_id`, `dept_id`)
|
||||
VALUES ( #{userId}, #{kvtId}, #{deptId});
|
||||
</insert>
|
||||
<insert id="dictionTypeAd">
|
||||
INSERT INTO `data_basete`.`dictionary`
|
||||
( `dictionary_name`, `dictionary_value`, `type`, `diction_status`
|
||||
)
|
||||
VALUES ( #{dictionaryName}, #{dictionaryValue}, #{type}, 0);
|
||||
|
||||
|
||||
</insert>
|
||||
<insert id="dataDisplayAdd">
|
||||
INSERT INTO `data_basete`.`data_display`
|
||||
(`war_name`, `type`, `value`)
|
||||
VALUES
|
||||
<foreach collection="dataDisplays" item="dataDisplays" separator=",">
|
||||
(#{dataDisplays.warName}, #{dataDisplays.type}, #{dataDisplays.value})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.muyu.common.security.annotation.EnableMyFeignClients;
|
|||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* 系统模块
|
||||
|
|
|
@ -306,5 +306,12 @@ public class SysUserController extends BaseController {
|
|||
return success(deptService.selectDeptTreeList(dept));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/selectUserId")
|
||||
public Result<SysUser> selectUserId(@RequestParam("userId") Long userId){
|
||||
SysUser sysUser = userService.selectUserById(userId);
|
||||
return Result.success(sysUser);
|
||||
}
|
||||
|
||||
// @PostMapping("/updateUserPermissions")
|
||||
// public Result updateUserPermissions(@RequestBody )
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue