refactor: 优化代码生成配置相关表名、 API 地址及相关描述
1、列映射表重命名为字段配置表
This commit is contained in:
parent
241a9cf85b
commit
2d0e1f42d4
@ -16,13 +16,29 @@
|
|||||||
|
|
||||||
package top.charles7c.cnadmin.tool.mapper;
|
package top.charles7c.cnadmin.tool.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import top.charles7c.cnadmin.common.base.BaseMapper;
|
import top.charles7c.cnadmin.common.base.BaseMapper;
|
||||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
import top.charles7c.cnadmin.tool.model.entity.FieldConfigDO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列映射 Mapper
|
* 字段配置 Mapper
|
||||||
*
|
*
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2023/4/12 23:56
|
* @since 2023/4/12 23:56
|
||||||
*/
|
*/
|
||||||
public interface ColumnMappingMapper extends BaseMapper<ColumnMappingDO> {}
|
public interface FieldConfigMapper extends BaseMapper<FieldConfigDO> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名称查询
|
||||||
|
*
|
||||||
|
* @param tableName
|
||||||
|
* 表名称
|
||||||
|
* @return 字段配置信息
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM `gen_field_config` WHERE `table_name` = #{tableName}")
|
||||||
|
List<FieldConfigDO> selectListByTableName(@Param("tableName") String tableName);
|
||||||
|
}
|
@ -42,17 +42,17 @@ import top.charles7c.cnadmin.common.enums.QueryTypeEnum;
|
|||||||
import top.charles7c.cnadmin.tool.enums.FormTypeEnum;
|
import top.charles7c.cnadmin.tool.enums.FormTypeEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列映射实体
|
* 字段配置实体
|
||||||
*
|
*
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2023/4/12 20:21
|
* @since 2023/4/12 20:21
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@TableName("gen_column_mapping")
|
@TableName("gen_field_config")
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@Schema(description = "列映射信息")
|
@Schema(description = "字段配置信息")
|
||||||
public class ColumnMappingDO implements Serializable {
|
public class FieldConfigDO implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ public class ColumnMappingDO implements Serializable {
|
|||||||
@TableField(fill = FieldFill.INSERT)
|
@TableField(fill = FieldFill.INSERT)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
public ColumnMappingDO(@NonNull Column column) {
|
public FieldConfigDO(@NonNull Column column) {
|
||||||
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConsts.SPACE)[0].toLowerCase();
|
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConsts.SPACE)[0].toLowerCase();
|
||||||
boolean isRequired = !column.isPk() && !column.isNullable();
|
boolean isRequired = !column.isPk() && !column.isNullable();
|
||||||
this.tableName = column.getTableName();
|
this.tableName = column.getTableName();
|
||||||
@ -150,13 +150,13 @@ public class ColumnMappingDO implements Serializable {
|
|||||||
this.setQueryType("String".equals(this.getFieldType()) ? QueryTypeEnum.INNER_LIKE : QueryTypeEnum.EQUAL);
|
this.setQueryType("String".equals(this.getFieldType()) ? QueryTypeEnum.INNER_LIKE : QueryTypeEnum.EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnMappingDO setColumnName(String columnName) {
|
public FieldConfigDO setColumnName(String columnName) {
|
||||||
this.columnName = columnName;
|
this.columnName = columnName;
|
||||||
this.fieldName = StrUtil.toCamelCase(this.columnName);
|
this.fieldName = StrUtil.toCamelCase(this.columnName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnMappingDO setColumnType(String columnType) {
|
public FieldConfigDO setColumnType(String columnType) {
|
||||||
this.columnType = columnType;
|
this.columnType = columnType;
|
||||||
Props generatorProp = PropsUtil.get("generator");
|
Props generatorProp = PropsUtil.get("generator");
|
||||||
this.fieldType = generatorProp.getStr(columnType);
|
this.fieldType = generatorProp.getStr(columnType);
|
@ -27,7 +27,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
import top.charles7c.cnadmin.tool.model.entity.FieldConfigDO;
|
||||||
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,16 +43,16 @@ public class GenConfigRequest implements Serializable {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列映射信息列表
|
* 字段配置
|
||||||
*/
|
*/
|
||||||
@Schema(description = "列映射信息列表")
|
@Schema(description = "字段配置")
|
||||||
@NotEmpty(message = "列映射信息不能为空")
|
@NotEmpty(message = "字段配置不能为空")
|
||||||
private List<ColumnMappingDO> columnMappings = new ArrayList<>();
|
private List<FieldConfigDO> fieldConfigs = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成配置信息
|
* 生成配置
|
||||||
*/
|
*/
|
||||||
@Schema(description = "生成配置信息")
|
@Schema(description = "生成配置")
|
||||||
@NotNull(message = "生成配置信息不能为空")
|
@NotNull(message = "生成配置不能为空")
|
||||||
private GenConfigDO genConfig;
|
private GenConfigDO genConfig;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
import top.charles7c.cnadmin.tool.model.entity.FieldConfigDO;
|
||||||
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
||||||
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
||||||
import top.charles7c.cnadmin.tool.model.request.GenConfigRequest;
|
import top.charles7c.cnadmin.tool.model.request.GenConfigRequest;
|
||||||
@ -60,15 +60,15 @@ public interface GeneratorService {
|
|||||||
GenConfigDO getGenConfig(String tableName) throws SQLException;
|
GenConfigDO getGenConfig(String tableName) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询列映射信息列表
|
* 查询字段配置列表
|
||||||
*
|
*
|
||||||
* @param tableName
|
* @param tableName
|
||||||
* 表名称
|
* 表名称
|
||||||
* @param requireSync
|
* @param requireSync
|
||||||
* 是否需要同步
|
* 是否需要同步
|
||||||
* @return 列映射信息列表
|
* @return 字段配置列表
|
||||||
*/
|
*/
|
||||||
List<ColumnMappingDO> listColumnMapping(String tableName, Boolean requireSync);
|
List<FieldConfigDO> listFieldConfig(String tableName, Boolean requireSync);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存代码生成配置信息
|
* 保存代码生成配置信息
|
||||||
|
@ -44,9 +44,9 @@ import top.charles7c.cnadmin.common.model.query.PageQuery;
|
|||||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||||
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
||||||
import top.charles7c.cnadmin.tool.config.properties.GeneratorProperties;
|
import top.charles7c.cnadmin.tool.config.properties.GeneratorProperties;
|
||||||
import top.charles7c.cnadmin.tool.mapper.ColumnMappingMapper;
|
import top.charles7c.cnadmin.tool.mapper.FieldConfigMapper;
|
||||||
import top.charles7c.cnadmin.tool.mapper.GenConfigMapper;
|
import top.charles7c.cnadmin.tool.mapper.GenConfigMapper;
|
||||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
import top.charles7c.cnadmin.tool.model.entity.FieldConfigDO;
|
||||||
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
||||||
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
||||||
import top.charles7c.cnadmin.tool.model.request.GenConfigRequest;
|
import top.charles7c.cnadmin.tool.model.request.GenConfigRequest;
|
||||||
@ -68,7 +68,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
|
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final GeneratorProperties generatorProperties;
|
private final GeneratorProperties generatorProperties;
|
||||||
private final ColumnMappingMapper columnMappingMapper;
|
private final FieldConfigMapper fieldConfigMapper;
|
||||||
private final GenConfigMapper genConfigMapper;
|
private final GenConfigMapper genConfigMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -113,67 +113,65 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ColumnMappingDO> listColumnMapping(String tableName, Boolean requireSync) {
|
public List<FieldConfigDO> listFieldConfig(String tableName, Boolean requireSync) {
|
||||||
List<ColumnMappingDO> columnMappingList = columnMappingMapper
|
List<FieldConfigDO> fieldConfigList = fieldConfigMapper.selectListByTableName(tableName);
|
||||||
.selectList(Wrappers.lambdaQuery(ColumnMappingDO.class).eq(ColumnMappingDO::getTableName, tableName));
|
if (CollUtil.isEmpty(fieldConfigList)) {
|
||||||
if (CollUtil.isEmpty(columnMappingList)) {
|
|
||||||
Collection<Column> columnList = MetaUtils.getColumns(dataSource, tableName);
|
Collection<Column> columnList = MetaUtils.getColumns(dataSource, tableName);
|
||||||
return columnList.stream().map(ColumnMappingDO::new).collect(Collectors.toList());
|
return columnList.stream().map(FieldConfigDO::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同步最新数据表列信息
|
// 同步最新数据表列信息
|
||||||
if (requireSync) {
|
if (requireSync) {
|
||||||
Collection<Column> columnList = MetaUtils.getColumns(dataSource, tableName);
|
Collection<Column> columnList = MetaUtils.getColumns(dataSource, tableName);
|
||||||
// 移除已不存在的列映射信息
|
// 移除已不存在的字段配置
|
||||||
List<String> columnNameList = columnList.stream().map(Column::getName).collect(Collectors.toList());
|
List<String> columnNameList = columnList.stream().map(Column::getName).collect(Collectors.toList());
|
||||||
columnMappingList.removeIf(column -> !columnNameList.contains(column.getColumnName()));
|
fieldConfigList.removeIf(column -> !columnNameList.contains(column.getColumnName()));
|
||||||
// 新增或更新列映射信息
|
// 新增或更新字段配置
|
||||||
Map<String, ColumnMappingDO> columnMappingMap = columnMappingList.stream()
|
Map<String, FieldConfigDO> fieldConfigMap = fieldConfigList.stream()
|
||||||
.collect(Collectors.toMap(ColumnMappingDO::getColumnName, Function.identity(), (key1, key2) -> key2));
|
.collect(Collectors.toMap(FieldConfigDO::getColumnName, Function.identity(), (key1, key2) -> key2));
|
||||||
for (Column column : columnList) {
|
for (Column column : columnList) {
|
||||||
ColumnMappingDO columnMapping = columnMappingMap.get(column.getName());
|
FieldConfigDO fieldConfig = fieldConfigMap.get(column.getName());
|
||||||
if (null != columnMapping) {
|
if (null != fieldConfig) {
|
||||||
// 更新已有列映射信息
|
// 更新已有字段配置
|
||||||
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConsts.SPACE)[0].toLowerCase();
|
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConsts.SPACE)[0].toLowerCase();
|
||||||
columnMapping.setColumnType(columnType).setComment(column.getComment());
|
fieldConfig.setColumnType(columnType).setComment(column.getComment());
|
||||||
} else {
|
} else {
|
||||||
// 新增列映射信息
|
// 新增字段配置
|
||||||
columnMapping = new ColumnMappingDO(column);
|
fieldConfig = new FieldConfigDO(column);
|
||||||
columnMappingList.add(columnMapping);
|
fieldConfigList.add(fieldConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return columnMappingList;
|
return fieldConfigList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void saveConfig(GenConfigRequest request, String tableName) {
|
public void saveConfig(GenConfigRequest request, String tableName) {
|
||||||
// 保存列映射信息
|
// 保存字段配置
|
||||||
columnMappingMapper
|
fieldConfigMapper.delete(Wrappers.lambdaQuery(FieldConfigDO.class).eq(FieldConfigDO::getTableName, tableName));
|
||||||
.delete(Wrappers.lambdaQuery(ColumnMappingDO.class).eq(ColumnMappingDO::getTableName, tableName));
|
List<FieldConfigDO> fieldConfigList = request.getFieldConfigs();
|
||||||
List<ColumnMappingDO> columnMappingList = request.getColumnMappings();
|
for (FieldConfigDO fieldConfig : fieldConfigList) {
|
||||||
for (ColumnMappingDO columnMapping : columnMappingList) {
|
if (fieldConfig.getShowInForm()) {
|
||||||
if (columnMapping.getShowInForm()) {
|
CheckUtils.throwIfNull(fieldConfig.getFormType(), "字段 [{}] 的表单类型不能为空", fieldConfig.getFieldName());
|
||||||
CheckUtils.throwIfNull(columnMapping.getFormType(), "字段 [{}] 的表单类型不能为空", columnMapping.getFieldName());
|
|
||||||
} else {
|
} else {
|
||||||
// 在表单中不显示,不需要设置必填
|
// 在表单中不显示,不需要设置必填
|
||||||
columnMapping.setIsRequired(false);
|
fieldConfig.setIsRequired(false);
|
||||||
}
|
}
|
||||||
if (columnMapping.getShowInQuery()) {
|
if (fieldConfig.getShowInQuery()) {
|
||||||
CheckUtils.throwIfNull(columnMapping.getFormType(), "字段 [{}] 的表单类型不能为空", columnMapping.getFieldName());
|
CheckUtils.throwIfNull(fieldConfig.getFormType(), "字段 [{}] 的表单类型不能为空", fieldConfig.getFieldName());
|
||||||
CheckUtils.throwIfNull(columnMapping.getQueryType(), "字段 [{}] 的查询方式不能为空", columnMapping.getFieldName());
|
CheckUtils.throwIfNull(fieldConfig.getQueryType(), "字段 [{}] 的查询方式不能为空", fieldConfig.getFieldName());
|
||||||
} else {
|
} else {
|
||||||
// 在查询中不显示,不需要设置查询方式
|
// 在查询中不显示,不需要设置查询方式
|
||||||
columnMapping.setQueryType(null);
|
fieldConfig.setQueryType(null);
|
||||||
}
|
}
|
||||||
// 既不在表单也不在查询中显示,不需要设置表单类型
|
// 既不在表单也不在查询中显示,不需要设置表单类型
|
||||||
if (!columnMapping.getShowInForm() && !columnMapping.getShowInQuery()) {
|
if (!fieldConfig.getShowInForm() && !fieldConfig.getShowInQuery()) {
|
||||||
columnMapping.setFormType(null);
|
fieldConfig.setFormType(null);
|
||||||
}
|
}
|
||||||
columnMapping.setTableName(tableName);
|
fieldConfig.setTableName(tableName);
|
||||||
}
|
}
|
||||||
columnMappingMapper.insertBatch(columnMappingList);
|
fieldConfigMapper.insertBatch(fieldConfigList);
|
||||||
|
|
||||||
// 保存或更新生成配置信息
|
// 保存或更新生成配置信息
|
||||||
GenConfigDO newGenConfig = request.getGenConfig();
|
GenConfigDO newGenConfig = request.getGenConfig();
|
||||||
|
@ -29,7 +29,7 @@ export function listTable(params: TableParam) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ColumnMappingRecord {
|
export interface FieldConfigRecord {
|
||||||
tableName: string;
|
tableName: string;
|
||||||
columnName: string;
|
columnName: string;
|
||||||
columnType: string;
|
columnType: string;
|
||||||
@ -45,8 +45,8 @@ export interface ColumnMappingRecord {
|
|||||||
createTime?: string;
|
createTime?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listColumnMapping(tableName: string, requireSync: boolean) {
|
export function listFieldConfig(tableName: string, requireSync: boolean) {
|
||||||
return axios.get<ColumnMappingRecord[]>(`${BASE_URL}/column/${tableName}?requireSync=${requireSync}`);
|
return axios.get<FieldConfigRecord[]>(`${BASE_URL}/field/${tableName}?requireSync=${requireSync}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GenConfigRecord {
|
export interface GenConfigRecord {
|
||||||
@ -63,14 +63,14 @@ export interface GenConfigRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getGenConfig(tableName: string) {
|
export function getGenConfig(tableName: string) {
|
||||||
return axios.get<GenConfigRecord>(`${BASE_URL}/table/${tableName}`);
|
return axios.get<GenConfigRecord>(`${BASE_URL}/config/${tableName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GeneratorConfigRecord {
|
export interface GeneratorConfigRecord {
|
||||||
genConfig: GenConfigRecord;
|
genConfig: GenConfigRecord;
|
||||||
columnMappings: ColumnMappingRecord[];
|
fieldConfigs: FieldConfigRecord[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveConfig(tableName: string, req: GeneratorConfigRecord) {
|
export function saveConfig(tableName: string, req: GeneratorConfigRecord) {
|
||||||
return axios.post(`${BASE_URL}/table/${tableName}`, req);
|
return axios.post(`${BASE_URL}/config/${tableName}`, req);
|
||||||
}
|
}
|
||||||
|
@ -28,24 +28,6 @@
|
|||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
</div>
|
</div>
|
||||||
<!-- 操作栏 -->
|
|
||||||
<div class="header-operation">
|
|
||||||
<a-row>
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-space>
|
|
||||||
<a-button type="primary" @click="toGenerate(ids[0])">
|
|
||||||
<template #icon><icon-robot-add /></template>代码生成
|
|
||||||
</a-button>
|
|
||||||
</a-space>
|
|
||||||
</a-col>
|
|
||||||
<a-col :span="12">
|
|
||||||
<right-toolbar
|
|
||||||
v-model:show-query="showQuery"
|
|
||||||
@refresh="getList"
|
|
||||||
/>
|
|
||||||
</a-col>
|
|
||||||
</a-row>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 列表区域 -->
|
<!-- 列表区域 -->
|
||||||
@ -54,11 +36,6 @@
|
|||||||
row-key="tableName"
|
row-key="tableName"
|
||||||
:data="tableList"
|
:data="tableList"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:row-selection="{
|
|
||||||
type: 'checkbox',
|
|
||||||
showCheckedAll: true,
|
|
||||||
onlyCurrent: false,
|
|
||||||
}"
|
|
||||||
:pagination="{
|
:pagination="{
|
||||||
showTotal: true,
|
showTotal: true,
|
||||||
showPageSize: true,
|
showPageSize: true,
|
||||||
@ -71,7 +48,6 @@
|
|||||||
size="large"
|
size="large"
|
||||||
@page-change="handlePageChange"
|
@page-change="handlePageChange"
|
||||||
@page-size-change="handlePageSizeChange"
|
@page-size-change="handlePageSizeChange"
|
||||||
@selection-change="handleSelectionChange"
|
|
||||||
>
|
>
|
||||||
<template #columns>
|
<template #columns>
|
||||||
<a-table-column title="序号">
|
<a-table-column title="序号">
|
||||||
@ -103,13 +79,20 @@
|
|||||||
type="text"
|
type="text"
|
||||||
size="small"
|
size="small"
|
||||||
title="生成"
|
title="生成"
|
||||||
@click="toGenerate(record.tableName)"
|
@click="handleGenerate(record.tableName)"
|
||||||
>
|
>
|
||||||
<template #icon><icon-robot-add /></template>生成
|
<template #icon><icon-robot-add /></template>生成
|
||||||
</a-button>
|
</a-button>
|
||||||
</template>
|
</template>
|
||||||
</a-table-column>
|
</a-table-column>
|
||||||
</template>
|
</template>
|
||||||
|
<template #pagination-left>
|
||||||
|
<a-tooltip content="刷新">
|
||||||
|
<div class="action-icon" @click="handleQuery">
|
||||||
|
<icon-refresh size="18" />
|
||||||
|
</div>
|
||||||
|
</a-tooltip>
|
||||||
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
|
|
||||||
<!-- 表单区域 -->
|
<!-- 表单区域 -->
|
||||||
@ -138,8 +121,8 @@
|
|||||||
size="small"
|
size="small"
|
||||||
title="同步"
|
title="同步"
|
||||||
:disabled="
|
:disabled="
|
||||||
columnMappingList.length !== 0 &&
|
fieldConfigList.length !== 0 &&
|
||||||
columnMappingList[0].createTime === null
|
fieldConfigList[0].createTime === null
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<template #icon><icon-sync /></template>同步
|
<template #icon><icon-sync /></template>同步
|
||||||
@ -148,9 +131,9 @@
|
|||||||
</a-popconfirm>
|
</a-popconfirm>
|
||||||
</template>
|
</template>
|
||||||
<a-table
|
<a-table
|
||||||
ref="columnMappingRef"
|
ref="fieldConfigRef"
|
||||||
:data="columnMappingList"
|
:data="fieldConfigList"
|
||||||
:loading="columnMappingLoading"
|
:loading="fieldConfigLoading"
|
||||||
:pagination="false"
|
:pagination="false"
|
||||||
:bordered="false"
|
:bordered="false"
|
||||||
size="large"
|
size="large"
|
||||||
@ -307,10 +290,10 @@
|
|||||||
import {
|
import {
|
||||||
TableRecord,
|
TableRecord,
|
||||||
TableParam,
|
TableParam,
|
||||||
ColumnMappingRecord,
|
FieldConfigRecord,
|
||||||
GenConfigRecord,
|
GenConfigRecord,
|
||||||
listTable,
|
listTable,
|
||||||
listColumnMapping,
|
listFieldConfig,
|
||||||
getGenConfig,
|
getGenConfig,
|
||||||
GeneratorConfigRecord,
|
GeneratorConfigRecord,
|
||||||
saveConfig,
|
saveConfig,
|
||||||
@ -323,16 +306,13 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
const tableList = ref<TableRecord[]>([]);
|
const tableList = ref<TableRecord[]>([]);
|
||||||
const columnMappingList = ref<ColumnMappingRecord[]>([]);
|
const fieldConfigList = ref<FieldConfigRecord[]>([]);
|
||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
const ids = ref<Array<string>>([]);
|
|
||||||
const title = ref('');
|
const title = ref('');
|
||||||
const single = ref(true);
|
|
||||||
const multiple = ref(true);
|
|
||||||
const showQuery = ref(true);
|
const showQuery = ref(true);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
const columnMappingLoading = ref(false);
|
const fieldConfigLoading = ref(false);
|
||||||
|
|
||||||
const data = reactive({
|
const data = reactive({
|
||||||
// 查询参数
|
// 查询参数
|
||||||
@ -344,6 +324,7 @@
|
|||||||
},
|
},
|
||||||
// 表单数据
|
// 表单数据
|
||||||
form: {} as GenConfigRecord,
|
form: {} as GenConfigRecord,
|
||||||
|
// 代码生成配置数据
|
||||||
config: {} as GeneratorConfigRecord,
|
config: {} as GeneratorConfigRecord,
|
||||||
// 表单验证规则
|
// 表单验证规则
|
||||||
rules: {
|
rules: {
|
||||||
@ -385,8 +366,8 @@
|
|||||||
tableComment = tableComment ? `(${tableComment})` : ' ';
|
tableComment = tableComment ? `(${tableComment})` : ' ';
|
||||||
title.value = `${tableName}${tableComment}配置`;
|
title.value = `${tableName}${tableComment}配置`;
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
// 查询列映射信息
|
// 查询字段配置
|
||||||
getColumnMappingList(tableName, false);
|
getFieldConfig(tableName, false);
|
||||||
// 查询生成配置
|
// 查询生成配置
|
||||||
getGenConfig(tableName).then((res) => {
|
getGenConfig(tableName).then((res) => {
|
||||||
form.value = res.data;
|
form.value = res.data;
|
||||||
@ -400,24 +381,23 @@
|
|||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
*/
|
*/
|
||||||
const handleRefresh = (tableName: string) => {
|
const handleRefresh = (tableName: string) => {
|
||||||
getColumnMappingList(tableName, true);
|
getFieldConfig(tableName, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询列映射信息
|
* 查询字段配置
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
* @param requireSync 是否需要同步
|
* @param requireSync 是否需要同步
|
||||||
*/
|
*/
|
||||||
const getColumnMappingList = (tableName: string, requireSync: boolean) => {
|
const getFieldConfig = (tableName: string, requireSync: boolean) => {
|
||||||
// 查询列映射信息
|
fieldConfigLoading.value = true;
|
||||||
columnMappingLoading.value = true;
|
listFieldConfig(tableName, requireSync)
|
||||||
listColumnMapping(tableName, requireSync)
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
columnMappingList.value = res.data;
|
fieldConfigList.value = res.data;
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
columnMappingLoading.value = false;
|
fieldConfigLoading.value = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -427,7 +407,7 @@
|
|||||||
const handleOk = () => {
|
const handleOk = () => {
|
||||||
proxy.$refs.formRef.validate((valid: any) => {
|
proxy.$refs.formRef.validate((valid: any) => {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
config.value.columnMappings = columnMappingList.value;
|
config.value.fieldConfigs = fieldConfigList.value;
|
||||||
config.value.genConfig = form.value;
|
config.value.genConfig = form.value;
|
||||||
saveConfig(form.value.tableName, config.value).then((res) => {
|
saveConfig(form.value.tableName, config.value).then((res) => {
|
||||||
handleCancel();
|
handleCancel();
|
||||||
@ -444,29 +424,18 @@
|
|||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
visible.value = false;
|
visible.value = false;
|
||||||
proxy.$refs.formRef?.resetFields();
|
proxy.$refs.formRef?.resetFields();
|
||||||
columnMappingList.value = [];
|
fieldConfigList.value = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成
|
* 生成代码
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableName 表名称
|
||||||
*/
|
*/
|
||||||
const toGenerate = (tableName: string) => {
|
const handleGenerate = (tableName: string) => {
|
||||||
proxy.$message.info('功能尚在开发中');
|
proxy.$message.info('功能尚在开发中');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 已选择的数据行发生改变时触发
|
|
||||||
*
|
|
||||||
* @param rowKeys ID 列表
|
|
||||||
*/
|
|
||||||
const handleSelectionChange = (rowKeys: Array<any>) => {
|
|
||||||
ids.value = rowKeys;
|
|
||||||
single.value = rowKeys.length !== 1;
|
|
||||||
multiple.value = !rowKeys.length;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询
|
* 查询
|
||||||
*/
|
*/
|
||||||
@ -517,4 +486,13 @@
|
|||||||
:deep(.gen-config.arco-form) {
|
:deep(.gen-config.arco-form) {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.action-icon {
|
||||||
|
cursor: pointer;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-icon:hover {
|
||||||
|
color: #0960bd;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||||
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||||
import top.charles7c.cnadmin.common.model.vo.R;
|
import top.charles7c.cnadmin.common.model.vo.R;
|
||||||
import top.charles7c.cnadmin.tool.model.entity.ColumnMappingDO;
|
import top.charles7c.cnadmin.tool.model.entity.FieldConfigDO;
|
||||||
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
import top.charles7c.cnadmin.tool.model.entity.GenConfigDO;
|
||||||
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
||||||
import top.charles7c.cnadmin.tool.model.request.GenConfigRequest;
|
import top.charles7c.cnadmin.tool.model.request.GenConfigRequest;
|
||||||
@ -58,21 +58,21 @@ public class GeneratorController {
|
|||||||
return R.ok(generatorService.pageTable(query, pageQuery));
|
return R.ok(generatorService.pageTable(query, pageQuery));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "查询字段配置列表", description = "查询字段配置列表")
|
||||||
|
@GetMapping("/field/{tableName}")
|
||||||
|
public R<List<FieldConfigDO>> listFieldConfig(@PathVariable String tableName,
|
||||||
|
@RequestParam(required = false, defaultValue = "false") Boolean requireSync) {
|
||||||
|
return R.ok(generatorService.listFieldConfig(tableName, requireSync));
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "查询生成配置信息", description = "查询生成配置信息")
|
@Operation(summary = "查询生成配置信息", description = "查询生成配置信息")
|
||||||
@GetMapping("/table/{tableName}")
|
@GetMapping("/config/{tableName}")
|
||||||
public R<GenConfigDO> getGenConfig(@PathVariable String tableName) throws SQLException {
|
public R<GenConfigDO> getGenConfig(@PathVariable String tableName) throws SQLException {
|
||||||
return R.ok(generatorService.getGenConfig(tableName));
|
return R.ok(generatorService.getGenConfig(tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "查询列映射信息列表", description = "查询列映射信息列表")
|
|
||||||
@GetMapping("/column/{tableName}")
|
|
||||||
public R<List<ColumnMappingDO>> listColumnMapping(@PathVariable String tableName,
|
|
||||||
@RequestParam(required = false, defaultValue = "false") Boolean requireSync) {
|
|
||||||
return R.ok(generatorService.listColumnMapping(tableName, requireSync));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "保存配置信息", description = "保存配置信息")
|
@Operation(summary = "保存配置信息", description = "保存配置信息")
|
||||||
@PostMapping("/table/{tableName}")
|
@PostMapping("/config/{tableName}")
|
||||||
public R saveConfig(@Validated @RequestBody GenConfigRequest request, @PathVariable String tableName) {
|
public R saveConfig(@Validated @RequestBody GenConfigRequest request, @PathVariable String tableName) {
|
||||||
generatorService.saveConfig(request, tableName);
|
generatorService.saveConfig(request, tableName);
|
||||||
return R.ok("保存成功");
|
return R.ok("保存成功");
|
||||||
|
@ -52,7 +52,7 @@ generator:
|
|||||||
- DATABASECHANGELOG
|
- DATABASECHANGELOG
|
||||||
- DATABASECHANGELOGLOCK
|
- DATABASECHANGELOGLOCK
|
||||||
- gen_config
|
- gen_config
|
||||||
- gen_column_mapping
|
- gen_field_config
|
||||||
|
|
||||||
--- ### 接口文档配置
|
--- ### 接口文档配置
|
||||||
springdoc:
|
springdoc:
|
||||||
|
@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS `gen_config` (
|
|||||||
PRIMARY KEY (`table_name`) USING BTREE
|
PRIMARY KEY (`table_name`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='生成配置表';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='生成配置表';
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `gen_column_mapping` (
|
CREATE TABLE IF NOT EXISTS `gen_field_config` (
|
||||||
`table_name` varchar(64) NOT NULL COMMENT '表名称',
|
`table_name` varchar(64) NOT NULL COMMENT '表名称',
|
||||||
`column_name` varchar(64) NOT NULL COMMENT '列名称',
|
`column_name` varchar(64) NOT NULL COMMENT '列名称',
|
||||||
`column_type` varchar(25) NOT NULL COMMENT '列类型',
|
`column_type` varchar(25) NOT NULL COMMENT '列类型',
|
||||||
@ -30,4 +30,4 @@ CREATE TABLE IF NOT EXISTS `gen_column_mapping` (
|
|||||||
`query_type` tinyint(1) UNSIGNED DEFAULT NULL COMMENT '查询方式',
|
`query_type` tinyint(1) UNSIGNED DEFAULT NULL COMMENT '查询方式',
|
||||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
INDEX `idx_table_name`(`table_name`) USING BTREE
|
INDEX `idx_table_name`(`table_name`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='列映射表';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字段配置表';
|
Loading…
Reference in New Issue
Block a user