瀏覽代碼

!349 代码生成 从对应数据源加载表结构信息 存储到主数据源 实现存储统一
* 数据库脚本修改,gen_table增加data_name字段,存储对应数据源名称
* 代码生成 从对应数据源加载表结构信息 存储到主数据源 实现存储统一(表结构需要增加对应的数据来源字段) https://gitee.com/…

WangBQ 1 年之前
父節點
當前提交
f2892a672a

+ 10 - 0
ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/helper/DataBaseHelper.java

@@ -12,6 +12,9 @@ import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.DatabaseMetaData;
 import java.sql.SQLException;
 import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
 
 
 /**
 /**
  * 数据库助手
  * 数据库助手
@@ -69,4 +72,11 @@ public class DataBaseHelper {
         // find_in_set(100 , '0,100,101')
         // find_in_set(100 , '0,100,101')
         return "find_in_set('%s' , %s) <> 0".formatted(var, var2);
         return "find_in_set('%s' , %s) <> 0".formatted(var, var2);
     }
     }
+
+    /**
+     * 获取当前加载的数据库名
+     */
+    public static List<String> getDataSourceNameList() {
+        return new ArrayList<>(DS.getDataSources().keySet());
+    }
 }
 }

+ 29 - 19
ruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/controller/GenController.java

@@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.io.IoUtil;
 import org.dromara.common.core.domain.R;
 import org.dromara.common.core.domain.R;
+import org.dromara.common.mybatis.helper.DataBaseHelper;
 import org.dromara.common.web.core.BaseController;
 import org.dromara.common.web.core.BaseController;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -94,11 +95,11 @@ public class GenController extends BaseController {
     @SaCheckPermission("tool:gen:import")
     @SaCheckPermission("tool:gen:import")
     @Log(title = "代码生成", businessType = BusinessType.IMPORT)
     @Log(title = "代码生成", businessType = BusinessType.IMPORT)
     @PostMapping("/importTable")
     @PostMapping("/importTable")
-    public R<Void> importTableSave(String tables) {
+    public R<Void> importTableSave(String tables, String dataName) {
         String[] tableNames = Convert.toStrArray(tables);
         String[] tableNames = Convert.toStrArray(tables);
         // 查询表信息
         // 查询表信息
-        List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
-        genTableService.importGenTable(tableList);
+        List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames, dataName);
+        genTableService.importGenTable(tableList, dataName);
         return R.ok();
         return R.ok();
     }
     }
 
 
@@ -142,53 +143,53 @@ public class GenController extends BaseController {
     /**
     /**
      * 生成代码(下载方式)
      * 生成代码(下载方式)
      *
      *
-     * @param tableName 表名
+     * @param tableId 表ID
      */
      */
     @SaCheckPermission("tool:gen:code")
     @SaCheckPermission("tool:gen:code")
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
-    @GetMapping("/download/{tableName}")
-    public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
-        byte[] data = genTableService.downloadCode(tableName);
+    @GetMapping("/download/{tableId}")
+    public void download(HttpServletResponse response, @PathVariable("tableId") Long tableId) throws IOException {
+        byte[] data = genTableService.downloadCode(tableId);
         genCode(response, data);
         genCode(response, data);
     }
     }
 
 
     /**
     /**
      * 生成代码(自定义路径)
      * 生成代码(自定义路径)
      *
      *
-     * @param tableName 表名
+     * @param tableId 表ID
      */
      */
     @SaCheckPermission("tool:gen:code")
     @SaCheckPermission("tool:gen:code")
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
-    @GetMapping("/genCode/{tableName}")
-    public R<Void> genCode(@PathVariable("tableName") String tableName) {
-        genTableService.generatorCode(tableName);
+    @GetMapping("/genCode/{tableId}")
+    public R<Void> genCode(@PathVariable("tableId") Long tableId) {
+        genTableService.generatorCode(tableId);
         return R.ok();
         return R.ok();
     }
     }
 
 
     /**
     /**
      * 同步数据库
      * 同步数据库
      *
      *
-     * @param tableName 表名
+     * @param tableId 表ID
      */
      */
     @SaCheckPermission("tool:gen:edit")
     @SaCheckPermission("tool:gen:edit")
     @Log(title = "代码生成", businessType = BusinessType.UPDATE)
     @Log(title = "代码生成", businessType = BusinessType.UPDATE)
