From 2684e96dc9b0e4601eb5578f232087f2a2938955 Mon Sep 17 00:00:00 2001 From: XiaoHH <1431984546@qq.com> Date: Sat, 25 Jun 2022 13:59:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=94=9F=E6=88=90=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=9A=84=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A0=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=8C=87=E5=AE=9A=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/gen/controller/GenController.java | 50 ++- .../java/com/ruoyi/gen/domain/GenTable.java | 14 + .../gen/mapper/GenTableColumnMapper.java | 8 +- .../com/ruoyi/gen/mapper/GenTableMapper.java | 12 +- .../gen/service/GenTableServiceImpl.java | 59 ++- .../ruoyi/gen/service/IGenTableService.java | 33 +- .../mapper/generator/GenTableColumnMapper.xml | 2 +- .../mapper/generator/GenTableMapper.xml | 416 +++++++++--------- ruoyi-ui/src/api/tool/gen.js | 160 +++---- ruoyi-ui/src/views/tool/gen/importTable.vue | 271 +++++++----- ruoyi-ui/src/views/tool/gen/index.vue | 43 +- sql/ry_20220613.sql | 1 + 12 files changed, 607 insertions(+), 462 deletions(-) diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java index b9f0142b..417ac036 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java @@ -8,14 +8,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; @@ -55,6 +48,17 @@ public class GenController extends BaseController return getDataTable(list); } + /** + * 查询所有可以生成代码的数据库名称列表 + */ + @RequiresPermissions("tool:gen:list") + @GetMapping("/schema/list") + public AjaxResult genSchemaList() + { + List list = genTableService.selectGenSchemaList(); + return AjaxResult.success(list); + } + /** * 修改代码生成业务 */ @@ -102,12 +106,12 @@ public class GenController extends BaseController */ @RequiresPermissions("tool:gen:import") @Log(title = "代码生成", businessType = BusinessType.IMPORT) - @PostMapping("/importTable") - public AjaxResult importTableSave(String tables) + @PostMapping("/importTable/{schemaName}") + public AjaxResult importTableSave(@PathVariable("schemaName") String schemaName, @RequestParam("tables") String tables) { String[] tableNames = Convert.toStrArray(tables); // 查询表信息 - List tableList = genTableService.selectDbTableListByNames(tableNames); + List tableList = genTableService.selectDbTableListByNames(schemaName, tableNames); genTableService.importGenTable(tableList); return AjaxResult.success(); } @@ -153,10 +157,10 @@ public class GenController extends BaseController */ @RequiresPermissions("tool:gen:code") @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/download/{tableName}") - public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException + @GetMapping("/download/{schemaName}/{tableName}") + public void download(HttpServletResponse response, @PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName) throws IOException { - byte[] data = genTableService.downloadCode(tableName); + byte[] data = genTableService.downloadCode(schemaName, tableName); genCode(response, data); } @@ -165,10 +169,10 @@ public class GenController extends BaseController */ @RequiresPermissions("tool:gen:code") @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/genCode/{tableName}") - public AjaxResult genCode(@PathVariable("tableName") String tableName) + @GetMapping("/genCode/{schemaName}/{tableName}") + public AjaxResult genCode(@PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName) { - genTableService.generatorCode(tableName); + genTableService.generatorCode(schemaName, tableName); return AjaxResult.success(); } @@ -177,10 +181,10 @@ public class GenController extends BaseController */ @RequiresPermissions("tool:gen:edit") @Log(title = "代码生成", businessType = BusinessType.UPDATE) - @GetMapping("/synchDb/{tableName}") - public AjaxResult synchDb(@PathVariable("tableName") String tableName) + @GetMapping("/synchDb/{schemaName}/{tableName}") + public AjaxResult synchDb(@PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName) { - genTableService.synchDb(tableName); + genTableService.synchDb(schemaName, tableName); return AjaxResult.success(); } @@ -189,11 +193,11 @@ public class GenController extends BaseController */ @RequiresPermissions("tool:gen:code") @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/batchGenCode") - public void batchGenCode(HttpServletResponse response, String tables) throws IOException + @GetMapping("/batchGenCode/{schemaName}") + public void batchGenCode(HttpServletResponse response, @PathVariable("schemaName") String schemaName, String tables) throws IOException { String[] tableNames = Convert.toStrArray(tables); - byte[] data = genTableService.downloadCode(tableNames); + byte[] data = genTableService.downloadCode(schemaName, tableNames); genCode(response, data); } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java index d08b7325..9a10498c 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java @@ -20,6 +20,10 @@ public class GenTable extends BaseEntity /** 编号 */ private Long tableId; + /** 库名称 */ + @NotBlank(message = "库名称不能为空") + private String schemaName; + /** 表名称 */ @NotBlank(message = "表名称不能为空") private String tableName; @@ -105,6 +109,16 @@ public class GenTable extends BaseEntity this.tableId = tableId; } + public String getSchemaName() + { + return schemaName; + } + + public void setSchemaName(String schemaName) + { + this.schemaName = schemaName; + } + public String getTableName() { return tableName; diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableColumnMapper.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableColumnMapper.java index e5df0027..fa663353 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableColumnMapper.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableColumnMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.gen.mapper; import java.util.List; import com.ruoyi.gen.domain.GenTableColumn; +import org.apache.ibatis.annotations.Param; /** * 业务字段 数据层 @@ -12,11 +13,12 @@ public interface GenTableColumnMapper { /** * 根据表名称查询列信息 - * - * @param tableName 表名称 + * + * @param schemaName 数据库名字 + * @param tableName 表名称 * @return 列信息 */ - public List selectDbTableColumnsByName(String tableName); + public List selectDbTableColumnsByName(@Param("schemaName") String schemaName, @Param("tableName") String tableName); /** * 查询业务字段列表 diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java index 3d36d88e..96710995 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.gen.mapper; import java.util.List; import com.ruoyi.gen.domain.GenTable; +import org.apache.ibatis.annotations.Param; /** * 业务 数据层 @@ -18,6 +19,13 @@ public interface GenTableMapper */ public List selectGenTableList(GenTable genTable); + /** + * 查询所有可以生成代码的数据库名称列表 + * + * @return 数据库名称列表 + */ + public List selectGenSchemaList(); + /** * 查询据库列表 * @@ -32,7 +40,7 @@ public interface GenTableMapper * @param tableNames 表名称组 * @return 数据库表集合 */ - public List selectDbTableListByNames(String[] tableNames); + public List selectDbTableListByNames(@Param("schemaName") String schemaName, @Param("tableNames") String[] tableNames); /** * 查询所有表信息 @@ -55,7 +63,7 @@ public interface GenTableMapper * @param tableName 表名称 * @return 业务信息 */ - public GenTable selectGenTableByName(String tableName); + public GenTable selectGenTableByName(@Param("schemaName") String schemaName, @Param("tableName") String tableName); /** * 新增业务 diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java index 861c68c9..83027e15 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java @@ -79,9 +79,20 @@ public class GenTableServiceImpl implements IGenTableService return genTableMapper.selectGenTableList(genTable); } + /** + * 查询所有可以生成代码的数据库名称列表 + * + * @return 数据库名称列表 + */ + @Override + public List selectGenSchemaList() + { + return genTableMapper.selectGenSchemaList(); + } + /** * 查询据库列表 - * + * * @param genTable 业务信息 * @return 数据库表集合 */ @@ -93,14 +104,15 @@ public class GenTableServiceImpl implements IGenTableService /** * 查询据库列表 - * + * + * @param schemaName 数据库的名称 * @param tableNames 表名称组 * @return 数据库表集合 */ @Override - public List selectDbTableListByNames(String[] tableNames) + public List selectDbTableListByNames(String schemaName, String[] tableNames) { - return genTableMapper.selectDbTableListByNames(tableNames); + return genTableMapper.selectDbTableListByNames(schemaName, tableNames); } /** @@ -170,7 +182,7 @@ public class GenTableServiceImpl implements IGenTableService if (row > 0) { // 保存列信息 - List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); + List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(table.getSchemaName(), tableName); for (GenTableColumn column : genTableColumns) { GenUtils.initColumnField(column, table); @@ -220,30 +232,32 @@ public class GenTableServiceImpl implements IGenTableService /** * 生成代码(下载方式) - * - * @param tableName 表名称 + * + * @param schemaName 库名称 + * @param tableName 表名称 * @return 数据 */ @Override - public byte[] downloadCode(String tableName) + public byte[] downloadCode(String schemaName, String tableName) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); - generatorCode(tableName, zip); + generatorCode(schemaName, tableName, zip); IOUtils.closeQuietly(zip); return outputStream.toByteArray(); } /** * 生成代码(自定义路径) - * - * @param tableName 表名称 + * + * @param schemaName 库名称 + * @param tableName 表名称 */ @Override - public void generatorCode(String tableName) + public void generatorCode(String schemaName, String tableName) { // 查询表信息 - GenTable table = genTableMapper.selectGenTableByName(tableName); + GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName); // 设置主子表信息 setSubTable(table); // 设置主键列信息 @@ -283,13 +297,13 @@ public class GenTableServiceImpl implements IGenTableService */ @Override @Transactional(rollbackFor = Exception.class) - public void synchDb(String tableName) + public void synchDb(String schemaName, String tableName) { - GenTable table = genTableMapper.selectGenTableByName(tableName); + GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName); List tableColumns = table.getColumns(); Map tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity())); - List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); + List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(schemaName, tableName); if (StringUtils.isEmpty(dbTableColumns)) { throw new ServiceException("同步数据失败,原表结构不存在"); @@ -333,18 +347,19 @@ public class GenTableServiceImpl implements IGenTableService /** * 批量生成代码(下载方式) - * + * + * @param schemaName 库名称 * @param tableNames 表数组 * @return 数据 */ @Override - public byte[] downloadCode(String[] tableNames) + public byte[] downloadCode(String schemaName, String[] tableNames) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); for (String tableName : tableNames) { - generatorCode(tableName, zip); + generatorCode(schemaName, tableName, zip); } IOUtils.closeQuietly(zip); return outputStream.toByteArray(); @@ -353,10 +368,10 @@ public class GenTableServiceImpl implements IGenTableService /** * 查询表信息并生成代码 */ - private void generatorCode(String tableName, ZipOutputStream zip) + private void generatorCode(String schemaName, String tableName, ZipOutputStream zip) { // 查询表信息 - GenTable table = genTableMapper.selectGenTableByName(tableName); + GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName); // 设置主子表信息 setSubTable(table); // 设置主键列信息 @@ -474,7 +489,7 @@ public class GenTableServiceImpl implements IGenTableService String subTableName = table.getSubTableName(); if (StringUtils.isNotEmpty(subTableName)) { - table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); + table.setSubTable(genTableMapper.selectGenTableByName(table.getSchemaName(), subTableName)); } } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java index 3d6e0ff6..16d35de0 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java @@ -19,6 +19,13 @@ public interface IGenTableService */ public List selectGenTableList(GenTable genTable); + /** + * 查询所有可以生成代码的数据库名称列表 + * + * @return 数据库名称列表 + */ + public List selectGenSchemaList(); + /** * 查询据库列表 * @@ -29,11 +36,12 @@ public interface IGenTableService /** * 查询据库列表 - * + * + * @param schemaName 数据库的名称 * @param tableNames 表名称组 * @return 数据库表集合 */ - public List selectDbTableListByNames(String[] tableNames); + public List selectDbTableListByNames(String schemaName, String[] tableNames); /** * 查询所有表信息 @@ -83,11 +91,12 @@ public interface IGenTableService /** * 生成代码(下载方式) - * - * @param tableName 表名称 + * + * @param schemaName 库名称 + * @param tableName 表名称 * @return 数据 */ - public byte[] downloadCode(String tableName); + public byte[] downloadCode(String schemaName, String tableName); /** * 生成代码(自定义路径) @@ -95,22 +104,24 @@ public interface IGenTableService * @param tableName 表名称 * @return 数据 */ - public void generatorCode(String tableName); + public void generatorCode(String schemaName, String tableName); /** * 同步数据库 - * - * @param tableName 表名称 + * + * @param schemaName 数据库的名称 + * @param tableName 表名称 */ - public void synchDb(String tableName); + public void synchDb(String schemaName, String tableName); /** * 批量生成代码(下载方式) - * + * + * @param schemaName 库名称 * @param tableNames 表数组 * @return 数据 */ - public byte[] downloadCode(String[] tableNames); + public byte[] downloadCode(String schemaName, String[] tableNames); /** * 修改保存参数校验 diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml index 83565467..b6bfce6b 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -41,7 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml index f93a32bb..d7156d98 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml @@ -1,202 +1,216 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table - - - - - - - - - - - - - - - - - - insert into gen_table ( - table_name, - table_comment, - class_name, - tpl_category, - package_name, - module_name, - business_name, - function_name, - function_author, - gen_type, - gen_path, - remark, - create_by, - create_time - )values( - #{tableName}, - #{tableComment}, - #{className}, - #{tplCategory}, - #{packageName}, - #{moduleName}, - #{businessName}, - #{functionName}, - #{functionAuthor}, - #{genType}, - #{genPath}, - #{remark}, - #{createBy}, - sysdate() - ) - - - - update gen_table - - table_name = #{tableName}, - table_comment = #{tableComment}, - sub_table_name = #{subTableName}, - sub_table_fk_name = #{subTableFkName}, - class_name = #{className}, - function_author = #{functionAuthor}, - gen_type = #{genType}, - gen_path = #{genPath}, - tpl_category = #{tplCategory}, - package_name = #{packageName}, - module_name = #{moduleName}, - business_name = #{businessName}, - function_name = #{functionName}, - options = #{options}, - update_by = #{updateBy}, - remark = #{remark}, - update_time = sysdate() - - where table_id = #{tableId} - - - - delete from gen_table where table_id in - - #{tableId} - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select table_id, schema_name, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table + + + + + + + + + + + + + + + + + + + + insert into gen_table ( + schema_name , + table_name, + table_comment, + class_name, + tpl_category, + package_name, + module_name, + business_name, + function_name, + function_author, + gen_type, + gen_path, + remark, + create_by, + create_time + )values( + #{schemaName}, + #{tableName}, + #{tableComment}, + #{className}, + #{tplCategory}, + #{packageName}, + #{moduleName}, + #{businessName}, + #{functionName}, + #{functionAuthor}, + #{genType}, + #{genPath}, + #{remark}, + #{createBy}, + sysdate() + ) + + + + update gen_table + + table_name = #{tableName}, + table_comment = #{tableComment}, + sub_table_name = #{subTableName}, + sub_table_fk_name = #{subTableFkName}, + class_name = #{className}, + function_author = #{functionAuthor}, + gen_type = #{genType}, + gen_path = #{genPath}, + tpl_category = #{tplCategory}, + package_name = #{packageName}, + module_name = #{moduleName}, + business_name = #{businessName}, + function_name = #{functionName}, + options = #{options}, + update_by = #{updateBy}, + remark = #{remark}, + update_time = sysdate() + + where table_id = #{tableId} + + + + delete from gen_table where table_id in + + #{tableId} + + + \ No newline at end of file diff --git a/ruoyi-ui/src/api/tool/gen.js b/ruoyi-ui/src/api/tool/gen.js index a17f1f2e..86568219 100644 --- a/ruoyi-ui/src/api/tool/gen.js +++ b/ruoyi-ui/src/api/tool/gen.js @@ -1,76 +1,84 @@ -import request from '@/utils/request' - -// 查询生成表数据 -export function listTable(query) { - return request({ - url: '/code/gen/list', - method: 'get', - params: query - }) -} -// 查询db数据库列表 -export function listDbTable(query) { - return request({ - url: '/code/gen/db/list', - method: 'get', - params: query - }) -} - -// 查询表详细信息 -export function getGenTable(tableId) { - return request({ - url: '/code/gen/' + tableId, - method: 'get' - }) -} - -// 修改代码生成信息 -export function updateGenTable(data) { - return request({ - url: '/code/gen', - method: 'put', - data: data - }) -} - -// 导入表 -export function importTable(data) { - return request({ - url: '/code/gen/importTable', - method: 'post', - params: data - }) -} - -// 预览生成代码 -export function previewTable(tableId) { - return request({ - url: '/code/gen/preview/' + tableId, - method: 'get' - }) -} - -// 删除表数据 -export function delTable(tableId) { - return request({ - url: '/code/gen/' + tableId, - method: 'delete' - }) -} - -// 生成代码(自定义路径) -export function genCode(tableName) { - return request({ - url: '/code/gen/genCode/' + tableName, - method: 'get' - }) -} - -// 同步数据库 -export function synchDb(tableName) { - return request({ - url: '/code/gen/synchDb/' + tableName, - method: 'get' - }) -} +import request from '@/utils/request' + +// 查询生成表数据 +export function listTable(query) { + return request({ + url: '/code/gen/list', + method: 'get', + params: query + }) +} + +export function listSchema() { + return request({ + url: '/code/gen/schema/list', + method: 'get', + }) +} + +// 查询db数据库列表 +export function listDbTable(query) { + return request({ + url: '/code/gen/db/list', + method: 'get', + params: query + }) +} + +// 查询表详细信息 +export function getGenTable(tableId) { + return request({ + url: '/code/gen/' + tableId, + method: 'get' + }) +} + +// 修改代码生成信息 +export function updateGenTable(data) { + return request({ + url: '/code/gen', + method: 'put', + data: data + }) +} + +// 导入表 +export function importTable(data, schemaName) { + return request({ + url: `/code/gen/importTable/${schemaName}`, + method: 'post', + params: data + }) +} + +// 预览生成代码 +export function previewTable(tableId) { + return request({ + url: '/code/gen/preview/' + tableId, + method: 'get' + }) +} + +// 删除表数据 +export function delTable(tableId) { + return request({ + url: '/code/gen/' + tableId, + method: 'delete' + }) +} + +// 生成代码(自定义路径) +export function genCode(tableName) { + return request({ + url: '/code/gen/genCode/' + tableName, + method: 'get' + }) +} + +// 同步数据库 +export function synchDb(schemaName, tableName) { + return request({ + url: `/code/gen/synchDb/${schemaName}/${tableName}`, + method: 'get' + }) +} diff --git a/ruoyi-ui/src/views/tool/gen/importTable.vue b/ruoyi-ui/src/views/tool/gen/importTable.vue index 9d738be0..4174cbf7 100644 --- a/ruoyi-ui/src/views/tool/gen/importTable.vue +++ b/ruoyi-ui/src/views/tool/gen/importTable.vue @@ -1,120 +1,151 @@ - - - + + + diff --git a/ruoyi-ui/src/views/tool/gen/index.vue b/ruoyi-ui/src/views/tool/gen/index.vue index eeb9efe5..c1ef0fa7 100644 --- a/ruoyi-ui/src/views/tool/gen/index.vue +++ b/ruoyi-ui/src/views/tool/gen/index.vue @@ -1,6 +1,14 @@ + { + genCode(schemaName, row.tableName).then(response => { this.$modal.msgSuccess("成功生成到自定义路径:" + row.genPath); }); } else { - this.$download.zip("/code/gen/batchGenCode?tables=" + tableNames, "ruoyi"); + this.$download.zip(`/code/gen/batchGenCode/${schemaName}?tables=${tableNames}`, "ruoyi"); } }, /** 同步数据库操作 */ handleSynchDb(row) { const tableName = row.tableName; this.$modal.confirm('确认要强制同步"' + tableName + '"表结构吗?').then(function() { - return synchDb(tableName); + return synchDb(row.schemaName, tableName); }).then(() => { this.$modal.msgSuccess("同步成功"); }).catch(() => {}); @@ -311,6 +347,7 @@ export default { // 多选框选中数据 handleSelectionChange(selection) { this.ids = selection.map(item => item.tableId); + this.schemaNames = selection.map(item => item.schemaName); this.tableNames = selection.map(item => item.tableName); this.single = selection.length != 1; this.multiple = !selection.length; diff --git a/sql/ry_20220613.sql b/sql/ry_20220613.sql index fad9d1b0..939e8c15 100644 --- a/sql/ry_20220613.sql +++ b/sql/ry_20220613.sql @@ -630,6 +630,7 @@ insert into sys_notice values('2', '维护通知:2018-07-01 若依系统凌晨 drop table if exists gen_table; create table gen_table ( table_id bigint(20) not null auto_increment comment '编号', + schema_name varchar(200) default '' comment '数据库名称', table_name varchar(200) default '' comment '表名称', table_comment varchar(500) default '' comment '表描述', sub_table_name varchar(64) default null comment '关联子表的表名',