type(AccreditServiceImpl,DataAccessServiceImpl)根据表单查询相应的表结构和表框架,新增接入同时会加入相应数据库的表结构和表框架

dev-1
王熙朝 2024-04-23 22:28:19 +08:00
parent 0324d7c70d
commit 8e2250f874
10 changed files with 310 additions and 33 deletions

View File

@ -3,6 +3,8 @@ package com.muyu.system.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.system.domain.SysUser;
import com.muyu.system.domain.ListStructure;
import com.muyu.system.domain.TableList;
import com.muyu.system.domain.TableName;
import com.muyu.system.domain.vo.DeptVO;
import com.muyu.system.domain.vo.SysUserVo;
@ -34,8 +36,8 @@ public class AccreditController extends BaseController {
* @return
*/
@PostMapping("tableNameList")
public Result<List<TableName>> tableNameList(){
List<TableName> list = service.tableNameList();
public Result<List<TableList>> tableNameList(){
List<TableList> list = service.tableNameList();
return Result.success(list);
}
@ -44,14 +46,19 @@ public class AccreditController extends BaseController {
* @return
*/
@GetMapping("tableNameList2")
public Result<List<String>> tableNameList2(){
public Result<List<String>> tableNameList2() throws SQLException {
List<String> list = service.tableNameList2();
return Result.success(list);
}
/**
*
* @return
* @throws SQLException
*/
@GetMapping("listSqlJdbc")
public Result listSqlJdbc() throws SQLException {
return service.listSqlJdbc();
public Result listSqlJdbc(@RequestParam String tableName) throws SQLException {
return service.listSqlJdbc(tableName);
}
/**
@ -85,4 +92,36 @@ public class AccreditController extends BaseController {
return success(list);
}
/**
*
* @return
*/
@PostMapping("/listListstructure")
public Result<List<ListStructure>> listListstructure(){
List<ListStructure> list = service.listListstructure();
return success(list);
}
/**
*
* @param name
* @return
*/
@PostMapping("selNameTableList/{name}")
public Result<TableList> selNameTableList(@PathVariable String name){
TableList tableList = service.selNameTableList(name);
return success(tableList);
}
/**
*
* @param tableName
* @return
*/
@PostMapping("/selNameListStructure/{tableName}")
public Result<List<ListStructure>> selNameListStructure(@PathVariable String tableName){
List<ListStructure> list = service.selNameListStructure(tableName);
return success(list);
}
}

View File

@ -0,0 +1,48 @@
package com.muyu.system.domain;
import lombok.Data;
@Data
public class ListStructure {
/**
*
*/
private String catalogName;
/**
*
*/
private String tableName;
/**
* java
*/
private String columnLassName;
/**
*
*/
private String columnTypeName;
/**
*
*/
private String columnName;
/**
*
*/
private Integer precisions;
/**
*
*/
private Integer scale;
/**
*
*/
private Integer isNull;
/**
*
*/
private String schemaName;
/**
*
*/
private String columnComments;
}

View File

@ -0,0 +1,25 @@
package com.muyu.system.domain;
import lombok.Data;
@Data
public class TableList {
/**
*
*/
private String name;
/**
*
*/
private String as;
/**
*
*/
private Integer dataTotal;
/**
*
*/
private String type;
private TableList tableList;
}

View File

@ -0,0 +1,15 @@
package com.muyu.system.domain;
import lombok.Data;
@Data
public class dictionaryMajor {
/**
*
*/
private String dictionaryName;
/**
*
*/
private Integer dictionaryExpression;
}

View File

@ -15,7 +15,7 @@ public class TableVo {
/**
*
*/
private String TableName;
private String tableName;
/**
*
*/
@ -25,7 +25,7 @@ public class TableVo {
*/
private String ordinalPosition;
/**
*
*
*/
private String columnDefault;
/**
@ -35,7 +35,7 @@ public class TableVo {
/**
*
*/
private String dateType;
private String dataType;
/**
*
*/
@ -61,11 +61,11 @@ public class TableVo {
*/
private String characterSetName;
/**
*
*
*/
private String collationName;
/**
*
*
*/
private String columnType;
/**

View File

@ -1,6 +1,8 @@
package com.muyu.system.mapper;
import com.muyu.system.domain.Library;
import com.muyu.system.domain.ListStructure;
import com.muyu.system.domain.TableList;
import com.muyu.system.domain.TableName;
import com.muyu.system.domain.vo.TableVo;
import org.apache.ibatis.annotations.Param;
@ -8,7 +10,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface AccreditMapper {
List<TableName> tableNameList();
List<TableList> tableNameList();
String database();
@ -21,6 +23,18 @@ public interface AccreditMapper {
void indexTableName(@Param("s") String s);
void indexListStructure(@Param("columnClassName") String columnClassName, @Param("columnTypeName") String columnTypeName, @Param("columnName") String columnName, @Param("tableName") String tableName, @Param("catalogName") String catalogName);
void insertListStructure(ListStructure listStructure);
void inserttableList(@Param("s") String s);
List<ListStructure> listListstructure();
TableList selNameTableList(@Param("name") String name);
List<ListStructure> selNameListStructure(@Param("tableName") String tableName);
int selectOneTableList(@Param("s") String s);
int selectOneSqlJdbc(@Param("s") String s);
}

View File

@ -2,6 +2,8 @@ package com.muyu.system.service;
import com.muyu.common.core.domain.Result;
import com.muyu.system.domain.Library;
import com.muyu.system.domain.ListStructure;
import com.muyu.system.domain.TableList;
import com.muyu.system.domain.TableName;
import com.muyu.system.domain.vo.TableVo;
@ -9,11 +11,17 @@ import java.sql.SQLException;
import java.util.List;
public interface AccreditService {
List<TableName> tableNameList();
List<TableList> tableNameList();
List<TableVo> selectTableXml(String tableName);
List<String> tableNameList2();
List<String> tableNameList2() throws SQLException;
Result listSqlJdbc() throws SQLException;
Result listSqlJdbc(String tableName) throws SQLException;
List<ListStructure> listListstructure();
TableList selNameTableList(String name);
List<ListStructure> selNameListStructure(String tableName);
}

View File

@ -2,6 +2,8 @@ package com.muyu.system.service.impl;
import com.muyu.common.core.domain.Result;
import com.muyu.system.domain.Library;
import com.muyu.system.domain.ListStructure;
import com.muyu.system.domain.TableList;
import com.muyu.system.domain.TableName;
import com.muyu.system.domain.vo.TableVo;
import com.muyu.system.mapper.AccreditMapper;
@ -10,15 +12,17 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class AccreditServiceImpl implements AccreditService {
@Autowired
private AccreditMapper mapper;
@Override
public List<TableName> tableNameList() {
List<TableName> list = mapper.tableNameList();
public List<TableList> tableNameList() {
List<TableList> list = mapper.tableNameList();
System.out.println(list);
return list;
}
@ -32,37 +36,131 @@ public class AccreditServiceImpl implements AccreditService {
}
@Override
public List<String> tableNameList2() {
public List<String> tableNameList2() throws SQLException {
List<String> list = mapper.tableNameList2();
for (String s : list) {
if (mapper.getNameSelTable(s)>1){
int i = mapper.selectOneTableList(s);
if (i>0){
}else{
mapper.indexTableName(s);
mapper.inserttableList(s);
}
int i1 = mapper.selectOneSqlJdbc(s);
if (i1>0){
}else{
listSqlJdbc(s);
}
}
return list;
}
@Override
public Result listSqlJdbc() throws SQLException {
public Result listSqlJdbc(String tableName) throws SQLException {
PreparedStatement pst = null;
Connection conn = null;
String database = mapper.database();
conn = DriverManager.getConnection("jdbc:mysql://129.211.23.219:3306/"+ database +"?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8","root","Qq4152637");
try {
pst = conn.prepareCall("select * from admin");
ResultSetMetaData rsd = pst.executeQuery().getMetaData();
pst = conn.prepareCall("select * from " + tableName);
// ResultSetMetaData rsd = pst.executeQuery().getMetaData();
ResultSetMetaData rsd = pst.getMetaData();
//获取元数据
DatabaseMetaData metaData = conn.getMetaData();
Map<String,String> columnComments =getColumnComments(metaData,tableName);
for (int i = 0; i < rsd.getColumnCount(); i++) {
System.out.println("java类型"+rsd.getColumnClassName(i+1));
System.out.println("数据库类型"+rsd.getColumnTypeName(i+1));
System.out.println("字段名称"+rsd.getColumnName(i+1));
System.out.println("表名"+rsd.getTableName(i+1));
System.out.println("数据库名"+rsd.getCatalogName(i+1));
mapper.indexListStructure(rsd.getColumnClassName(i+1),rsd.getColumnTypeName(i+1),rsd.getColumnName(i+1),rsd.getTableName(i+1),rsd.getCatalogName(i+1));
System.out.println("模式名"+rsd.getSchemaName(i+1));
System.out.println("列数"+rsd.getColumnCount());
System.out.println("列类型"+rsd.getColumnType(i+1));
System.out.println("列标签"+rsd.getColumnLabel(i+1));
System.out.println("列显示大小"+rsd.getColumnDisplaySize(i+1));
System.out.println("精度"+rsd.getPrecision(i+1));
System.out.println("规模"+rsd.getScale(i+1));
System.out.println("自增"+rsd.isAutoIncrement(i+1));
System.out.println("是否为空"+rsd.isNullable(i+1));
System.out.println("区分大小写"+rsd.isCaseSensitive(i+1));
System.out.println("是否是货币"+rsd.isCurrency(i+1));
System.out.println("可搜索"+rsd.isSearchable(i+1));
System.out.println("签署"+rsd.isSigned(i+1));
System.out.println("绝对可以写"+rsd.isDefinitelyWritable(i+1));
System.out.println("只读"+rsd.isReadOnly(i+1));
System.out.println("是可写的"+rsd.isWritable(i+1));
System.out.println("注解"+columnComments.get(rsd.getColumnName(i+1)));
ListStructure listStructure = new ListStructure();
//获取数据库名
listStructure.setCatalogName(rsd.getCatalogName(i+1));
//获取表名
listStructure.setTableName(rsd.getTableName(i+1));
//获取java类型
listStructure.setColumnLassName(rsd.getColumnClassName(i+1));
//获取映射类型
listStructure.setColumnTypeName(rsd.getColumnTypeName(i+1));
//获取字段名称
listStructure.setColumnName(rsd.getColumnName(i+1));
//获取长度
listStructure.setPrecisions(rsd.getPrecision(i+1));
//获取小数
listStructure.setScale(rsd.getScale(i+1));
//获取非空
listStructure.setIsNull(rsd.isNullable(i+1));
//获取默认
listStructure.setSchemaName(rsd.getSchemaName(i+1));
//获取注解
listStructure.setColumnComments(columnComments.get(rsd.getColumnName(i+1)));
mapper.insertListStructure(listStructure);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return Result.success("");
return Result.success("OK");
}
@Override
public List<ListStructure> listListstructure() {
return mapper.listListstructure();
}
@Override
public TableList selNameTableList(String name) {
return mapper.selNameTableList(name);
}
@Override
public List<ListStructure> selNameListStructure(String tableName) {
return mapper.selNameListStructure(tableName);
}
//获取字段注解
private Map<String,String> getColumnComments(DatabaseMetaData metaData,String typeName){
Map<String,String> columnComents = new HashMap<>();
try (ResultSet colums = metaData.getColumns(null,null,typeName,null)){
while (colums.next()){
String columsName = colums.getString("COLUMN_NAME");
String columsComment = colums.getString("REMARKS");
columnComents.put(columsName,columsComment);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return columnComents;
}
//获取字段默认值
private Map<String,String> getDefault(DatabaseMetaData metaData,String defaultName){
Map<String,String> defaults = new HashMap<>();
try (ResultSet colums = metaData.getColumns(null,null,defaultName,null)){
while (colums.next()){
String columsName = colums.getString("COLUMN_NAME");
String defaultComment = colums.getString("COLUMN_DEFAULT");
defaults.put(columsName,defaultComment);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return defaults;
}
}

View File

@ -65,9 +65,10 @@ public class DataAccessServiceImpl implements IDataAccessService
List<SysDept> list = sysDeptMapper.listDeptList();
DataAccess dataAccess1 = dataAccessMapper.oneDataAccess();
for (SysDept sysDept : list) {
//添加中间件
dataAccessMapper.insertMiddle(sysDept.getDeptId(),dataAccess1.getId());
}
accreditService.listSqlJdbc();
accreditService.tableNameList2();
return i;
}

View File

@ -7,14 +7,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into table_name (table_name)
values (#{s});
</insert>
<insert id="indexListStructure">
insert into list_structure (column_lass_ame,column_type_name,column_name,table_name,catalog_name)
values (#{columnClassName},#{columnTypeName},#{columnName},#{tableName},#{catalogName});
<insert id="insertListStructure">
insert into list_structure (catalog_name,table_name,column_lass_name,column_type_name,column_name,precisions,scale,is_null,schema_name,column_comments)
values (#{catalogName},#{tableName},#{columnLassName},#{columnTypeName},#{columnName},#{precisions},#{scale},#{isNull},#{schemaName},#{columnComments});
</insert>
<insert id="inserttableList">
insert into tableList (name)
values (#{s});
</insert>
<select id="tableNameList" resultType="com.muyu.system.domain.TableName">
select *
from table_name
</select>
<select id="selectTableXml" resultType="com.muyu.system.domain.vo.TableVo">
SELECT *
FROM information_schema.columns
@ -30,5 +30,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(table_name)
from table_name where table_name = #{s};
</select>
<select id="tableNameList" resultType="com.muyu.system.domain.TableList">
select *
from tableList
</select>
<select id="listListstructure" resultType="com.muyu.system.domain.ListStructure">
select *
from list_structure
</select>
<select id="selNameTableList" resultType="com.muyu.system.domain.TableList">
select *
from tableList where name = #{name}
</select>
<select id="selNameListStructure" resultType="com.muyu.system.domain.ListStructure">
select *
from list_structure
<where>
<if test="tableName!=null and tableName!=''">
table_name = #{tableName}
</if>
</where>
</select>
<select id="selectOneTableList" resultType="java.lang.Integer">
select count(name)
from tableList where name = #{s};
</select>
<select id="selectOneSqlJdbc" resultType="java.lang.Integer">
select count(table_name)
from list_structure where table_name = #{s};
</select>
</mapper>