-    @GetMapping("/synchDb/{tableName}")
-    public R<Void> synchDb(@PathVariable("tableName") String tableName) {
-        genTableService.synchDb(tableName);
+    @GetMapping("/synchDb/{tableId}")
+    public R<Void> synchDb(@PathVariable("tableId") Long tableId) {
+        genTableService.synchDb(tableId);
         return R.ok();
         return R.ok();
     }
     }
 
 
     /**
     /**
      * 批量生成代码
      * 批量生成代码
      *
      *
-     * @param tables 表名
+     * @param tableIdStr 表ID
      */
      */
     @SaCheckPermission("tool:gen:code")
     @SaCheckPermission("tool:gen:code")
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
     @Log(title = "代码生成", businessType = BusinessType.GENCODE)
     @GetMapping("/batchGenCode")
     @GetMapping("/batchGenCode")
-    public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
-        String[] tableNames = Convert.toStrArray(tables);
-        byte[] data = genTableService.downloadCode(tableNames);
+    public void batchGenCode(HttpServletResponse response, String tableIdStr) throws IOException {
+        String[] tableIds = Convert.toStrArray(tableIdStr);
+        byte[] data = genTableService.downloadCode(tableIds);
         genCode(response, data);
         genCode(response, data);
     }
     }
 
 
@@ -204,4 +205,13 @@ public class GenController extends BaseController {
         response.setContentType("application/octet-stream; charset=UTF-8");
         response.setContentType("application/octet-stream; charset=UTF-8");
         IoUtil.write(response.getOutputStream(), false, data);
         IoUtil.write(response.getOutputStream(), false, data);
     }
     }
+
+    /**
+     * 查询数据源名称列表
+     */
+    @SaCheckPermission("tool:gen:list")
+    @GetMapping(value = "/getDataNames")
+    public R<Object> getCurrentDataSourceNameList(){
+        return R.ok(DataBaseHelper.getDataSourceNameList());
+    }
 }
 }

+ 6 - 0
ruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/domain/GenTable.java

@@ -31,6 +31,12 @@ public class GenTable extends BaseEntity {
     @TableId(value = "table_id")
     @TableId(value = "table_id")
     private Long tableId;
     private Long tableId;
 
 
+    /**
+     * 数据源名称
+     */
+    @NotBlank(message = "数据源名称不能为空")
+    private String dataName;
+
     /**
     /**
      * 表名称
      * 表名称
      */
      */

+ 4 - 1
ruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/mapper/GenTableColumnMapper.java

@@ -1,5 +1,6 @@
 package org.dromara.generator.mapper;
 package org.dromara.generator.mapper;
 
 
+import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
 import org.dromara.generator.domain.GenTableColumn;
 import org.dromara.generator.domain.GenTableColumn;
@@ -17,8 +18,10 @@ public interface GenTableColumnMapper extends BaseMapperPlus<GenTableColumn, Gen
      * 根据表名称查询列信息
      * 根据表名称查询列信息
      *
      *
      * @param tableName 表名称
      * @param tableName 表名称
+     * @param dataName
      * @return 列信息
      * @return 列信息
      */
      */
-    List<GenTableColumn> selectDbTableColumnsByName(String tableName);
+    @DS("#dataName")
+    List<GenTableColumn> selectDbTableColumnsByName(String tableName, String dataName);
 
 
 }
 }

+ 3 - 0
ruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/mapper/GenTableMapper.java

@@ -1,5 +1,6 @@
 package org.dromara.generator.mapper;
 package org.dromara.generator.mapper;
 
 
