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)); + } }