mirror of
https://github.com/YunaiV/ruoyi-vue-pro.git
synced 2026-04-19 12:48:38 +00:00
Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/ruoyi-vue-pro
# Conflicts: # README.md # pom.xml # yudao-dependencies/pom.xml # yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/app/file/AppFileController.java # yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java # yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImplTest.java # yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notify/NotifyMessageServiceImplTest.java # yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/sms/SmsCodeServiceImplTest.java
This commit is contained in:
@@ -2,19 +2,19 @@ package cn.iocoder.yudao.module.infra.controller.app.file;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresignedUrlRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.app.file.vo.AppFileUploadReqVO;
|
||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "用户 App - 文件存储")
|
||||
@@ -35,4 +35,16 @@ public class AppFileController {
|
||||
return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
|
||||
}
|
||||
|
||||
@GetMapping("/presigned-url")
|
||||
@Operation(summary = "获取文件预签名地址", description = "模式二:前端上传文件:用于前端直接上传七牛、阿里云 OSS 等文件存储器")
|
||||
public CommonResult<FilePresignedUrlRespVO> getFilePresignedUrl(@RequestParam("path") String path) throws Exception {
|
||||
return success(fileService.getFilePresignedUrl(path));
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建文件", description = "模式二:前端上传文件:配合 presigned-url 接口,记录上传了上传的文件")
|
||||
public CommonResult<Long> createFile(@Valid @RequestBody FileCreateReqVO createReqVO) {
|
||||
return success(fileService.createFile(createReqVO));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface CodegenColumnMapper extends BaseMapperX<CodegenColumnDO> {
|
||||
default List<CodegenColumnDO> selectListByTableId(Long tableId) {
|
||||
return selectList(new LambdaQueryWrapperX<CodegenColumnDO>()
|
||||
.eq(CodegenColumnDO::getTableId, tableId)
|
||||
.orderByAsc(CodegenColumnDO::getId));
|
||||
.orderByAsc(CodegenColumnDO::getOrdinalPosition));
|
||||
}
|
||||
|
||||
default void deleteListByTableId(Long tableId) {
|
||||
|
||||
@@ -34,4 +34,10 @@ public class CodegenProperties {
|
||||
@NotNull(message = "代码生成的前端类型不能为空")
|
||||
private Integer frontType;
|
||||
|
||||
/**
|
||||
* 是否生成单元测试
|
||||
*/
|
||||
@NotNull(message = "是否生成单元测试不能为空")
|
||||
private Boolean unitTestEnable;
|
||||
|
||||
}
|
||||
|
||||
@@ -22,13 +22,14 @@ 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;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
@@ -179,11 +180,18 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
&& tableField.getMetaInfo().isNullable() == codegenColumn.getNullable()
|
||||
&& tableField.isKeyFlag() == codegenColumn.getPrimaryKey()
|
||||
&& tableField.getComment().equals(codegenColumn.getColumnComment());
|
||||
Set<String> modifyFieldNames = tableFields.stream()
|
||||
.filter(tableField -> codegenColumnDOMap.get(tableField.getColumnName()) != null
|
||||
&& !primaryKeyPredicate.test(tableField, codegenColumnDOMap.get(tableField.getColumnName())))
|
||||
.map(TableField::getColumnName)
|
||||
.collect(Collectors.toSet());
|
||||
Set<String> modifyFieldNames = IntStream.range(0, tableFields.size()).mapToObj(index -> {
|
||||
TableField tableField = tableFields.get(index);
|
||||
String columnName = tableField.getColumnName();
|
||||
CodegenColumnDO codegenColumn = codegenColumnDOMap.get(columnName);
|
||||
if (codegenColumn == null) {
|
||||
return null;
|
||||
}
|
||||
if (!primaryKeyPredicate.test(tableField, codegenColumn) || codegenColumn.getOrdinalPosition() != index) {
|
||||
return columnName;
|
||||
}
|
||||
return null;
|
||||
}).filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
// 3.2 计算需要【删除】的字段
|
||||
Set<String> tableFieldNames = convertSet(tableFields, TableField::getName);
|
||||
Set<Long> deleteColumnIds = codegenColumns.stream()
|
||||
|
||||
@@ -398,6 +398,11 @@ public class CodegenEngine {
|
||||
Map<String, String> templates = new LinkedHashMap<>();
|
||||
templates.putAll(SERVER_TEMPLATES);
|
||||
templates.putAll(FRONT_TEMPLATES.row(frontType));
|
||||
// 如果禁用单元测试,则移除对应的模版
|
||||
if (Boolean.FALSE.equals(codegenProperties.getUnitTestEnable())) {
|
||||
templates.remove(javaTemplatePath("test/serviceTest"));
|
||||
templates.remove("codegen/sql/h2.vm");
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||
@@ -18,7 +17,6 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -49,12 +47,11 @@ public class DatabaseTableServiceImpl implements DatabaseTableService {
|
||||
// 获得数据源配置
|
||||
DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId);
|
||||
Assert.notNull(config, "数据源({}) 不存在!", dataSourceConfigId);
|
||||
DbType dbType = JdbcUtils.getDbType(config.getUrl());
|
||||
|
||||
// 使用 MyBatis Plus Generator 解析表结构
|
||||
DataSourceConfig.Builder dataSourceConfigBuilder = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(),
|
||||
config.getPassword());
|
||||
if (Objects.equals(dbType, DbType.SQL_SERVER)) { // 特殊:SQLServer jdbc 非标准,参见 https://github.com/baomidou/mybatis-plus/issues/5419
|
||||
if (JdbcUtils.isSQLServer(config.getUrl())) { // 特殊:SQLServer jdbc 非标准,参见 https://github.com/baomidou/mybatis-plus/issues/5419
|
||||
dataSourceConfigBuilder.databaseQueryClass(SQLQuery.class);
|
||||
}
|
||||
StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder().enableSkipView(); // 忽略视图,业务上一般用不到
|
||||
|
||||
@@ -24,12 +24,11 @@ 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 org.junit.jupiter.api.Disabled;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -234,17 +233,16 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO @芋艿:这个单测会随机性失败,需要定位下;
|
||||
public void testSyncCodegenFromDB() {
|
||||
// mock 数据(CodegenTableDO)
|
||||
CodegenTableDO table = randomPojo(CodegenTableDO.class, o -> o.setTableName("t_yunai")
|
||||
.setDataSourceConfigId(1L).setScene(CodegenSceneEnum.ADMIN.getScene()));
|
||||
codegenTableMapper.insert(table);
|
||||
CodegenColumnDO column01 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId())
|
||||
.setColumnName("id"));
|
||||
.setColumnName("id").setPrimaryKey(true).setOrdinalPosition(0));
|
||||
codegenColumnMapper.insert(column01);
|
||||
CodegenColumnDO column02 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId())
|
||||
.setColumnName("name"));
|
||||
.setColumnName("name").setOrdinalPosition(1));
|
||||
codegenColumnMapper.insert(column02);
|
||||
// 准备参数
|
||||
Long tableId = table.getId();
|
||||
@@ -263,7 +261,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai")))
|
||||
.thenReturn(tableInfo);
|
||||
// mock 方法(CodegenTableDO)
|
||||
List<CodegenColumnDO> newColumns = randomPojoList(CodegenColumnDO.class);
|
||||
List<CodegenColumnDO> newColumns = randomPojoList(CodegenColumnDO.class, 2);
|
||||
when(codegenBuilder.buildColumns(eq(table.getId()), argThat(tableFields -> {
|
||||
assertEquals(2, tableFields.size());
|
||||
assertSame(tableInfo.getFields(), tableFields);
|
||||
@@ -457,9 +455,11 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
.setTemplateType(CodegenTemplateTypeEnum.ONE.getType()));
|
||||
codegenTableMapper.insert(table);
|
||||
// mock 数据(CodegenColumnDO)
|
||||
CodegenColumnDO column01 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId()));
|
||||
CodegenColumnDO column01 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId())
|
||||
.setOrdinalPosition(1));
|
||||
codegenColumnMapper.insert(column01);
|
||||
CodegenColumnDO column02 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId()));
|
||||
CodegenColumnDO column02 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId())
|
||||
.setOrdinalPosition(2));
|
||||
codegenColumnMapper.insert(column02);
|
||||
// mock 执行生成
|
||||
Map<String, String> codes = MapUtil.of(randomString(), randomString());
|
||||
@@ -486,9 +486,11 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
.setTemplateType(CodegenTemplateTypeEnum.MASTER_NORMAL.getType()));
|
||||
codegenTableMapper.insert(table);
|
||||
// mock 数据(CodegenColumnDO)
|
||||
CodegenColumnDO column01 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId()));
|
||||
CodegenColumnDO column01 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId())
|
||||
.setOrdinalPosition(1));
|
||||
codegenColumnMapper.insert(column01);
|
||||
CodegenColumnDO column02 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId()));
|
||||
CodegenColumnDO column02 = randomPojo(CodegenColumnDO.class, o -> o.setTableId(table.getId())
|
||||
.setOrdinalPosition(2));
|
||||
codegenColumnMapper.insert(column02);
|
||||
// mock 数据(sub CodegenTableDO)
|
||||
CodegenTableDO subTable = randomPojo(CodegenTableDO.class,
|
||||
|
||||
Reference in New Issue
Block a user