+import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
@@ -55,4 +56,6 @@ public interface GenTableMapper extends BaseMapperPlus<GenTable, GenTable> {
      */
      */
     GenTable selectGenTableByName(String tableName);
     GenTable selectGenTableByName(String tableName);
 
 
+    @DS("")
+    List<String> selectTableNameList(String dataName);
 }
 }

+ 46 - 32
ruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/service/GenTableServiceImpl.java

@@ -5,13 +5,18 @@ import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.lang.Dict;
 import cn.hutool.core.lang.Dict;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
 import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
 import org.dromara.common.core.constant.Constants;
 import org.dromara.common.core.constant.Constants;
-import org.dromara.generator.constant.GenConstants;
 import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.StreamUtils;
 import org.dromara.common.core.utils.StreamUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.core.utils.StringUtils;
@@ -20,6 +25,7 @@ import org.dromara.common.json.utils.JsonUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.common.satoken.utils.LoginHelper;
+import org.dromara.generator.constant.GenConstants;
 import org.dromara.generator.domain.GenTable;
 import org.dromara.generator.domain.GenTable;
 import org.dromara.generator.domain.GenTableColumn;
 import org.dromara.generator.domain.GenTableColumn;
 import org.dromara.generator.mapper.GenTableColumnMapper;
 import org.dromara.generator.mapper.GenTableColumnMapper;
@@ -27,11 +33,6 @@ import org.dromara.generator.mapper.GenTableMapper;
 import org.dromara.generator.util.GenUtils;
 import org.dromara.generator.util.GenUtils;
 import org.dromara.generator.util.VelocityInitializer;
 import org.dromara.generator.util.VelocityInitializer;
 import org.dromara.generator.util.VelocityUtils;
 import org.dromara.generator.util.VelocityUtils;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
@@ -40,7 +41,11 @@ import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.StringWriter;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 import java.util.zip.ZipOutputStream;
 
 
@@ -49,7 +54,7 @@ import java.util.zip.ZipOutputStream;
  *
  *
  * @author Lion Li
  * @author Lion Li
  */
  */
-@DS("#header.datasource")
+// @DS("#header.datasource")
 @Slf4j
 @Slf4j
 @RequiredArgsConstructor
 @RequiredArgsConstructor
 @Service
 @Service
@@ -94,16 +99,19 @@ public class GenTableServiceImpl implements IGenTableService {
     private QueryWrapper<GenTable> buildGenTableQueryWrapper(GenTable genTable) {
     private QueryWrapper<GenTable> buildGenTableQueryWrapper(GenTable genTable) {
         Map<String, Object> params = genTable.getParams();
         Map<String, Object> params = genTable.getParams();
         QueryWrapper<GenTable> wrapper = Wrappers.query();
         QueryWrapper<GenTable> wrapper = Wrappers.query();
-        wrapper.like(StringUtils.isNotBlank(genTable.getTableName()), "lower(table_name)", StringUtils.lowerCase(genTable.getTableName()))
+        wrapper
+            .eq(StringUtils.isNotEmpty(genTable.getDataName()),"data_name", genTable.getDataName())
+            .like(StringUtils.isNotBlank(genTable.getTableName()), "lower(table_name)", StringUtils.lowerCase(genTable.getTableName()))
             .like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(table_comment)", StringUtils.lowerCase(genTable.getTableComment()))
             .like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(table_comment)", StringUtils.lowerCase(genTable.getTableComment()))
             .between(params.get("beginTime") != null && params.get("endTime") != null,
             .between(params.get("beginTime") != null && params.get("endTime") != null,
                 "create_time", params.get("beginTime"), params.get("endTime"));
                 "create_time", params.get("beginTime"), params.get("endTime"));
         return wrapper;
         return wrapper;
     }
     }
 
 
-
+    @DS("#genTable.dataName")
     @Override
     @Override
     public TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery) {
     public TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery) {
+        genTable.getParams().put("genTableNames",baseMapper.selectTableNameList(genTable.getDataName()));
         Page<GenTable> page = baseMapper.selectPageDbTableList(pageQuery.build(), genTable);
         Page<GenTable> page = baseMapper.selectPageDbTableList(pageQuery.build(), genTable);
         return TableDataInfo.build(page);
         return TableDataInfo.build(page);
     }
     }
