reactor:移除 infra 对 system 的依赖
This commit is contained in:
@@ -26,11 +26,6 @@
|
||||
</dependency>
|
||||
|
||||
<!-- 依赖服务 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
<artifactId>yudao-module-system-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
<artifactId>yudao-module-infra-api</artifactId>
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserNickname;
|
||||
import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment;
|
||||
|
||||
@Tag(name = "管理后台 - 代码生成器")
|
||||
@@ -93,7 +94,7 @@ public class CodegenController {
|
||||
@PostMapping("/create-list")
|
||||
@PreAuthorize("@ss.hasPermission('infra:codegen:create')")
|
||||
public CommonResult<List<Long>> createCodegenList(@Valid @RequestBody CodegenCreateListReqVO reqVO) {
|
||||
return success(codegenService.createCodegenList(getLoginUserId(), reqVO));
|
||||
return success(codegenService.createCodegenList(getLoginUserNickname(), reqVO));
|
||||
}
|
||||
|
||||
@Operation(summary = "更新数据库的表和字段定义")
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ApiErrorLogRespVO {
|
||||
|
||||
@Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "用户类型", converter = DictConvert.class)
|
||||
@DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.USER_TYPE)
|
||||
@DictFormat(DictTypeConstants.USER_TYPE)
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard")
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.enums.codegen;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 代码生成器的字段 HTML 展示枚举
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum CodegenColumnHtmlTypeEnum {
|
||||
|
||||
INPUT("input"), // 文本框
|
||||
TEXTAREA("textarea"), // 文本域
|
||||
SELECT("select"), // 下拉框
|
||||
RADIO("radio"), // 单选框
|
||||
CHECKBOX("checkbox"), // 复选框
|
||||
DATETIME("datetime"), // 日期控件
|
||||
IMAGE_UPLOAD("imageUpload"), // 上传图片
|
||||
FILE_UPLOAD("fileUpload"), // 上传文件
|
||||
EDITOR("editor"), // 富文本控件
|
||||
;
|
||||
|
||||
/**
|
||||
* 条件
|
||||
*/
|
||||
private final String type;
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.enums.codegen;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 代码生成器的字段过滤条件枚举
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum CodegenColumnListConditionEnum {
|
||||
|
||||
EQ("="),
|
||||
NE("!="),
|
||||
GT(">"),
|
||||
GTE(">="),
|
||||
LT("<"),
|
||||
LTE("<="),
|
||||
LIKE("LIKE"),
|
||||
BETWEEN("BETWEEN");
|
||||
|
||||
/**
|
||||
* 条件
|
||||
*/
|
||||
private final String condition;
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.enums.codegen;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 代码生成的前端类型枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum CodegenFrontTypeEnum {
|
||||
|
||||
VUE2_ELEMENT_UI(10), // Vue2 Element UI 标准模版
|
||||
|
||||
VUE3_ELEMENT_PLUS(20), // Vue3 Element Plus 标准模版
|
||||
|
||||
VUE3_VBEN2_ANTD_SCHEMA(30), // Vue3 VBEN2 + ANTD + Schema 模版
|
||||
|
||||
VUE3_VBEN5_ANTD_SCHEMA(40), // Vue3 VBEN5 + ANTD + schema 模版
|
||||
|
||||
VUE3_VBEN5_ANTD_GENERAL(41), // Vue3 VBEN5 + ANTD 标准模版
|
||||
;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final Integer type;
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.enums.codegen;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import static cn.hutool.core.util.ArrayUtil.*;
|
||||
|
||||
/**
|
||||
* 代码生成的场景枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum CodegenSceneEnum {
|
||||
|
||||
ADMIN(1, "管理后台", "admin", ""),
|
||||
APP(2, "用户 APP", "app", "App");
|
||||
|
||||
/**
|
||||
* 场景
|
||||
*/
|
||||
private final Integer scene;
|
||||
/**
|
||||
* 场景名
|
||||
*/
|
||||
private final String name;
|
||||
/**
|
||||
* 基础包名
|
||||
*/
|
||||
private final String basePackage;
|
||||
/**
|
||||
* Controller 和 VO 类的前缀
|
||||
*/
|
||||
private final String prefixClass;
|
||||
|
||||
public static CodegenSceneEnum valueOf(Integer scene) {
|
||||
return firstMatch(sceneEnum -> sceneEnum.getScene().equals(scene), values());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.enums.codegen;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 代码生成模板类型
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum CodegenTemplateTypeEnum {
|
||||
|
||||
ONE(1), // 单表(增删改查)
|
||||
TREE(2), // 树表(增删改查)
|
||||
|
||||
MASTER_NORMAL(10), // 主子表 - 主表 - 普通模式
|
||||
MASTER_ERP(11), // 主子表 - 主表 - ERP 模式
|
||||
MASTER_INNER(12), // 主子表 - 主表 - 内嵌模式
|
||||
SUB(15), // 主子表 - 子表
|
||||
;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final Integer type;
|
||||
|
||||
/**
|
||||
* 是否为主表
|
||||
*
|
||||
* @param type 类型
|
||||
* @return 是否主表
|
||||
*/
|
||||
public static boolean isMaster(Integer type) {
|
||||
return ObjectUtils.equalsAny(type,
|
||||
MASTER_NORMAL.type, MASTER_ERP.type, MASTER_INNER.type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为树表
|
||||
*
|
||||
* @param type 类型
|
||||
* @return 是否树表
|
||||
*/
|
||||
public static boolean isTree(Integer type) {
|
||||
return Objects.equals(type, TREE.type);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.enums.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ConfigTypeEnum {
|
||||
|
||||
/**
|
||||
* 系统配置
|
||||
*/
|
||||
SYSTEM(1),
|
||||
/**
|
||||
* 自定义配置
|
||||
*/
|
||||
CUSTOM(2);
|
||||
|
||||
private final Integer type;
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.enums.logger;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* API 异常数据的处理状态
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ApiErrorLogProcessStatusEnum {
|
||||
|
||||
INIT(0, "未处理"),
|
||||
DONE(1, "已处理"),
|
||||
IGNORE(2, "已忽略");
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private final Integer status;
|
||||
/**
|
||||
* 资源类型名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* 占位
|
||||
*/
|
||||
package cn.iocoder.yudao.module.infra.enums;
|
||||
@@ -1,10 +1,9 @@
|
||||
package cn.iocoder.yudao.module.infra.framework.rpc.config;
|
||||
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(value = "infraRpcConfiguration", proxyBeanMethods = false)
|
||||
@EnableFeignClients(clients = AdminUserApi.class)
|
||||
@EnableFeignClients()
|
||||
public class RpcConfiguration {
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ public interface CodegenService {
|
||||
/**
|
||||
* 基于数据库的表结构,创建代码生成器的表定义
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param author 作者
|
||||
* @param reqVO 表信息
|
||||
* @return 创建的表定义的编号数组
|
||||
*/
|
||||
List<Long> createCodegenList(Long userId, CodegenCreateListReqVO reqVO);
|
||||
List<Long> createCodegenList(String author, CodegenCreateListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新数据库的表和字段定义
|
||||
|
||||
@@ -18,7 +18,6 @@ import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine;
|
||||
import cn.iocoder.yudao.module.infra.service.db.DatabaseTableService;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableField;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
@@ -52,9 +51,6 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
@Resource
|
||||
private CodegenColumnMapper codegenColumnMapper;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi userApi;
|
||||
|
||||
@Resource
|
||||
private CodegenBuilder codegenBuilder;
|
||||
@Resource
|
||||
@@ -65,21 +61,21 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<Long> createCodegenList(Long userId, CodegenCreateListReqVO reqVO) {
|
||||
public List<Long> createCodegenList(String author, CodegenCreateListReqVO reqVO) {
|
||||
List<Long> ids = new ArrayList<>(reqVO.getTableNames().size());
|
||||
// 遍历添加。虽然效率会低一点,但是没必要做成完全批量,因为不会这么大量
|
||||
reqVO.getTableNames().forEach(tableName -> ids.add(createCodegen(userId, reqVO.getDataSourceConfigId(), tableName)));
|
||||
reqVO.getTableNames().forEach(tableName -> ids.add(createCodegen(author, reqVO.getDataSourceConfigId(), tableName)));
|
||||
return ids;
|
||||
}
|
||||
|
||||
private Long createCodegen(Long userId, Long dataSourceConfigId, String tableName) {
|
||||
private Long createCodegen(String author, Long dataSourceConfigId, String tableName) {
|
||||
// 从数据库中,获得数据库表结构
|
||||
TableInfo tableInfo = databaseTableService.getTable(dataSourceConfigId, tableName);
|
||||
// 导入
|
||||
return createCodegen0(userId, dataSourceConfigId, tableInfo);
|
||||
return createCodegen0(author, dataSourceConfigId, tableInfo);
|
||||
}
|
||||
|
||||
private Long createCodegen0(Long userId, Long dataSourceConfigId, TableInfo tableInfo) {
|
||||
private Long createCodegen0(String author, Long dataSourceConfigId, TableInfo tableInfo) {
|
||||
// 校验导入的表和字段非空
|
||||
validateTableInfo(tableInfo);
|
||||
// 校验是否已经存在
|
||||
@@ -93,7 +89,7 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
table.setDataSourceConfigId(dataSourceConfigId);
|
||||
table.setScene(CodegenSceneEnum.ADMIN.getScene()); // 默认配置下,使用管理后台的模板
|
||||
table.setFrontType(codegenProperties.getFrontType());
|
||||
table.setAuthor(userApi.getUser(userId).getCheckedData().getNickname());
|
||||
table.setAuthor(author);
|
||||
codegenTableMapper.insert(table);
|
||||
|
||||
// 构建 CodegenColumnDO 数组,插入到 DB 中
|
||||
|
||||
@@ -20,8 +20,6 @@ import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine;
|
||||
import cn.iocoder.yudao.module.infra.service.db.DatabaseTableService;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableField;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -34,7 +32,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
@@ -66,9 +63,6 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
@MockBean
|
||||
private DatabaseTableService databaseTableService;
|
||||
|
||||
@MockBean
|
||||
private AdminUserApi userApi;
|
||||
|
||||
@MockBean
|
||||
private CodegenBuilder codegenBuilder;
|
||||
@MockBean
|
||||
@@ -80,7 +74,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
@Test
|
||||
public void testCreateCodegenList() {
|
||||
// 准备参数
|
||||
Long userId = randomLongId();
|
||||
String author = randomString();
|
||||
CodegenCreateListReqVO reqVO = randomPojo(CodegenCreateListReqVO.class,
|
||||
o -> o.setDataSourceConfigId(1L).setTableNames(Collections.singletonList("t_yunai")));
|
||||
// mock 方法(TableInfo)
|
||||
@@ -98,9 +92,6 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
// mock 方法(CodegenTableDO)
|
||||
CodegenTableDO table = randomPojo(CodegenTableDO.class);
|
||||
when(codegenBuilder.buildTable(same(tableInfo))).thenReturn(table);
|
||||
// mock 方法(AdminUserRespDTO)
|
||||
AdminUserRespDTO user = randomPojo(AdminUserRespDTO.class, o -> o.setNickname("芋头"));
|
||||
when(userApi.getUser(eq(userId))).thenReturn(success(user));
|
||||
// mock 方法(CodegenColumnDO)
|
||||
List<CodegenColumnDO> columns = randomPojoList(CodegenColumnDO.class);
|
||||
when(codegenBuilder.buildColumns(eq(table.getId()), same(fields)))
|
||||
@@ -109,7 +100,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
when(codegenProperties.getFrontType()).thenReturn(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType());
|
||||
|
||||
// 调用
|
||||
List<Long> result = codegenService.createCodegenList(userId, reqVO);
|
||||
List<Long> result = codegenService.createCodegenList(author, reqVO);
|
||||
// 断言
|
||||
assertEquals(1, result.size());
|
||||
// 断言(CodegenTableDO)
|
||||
@@ -118,7 +109,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
assertEquals(1L, dbTable.getDataSourceConfigId());
|
||||
assertEquals(CodegenSceneEnum.ADMIN.getScene(), dbTable.getScene());
|
||||
assertEquals(CodegenFrontTypeEnum.VUE3_ELEMENT_PLUS.getType(), dbTable.getFrontType());
|
||||
assertEquals("芋头", dbTable.getAuthor());
|
||||
assertEquals(author, dbTable.getAuthor());
|
||||
// 断言(CodegenColumnDO)
|
||||
List<CodegenColumnDO> dbColumns = codegenColumnMapper.selectList();
|
||||
assertEquals(columns.size(), dbColumns.size());
|
||||
|
||||
Reference in New Issue
Block a user