mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-15 00:57:14 +08:00
feat: 新增查询生成配置信息接口
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
|
||||
package top.charles7c.cnadmin.tool.mapper;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseMapper;
|
||||
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
||||
|
||||
@@ -25,4 +29,14 @@ import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
||||
* @author Charles7c
|
||||
* @since 2023/4/12 23:56
|
||||
*/
|
||||
public interface GenConfigMapper extends BaseMapper<GenConfigDO> {}
|
||||
public interface GenConfigMapper extends BaseMapper<GenConfigDO> {
|
||||
|
||||
/**
|
||||
* 查询推荐作者名
|
||||
*
|
||||
* @param lessThanDate
|
||||
* 截止时间
|
||||
* @return 推荐作者名
|
||||
*/
|
||||
String selectRecommendAuthor(@Param("lessThanDate") Date lessThanDate);
|
||||
}
|
||||
|
@@ -112,16 +112,10 @@ public class ColumnMappingDO implements Serializable {
|
||||
private Boolean showInList;
|
||||
|
||||
/**
|
||||
* 是否在新增中显示
|
||||
* 是否在表单中显示
|
||||
*/
|
||||
@Schema(description = "是否在新增中显示")
|
||||
private Boolean showInAdd;
|
||||
|
||||
/**
|
||||
* 是否在修改中显示
|
||||
*/
|
||||
@Schema(description = "是否在修改中显示")
|
||||
private Boolean showInUpdate;
|
||||
@Schema(description = "是否在表单中显示")
|
||||
private Boolean showInForm;
|
||||
|
||||
/**
|
||||
* 是否在查询中显示
|
||||
|
@@ -20,6 +20,9 @@ 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;
|
||||
@@ -34,6 +37,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
*/
|
||||
@Data
|
||||
@TableName("gen_config")
|
||||
@Accessors(chain = true)
|
||||
@Schema(description = "生成配置信息")
|
||||
public class GenConfigDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -42,57 +47,68 @@ public class GenConfigDO implements Serializable {
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
@Schema(description = "ID")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@Schema(description = "表名称")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
@Schema(description = "模块名称")
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 包名称
|
||||
*/
|
||||
@Schema(description = "包名称")
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 前端路径
|
||||
*/
|
||||
@Schema(description = "前端路径")
|
||||
private String frontendPath;
|
||||
|
||||
/**
|
||||
* 业务名称
|
||||
*/
|
||||
@Schema(description = "业务名称")
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
@Schema(description = "作者")
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* 前端路径
|
||||
*/
|
||||
private String frontendPath;
|
||||
|
||||
/**
|
||||
* 表前缀
|
||||
*/
|
||||
@Schema(description = "表前缀")
|
||||
private String tablePrefix;
|
||||
|
||||
/**
|
||||
* 是否覆盖
|
||||
*/
|
||||
@Schema(description = "是否覆盖")
|
||||
private Boolean isOverride;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ 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.entity.GenConfigDO;
|
||||
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
||||
import top.charles7c.cnadmin.tool.model.vo.TableVO;
|
||||
|
||||
@@ -41,9 +42,22 @@ public interface GeneratorService {
|
||||
* @param pageQuery
|
||||
* 分页查询条件
|
||||
* @return 表信息分页列表
|
||||
* @throws SQLException
|
||||
* /
|
||||
*/
|
||||
PageDataVO<TableVO> pageTable(TableQuery query, PageQuery pageQuery) throws SQLException;
|
||||
|
||||
/**
|
||||
* 查询生成配置信息
|
||||
*
|
||||
* @param tableName
|
||||
* 表名称
|
||||
* @return 生成配置信息
|
||||
* @throws SQLException
|
||||
* /
|
||||
*/
|
||||
GenConfigDO getGenConfig(String tableName) throws SQLException;
|
||||
|
||||
/**
|
||||
* 查询列映射信息列表
|
||||
*
|
||||
|
@@ -32,6 +32,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.db.meta.Column;
|
||||
|
||||
@@ -42,7 +44,9 @@ 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.mapper.GenConfigMapper;
|
||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
||||
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
||||
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
||||
import top.charles7c.cnadmin.tool.model.vo.TableVO;
|
||||
import top.charles7c.cnadmin.tool.service.GeneratorService;
|
||||
@@ -63,6 +67,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
private final DataSource dataSource;
|
||||
private final GeneratorProperties generatorProperties;
|
||||
private final ColumnMappingMapper columnMappingMapper;
|
||||
private final GenConfigMapper genConfigMapper;
|
||||
|
||||
@Override
|
||||
public PageDataVO<TableVO> pageTable(TableQuery query, PageQuery pageQuery) throws SQLException {
|
||||
@@ -76,6 +81,31 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
return PageDataVO.build(pageQuery.getPage(), pageQuery.getSize(), tableVOList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenConfigDO getGenConfig(String tableName) throws SQLException {
|
||||
GenConfigDO genConfig =
|
||||
genConfigMapper.selectOne(Wrappers.lambdaQuery(GenConfigDO.class).eq(GenConfigDO::getTableName, tableName));
|
||||
if (null == genConfig) {
|
||||
genConfig = new GenConfigDO().setTableName(tableName);
|
||||
String packageName = ClassUtil.getPackage(GeneratorService.class);
|
||||
genConfig.setPackageName(StrUtil.subBefore(packageName, StringConsts.DOT, true));
|
||||
List<Table> tableList = MetaUtils.getTables(dataSource, tableName);
|
||||
if (CollUtil.isNotEmpty(tableList)) {
|
||||
Table table = tableList.get(0);
|
||||
genConfig.setBusinessName(StrUtil.replace(table.getComment(), "表", StringConsts.EMPTY));
|
||||
}
|
||||
String recommendAuthor = genConfigMapper.selectRecommendAuthor(DateUtil.lastWeek().toJdkDate());
|
||||
if (StrUtil.isNotBlank(recommendAuthor)) {
|
||||
genConfig.setAuthor(recommendAuthor);
|
||||
}
|
||||
int underLineIndex = StrUtil.indexOf(tableName, StringConsts.C_UNDERLINE);
|
||||
if (-1 != underLineIndex) {
|
||||
genConfig.setTablePrefix(StrUtil.subPre(tableName, underLineIndex + 1));
|
||||
}
|
||||
}
|
||||
return genConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ColumnMappingDO> listColumnMapping(String tableName) {
|
||||
List<ColumnMappingDO> columnMappingList = columnMappingMapper
|
||||
@@ -89,8 +119,9 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
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);
|
||||
.setShowInForm(isRequired).setShowInQuery(isRequired).setFormType(FormTypeEnum.TEXT);
|
||||
columnMapping.setQueryType(
|
||||
"String".equals(columnMapping.getFieldType()) ? QueryTypeEnum.INNER_LIKE : QueryTypeEnum.EQUAL);
|
||||
columnMappingList.add(columnMapping);
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.db.Db;
|
||||
import cn.hutool.db.Entity;
|
||||
import cn.hutool.db.meta.Column;
|
||||
@@ -49,7 +50,27 @@ public class MetaUtils {
|
||||
* @return 表信息列表
|
||||
*/
|
||||
public static List<Table> getTables(DataSource dataSource) throws SQLException {
|
||||
List<Entity> tableEntityList = Db.use(dataSource).query("SHOW TABLE STATUS");
|
||||
return getTables(dataSource, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有表信息
|
||||
*
|
||||
* @param dataSource
|
||||
* 数据源
|
||||
* @param tableName
|
||||
* 表名称
|
||||
* @return 表信息列表
|
||||
*/
|
||||
public static List<Table> getTables(DataSource dataSource, String tableName) throws SQLException {
|
||||
String querySql = "SHOW TABLE STATUS";
|
||||
List<Entity> tableEntityList;
|
||||
Db db = Db.use(dataSource);
|
||||
if (StrUtil.isNotBlank(tableName)) {
|
||||
tableEntityList = db.query(String.format("%s WHERE NAME = ?", querySql), tableName);
|
||||
} else {
|
||||
tableEntityList = db.query(querySql);
|
||||
}
|
||||
List<Table> tableList = new ArrayList<>(tableEntityList.size());
|
||||
for (Entity tableEntity : tableEntityList) {
|
||||
Table table = new Table(tableEntity.getStr("NAME"));
|
||||
|
Reference in New Issue
Block a user