mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 21:00:53 +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")); | ||||
|   | ||||
| @@ -0,0 +1,12 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||||
| <mapper namespace="top.charles7c.cnadmin.tool.mapper.GenConfigMapper"> | ||||
|     <select id="selectRecommendAuthor" resultType="java.lang.String"> | ||||
|         SELECT `author` | ||||
|         FROM `gen_config` | ||||
|         WHERE #{lessThanDate} > `create_time` | ||||
|         GROUP BY `author` | ||||
|         ORDER BY COUNT(*) DESC | ||||
|         LIMIT 1 | ||||
|     </select> | ||||
| </mapper> | ||||
| @@ -40,8 +40,7 @@ export interface ColumnMappingRecord { | ||||
|   sort: number; | ||||
|   isRequired: boolean; | ||||
|   showInList: boolean; | ||||
|   showInAdd: boolean; | ||||
|   showInUpdate: boolean; | ||||
|   showInForm: boolean; | ||||
|   showInQuery: boolean; | ||||
|   formType: string; | ||||
|   queryType: string; | ||||
| @@ -49,6 +48,10 @@ export interface ColumnMappingRecord { | ||||
|   updateTime: string; | ||||
| } | ||||
|  | ||||
| export function listColumnMapping(tableName: string) { | ||||
|   return axios.get<ColumnMappingRecord[]>(`${BASE_URL}/column/${tableName}`); | ||||
| } | ||||
|  | ||||
| export interface GenConfigRecord { | ||||
|   id: string; | ||||
|   tableName: string; | ||||
| @@ -63,6 +66,6 @@ export interface GenConfigRecord { | ||||
|   updateTime: string; | ||||
| } | ||||
|  | ||||
| export function listColumnMapping(tableName: string) { | ||||
|   return axios.get<ColumnMappingRecord[]>(`${BASE_URL}/column/${tableName}`); | ||||
| } | ||||
| export function getGenConfig(tableName: string) { | ||||
|   return axios.get<GenConfigRecord>(`${BASE_URL}/table/${tableName}`); | ||||
| } | ||||
|   | ||||
| @@ -125,6 +125,19 @@ | ||||
|         @cancel="handleCancel" | ||||
|       > | ||||
|         <a-card title="字段配置" class="field-config"> | ||||
|           <template #extra> | ||||
|             <a-space> | ||||
|               <a-button | ||||
|                 type="primary" | ||||
|                 status="success" | ||||
|                 size="small" | ||||
|                 title="同步" | ||||
|                 disabled | ||||
|               > | ||||
|                 <template #icon><icon-sync /></template>同步 | ||||
|               </a-button> | ||||
|             </a-space> | ||||
|           </template> | ||||
|           <a-table | ||||
|             ref="columnMappingRef" | ||||
|             :data="columnMappingList" | ||||
| @@ -156,16 +169,6 @@ | ||||
|                   <a-input v-model="record.comment" /> | ||||
|                 </template> | ||||
|               </a-table-column> | ||||
|               <a-table-column | ||||
|                 title="必填" | ||||
|                 data-index="isRequired" | ||||
|                 :width="60" | ||||
|                 align="center" | ||||
|               > | ||||
|                 <template #cell="{ record }"> | ||||
|                   <a-checkbox v-model="record.isRequired" value="true" /> | ||||
|                 </template> | ||||
|               </a-table-column> | ||||
|               <a-table-column | ||||
|                 title="列表" | ||||
|                 data-index="showInList" | ||||
| @@ -177,23 +180,34 @@ | ||||
|                 </template> | ||||
|               </a-table-column> | ||||
|               <a-table-column | ||||
|                 title="新增" | ||||
|                 data-index="showInAdd" | ||||
|                 title="表单" | ||||
|                 data-index="showInForm" | ||||
|                 :width="60" | ||||
|                 align="center" | ||||
|               > | ||||
|                 <template #cell="{ record }"> | ||||
|                   <a-checkbox v-model="record.showInAdd" value="true" /> | ||||
|                   <a-checkbox v-model="record.showInForm" value="true" /> | ||||
|                 </template> | ||||
|               </a-table-column> | ||||
|               <a-table-column | ||||
|                 title="修改" | ||||
|                 data-index="showInUpdate" | ||||
|                 title="必填" | ||||
|                 data-index="isRequired" | ||||
|                 :width="60" | ||||
|                 align="center" | ||||
|               > | ||||
|                 <template #cell="{ record }"> | ||||
|                   <a-checkbox v-model="record.showInUpdate" value="true" /> | ||||
|                   <a-checkbox v-if="record.showInForm" v-model="record.isRequired" value="true" /> | ||||
|                   <a-checkbox v-else disabled /> | ||||
|                 </template> | ||||
|               </a-table-column> | ||||
|               <a-table-column | ||||
|                 title="查询" | ||||
|                 data-index="showInQuery" | ||||
|                 :width="60" | ||||
|                 align="center" | ||||
|               > | ||||
|                 <template #cell="{ record }"> | ||||
|                   <a-checkbox v-model="record.showInQuery" value="true" /> | ||||
|                 </template> | ||||
|               </a-table-column> | ||||
|               <a-table-column | ||||
| @@ -203,19 +217,23 @@ | ||||
|               > | ||||
|                 <template #cell="{ record }"> | ||||
|                   <a-select | ||||
|                     v-if="record.showInForm || record.showInQuery" | ||||
|                     v-model="record.formType" | ||||
|                     :options="FormTypeEnum" | ||||
|                     placeholder="请选择表单类型" | ||||
|                   /> | ||||
|                   <span v-else>无需设置</span> | ||||
|                 </template> | ||||
|               </a-table-column> | ||||
|               <a-table-column title="查询方式" data-index="queryType"> | ||||
|                 <template #cell="{ record }"> | ||||
|                   <a-select | ||||
|                     v-if="record.showInQuery" | ||||
|                     v-model="record.queryType" | ||||
|                     :options="QueryTypeEnum" | ||||
|                     placeholder="请选择查询方式" | ||||
|                   /> | ||||
|                   <span v-else>无需设置</span> | ||||
|                 </template> | ||||
|               </a-table-column> | ||||
|             </template> | ||||
| @@ -284,6 +302,7 @@ | ||||
|     GenConfigRecord, | ||||
|     listTable, | ||||
|     listColumnMapping, | ||||
|     getGenConfig, | ||||
|   } from '@/api/tool/generator'; | ||||
|  | ||||
|   const { proxy } = getCurrentInstance() as any; | ||||
| @@ -348,10 +367,13 @@ | ||||
|    * @param tableName 表名称 | ||||
|    */ | ||||
|   const toConfig = (tableName: string) => { | ||||
|     title.value = `${tableName} 配置`; | ||||
|     form.value.isOverride = false; | ||||
|     let tableComment = tableList.value.filter( | ||||
|       (t) => t.tableName === tableName | ||||
|     )[0].comment; | ||||
|     tableComment = tableComment ? `(${tableComment})` : ' '; | ||||
|     title.value = `${tableName}${tableComment}配置`; | ||||
|     visible.value = true; | ||||
|     // 查询所有字段信息 | ||||
|     // 查询列映射信息 | ||||
|     columnMappingLoading.value = true; | ||||
|     listColumnMapping(tableName) | ||||
|       .then((res) => { | ||||
| @@ -360,6 +382,11 @@ | ||||
|       .finally(() => { | ||||
|         columnMappingLoading.value = false; | ||||
|       }); | ||||
|     // 查询生成配置 | ||||
|     getGenConfig(tableName).then((res) => { | ||||
|       form.value = res.data; | ||||
|       form.value.isOverride = false; | ||||
|     }); | ||||
|   }; | ||||
|  | ||||
|   /** | ||||
|   | ||||
| @@ -34,6 +34,7 @@ import top.charles7c.cnadmin.common.model.query.PageQuery; | ||||
| import top.charles7c.cnadmin.common.model.vo.PageDataVO; | ||||
| import top.charles7c.cnadmin.common.model.vo.R; | ||||
| 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; | ||||
| @@ -59,6 +60,12 @@ public class GeneratorController { | ||||
|         return R.ok(generatorService.pageTable(query, pageQuery)); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询生成配置信息", description = "查询生成配置信息") | ||||
|     @GetMapping("/table/{tableName}") | ||||
|     public R<GenConfigDO> getGenConfig(@PathVariable String tableName) throws SQLException { | ||||
|         return R.ok(generatorService.getGenConfig(tableName)); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询列映射信息列表", description = "查询列映射信息列表") | ||||
|     @GetMapping("/column/{tableName}") | ||||
|     public R<List<ColumnMappingDO>> listColumnMapping(@PathVariable String tableName) { | ||||
|   | ||||
| @@ -28,8 +28,7 @@ CREATE TABLE IF NOT EXISTS `gen_column_mapping` ( | ||||
|     `sort` int(11) UNSIGNED DEFAULT 999 COMMENT '排序', | ||||
|     `is_required` bit(1) DEFAULT b'1' COMMENT '是否必填', | ||||
|     `show_in_list` bit(1) DEFAULT b'1' COMMENT '是否在列表中显示', | ||||
|     `show_in_add` bit(1) DEFAULT b'1' COMMENT '是否在新增中显示', | ||||
|     `show_in_update` bit(1) DEFAULT b'1' COMMENT '是否在修改中显示', | ||||
|     `show_in_form` bit(1) DEFAULT b'1' COMMENT '是否在表单中显示', | ||||
|     `show_in_query` bit(1) DEFAULT b'1' COMMENT '是否在查询中显示', | ||||
|     `form_type` tinyint(1) UNSIGNED DEFAULT NULL COMMENT '表单类型', | ||||
|     `query_type` tinyint(1) UNSIGNED DEFAULT NULL COMMENT '查询方式', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user