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