Commit 358902a4 by 宋珺琪

数据表统计功能修改(西藏)

parent d0a429d2
......@@ -15,10 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.*;
import java.util.*;
/**
......@@ -32,7 +29,8 @@ public class DatabaseController {
@OperLog(message = "表名模糊搜索",operation = OperationType.QUERY)
@PostMapping("/selecttable")
@ApiOperation(value = "表名模糊搜索")
public MapRestResult selecttable(@RequestParam(required = false) String table,
public MapRestResult selecttable(@RequestParam(required = false) String type,
@RequestParam(required = false) String table,
@RequestParam(name = "page", defaultValue = "1") Integer page,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
......@@ -51,18 +49,55 @@ public class DatabaseController {
Connection connect = JDBCUtil.getConnection();
Statement stmt =null;
ResultSet rs = null;
// ("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and (TABLE_NAME like 'sk%' or TABLE_NAME like 'ksh%') ")
try
{
// Connection connect = DriverManager.getConnection("jdbc:mysql://47.92.48.137:3900/skyp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai", "root","gkptCcYy123");
// 连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码
stmt = connect.createStatement();
if (StringUtil.isEmpty(table)){
stmt = connect.createStatement();
if (!StringUtil.isEmpty(type) && StringUtil.isEmpty(table) && type.equals("sk")){
//sk 列表
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and TABLE_NAME like 'sk%' ");
}else if (!StringUtil.isEmpty(type) && StringUtil.isEmpty(table) && type.equals("ksh")){
//ksh 列表
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and TABLE_NAME like 'ksh%' ");
}else if (!StringUtil.isEmpty(type) && StringUtil.isEmpty(table) && type.equals("xz")){
//xz 列表
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and (TABLE_NAME not like 'sk%' and TABLE_NAME not like 'ksh%') ");
}else if (!StringUtil.isEmpty(type) && !StringUtil.isEmpty(table) && type.equals("sk")){
//sk 模糊
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and TABLE_NAME like '%"+table+"%' and TABLE_NAME like 'sk%' ");
}else if (!StringUtil.isEmpty(type) && !StringUtil.isEmpty(table) && type.equals("ksh")){
//ksh 模糊
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and TABLE_NAME like '%"+table+"%'and TABLE_NAME like 'ksh%' ");
}else if (!StringUtil.isEmpty(type) && !StringUtil.isEmpty(table) && type.equals("xz")){
//xz 模糊
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and TABLE_NAME like '%"+table+"%'and (TABLE_NAME not like 'sk%' and TABLE_NAME not like 'ksh%') ");
} else if (StringUtil.isEmpty(type)&& StringUtil.isEmpty(table)){
//查询所有的
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' ");//limit " + page + ","+pageSize+"
}else if(StringUtil.isEmpty(type)&& !StringUtil.isEmpty(table)){
// 模糊查询
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and TABLE_NAME like '%"+table+"%'");
}
// ("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and TABLE_NAME like '%"+table+"%' and (TABLE_NAME like 'sk%' or TABLE_NAME like 'ksh%')");
/* if (StringUtil.isEmpty(table)){
//查询所有的
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and (TABLE_NAME like 'sk%' or TABLE_NAME like 'ksh%') ");//limit " + page + ","+pageSize+"
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' ");//limit " + page + ","+pageSize+"
}else {
// 模糊查询
rs = stmt.executeQuery
("select TABLE_NAME '表名称',table_comment '表说明',CREATE_TIME '创建时间' from information_schema.tables where table_schema='skyp' and TABLE_NAME like '%"+table+"%' and (TABLE_NAME like 'sk%' or TABLE_NAME like 'ksh%')");
}
}*/
// sk 、 ksh 、xz 三种类型
while (rs.next())
{
Map<Object, Object> map = new HashMap<>();
......@@ -98,6 +133,73 @@ public class DatabaseController {
}
@OperLog(message = "统计表",operation = OperationType.QUERY)
@PostMapping("/count")
@ApiOperation(value = "统计表")
public MapRestResult count(String table) throws SQLException {
Connection connect = JDBCUtil.getConnection();
Statement stmt =null;
Statement stmt1 =null;
Statement stmt2 =null;
ResultSet rs = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
Map<Object, Object> map = new HashMap<>();
int count = 0;
try {
stmt = connect.createStatement();
rs = stmt.executeQuery
("SELECT COUNT(*)count from information_schema.tables where table_schema='skyp' and table_name like 'ksh%'");
if(rs.next()){
int ksh = rs.getInt("count");
count+= ksh;
map.put("ksh",ksh);
rs.last();
}
stmt1 = connect.createStatement();
rs1 = stmt1.executeQuery
("SELECT COUNT(*)count from information_schema.tables where table_schema='skyp' and table_name like 'sk%'");
if(rs1.next()){
int sk = rs1.getInt("count");
count+=sk;
map.put("sk",sk);
rs.last();
}
stmt2 = connect.createStatement();
rs2 = stmt2.executeQuery
("SELECT COUNT(*)count from information_schema.tables where table_schema='skyp' and (TABLE_NAME not like 'sk%' and TABLE_NAME not like 'ksh%')");
if(rs2.next()){
int xz = rs2.getInt("count");
count+=xz;
map.put("xz",xz);
rs.last();
}
/* while (rs.next())
{
int ksh = rs.getInt("count");
map.put("sk",ksh);
map.put("ksh",);
map.put("xz",);
}*/
}
catch (Exception e)
{
e.printStackTrace();
return new MapRestResult().error("get data error!");
}finally {
stmt1.close();
stmt2.close();
rs1.close();
rs2.close();
JDBCUtil.close(connect, stmt, rs);
}
return new MapRestResult(200,"ok",count,map);
}
@OperLog(message = "表详情",operation = OperationType.QUERY)
@PostMapping("/details")
@ApiOperation(value = "表详情")
......@@ -119,8 +221,8 @@ public class DatabaseController {
{
// Connection connect = DriverManager.getConnection("jdbc:mysql://47.92.48.137:3900/skyp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai", "root","gkptCcYy123");
// 连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码
stmt = connect.createStatement();
rs = stmt.executeQuery
stmt = connect.createStatement();
rs = stmt.executeQuery
("select COLUMN_NAME '列名',COLUMN_TYPE '类型' ,COLUMN_COMMENT '字段说明' from information_schema.COLUMNS where TABLE_NAME='"+table+"'");
while (rs.next())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment