Commit ee7b3fb2750951c680f76d059cae7f01ec644e53
1 parent
23bb3ebd
reactor:移除 infra 对 system 的依赖
Showing
5 changed files
with
13 additions
and
30 deletions
yudao-module-infra/yudao-module-infra-biz/pom.xml
| ... | ... | @@ -21,11 +21,6 @@ |
| 21 | 21 | <dependencies> |
| 22 | 22 | <dependency> |
| 23 | 23 | <groupId>cn.iocoder.boot</groupId> |
| 24 | - <artifactId>yudao-module-system-api</artifactId> | |
| 25 | - <version>${revision}</version> | |
| 26 | - </dependency> | |
| 27 | - <dependency> | |
| 28 | - <groupId>cn.iocoder.boot</groupId> | |
| 29 | 24 | <artifactId>yudao-module-infra-api</artifactId> |
| 30 | 25 | <version>${revision}</version> |
| 31 | 26 | </dependency> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/CodegenController.java
| ... | ... | @@ -34,7 +34,7 @@ import java.util.List; |
| 34 | 34 | import java.util.Map; |
| 35 | 35 | |
| 36 | 36 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 37 | -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 37 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserNickname; | |
| 38 | 38 | import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment; |
| 39 | 39 | |
| 40 | 40 | @Tag(name = "管理后台 - 代码生成器") |
| ... | ... | @@ -93,7 +93,7 @@ public class CodegenController { |
| 93 | 93 | @PostMapping("/create-list") |
| 94 | 94 | @PreAuthorize("@ss.hasPermission('infra:codegen:create')") |
| 95 | 95 | public CommonResult<List<Long>> createCodegenList(@Valid @RequestBody CodegenCreateListReqVO reqVO) { |
| 96 | - return success(codegenService.createCodegenList(getLoginUserId(), reqVO)); | |
| 96 | + return success(codegenService.createCodegenList(getLoginUserNickname(), reqVO)); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | @Operation(summary = "更新数据库的表和字段定义") | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenService.java
| ... | ... | @@ -21,11 +21,11 @@ public interface CodegenService { |
| 21 | 21 | /** |
| 22 | 22 | * 基于数据库的表结构,创建代码生成器的表定义 |
| 23 | 23 | * |
| 24 | - * @param userId 用户编号 | |
| 24 | + * @param author 作者 | |
| 25 | 25 | * @param reqVO 表信息 |
| 26 | 26 | * @return 创建的表定义的编号数组 |
| 27 | 27 | */ |
| 28 | - List<Long> createCodegenList(Long userId, CodegenCreateListReqVO reqVO); | |
| 28 | + List<Long> createCodegenList(String author, CodegenCreateListReqVO reqVO); | |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * 更新数据库的表和字段定义 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java
| ... | ... | @@ -18,7 +18,6 @@ import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; |
| 18 | 18 | import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder; |
| 19 | 19 | import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine; |
| 20 | 20 | import cn.iocoder.yudao.module.infra.service.db.DatabaseTableService; |
| 21 | -import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 22 | 21 | import com.baomidou.mybatisplus.generator.config.po.TableField; |
| 23 | 22 | import com.baomidou.mybatisplus.generator.config.po.TableInfo; |
| 24 | 23 | import com.google.common.annotations.VisibleForTesting; |
| ... | ... | @@ -53,9 +52,6 @@ public class CodegenServiceImpl implements CodegenService { |
| 53 | 52 | private CodegenColumnMapper codegenColumnMapper; |
| 54 | 53 | |
| 55 | 54 | @Resource |
| 56 | - private AdminUserApi userApi; | |
| 57 | - | |
| 58 | - @Resource | |
| 59 | 55 | private CodegenBuilder codegenBuilder; |
| 60 | 56 | @Resource |
| 61 | 57 | private CodegenEngine codegenEngine; |
| ... | ... | @@ -65,21 +61,21 @@ public class CodegenServiceImpl implements CodegenService { |
| 65 | 61 | |
| 66 | 62 | @Override |
| 67 | 63 | @Transactional(rollbackFor = Exception.class) |
| 68 | - public List<Long> createCodegenList(Long userId, CodegenCreateListReqVO reqVO) { | |
| 64 | + public List<Long> createCodegenList(String author, CodegenCreateListReqVO reqVO) { | |
| 69 | 65 | List<Long> ids = new ArrayList<>(reqVO.getTableNames().size()); |
| 70 | 66 | // 遍历添加。虽然效率会低一点,但是没必要做成完全批量,因为不会这么大量 |
| 71 | - reqVO.getTableNames().forEach(tableName -> ids.add(createCodegen(userId, reqVO.getDataSourceConfigId(), tableName))); | |
| 67 | + reqVO.getTableNames().forEach(tableName -> ids.add(createCodegen(author, reqVO.getDataSourceConfigId(), tableName))); | |
| 72 | 68 | return ids; |
| 73 | 69 | } |
| 74 | 70 | |
| 75 | - private Long createCodegen(Long userId, Long dataSourceConfigId, String tableName) { | |
| 71 | + private Long createCodegen(String author, Long dataSourceConfigId, String tableName) { | |
| 76 | 72 | // 从数据库中,获得数据库表结构 |
| 77 | 73 | TableInfo tableInfo = databaseTableService.getTable(dataSourceConfigId, tableName); |
| 78 | 74 | // 导入 |
| 79 | - return createCodegen0(userId, dataSourceConfigId, tableInfo); | |
| 75 | + return createCodegen0(author, dataSourceConfigId, tableInfo); | |
| 80 | 76 | } |
| 81 | 77 | |
| 82 | - private Long createCodegen0(Long userId, Long dataSourceConfigId, TableInfo tableInfo) { | |
| 78 | + private Long createCodegen0(String author, Long dataSourceConfigId, TableInfo tableInfo) { | |
| 83 | 79 | // 校验导入的表和字段非空 |
| 84 | 80 | validateTableInfo(tableInfo); |
| 85 | 81 | // 校验是否已经存在 |
| ... | ... | @@ -93,7 +89,7 @@ public class CodegenServiceImpl implements CodegenService { |
| 93 | 89 | table.setDataSourceConfigId(dataSourceConfigId); |
| 94 | 90 | table.setScene(CodegenSceneEnum.ADMIN.getScene()); // 默认配置下,使用管理后台的模板 |
| 95 | 91 | table.setFrontType(codegenProperties.getFrontType()); |
| 96 | - table.setAuthor(userApi.getUser(userId).getNickname()); | |
| 92 | + table.setAuthor(author); | |
| 97 | 93 | codegenTableMapper.insert(table); |
| 98 | 94 | |
| 99 | 95 | // 构建 CodegenColumnDO 数组,插入到 DB 中 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImplTest.java
| ... | ... | @@ -20,8 +20,6 @@ import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; |
| 20 | 20 | import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder; |
| 21 | 21 | import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine; |
| 22 | 22 | import cn.iocoder.yudao.module.infra.service.db.DatabaseTableService; |
| 23 | -import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 24 | -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | |
| 25 | 23 | import com.baomidou.mybatisplus.generator.config.po.TableField; |
| 26 | 24 | import com.baomidou.mybatisplus.generator.config.po.TableInfo; |
| 27 | 25 | import jakarta.annotation.Resource; |
| ... | ... | @@ -66,9 +64,6 @@ public class CodegenServiceImplTest extends BaseDbUnitTest { |
| 66 | 64 | private DatabaseTableService databaseTableService; |
| 67 | 65 | |
| 68 | 66 | @MockBean |
| 69 | - private AdminUserApi userApi; | |
| 70 | - | |
| 71 | - @MockBean | |
| 72 | 67 | private CodegenBuilder codegenBuilder; |
| 73 | 68 | @MockBean |
| 74 | 69 | private CodegenEngine codegenEngine; |
| ... | ... | @@ -79,7 +74,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest { |
| 79 | 74 | @Test |
| 80 | 75 | public void testCreateCodegenList() { |
| 81 | 76 | // 准备参数 |
| 82 | - Long userId = randomLongId(); | |
| 77 | + String author = randomString(); | |
| 83 | 78 | CodegenCreateListReqVO reqVO = randomPojo(CodegenCreateListReqVO.class, |
| 84 | 79 | o -> o.setDataSourceConfigId(1L).setTableNames(Collections.singletonList("t_yunai"))); |
| 85 | 80 | // mock 方法(TableInfo) |
| ... | ... | @@ -97,9 +92,6 @@ public class CodegenServiceImplTest extends BaseDbUnitTest { |
| 97 | 92 | // mock 方法(CodegenTableDO) |
| 98 | 93 | CodegenTableDO table = randomPojo(CodegenTableDO.class); |
| 99 | 94 | when(codegenBuilder.buildTable(same(tableInfo))).thenReturn(table); |
| 100 | - // mock 方法(AdminUserRespDTO) | |
| 101 | - AdminUserRespDTO user = randomPojo(AdminUserRespDTO.class, o -> o.setNickname("芋头")); | |
| 102 | - when(userApi.getUser(eq(userId))).thenReturn(user); | |
| 103 | 95 | // mock 方法(CodegenColumnDO) |
| 104 | 96 | List<CodegenColumnDO> columns = randomPojoList(CodegenColumnDO.class); |
| 105 | 97 | when(codegenBuilder.buildColumns(eq(table.getId()), same(fields))) |
| ... | ... | @@ -108,7 +100,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest { |
| 108 | 100 | when(codegenProperties.getFrontType()).thenReturn(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType()); |
| 109 | 101 | |
| 110 | 102 | // 调用 |
| 111 | - List<Long> result = codegenService.createCodegenList(userId, reqVO); | |
| 103 | + List<Long> result = codegenService.createCodegenList(author, reqVO); | |
| 112 | 104 | // 断言 |
| 113 | 105 | assertEquals(1, result.size()); |
| 114 | 106 | // 断言(CodegenTableDO) |
| ... | ... | @@ -117,7 +109,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest { |
| 117 | 109 | assertEquals(1L, dbTable.getDataSourceConfigId()); |
| 118 | 110 | assertEquals(CodegenSceneEnum.ADMIN.getScene(), dbTable.getScene()); |
| 119 | 111 | assertEquals(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), dbTable.getFrontType()); |
| 120 | - assertEquals("芋头", dbTable.getAuthor()); | |
| 112 | + assertEquals(author, dbTable.getAuthor()); | |
| 121 | 113 | // 断言(CodegenColumnDO) |
| 122 | 114 | List<CodegenColumnDO> dbColumns = codegenColumnMapper.selectList(); |
| 123 | 115 | assertEquals(columns.size(), dbColumns.size()); | ... | ... |