@@ -112,10 +120,12 @@ public class GenTableServiceImpl implements IGenTableService {
      * 查询据库列表
      * 查询据库列表
      *
      *
      * @param tableNames 表名称组
      * @param tableNames 表名称组
+     * @param dataName
      * @return 数据库表集合
      * @return 数据库表集合
      */
      */
+    @DS("#dataName")
     @Override
     @Override
-    public List<GenTable> selectDbTableListByNames(String[] tableNames) {
+    public List<GenTable> selectDbTableListByNames(String[] tableNames, String dataName) {
         return baseMapper.selectDbTableListByNames(tableNames);
         return baseMapper.selectDbTableListByNames(tableNames);
     }
     }
 
 
@@ -166,19 +176,21 @@ public class GenTableServiceImpl implements IGenTableService {
      * 导入表结构
      * 导入表结构
      *
      *
      * @param tableList 导入表列表
      * @param tableList 导入表列表
+     * @param dataName
      */
      */
-    @Transactional(rollbackFor = Exception.class)
+    @DSTransactional
     @Override
     @Override
-    public void importGenTable(List<GenTable> tableList) {
+    public void importGenTable(List<GenTable> tableList, String dataName) {
         String operName = LoginHelper.getUsername();
         String operName = LoginHelper.getUsername();
         try {
         try {
             for (GenTable table : tableList) {
             for (GenTable table : tableList) {
                 String tableName = table.getTableName();
                 String tableName = table.getTableName();
                 GenUtils.initTable(table, operName);
                 GenUtils.initTable(table, operName);
+                table.setDataName(dataName);
                 int row = baseMapper.insert(table);
                 int row = baseMapper.insert(table);
                 if (row > 0) {
                 if (row > 0) {
                     // 保存列信息
                     // 保存列信息
-                    List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
+                    List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName, dataName);
                     List<GenTableColumn> saveColumns = new ArrayList<>();
                     List<GenTableColumn> saveColumns = new ArrayList<>();
                     for (GenTableColumn column : genTableColumns) {
                     for (GenTableColumn column : genTableColumns) {
                         GenUtils.initColumnField(column, table);
                         GenUtils.initColumnField(column, table);
@@ -231,14 +243,14 @@ public class GenTableServiceImpl implements IGenTableService {
     /**
     /**
      * 生成代码(下载方式)
      * 生成代码(下载方式)
      *
      *
-     * @param tableName 表名称
+     * @param tableId 表名称
      * @return 数据
      * @return 数据
      */
      */
     @Override
     @Override
-    public byte[] downloadCode(String tableName) {
+    public byte[] downloadCode(Long tableId) {
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         ZipOutputStream zip = new ZipOutputStream(outputStream);
         ZipOutputStream zip = new ZipOutputStream(outputStream);
-        generatorCode(tableName, zip);
+        generatorCode(tableId, zip);
         IoUtil.close(zip);
         IoUtil.close(zip);
         return outputStream.toByteArray();
         return outputStream.toByteArray();
     }
     }
@@ -246,12 +258,12 @@ public class GenTableServiceImpl implements IGenTableService {
     /**
     /**
      * 生成代码(自定义路径)
      * 生成代码(自定义路径)
      *
      *
-     * @param tableName 表名称
+     * @param tableId 表名称
      */
      */
     @Override
     @Override
-    public void generatorCode(String tableName) {
+    public void generatorCode(Long tableId) {
         // 查询表信息
         // 查询表信息
-        GenTable table = baseMapper.selectGenTableByName(tableName);
+        GenTable table = baseMapper.selectGenTableById(tableId);
         // 设置主键列信息
         // 设置主键列信息
         setPkColumn(table);
         setPkColumn(table);
 
 
@@ -280,16 +292,16 @@ public class GenTableServiceImpl implements IGenTableService {
     /**
     /**
      * 同步数据库
      * 同步数据库
      *
      *
-     * @param tableName 表名称
+     * @param tableId 表名称
      */
      */
-    @Transactional(rollbackFor = Exception.class)
+    @DSTransactional
     @Override
     @Override
-    public void synchDb(String tableName) {
-        GenTable table = baseMapper.selectGenTableByName(tableName);
+    public void synchDb(Long tableId) {
+        GenTable table = baseMapper.selectGenTableById(tableId);
         List<GenTableColumn> tableColumns = table.getColumns();
         List<GenTableColumn> tableColumns = table.getColumns();
         Map<String, GenTableColumn> tableColumnMap = StreamUtils.toIdentityMap(tableColumns, GenTableColumn::getColumnName);
         Map<String, GenTableColumn> tableColumnMap = StreamUtils.toIdentityMap(tableColumns, GenTableColumn::getColumnName);
 
 
-        List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
+        List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(table.getTableName(), table.getDataName());
         if (CollUtil.isEmpty(dbTableColumns)) {
         if (CollUtil.isEmpty(dbTableColumns)) {
             throw new ServiceException("同步数据失败,原表结构不存在");
             throw new ServiceException("同步数据失败,原表结构不存在");
         }
         }
@@ -322,22 +334,24 @@ public class GenTableServiceImpl implements IGenTableService {
         List<GenTableColumn> delColumns = StreamUtils.filter(tableColumns, column -> !dbTableColumnNames.contains(column.getColumnName()));
         List<GenTableColumn> delColumns = StreamUtils.filter(tableColumns, column -> !dbTableColumnNames.contains(column.getColumnName()));
         if (CollUtil.isNotEmpty(delColumns)) {
         if (CollUtil.isNotEmpty(delColumns)) {
             List<Long> ids = StreamUtils.toList(delColumns, GenTableColumn::getColumnId);
             List<Long> ids = StreamUtils.toList(delColumns, GenTableColumn::getColumnId);
-            genTableColumnMapper.deleteBatchIds(ids);
+            if (CollUtil.isNotEmpty(ids)) {
+                genTableColumnMapper.deleteBatchIds(ids);
+            }
         }
         }
     }
     }
 
 
     /**
     /**
      * 批量生成代码(下载方式)
      * 批量生成代码(下载方式)
      *
      *
-     * @param tableNames 表数组
+     * @param tableIds 表ID数组
      * @return 数据
      * @return 数据
      */
      */
     @Override
     @Override
-    public byte[] downloadCode(String[] tableNames) {
+    public byte[] downloadCode(String[] tableIds) {
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         ZipOutputStream zip = new ZipOutputStream(outputStream);
         ZipOutputStream zip = new ZipOutputStream(outputStream);
-        for (String tableName : tableNames) {
-            generatorCode(tableName, zip);
+        for (String tableId : tableIds) {
+            generatorCode(Long.parseLong(tableId), zip);
         }
         }
         IoUtil.close(zip);
         IoUtil.close(zip);
         return outputStream.toByteArray();
         return outputStream.toByteArray();
@@ -346,9 +360,9 @@ public class GenTableServiceImpl implements IGenTableService {
     /**
     /**
      * 查询表信息并生成代码
      * 查询表信息并生成代码
      */
      */
-    private void generatorCode(String tableName, ZipOutputStream zip) {
+    private void generatorCode(Long tableId, ZipOutputStream zip) {
         // 查询表信息
         // 查询表信息
-        GenTable table = baseMapper.selectGenTableByName(tableName);
+        GenTable table = baseMapper.selectGenTableById(tableId);
         List<Long> menuIds = new ArrayList<>();
         List<Long> menuIds = new ArrayList<>();
         for (int i = 0; i < 6; i++) {
         for (int i = 0; i < 6; i++) {
             menuIds.add(identifierGenerator.nextId(null).longValue());
             menuIds.add(identifierGenerator.nextId(null).longValue());

+ 12 - 10
ruoyi-modules/ruoyi-generator/src/main/java/org/dromara/generator/service/IGenTableService.java

@@ -43,9 +43,10 @@ public interface IGenTableService {
      * 查询据库列表
      * 查询据库列表
      *
      *
      * @param tableNames 表名称组
      * @param tableNames 表名称组
+     * @param dataName
      * @return 数据库表集合
      * @return 数据库表集合
      */
      */
-    List<GenTable> selectDbTableListByNames(String[] tableNames);
+    List<GenTable> selectDbTableListByNames(String[] tableNames, String dataName);
 
 
     /**
     /**
      * 查询所有表信息
      * 查询所有表信息
@@ -82,8 +83,9 @@ public interface IGenTableService {
      * 导入表结构
      * 导入表结构
      *
      *
      * @param tableList 导入表列表
      * @param tableList 导入表列表
+     * @param dataName
      */
      */
-    void importGenTable(List<GenTable> tableList);
+    void importGenTable(List<GenTable> tableList, String dataName);
 
 
     /**
     /**
      * 预览代码
      * 预览代码
@@ -96,33 +98,33 @@ public interface IGenTableService {
     /**
     /**
      * 生成代码(下载方式)
      * 生成代码(下载方式)
      *
      *
-     * @param tableName 表名称
+     * @param tableId 表名称
      * @return 数据
      * @return 数据
      */
      */
-    byte[] downloadCode(String tableName);
+    byte[] downloadCode(Long tableId);
 
 
     /**
     /**
      * 生成代码(自定义路径)
      * 生成代码(自定义路径)
      *
      *
-     * @param tableName 表名称
+     * @param tableId 表名称
      * @return 数据
      * @return 数据
      */
      */
-    void generatorCode(String tableName);
+    void generatorCode(Long tableId);
 
 
     /**
     /**
      * 同步数据库
      * 同步数据库
      *
      *
-     * @param tableName 表名称
+     * @param tableId 表名称
      */
      */
-    void synchDb(String tableName);
+    void synchDb(Long tableId);
 
 
     /**
     /**
      * 批量生成代码(下载方式)
      * 批量生成代码(下载方式)
      *
      *
-     * @param tableNames 表数组
+     * @param tableIds 表ID数组
      * @return 数据
      * @return 数据
      */
      */
-    byte[] downloadCode(String[] tableNames);
+    byte[] downloadCode(String[] tableIds);
 
 
     /**
     /**
      * 修改保存参数校验
      * 修改保存参数校验

+ 30 - 7
ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml

@@ -20,7 +20,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             from information_schema.tables
             from information_schema.tables
             where table_schema = (select database())
             where table_schema = (select database())
             AND table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
             AND table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
-            AND table_name NOT IN (select table_name from gen_table)
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND table_name NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
             <if test="genTable.tableName != null and genTable.tableName != ''">
             <if test="genTable.tableName != null and genTable.tableName != ''">
                 AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
                 AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
             </if>
             </if>
@@ -36,7 +41,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             and dt.table_name = uo.object_name
             and dt.table_name = uo.object_name
             and uo.object_type = 'TABLE'
             and uo.object_type = 'TABLE'
             AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
             AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
-            AND lower(dt.table_name) NOT IN (select table_name from gen_table)
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND lower(dt.table_name) NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
             <if test="genTable.tableName != null and genTable.tableName != ''">
             <if test="genTable.tableName != null and genTable.tableName != ''">
                 AND lower(dt.table_name) like lower(concat(concat('%', #{genTable.tableName}), '%'))
                 AND lower(dt.table_name) like lower(concat(concat('%', #{genTable.tableName}), '%'))
             </if>
             </if>
@@ -60,7 +70,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                     AND n.nspname <![CDATA[ <> ]]> ''::name
                     AND n.nspname <![CDATA[ <> ]]> ''::name
             ) list_table
             ) list_table
             where table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
             where table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
-            AND table_name NOT IN (select table_name from gen_table)
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND table_name NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
             <if test="genTable.tableName != null and genTable.tableName != ''">
             <if test="genTable.tableName != null and genTable.tableName != ''">
                 AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
                 AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
             </if>
             </if>
@@ -78,7 +93,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
                 INNER JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID
                     AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
                     AND F.MINOR_ID = 0 AND D.XTYPE = 'U' AND D.NAME != 'DTPROPERTIES'
                     AND D.NAME NOT LIKE 'xxl_job_%' AND D.NAME NOT LIKE 'gen_%'
                     AND D.NAME NOT LIKE 'xxl_job_%' AND D.NAME NOT LIKE 'gen_%'
-                    AND D.NAME NOT IN (select table_name from gen_table)
+            <if test="genTable.params.genTableNames != null and genTable.params.genTableNames.size > 0">
+                AND D.NAME NOT IN
+                <foreach collection="genTable.params.genTableNames" open="(" close=")" separator="," item="item">
+                    #{item}
+                </foreach>
+            </if>
             <if test="genTable.tableName != null and genTable.tableName != ''">
             <if test="genTable.tableName != null and genTable.tableName != ''">
                 AND lower(D.NAME) like lower(concat(N'%', N'${genTable.tableName}', N'%'))
                 AND lower(D.NAME) like lower(concat(N'%', N'${genTable.tableName}', N'%'))
             </if>
             </if>
@@ -194,7 +214,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
     </select>
 
 
     <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
     <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
-        SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
+        SELECT t.table_id, t.data_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
         FROM gen_table t
         FROM gen_table t
              LEFT JOIN gen_table_column c ON t.table_id = c.table_id
              LEFT JOIN gen_table_column c ON t.table_id = c.table_id
@@ -202,7 +222,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
     </select>
 
 
     <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
     <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
-        SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
+        SELECT t.table_id, t.data_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
         FROM gen_table t
         FROM gen_table t
              LEFT JOIN gen_table_column c ON t.table_id = c.table_id
              LEFT JOIN gen_table_column c ON t.table_id = c.table_id
@@ -210,11 +230,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
     </select>
 
 
     <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
     <select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
-        SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
+        SELECT t.table_id, t.data_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark,
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
                c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
         FROM gen_table t
         FROM gen_table t
              LEFT JOIN gen_table_column c ON t.table_id = c.table_id
              LEFT JOIN gen_table_column c ON t.table_id = c.table_id
         order by c.sort
         order by c.sort
     </select>
     </select>
 
 
+    <select id="selectTableNameList" resultType="java.lang.String">
+        select table_name from gen_table where data_name = #{dataName,jdbcType=VARCHAR}
+    </select>
 </mapper>
 </mapper>

+ 2 - 0
script/sql/oracle/oracle_ry_vue_5.X.sql

@@ -910,6 +910,7 @@ insert into sys_notice values('2', '000000', '维护通知:2018-07-01 系统
 -- ----------------------------
 -- ----------------------------
 create table gen_table (
 create table gen_table (
   table_id          number(20)       not null,
   table_id          number(20)       not null,
+  data_name         varchar2(200)    default '',
   table_name        varchar2(200)    default '',
   table_name        varchar2(200)    default '',
   table_comment     varchar2(500)    default '',
   table_comment     varchar2(500)    default '',
   sub_table_name    varchar(64)      default null,
   sub_table_name    varchar(64)      default null,
@@ -936,6 +937,7 @@ alter table gen_table add constraint pk_gen_table primary key (table_id);
 
 
 comment on table  gen_table                   is '代码生成业务表';
 comment on table  gen_table                   is '代码生成业务表';
 comment on column gen_table.table_id          is '编号';
 comment on column gen_table.table_id          is '编号';
+comment on column gen_table.data_name         is '数据源名称';
 comment on column gen_table.table_name        is '表名称';
 comment on column gen_table.table_name        is '表名称';
 comment on column gen_table.table_comment     is '表描述';
 comment on column gen_table.table_comment     is '表描述';
 comment on column gen_table.sub_table_name    is '关联子表的表名';
 comment on column gen_table.sub_table_name    is '关联子表的表名';

+ 2 - 0
script/sql/postgres/postgres_ry_vue_5.X.sql

@@ -935,6 +935,7 @@ drop table if exists gen_table;
 create table if not exists gen_table
 create table if not exists gen_table
 (
 (
     table_id          int8,
     table_id          int8,
+    data_name         varchar(200)  default ''::varchar,
     table_name        varchar(200)  default ''::varchar,
     table_name        varchar(200)  default ''::varchar,
     table_comment     varchar(500)  default ''::varchar,
     table_comment     varchar(500)  default ''::varchar,
     sub_table_name    varchar(64)   default ''::varchar,
     sub_table_name    varchar(64)   default ''::varchar,
@@ -960,6 +961,7 @@ create table if not exists gen_table
 
 
 comment on table gen_table is '代码生成业务表';
 comment on table gen_table is '代码生成业务表';
 comment on column gen_table.table_id is '编号';
 comment on column gen_table.table_id is '编号';
+comment on column gen_table.data_name is '数据源名称';
 comment on column gen_table.table_name is '表名称';
 comment on column gen_table.table_name is '表名称';
 comment on column gen_table.table_comment is '表描述';
 comment on column gen_table.table_comment is '表描述';
 comment on column gen_table.sub_table_name is '关联子表的表名';
 comment on column gen_table.sub_table_name is '关联子表的表名';

+ 1 - 0
script/sql/ry_vue_5.X.sql

@@ -686,6 +686,7 @@ insert into sys_notice values('2', '000000', '维护通知:2018-07-01 系统
 drop table if exists gen_table;
 drop table if exists gen_table;
 create table gen_table (
 create table gen_table (
   table_id          bigint(20)      not null                   comment '编号',
   table_id          bigint(20)      not null                   comment '编号',
+  data_name         varchar(200)    default ''                 comment '数据源名称',
   table_name        varchar(200)    default ''                 comment '表名称',
   table_name        varchar(200)    default ''                 comment '表名称',
   table_comment     varchar(500)    default ''                 comment '表描述',
   table_comment     varchar(500)    default ''                 comment '表描述',
   sub_table_name    varchar(64)     default null               comment '关联子表的表名',
   sub_table_name    varchar(64)     default null               comment '关联子表的表名',

+ 7 - 0
script/sql/sqlserver/sqlserver_ry_vue_5.X.sql

@@ -254,6 +254,7 @@ GO
 CREATE TABLE gen_table
 CREATE TABLE gen_table
 (
 (
     table_id          bigint                         NOT NULL,
     table_id          bigint                         NOT NULL,
+    data_name         nvarchar(200) DEFAULT ''       NULL,
     table_name        nvarchar(200) DEFAULT ''       NULL,
     table_name        nvarchar(200) DEFAULT ''       NULL,
     table_comment     nvarchar(500) DEFAULT ''       NULL,
     table_comment     nvarchar(500) DEFAULT ''       NULL,
     sub_table_name    nvarchar(64)                   NULL,
     sub_table_name    nvarchar(64)                   NULL,
@@ -287,6 +288,12 @@ EXEC sys.sp_addextendedproperty
     'TABLE', N'gen_table',
     'TABLE', N'gen_table',
     'COLUMN', N'table_id'
     'COLUMN', N'table_id'
 GO
 GO
+EXEC sys.sp_addextendedproperty
+    'MS_Description', N'数据源名称' ,
+    'SCHEMA', N'dbo',
+    'TABLE', N'gen_table',
+    'COLUMN', N'data_name'
+GO
 EXEC sys.sp_addextendedproperty
 EXEC sys.sp_addextendedproperty
     'MS_Description', N'表名称' ,
     'MS_Description', N'表名称' ,
     'SCHEMA', N'dbo',
     'SCHEMA', N'dbo',