💩 修改冗余的代码
This commit is contained in:
parent
7633593bfc
commit
c47a65b5de
|
@ -12,7 +12,7 @@ public class VmsHolder {
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
prop.put("resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
||||||
Velocity.init(prop);
|
Velocity.init(prop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class TableController {
|
||||||
@Resource
|
@Resource
|
||||||
private TableService tableService;
|
private TableService tableService;
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "当前数据库信息", description = "当前连接的数据库信息")
|
@Operation(summary = "当前数据库信息", description = "当前连接的数据库信息")
|
||||||
@GetMapping("databaseInfoMetaData")
|
@GetMapping("databaseInfoMetaData")
|
||||||
public Result<DatabaseInfoMetaData> databaseInfoMetaData() {
|
public Result<DatabaseInfoMetaData> databaseInfoMetaData() {
|
||||||
|
|
|
@ -2,8 +2,8 @@ package cn.bunny.core.factory;
|
||||||
|
|
||||||
import cn.bunny.domain.entity.ColumnMetaData;
|
import cn.bunny.domain.entity.ColumnMetaData;
|
||||||
import cn.bunny.domain.entity.TableMetaData;
|
import cn.bunny.domain.entity.TableMetaData;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
@ -16,9 +16,14 @@ import java.util.Set;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public abstract class AbstractDatabaseInfo {
|
public abstract class AbstractDatabaseInfo {
|
||||||
@Resource
|
|
||||||
public DataSource dataSource;
|
public DataSource dataSource;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setDataSource(DataSource dataSource) {
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取表的所有主键列名
|
* 获取表的所有主键列名
|
||||||
*
|
*
|
||||||
|
@ -26,7 +31,7 @@ public abstract class AbstractDatabaseInfo {
|
||||||
* @return 主键列名的集合
|
* @return 主键列名的集合
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public Set<String> getPrimaryKeyColumns(String tableName) {
|
public Set<String> findPrimaryKeyColumns(String tableName) {
|
||||||
// 主键的key
|
// 主键的key
|
||||||
Set<String> primaryKeys = new HashSet<>();
|
Set<String> primaryKeys = new HashSet<>();
|
||||||
|
|
||||||
|
@ -61,4 +66,5 @@ public abstract class AbstractDatabaseInfo {
|
||||||
* @return 当前表所有的列内容
|
* @return 当前表所有的列内容
|
||||||
*/
|
*/
|
||||||
public abstract List<ColumnMetaData> tableColumnInfo(String name);
|
public abstract List<ColumnMetaData> tableColumnInfo(String name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class ConcreteDatabaseInfo extends AbstractDatabaseInfo {
|
||||||
DatabaseMetaData metaData = connection.getMetaData();
|
DatabaseMetaData metaData = connection.getMetaData();
|
||||||
Map<String, ColumnMetaData> map = new LinkedHashMap<>();
|
Map<String, ColumnMetaData> map = new LinkedHashMap<>();
|
||||||
// 当前表的主键
|
// 当前表的主键
|
||||||
Set<String> primaryKeyColumns = getPrimaryKeyColumns(tableName);
|
Set<String> primaryKeyColumns = findPrimaryKeyColumns(tableName);
|
||||||
|
|
||||||
// 当前表的列信息
|
// 当前表的列信息
|
||||||
try (ResultSet columnsRs = metaData.getColumns(null, null, tableName, null)) {
|
try (ResultSet columnsRs = metaData.getColumns(null, null, tableName, null)) {
|
||||||
|
|
|
@ -3,15 +3,15 @@ package cn.bunny.service.impl;
|
||||||
import cn.bunny.core.factory.ConcreteSqlParserDatabaseInfo;
|
import cn.bunny.core.factory.ConcreteSqlParserDatabaseInfo;
|
||||||
import cn.bunny.domain.entity.TableMetaData;
|
import cn.bunny.domain.entity.TableMetaData;
|
||||||
import cn.bunny.service.SqlParserService;
|
import cn.bunny.service.SqlParserService;
|
||||||
import jakarta.annotation.Resource;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class SqlParserServiceImpl implements SqlParserService {
|
public class SqlParserServiceImpl implements SqlParserService {
|
||||||
|
|
||||||
@Resource
|
private final ConcreteSqlParserDatabaseInfo sqlParserDatabaseInfo;
|
||||||
private ConcreteSqlParserDatabaseInfo sqlParserDatabaseInfo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析SQL内容
|
* 解析SQL内容
|
||||||
|
|
|
@ -5,19 +5,18 @@ import cn.bunny.domain.entity.ColumnMetaData;
|
||||||
import cn.bunny.domain.entity.DatabaseInfoMetaData;
|
import cn.bunny.domain.entity.DatabaseInfoMetaData;
|
||||||
import cn.bunny.domain.entity.TableMetaData;
|
import cn.bunny.domain.entity.TableMetaData;
|
||||||
import cn.bunny.service.TableService;
|
import cn.bunny.service.TableService;
|
||||||
import jakarta.annotation.Resource;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class TableServiceImpl implements TableService {
|
public class TableServiceImpl implements TableService {
|
||||||
|
|
||||||
@Resource
|
private final ConcreteDatabaseInfo databaseInfoCore;
|
||||||
private ConcreteDatabaseInfo databaseInfoCore;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取表属性
|
* 获取表属性
|
||||||
|
@ -25,15 +24,9 @@ public class TableServiceImpl implements TableService {
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
* @return 表属性
|
* @return 表属性
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
|
||||||
@Override
|
@Override
|
||||||
public TableMetaData tableMetaData(String tableName) {
|
public TableMetaData tableMetaData(String tableName) {
|
||||||
TableMetaData tableInfoVo = new TableMetaData();
|
return databaseInfoCore.getTableMetadata(tableName);
|
||||||
|
|
||||||
TableMetaData tableMetaData = databaseInfoCore.getTableMetadata(tableName);
|
|
||||||
BeanUtils.copyProperties(tableMetaData, tableInfoVo);
|
|
||||||
|
|
||||||
return tableInfoVo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,17 +34,9 @@ public class TableServiceImpl implements TableService {
|
||||||
*
|
*
|
||||||
* @return 所有表信息
|
* @return 所有表信息
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
|
||||||
@Override
|
@Override
|
||||||
public List<TableMetaData> databaseTableList(String dbName) {
|
public List<TableMetaData> databaseTableList(String dbName) {
|
||||||
List<TableMetaData> allTableInfo = databaseInfoCore.databaseTableList(dbName);
|
return databaseInfoCore.databaseTableList(dbName);
|
||||||
|
|
||||||
return allTableInfo.stream().map(tableMetaData -> {
|
|
||||||
TableMetaData tableInfoVo = new TableMetaData();
|
|
||||||
BeanUtils.copyProperties(tableMetaData, tableInfoVo);
|
|
||||||
|
|
||||||
return tableInfoVo;
|
|
||||||
}).toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +45,6 @@ public class TableServiceImpl implements TableService {
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
* @return 当前表所有的列内容
|
* @return 当前表所有的列内容
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
|
||||||
@Override
|
@Override
|
||||||
public List<ColumnMetaData> tableColumnInfo(String tableName) {
|
public List<ColumnMetaData> tableColumnInfo(String tableName) {
|
||||||
return databaseInfoCore.tableColumnInfo(tableName);
|
return databaseInfoCore.tableColumnInfo(tableName);
|
||||||
|
|
|
@ -12,7 +12,7 @@ import cn.bunny.service.VmsService;
|
||||||
import cn.bunny.utils.ResourceFileUtil;
|
import cn.bunny.utils.ResourceFileUtil;
|
||||||
import cn.bunny.utils.VmsUtil;
|
import cn.bunny.utils.VmsUtil;
|
||||||
import cn.hutool.crypto.digest.MD5;
|
import cn.hutool.crypto.digest.MD5;
|
||||||
import jakarta.annotation.Resource;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -32,13 +32,11 @@ import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class VmsServiceImpl implements VmsService {
|
public class VmsServiceImpl implements VmsService {
|
||||||
|
|
||||||
@Resource
|
private final ConcreteDatabaseInfo databaseInfoCore;
|
||||||
ConcreteDatabaseInfo databaseInfoCore;
|
private final ConcreteSqlParserDatabaseInfo sqlParserDatabaseInfo;
|
||||||
|
|
||||||
@Resource
|
|
||||||
ConcreteSqlParserDatabaseInfo sqlParserDatabaseInfo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成服务端代码
|
* 生成服务端代码
|
||||||
|
|
|
@ -3,7 +3,7 @@ server:
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
active: prod
|
||||||
application:
|
application:
|
||||||
name: generator-code
|
name: generator-code
|
||||||
thymeleaf:
|
thymeleaf:
|
||||||
|
|
Loading…
Reference in New Issue