From 0b939f3d57b63e0ba4d41e6f990656940b33d8a8 Mon Sep 17 00:00:00 2001 From: PIGCLOUD Date: Sat, 15 Nov 2025 20:38:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(gen-table):=20=E6=89=B9=E9=87=8F=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E6=94=AF=E6=8C=81=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E5=8D=95=E8=A1=A8=E7=9A=84=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GenTableController.java | 229 ++++++++++-------- 1 file changed, 122 insertions(+), 107 deletions(-) diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java index 2d112f644..3da6ac9b2 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java @@ -48,123 +48,138 @@ import java.util.List; @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class GenTableController { - private final GenTableColumnService tableColumnService; + private final GenTableColumnService tableColumnService; - private final GenTableService tableService; + private final GenTableService tableService; - /** - * 分页查询 - * @param page 分页对象 - * @param table 列属性 - * @return - */ - @Operation(summary = "分页查询", description = "分页查询") - @GetMapping("/page") - public R getTablePage(Page page, GenTable table) { - return R.ok(tableService.queryTablePage(page, table)); - } + /** + * 分页查询 + * + * @param page 分页对象 + * @param table 列属性 + * @return + */ + @Operation(summary = "分页查询", description = "分页查询") + @GetMapping("/page") + public R getTablePage(Page page, GenTable table) { + return R.ok(tableService.queryTablePage(page, table)); + } - /** - * 通过id查询表信息(代码生成设置 + 表 + 字段设置) - * @param id id - * @return R - */ - @Operation(summary = "通过id查询", description = "通过id查询") - @GetMapping("/{id}") - public R getTable(@PathVariable("id") Long id) { - return R.ok(tableService.getById(id)); - } + /** + * 通过id查询表信息(代码生成设置 + 表 + 字段设置) + * + * @param id id + * @return R + */ + @Operation(summary = "通过id查询", description = "通过id查询") + @GetMapping("/{id}") + public R getTable(@PathVariable("id") Long id) { + return R.ok(tableService.getById(id)); + } - /** - * 查询数据源所有表 - * @param dsName 数据源 - */ - @GetMapping("/list/{dsName}") - public R listTable(@PathVariable("dsName") String dsName) { - return R.ok(tableService.queryTableList(dsName)); - } + /** + * 查询数据源所有表 + * + * @param dsName 数据源 + */ + @GetMapping("/list/{dsName}") + public R listTable(@PathVariable("dsName") String dsName) { + return R.ok(tableService.queryTableList(dsName)); + } - /** - * 获取表信息 - * @param dsName 数据源 - * @param tableName 表名称 - */ - @GetMapping("/{dsName}/{tableName}") - public R getTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) { - return R.ok(tableService.queryOrBuildTable(dsName, tableName)); - } + /** + * 获取表信息 + * + * @param dsName 数据源 + * @param tableName 表名称 + */ + @GetMapping("/{dsName}/{tableName}") + public R getTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) { + return R.ok(tableService.queryOrBuildTable(dsName, tableName)); + } - /** - * 查询表DDL语句 - * @param dsName 数据源 - * @param tableName 表名称 - */ - @GetMapping("/column/{dsName}/{tableName}") - public R getColumn(@PathVariable("dsName") String dsName, @PathVariable String tableName) throws Exception { - return R.ok(tableService.queryTableColumn(dsName, tableName)); - } + /** + * 查询表DDL语句 + * + * @param dsName 数据源 + * @param tableName 表名称 + */ + @GetMapping("/column/{dsName}/{tableName}") + public R getColumn(@PathVariable("dsName") String dsName, @PathVariable String tableName) throws Exception { + return R.ok(tableService.queryTableColumn(dsName, tableName)); + } - /** - * 查询表DDL语句 - * @param dsName 数据源 - * @param tableName 表名称 - */ - @GetMapping("/ddl/{dsName}/{tableName}") - public R getDdl(@PathVariable("dsName") String dsName, @PathVariable String tableName) throws Exception { - return R.ok(tableService.queryTableDdl(dsName, tableName)); - } + /** + * 查询表DDL语句 + * + * @param dsName 数据源 + * @param tableName 表名称 + */ + @GetMapping("/ddl/{dsName}/{tableName}") + public R getDdl(@PathVariable("dsName") String dsName, @PathVariable String tableName) throws Exception { + return R.ok(tableService.queryTableDdl(dsName, tableName)); + } - /** - * 同步表信息 - * @param dsName 数据源 - * @param tableName 表名称 - */ - @GetMapping("/sync/{dsName}/{tableName}") - public R syncTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) { - // 表配置删除 - tableService.remove( - Wrappers.lambdaQuery().eq(GenTable::getDsName, dsName).eq(GenTable::getTableName, tableName)); - // 字段配置删除 - tableColumnService.remove(Wrappers.lambdaQuery() - .eq(GenTableColumnEntity::getDsName, dsName) - .eq(GenTableColumnEntity::getTableName, tableName)); - return R.ok(tableService.queryOrBuildTable(dsName, tableName)); - } + /** + * 同步表信息 + * + * @param dsName 数据源名称 + * @param tableName 表名称 + * @param isBatch 是否批量操作 + * @return 操作结果 + */ + @GetMapping("/sync/{dsName}/{tableName}") + public R syncTable(@PathVariable("dsName") String dsName, @PathVariable String tableName, @RequestParam(required = false) boolean isBatch) { + // 批量操作同步的时候,不需要删除 + if (!isBatch) { + // 表配置删除 + tableService.remove( + Wrappers.lambdaQuery().eq(GenTable::getDsName, dsName).eq(GenTable::getTableName, tableName)); + // 字段配置删除 + tableColumnService.remove(Wrappers.lambdaQuery() + .eq(GenTableColumnEntity::getDsName, dsName) + .eq(GenTableColumnEntity::getTableName, tableName)); + } + return R.ok(tableService.queryOrBuildTable(dsName, tableName)); + } - /** - * 修改列属性 - * @param table 列属性 - * @return R - */ - @Operation(summary = "修改列属性", description = "修改列属性") - @SysLog("修改列属性") - @PutMapping - public R updateById(@RequestBody GenTable table) { - return R.ok(tableService.updateById(table)); - } + /** + * 修改列属性 + * + * @param table 列属性 + * @return R + */ + @Operation(summary = "修改列属性", description = "修改列属性") + @SysLog("修改列属性") + @PutMapping + public R updateById(@RequestBody GenTable table) { + return R.ok(tableService.updateById(table)); + } - /** - * 修改表字段数据 - * @param dsName 数据源 - * @param tableName 表名称 - * @param tableFieldList 字段列表 - */ - @PutMapping("/field/{dsName}/{tableName}") - public R updateTableField(@PathVariable("dsName") String dsName, @PathVariable String tableName, - @RequestBody List tableFieldList) { - tableColumnService.updateTableField(dsName, tableName, tableFieldList); - return R.ok(); - } + /** + * 修改表字段数据 + * + * @param dsName 数据源 + * @param tableName 表名称 + * @param tableFieldList 字段列表 + */ + @PutMapping("/field/{dsName}/{tableName}") + public R updateTableField(@PathVariable("dsName") String dsName, @PathVariable String tableName, + @RequestBody List tableFieldList) { + tableColumnService.updateTableField(dsName, tableName, tableFieldList); + return R.ok(); + } - /** - * 导出excel 表格 - * @param table 查询条件 - * @return excel 文件流 - */ - @ResponseExcel - @GetMapping("/export") - public List export(GenTable table) { - return tableService.list(Wrappers.query(table)); - } + /** + * 导出excel 表格 + * + * @param table 查询条件 + * @return excel 文件流 + */ + @ResponseExcel + @GetMapping("/export") + public List export(GenTable table) { + return tableService.list(Wrappers.query(table)); + } }