Commit 3f8a5abe244ae115675425f8de3fac2b52ac213e
Committed by
GitHub
Merge pull request #12 from shanzhiliu/master
代码生成模块,基于DB导入时,多个schema下有相同的表,导入异常的问题处理
Showing
3 changed files
with
12 additions
and
7 deletions
src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaColumnMapper.java
| @@ -10,9 +10,10 @@ import java.util.List; | @@ -10,9 +10,10 @@ import java.util.List; | ||
| 10 | @Mapper | 10 | @Mapper |
| 11 | public interface ToolSchemaColumnMapper extends BaseMapperX<ToolSchemaColumnDO> { | 11 | public interface ToolSchemaColumnMapper extends BaseMapperX<ToolSchemaColumnDO> { |
| 12 | 12 | ||
| 13 | - default List<ToolSchemaColumnDO> selectListByTableName(String tableName) { | 13 | + default List<ToolSchemaColumnDO> selectListByTableName(String tableSchema, String tableName) { |
| 14 | return selectList(new QueryWrapper<ToolSchemaColumnDO>().eq("table_name", tableName) | 14 | return selectList(new QueryWrapper<ToolSchemaColumnDO>().eq("table_name", tableName) |
| 15 | - .orderByAsc("ordinal_position")); | 15 | + .eq("table_schema", tableSchema) |
| 16 | + .orderByAsc("ordinal_position")); | ||
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | } | 19 | } |
src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaTableMapper.java
| @@ -22,8 +22,9 @@ public interface ToolSchemaTableMapper extends BaseMapperX<ToolSchemaTableDO> { | @@ -22,8 +22,9 @@ public interface ToolSchemaTableMapper extends BaseMapperX<ToolSchemaTableDO> { | ||
| 22 | return selectList(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema", tableSchema)); | 22 | return selectList(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema", tableSchema)); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | - default ToolSchemaTableDO selectByTableName(String tableName) { | ||
| 26 | - return selectOne(new QueryWrapper<ToolSchemaTableDO>().eq("table_name", tableName)); | 25 | + default ToolSchemaTableDO selectByTableName1(String tableSchema, String tableName) { |
| 26 | + return selectOne(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema",tableSchema) | ||
| 27 | + .eq("table_name", tableName)); | ||
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | } | 30 | } |
src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java
| @@ -101,9 +101,11 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | @@ -101,9 +101,11 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | ||
| 101 | 101 | ||
| 102 | @Override | 102 | @Override |
| 103 | public Long createCodegen(String tableName) { | 103 | public Long createCodegen(String tableName) { |
| 104 | + //获取当前schema | ||
| 105 | + String tableSchema = codegenProperties.getDbSchemas().iterator().next(); | ||
| 104 | // 从数据库中,获得数据库表结构 | 106 | // 从数据库中,获得数据库表结构 |
| 105 | - ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableName(tableName); | ||
| 106 | - List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableName); | 107 | + ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableName1(tableSchema, tableName); |
| 108 | + List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, tableName); | ||
| 107 | // 导入 | 109 | // 导入 |
| 108 | return this.createCodegen0(ToolCodegenImportTypeEnum.DB, schemaTable, schemaColumns); | 110 | return this.createCodegen0(ToolCodegenImportTypeEnum.DB, schemaTable, schemaColumns); |
| 109 | } | 111 | } |
| @@ -141,8 +143,9 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | @@ -141,8 +143,9 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { | ||
| 141 | if (table == null) { | 143 | if (table == null) { |
| 142 | throw exception(CODEGEN_TABLE_NOT_EXISTS); | 144 | throw exception(CODEGEN_TABLE_NOT_EXISTS); |
| 143 | } | 145 | } |
| 146 | + String tableSchema = codegenProperties.getDbSchemas().iterator().next(); | ||
| 144 | // 从数据库中,获得数据库表结构 | 147 | // 从数据库中,获得数据库表结构 |
| 145 | - List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(table.getTableName()); | 148 | + List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, table.getTableName()); |
| 146 | 149 | ||
| 147 | // 执行同步 | 150 | // 执行同步 |
| 148 | this.syncCodegen0(tableId, schemaColumns); | 151 | this.syncCodegen0(tableId, schemaColumns); |