mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-10 08:57:14 +08:00
feat: 新增查询列映射信息列表接口
提取 QueryTypeEnum 枚举
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.tool.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 代码生成器配置属性
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/8/5 11:08
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "generator")
|
||||
public class GeneratorProperties {
|
||||
|
||||
/**
|
||||
* 排除数据表(哪些数据表不展示在代码生成中)
|
||||
*/
|
||||
private String[] excludeTables;
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.tool.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
|
||||
/**
|
||||
* 表单类型枚举
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/8/6 10:49
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum FormTypeEnum implements BaseEnum<Integer, String> {
|
||||
|
||||
/**
|
||||
* 文本框
|
||||
*/
|
||||
TEXT(1, "文本框"),
|
||||
/**
|
||||
* 文本域
|
||||
*/
|
||||
TEXT_AREA(2, "文本域"),
|
||||
/**
|
||||
* 下拉框
|
||||
*/
|
||||
SELECT(3, "下拉框"),
|
||||
/**
|
||||
* 单选框
|
||||
*/
|
||||
RADIO(4, "单选框"),
|
||||
/**
|
||||
* 日期框
|
||||
*/
|
||||
DATE(5, "日期框"),
|
||||
/**
|
||||
* 日期时间框
|
||||
*/
|
||||
DATE_TIME(6, "日期时间框"),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.tool.mapper;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseMapper;
|
||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
||||
|
||||
/**
|
||||
* 列映射 Mapper
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/4/12 23:56
|
||||
*/
|
||||
public interface ColumnMappingMapper extends BaseMapper<ColumnMappingDO> {}
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.tool.mapper;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseMapper;
|
||||
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
||||
|
||||
/**
|
||||
* 生成配置 Mapper
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/4/12 23:56
|
||||
*/
|
||||
public interface GenConfigMapper extends BaseMapper<GenConfigDO> {}
|
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.tool.model.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.setting.dialect.Props;
|
||||
import cn.hutool.setting.dialect.PropsUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.enums.QueryTypeEnum;
|
||||
import top.charles7c.cnadmin.tool.enums.FormTypeEnum;
|
||||
|
||||
/**
|
||||
* 列映射实体
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/4/12 20:21
|
||||
*/
|
||||
@Data
|
||||
@TableName("gen_column_mapping")
|
||||
@Accessors(chain = true)
|
||||
@Schema(description = "列映射信息")
|
||||
public class ColumnMappingDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
@Schema(description = "ID")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@Schema(description = "表名称")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 列名称
|
||||
*/
|
||||
@Schema(description = "列名称")
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* 列类型
|
||||
*/
|
||||
@Schema(description = "列类型")
|
||||
private String columnType;
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
@Schema(description = "字段名称")
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 字段类型
|
||||
*/
|
||||
@Schema(description = "字段类型")
|
||||
private String fieldType;
|
||||
|
||||
/**
|
||||
* 注释
|
||||
*/
|
||||
@Schema(description = "注释")
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@Schema(description = "是否必填")
|
||||
private Boolean isRequired;
|
||||
|
||||
/**
|
||||
* 是否在列表中显示
|
||||
*/
|
||||
@Schema(description = "是否在列表中显示")
|
||||
private Boolean showInList;
|
||||
|
||||
/**
|
||||
* 是否在新增中显示
|
||||
*/
|
||||
@Schema(description = "是否在新增中显示")
|
||||
private Boolean showInAdd;
|
||||
|
||||
/**
|
||||
* 是否在修改中显示
|
||||
*/
|
||||
@Schema(description = "是否在修改中显示")
|
||||
private Boolean showInUpdate;
|
||||
|
||||
/**
|
||||
* 是否在查询中显示
|
||||
*/
|
||||
@Schema(description = "是否在查询中显示")
|
||||
private Boolean showInQuery;
|
||||
|
||||
/**
|
||||
* 表单类型
|
||||
*/
|
||||
@Schema(description = "表单类型")
|
||||
private FormTypeEnum formType;
|
||||
|
||||
/**
|
||||
* 查询方式
|
||||
*/
|
||||
@Schema(description = "查询方式")
|
||||
private QueryTypeEnum queryType;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
public ColumnMappingDO setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
this.fieldName = StrUtil.toCamelCase(this.columnName);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ColumnMappingDO setColumnType(String columnType) {
|
||||
this.columnType = columnType;
|
||||
Props generatorProp = PropsUtil.get("generator");
|
||||
this.fieldType = generatorProp.getStr(columnType);
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.tool.model.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
/**
|
||||
* 生成配置实体
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/4/12 20:21
|
||||
*/
|
||||
@Data
|
||||
@TableName("gen_config")
|
||||
public class GenConfigDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 包名称
|
||||
*/
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 业务名称
|
||||
*/
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* 前端路径
|
||||
*/
|
||||
private String frontendPath;
|
||||
|
||||
/**
|
||||
* 表前缀
|
||||
*/
|
||||
private String tablePrefix;
|
||||
|
||||
/**
|
||||
* 是否覆盖
|
||||
*/
|
||||
private Boolean isOverride;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
}
|
@@ -44,9 +44,9 @@ public class TableVO implements Serializable {
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 注释
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "注释")
|
||||
@Schema(description = "描述")
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
|
@@ -17,9 +17,11 @@
|
||||
package top.charles7c.cnadmin.tool.service;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
||||
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
||||
import top.charles7c.cnadmin.tool.model.vo.TableVO;
|
||||
|
||||
@@ -32,13 +34,22 @@ import top.charles7c.cnadmin.tool.model.vo.TableVO;
|
||||
public interface GeneratorService {
|
||||
|
||||
/**
|
||||
* 分页查询列表
|
||||
* 分页查询表信息列表
|
||||
*
|
||||
* @param query
|
||||
* 查询条件
|
||||
* @param pageQuery
|
||||
* 分页查询条件
|
||||
* @return 分页列表信息
|
||||
* @return 表信息分页列表
|
||||
*/
|
||||
PageDataVO<TableVO> pageTable(TableQuery query, PageQuery pageQuery) throws SQLException;
|
||||
|
||||
/**
|
||||
* 查询列映射信息列表
|
||||
*
|
||||
* @param tableName
|
||||
* 表名称
|
||||
* @return 列映射信息列表
|
||||
*/
|
||||
List<ColumnMappingDO> listColumnMapping(String tableName);
|
||||
}
|
||||
|
@@ -17,6 +17,8 @@
|
||||
package top.charles7c.cnadmin.tool.service.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -26,11 +28,21 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.db.meta.Column;
|
||||
|
||||
import top.charles7c.cnadmin.common.constant.StringConsts;
|
||||
import top.charles7c.cnadmin.common.enums.QueryTypeEnum;
|
||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||
import top.charles7c.cnadmin.tool.config.properties.GeneratorProperties;
|
||||
import top.charles7c.cnadmin.tool.enums.FormTypeEnum;
|
||||
import top.charles7c.cnadmin.tool.mapper.ColumnMappingMapper;
|
||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
||||
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
||||
import top.charles7c.cnadmin.tool.model.vo.TableVO;
|
||||
import top.charles7c.cnadmin.tool.service.GeneratorService;
|
||||
@@ -49,6 +61,8 @@ import top.charles7c.cnadmin.tool.util.Table;
|
||||
public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
private final DataSource dataSource;
|
||||
private final GeneratorProperties generatorProperties;
|
||||
private final ColumnMappingMapper columnMappingMapper;
|
||||
|
||||
@Override
|
||||
public PageDataVO<TableVO> pageTable(TableQuery query, PageQuery pageQuery) throws SQLException {
|
||||
@@ -57,9 +71,29 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
if (StrUtil.isNotBlank(tableName)) {
|
||||
tableList.removeIf(table -> !StrUtil.containsAny(table.getTableName(), tableName));
|
||||
}
|
||||
tableList
|
||||
.removeIf(table -> StrUtil.equalsAny(table.getTableName(), "DATABASECHANGELOG", "DATABASECHANGELOGLOCK"));
|
||||
tableList.removeIf(table -> StrUtil.equalsAny(table.getTableName(), generatorProperties.getExcludeTables()));
|
||||
List<TableVO> tableVOList = BeanUtil.copyToList(tableList, TableVO.class);
|
||||
return PageDataVO.build(pageQuery.getPage(), pageQuery.getSize(), tableVOList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ColumnMappingDO> listColumnMapping(String tableName) {
|
||||
List<ColumnMappingDO> columnMappingList = columnMappingMapper
|
||||
.selectList(Wrappers.lambdaQuery(ColumnMappingDO.class).eq(ColumnMappingDO::getTableName, tableName));
|
||||
if (CollUtil.isEmpty(columnMappingList)) {
|
||||
Collection<Column> columnList = MetaUtils.getColumns(dataSource, tableName);
|
||||
columnMappingList = new ArrayList<>(columnList.size());
|
||||
for (Column column : columnList) {
|
||||
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConsts.SPACE)[0];
|
||||
boolean isRequired = !column.isPk() && !column.isNullable();
|
||||
ColumnMappingDO columnMapping = new ColumnMappingDO().setTableName(tableName)
|
||||
.setColumnName(column.getName()).setColumnType(columnType.toLowerCase())
|
||||
.setComment(column.getComment()).setIsRequired(isRequired).setShowInList(true)
|
||||
.setShowInAdd(isRequired).setShowInUpdate(isRequired).setShowInQuery(isRequired)
|
||||
.setFormType(FormTypeEnum.TEXT).setQueryType(QueryTypeEnum.EQUAL);
|
||||
columnMappingList.add(columnMapping);
|
||||
}
|
||||
}
|
||||
return columnMappingList;
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package top.charles7c.cnadmin.tool.util;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -28,6 +29,8 @@ import lombok.NoArgsConstructor;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.db.Db;
|
||||
import cn.hutool.db.Entity;
|
||||
import cn.hutool.db.meta.Column;
|
||||
import cn.hutool.db.meta.MetaUtil;
|
||||
|
||||
/**
|
||||
* 数据库元数据信息工具类
|
||||
@@ -59,4 +62,18 @@ public class MetaUtils {
|
||||
}
|
||||
return tableList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有列信息
|
||||
*
|
||||
* @param dataSource
|
||||
* 数据源
|
||||
* @param tableName
|
||||
* 表名称
|
||||
* @return 列信息列表
|
||||
*/
|
||||
public static Collection<Column> getColumns(DataSource dataSource, String tableName) {
|
||||
cn.hutool.db.meta.Table table = MetaUtil.getTableMeta(dataSource, tableName);
|
||||
return table.getColumns();
|
||||
}
|
||||
}
|
||||
|
27
continew-admin-tool/src/main/resources/generator.properties
Normal file
27
continew-admin-tool/src/main/resources/generator.properties
Normal file
@@ -0,0 +1,27 @@
|
||||
# Database type to Java type(ELADMIN)
|
||||
tinyint=Integer
|
||||
smallint=Integer
|
||||
mediumint=Integer
|
||||
int=Integer
|
||||
integer=Integer
|
||||
|
||||
bigint=Long
|
||||
|
||||
float=Float
|
||||
|
||||
double=Double
|
||||
|
||||
decimal=BigDecimal
|
||||
|
||||
bit=Boolean
|
||||
|
||||
char=String
|
||||
varchar=String
|
||||
tinytext=String
|
||||
text=String
|
||||
mediumtext=String
|
||||
longtext=String
|
||||
|
||||
date=LocalDate
|
||||
datetime=LocalDateTime
|
||||
timestamp=LocalDateTime
|
Reference in New Issue
Block a user