Commit 35d171b1d97e5ea9b10d0f86737091e1752bae78
1 parent
fc3bb430
🔧 简化 file 模块的 VO
Showing
12 changed files
with
82 additions
and
157 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.java
| ... | ... | @@ -2,16 +2,15 @@ package cn.iocoder.yudao.module.infra.controller.admin.file; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | 6 | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigRespVO; |
| 8 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; | |
| 9 | -import cn.iocoder.yudao.module.infra.convert.file.FileConfigConvert; | |
| 8 | +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; | |
| 10 | 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; |
| 11 | 10 | import cn.iocoder.yudao.module.infra.service.file.FileConfigService; |
| 12 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 14 | 11 | import io.swagger.v3.oas.annotations.Operation; |
| 12 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 13 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | 14 | import org.springframework.security.access.prepost.PreAuthorize; |
| 16 | 15 | import org.springframework.validation.annotation.Validated; |
| 17 | 16 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -33,14 +32,14 @@ public class FileConfigController { |
| 33 | 32 | @PostMapping("/create") |
| 34 | 33 | @Operation(summary = "创建文件配置") |
| 35 | 34 | @PreAuthorize("@ss.hasPermission('infra:file-config:create')") |
| 36 | - public CommonResult<Long> createFileConfig(@Valid @RequestBody FileConfigCreateReqVO createReqVO) { | |
| 35 | + public CommonResult<Long> createFileConfig(@Valid @RequestBody FileConfigSaveReqVO createReqVO) { | |
| 37 | 36 | return success(fileConfigService.createFileConfig(createReqVO)); |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | 39 | @PutMapping("/update") |
| 41 | 40 | @Operation(summary = "更新文件配置") |
| 42 | 41 | @PreAuthorize("@ss.hasPermission('infra:file-config:update')") |
| 43 | - public CommonResult<Boolean> updateFileConfig(@Valid @RequestBody FileConfigUpdateReqVO updateReqVO) { | |
| 42 | + public CommonResult<Boolean> updateFileConfig(@Valid @RequestBody FileConfigSaveReqVO updateReqVO) { | |
| 44 | 43 | fileConfigService.updateFileConfig(updateReqVO); |
| 45 | 44 | return success(true); |
| 46 | 45 | } |
| ... | ... | @@ -67,8 +66,8 @@ public class FileConfigController { |
| 67 | 66 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 68 | 67 | @PreAuthorize("@ss.hasPermission('infra:file-config:query')") |
| 69 | 68 | public CommonResult<FileConfigRespVO> getFileConfig(@RequestParam("id") Long id) { |
| 70 | - FileConfigDO fileConfig = fileConfigService.getFileConfig(id); | |
| 71 | - return success(FileConfigConvert.INSTANCE.convert(fileConfig)); | |
| 69 | + FileConfigDO config = fileConfigService.getFileConfig(id); | |
| 70 | + return success(BeanUtils.toBean(config, FileConfigRespVO.class)); | |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | 73 | @GetMapping("/page") |
| ... | ... | @@ -76,7 +75,7 @@ public class FileConfigController { |
| 76 | 75 | @PreAuthorize("@ss.hasPermission('infra:file-config:query')") |
| 77 | 76 | public CommonResult<PageResult<FileConfigRespVO>> getFileConfigPage(@Valid FileConfigPageReqVO pageVO) { |
| 78 | 77 | PageResult<FileConfigDO> pageResult = fileConfigService.getFileConfigPage(pageVO); |
| 79 | - return success(FileConfigConvert.INSTANCE.convertPage(pageResult)); | |
| 78 | + return success(BeanUtils.toBean(pageResult, FileConfigRespVO.class)); | |
| 80 | 79 | } |
| 81 | 80 | |
| 82 | 81 | @GetMapping("/test") | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
| ... | ... | @@ -4,17 +4,17 @@ import cn.hutool.core.io.IoUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | 8 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 8 | 9 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 9 | 10 | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO; |
| 10 | 11 | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileRespVO; |
| 11 | 12 | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileUploadReqVO; |
| 12 | -import cn.iocoder.yudao.module.infra.convert.file.FileConvert; | |
| 13 | 13 | import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; |
| 14 | 14 | import cn.iocoder.yudao.module.infra.service.file.FileService; |
| 15 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 16 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 17 | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 17 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 18 | 18 | import lombok.extern.slf4j.Slf4j; |
| 19 | 19 | import org.springframework.http.HttpStatus; |
| 20 | 20 | import org.springframework.security.access.prepost.PreAuthorize; |
| ... | ... | @@ -86,7 +86,7 @@ public class FileController { |
| 86 | 86 | @PreAuthorize("@ss.hasPermission('infra:file:query')") |
| 87 | 87 | public CommonResult<PageResult<FileRespVO>> getFilePage(@Valid FilePageReqVO pageVO) { |
| 88 | 88 | PageResult<FileDO> pageResult = fileService.getFilePage(pageVO); |
| 89 | - return success(FileConvert.INSTANCE.convertPage(pageResult)); | |
| 89 | + return success(BeanUtils.toBean(pageResult, FileRespVO.class)); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigBaseVO.java deleted
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | - | |
| 6 | -import javax.validation.constraints.NotNull; | |
| 7 | - | |
| 8 | -/** | |
| 9 | -* 文件配置 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 10 | -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 11 | -*/ | |
| 12 | -@Data | |
| 13 | -public class FileConfigBaseVO { | |
| 14 | - | |
| 15 | - @Schema(description = "配置名", requiredMode = Schema.RequiredMode.REQUIRED, example = "S3 - 阿里云") | |
| 16 | - @NotNull(message = "配置名不能为空") | |
| 17 | - private String name; | |
| 18 | - | |
| 19 | - @Schema(description = "备注", example = "我是备注") | |
| 20 | - private String remark; | |
| 21 | - | |
| 22 | -} |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigPageReqVO.java
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java
| ... | ... | @@ -3,32 +3,31 @@ package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config; |
| 3 | 3 | import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; |
| 4 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 5 | import lombok.Data; |
| 6 | -import lombok.EqualsAndHashCode; | |
| 7 | -import lombok.ToString; | |
| 8 | 6 | |
| 9 | -import javax.validation.constraints.NotNull; | |
| 10 | 7 | import java.time.LocalDateTime; |
| 11 | 8 | |
| 12 | 9 | @Schema(description = "管理后台 - 文件配置 Response VO") |
| 13 | 10 | @Data |
| 14 | -@EqualsAndHashCode(callSuper = true) | |
| 15 | -@ToString(callSuper = true) | |
| 16 | -public class FileConfigRespVO extends FileConfigBaseVO { | |
| 11 | +public class FileConfigRespVO { | |
| 17 | 12 | |
| 18 | 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 19 | 14 | private Long id; |
| 20 | 15 | |
| 16 | + @Schema(description = "配置名", requiredMode = Schema.RequiredMode.REQUIRED, example = "S3 - 阿里云") | |
| 17 | + private String name; | |
| 18 | + | |
| 21 | 19 | @Schema(description = "存储器,参见 FileStorageEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 22 | - @NotNull(message = "存储器不能为空") | |
| 23 | 20 | private Integer storage; |
| 24 | 21 | |
| 25 | 22 | @Schema(description = "是否为主配置", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 26 | - @NotNull(message = "是否为主配置不能为空") | |
| 27 | 23 | private Boolean master; |
| 28 | 24 | |
| 29 | 25 | @Schema(description = "存储配置", requiredMode = Schema.RequiredMode.REQUIRED) |
| 30 | 26 | private FileClientConfig config; |
| 31 | 27 | |
| 28 | + @Schema(description = "备注", example = "我是备注") | |
| 29 | + private String remark; | |
| 30 | + | |
| 32 | 31 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 33 | 32 | private LocalDateTime createTime; |
| 34 | 33 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigCreateReqVO.java renamed to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigSaveReqVO.java
100755 → 100644
| ... | ... | @@ -2,17 +2,20 @@ package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | 5 | |
| 8 | 6 | import javax.validation.constraints.NotNull; |
| 9 | 7 | import java.util.Map; |
| 10 | 8 | |
| 11 | -@Schema(description = "管理后台 - 文件配置创建 Request VO") | |
| 9 | +@Schema(description = "管理后台 - 文件配置创建/修改 Request VO") | |
| 12 | 10 | @Data |
| 13 | -@EqualsAndHashCode(callSuper = true) | |
| 14 | -@ToString(callSuper = true) | |
| 15 | -public class FileConfigCreateReqVO extends FileConfigBaseVO { | |
| 11 | +public class FileConfigSaveReqVO { | |
| 12 | + | |
| 13 | + @Schema(description = "编号", example = "1") | |
| 14 | + private Long id; | |
| 15 | + | |
| 16 | + @Schema(description = "配置名", requiredMode = Schema.RequiredMode.REQUIRED, example = "S3 - 阿里云") | |
| 17 | + @NotNull(message = "配置名不能为空") | |
| 18 | + private String name; | |
| 16 | 19 | |
| 17 | 20 | @Schema(description = "存储器,参见 FileStorageEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 18 | 21 | @NotNull(message = "存储器不能为空") |
| ... | ... | @@ -22,4 +25,7 @@ public class FileConfigCreateReqVO extends FileConfigBaseVO { |
| 22 | 25 | @NotNull(message = "存储配置不能为空") |
| 23 | 26 | private Map<String, Object> config; |
| 24 | 27 | |
| 28 | + @Schema(description = "备注", example = "我是备注") | |
| 29 | + private String remark; | |
| 30 | + | |
| 25 | 31 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | - | |
| 8 | -import javax.validation.constraints.NotNull; | |
| 9 | -import java.util.Map; | |
| 10 | - | |
| 11 | -@Schema(description = "管理后台 - 文件配置更新 Request VO") | |
| 12 | -@Data | |
| 13 | -@EqualsAndHashCode(callSuper = true) | |
| 14 | -@ToString(callSuper = true) | |
| 15 | -public class FileConfigUpdateReqVO extends FileConfigBaseVO { | |
| 16 | - | |
| 17 | - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 18 | - @NotNull(message = "编号不能为空") | |
| 19 | - private Long id; | |
| 20 | - | |
| 21 | - @Schema(description = "存储配置,配置是动态参数,所以使用 Map 接收", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 22 | - @NotNull(message = "存储配置不能为空") | |
| 23 | - private Map<String, Object> config; | |
| 24 | - | |
| 25 | -} |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConfigConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.convert.file; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigRespVO; | |
| 6 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; | |
| 3 | +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; | |
| 7 | 4 | import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; |
| 8 | 5 | import org.mapstruct.Mapper; |
| 9 | 6 | import org.mapstruct.Mapping; |
| 10 | 7 | import org.mapstruct.factory.Mappers; |
| 11 | 8 | |
| 12 | -import java.util.List; | |
| 13 | - | |
| 14 | 9 | /** |
| 15 | 10 | * 文件配置 Convert |
| 16 | 11 | * |
| ... | ... | @@ -22,15 +17,6 @@ public interface FileConfigConvert { |
| 22 | 17 | FileConfigConvert INSTANCE = Mappers.getMapper(FileConfigConvert.class); |
| 23 | 18 | |
| 24 | 19 | @Mapping(target = "config", ignore = true) |
| 25 | - FileConfigDO convert(FileConfigCreateReqVO bean); | |
| 26 | - | |
| 27 | - @Mapping(target = "config", ignore = true) | |
| 28 | - FileConfigDO convert(FileConfigUpdateReqVO bean); | |
| 29 | - | |
| 30 | - FileConfigRespVO convert(FileConfigDO bean); | |
| 31 | - | |
| 32 | - List<FileConfigRespVO> convertList(List<FileConfigDO> list); | |
| 33 | - | |
| 34 | - PageResult<FileConfigRespVO> convertPage(PageResult<FileConfigDO> page); | |
| 20 | + FileConfigDO convert(FileConfigSaveReqVO bean); | |
| 35 | 21 | |
| 36 | 22 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/file/FileConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.infra.convert.file; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileRespVO; | |
| 5 | -import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; | |
| 6 | -import org.mapstruct.Mapper; | |
| 7 | -import org.mapstruct.factory.Mappers; | |
| 8 | - | |
| 9 | -@Mapper | |
| 10 | -public interface FileConvert { | |
| 11 | - | |
| 12 | - FileConvert INSTANCE = Mappers.getMapper(FileConvert.class); | |
| 13 | - | |
| 14 | - FileRespVO convert(FileDO bean); | |
| 15 | - | |
| 16 | - PageResult<FileRespVO> convertPage(PageResult<FileDO> page); | |
| 17 | - | |
| 18 | -} |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java
| ... | ... | @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.infra.service.file; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.file.core.client.FileClient; |
| 5 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; | |
| 6 | 5 | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; |
| 7 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; | |
| 8 | 7 | import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; |
| 9 | 8 | |
| 10 | 9 | import javax.validation.Valid; |
| ... | ... | @@ -22,14 +21,14 @@ public interface FileConfigService { |
| 22 | 21 | * @param createReqVO 创建信息 |
| 23 | 22 | * @return 编号 |
| 24 | 23 | */ |
| 25 | - Long createFileConfig(@Valid FileConfigCreateReqVO createReqVO); | |
| 24 | + Long createFileConfig(@Valid FileConfigSaveReqVO createReqVO); | |
| 26 | 25 | |
| 27 | 26 | /** |
| 28 | 27 | * 更新文件配置 |
| 29 | 28 | * |
| 30 | 29 | * @param updateReqVO 更新信息 |
| 31 | 30 | */ |
| 32 | - void updateFileConfig(@Valid FileConfigUpdateReqVO updateReqVO); | |
| 31 | + void updateFileConfig(@Valid FileConfigSaveReqVO updateReqVO); | |
| 33 | 32 | |
| 34 | 33 | /** |
| 35 | 34 | * 更新文件配置为 Master | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java
| ... | ... | @@ -4,14 +4,14 @@ import cn.hutool.core.io.resource.ResourceUtil; |
| 4 | 4 | import cn.hutool.core.util.IdUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | 8 | import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; |
| 8 | 9 | import cn.iocoder.yudao.framework.file.core.client.FileClient; |
| 9 | 10 | import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; |
| 10 | 11 | import cn.iocoder.yudao.framework.file.core.client.FileClientFactory; |
| 11 | 12 | import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum; |
| 12 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; | |
| 13 | 13 | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; |
| 14 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; | |
| 14 | +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; | |
| 15 | 15 | import cn.iocoder.yudao.module.infra.convert.file.FileConfigConvert; |
| 16 | 16 | import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; |
| 17 | 17 | import cn.iocoder.yudao.module.infra.dal.mysql.file.FileConfigMapper; |
| ... | ... | @@ -63,7 +63,7 @@ public class FileConfigServiceImpl implements FileConfigService { |
| 63 | 63 | return fileClientFactory.getFileClient(null == config ? id : config.getId()); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - }); | |
| 66 | + }); | |
| 67 | 67 | |
| 68 | 68 | @Resource |
| 69 | 69 | private FileClientFactory fileClientFactory; |
| ... | ... | @@ -75,7 +75,7 @@ public class FileConfigServiceImpl implements FileConfigService { |
| 75 | 75 | private Validator validator; |
| 76 | 76 | |
| 77 | 77 | @Override |
| 78 | - public Long createFileConfig(FileConfigCreateReqVO createReqVO) { | |
| 78 | + public Long createFileConfig(FileConfigSaveReqVO createReqVO) { | |
| 79 | 79 | FileConfigDO fileConfig = FileConfigConvert.INSTANCE.convert(createReqVO) |
| 80 | 80 | .setConfig(parseClientConfig(createReqVO.getStorage(), createReqVO.getConfig())) |
| 81 | 81 | .setMaster(false); // 默认非 master |
| ... | ... | @@ -84,7 +84,7 @@ public class FileConfigServiceImpl implements FileConfigService { |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | @Override |
| 87 | - public void updateFileConfig(FileConfigUpdateReqVO updateReqVO) { | |
| 87 | + public void updateFileConfig(FileConfigSaveReqVO updateReqVO) { | |
| 88 | 88 | // 校验存在 |
| 89 | 89 | FileConfigDO config = validateFileConfigExists(updateReqVO.getId()); |
| 90 | 90 | // 更新 |
| ... | ... | @@ -126,7 +126,7 @@ public class FileConfigServiceImpl implements FileConfigService { |
| 126 | 126 | // 校验存在 |
| 127 | 127 | FileConfigDO config = validateFileConfigExists(id); |
| 128 | 128 | if (Boolean.TRUE.equals(config.getMaster())) { |
| 129 | - throw exception(FILE_CONFIG_DELETE_FAIL_MASTER); | |
| 129 | + throw exception(FILE_CONFIG_DELETE_FAIL_MASTER); | |
| 130 | 130 | } |
| 131 | 131 | // 删除 |
| 132 | 132 | fileConfigMapper.deleteById(id); | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java
| ... | ... | @@ -11,9 +11,8 @@ import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClient; |
| 11 | 11 | import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClientConfig; |
| 12 | 12 | import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum; |
| 13 | 13 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 14 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigCreateReqVO; | |
| 15 | 14 | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigPageReqVO; |
| 16 | -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigUpdateReqVO; | |
| 15 | +import cn.iocoder.yudao.module.infra.controller.admin.file.vo.config.FileConfigSaveReqVO; | |
| 17 | 16 | import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileConfigDO; |
| 18 | 17 | import cn.iocoder.yudao.module.infra.dal.mysql.file.FileConfigMapper; |
| 19 | 18 | import lombok.Data; |
| ... | ... | @@ -41,10 +40,10 @@ import static org.mockito.ArgumentMatchers.eq; |
| 41 | 40 | import static org.mockito.Mockito.*; |
| 42 | 41 | |
| 43 | 42 | /** |
| 44 | -* {@link FileConfigServiceImpl} 的单元测试类 | |
| 45 | -* | |
| 46 | -* @author 芋道源码 | |
| 47 | -*/ | |
| 43 | + * {@link FileConfigServiceImpl} 的单元测试类 | |
| 44 | + * | |
| 45 | + * @author 芋道源码 | |
| 46 | + */ | |
| 48 | 47 | @Import(FileConfigServiceImpl.class) |
| 49 | 48 | public class FileConfigServiceImplTest extends BaseDbUnitTest { |
| 50 | 49 | |
| ... | ... | @@ -64,8 +63,9 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { |
| 64 | 63 | // 准备参数 |
| 65 | 64 | Map<String, Object> config = MapUtil.<String, Object>builder().put("basePath", "/yunai") |
| 66 | 65 | .put("domain", "https://www.iocoder.cn").build(); |
| 67 | - FileConfigCreateReqVO reqVO = randomPojo(FileConfigCreateReqVO.class, | |
| 68 | - o -> o.setStorage(FileStorageEnum.LOCAL.getStorage()).setConfig(config)); | |
| 66 | + FileConfigSaveReqVO reqVO = randomPojo(FileConfigSaveReqVO.class, | |
| 67 | + o -> o.setStorage(FileStorageEnum.LOCAL.getStorage()).setConfig(config)) | |
| 68 | + .setId(null); // 避免 id 被赋值 | |
| 69 | 69 | |
| 70 | 70 | // 调用 |
| 71 | 71 | Long fileConfigId = fileConfigService.createFileConfig(reqVO); |
| ... | ... | @@ -73,7 +73,7 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { |
| 73 | 73 | assertNotNull(fileConfigId); |
| 74 | 74 | // 校验记录的属性是否正确 |
| 75 | 75 | FileConfigDO fileConfig = fileConfigMapper.selectById(fileConfigId); |
| 76 | - assertPojoEquals(reqVO, fileConfig, "config"); | |
| 76 | + assertPojoEquals(reqVO, fileConfig, "id", "config"); | |
| 77 | 77 | assertFalse(fileConfig.getMaster()); |
| 78 | 78 | assertEquals("/yunai", ((LocalFileClientConfig) fileConfig.getConfig()).getBasePath()); |
| 79 | 79 | assertEquals("https://www.iocoder.cn", ((LocalFileClientConfig) fileConfig.getConfig()).getDomain()); |
| ... | ... | @@ -88,8 +88,9 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { |
| 88 | 88 | .setConfig(new LocalFileClientConfig().setBasePath("/yunai").setDomain("https://www.iocoder.cn"))); |
| 89 | 89 | fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据 |
| 90 | 90 | // 准备参数 |
| 91 | - FileConfigUpdateReqVO reqVO = randomPojo(FileConfigUpdateReqVO.class, o -> { | |
| 91 | + FileConfigSaveReqVO reqVO = randomPojo(FileConfigSaveReqVO.class, o -> { | |
| 92 | 92 | o.setId(dbFileConfig.getId()); // 设置更新的 ID |
| 93 | + o.setStorage(FileStorageEnum.LOCAL.getStorage()); | |
| 93 | 94 | Map<String, Object> config = MapUtil.<String, Object>builder().put("basePath", "/yunai2") |
| 94 | 95 | .put("domain", "https://doc.iocoder.cn").build(); |
| 95 | 96 | o.setConfig(config); |
| ... | ... | @@ -109,7 +110,7 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { |
| 109 | 110 | @Test |
| 110 | 111 | public void testUpdateFileConfig_notExists() { |
| 111 | 112 | // 准备参数 |
| 112 | - FileConfigUpdateReqVO reqVO = randomPojo(FileConfigUpdateReqVO.class); | |
| 113 | + FileConfigSaveReqVO reqVO = randomPojo(FileConfigSaveReqVO.class); | |
| 113 | 114 | |
| 114 | 115 | // 调用, 并断言异常 |
| 115 | 116 | assertServiceException(() -> fileConfigService.updateFileConfig(reqVO), FILE_CONFIG_NOT_EXISTS); |
| ... | ... | @@ -148,8 +149,8 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { |
| 148 | 149 | |
| 149 | 150 | // 调用 |
| 150 | 151 | fileConfigService.deleteFileConfig(id); |
| 151 | - // 校验数据不存在了 | |
| 152 | - assertNull(fileConfigMapper.selectById(id)); | |
| 152 | + // 校验数据不存在了 | |
| 153 | + assertNull(fileConfigMapper.selectById(id)); | |
| 153 | 154 | // 验证 cache |
| 154 | 155 | assertNull(fileConfigService.getClientCache().getIfPresent(id)); |
| 155 | 156 | } |
| ... | ... | @@ -177,30 +178,30 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { |
| 177 | 178 | |
| 178 | 179 | @Test |
| 179 | 180 | public void testGetFileConfigPage() { |
| 180 | - // mock 数据 | |
| 181 | - FileConfigDO dbFileConfig = randomFileConfigDO().setName("芋道源码") | |
| 182 | - .setStorage(FileStorageEnum.LOCAL.getStorage()); | |
| 183 | - dbFileConfig.setCreateTime(LocalDateTimeUtil.parse("2020-01-23", DatePattern.NORM_DATE_PATTERN));// 等会查询到 | |
| 184 | - fileConfigMapper.insert(dbFileConfig); | |
| 185 | - // 测试 name 不匹配 | |
| 186 | - fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setName("源码"))); | |
| 187 | - // 测试 storage 不匹配 | |
| 188 | - fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setStorage(FileStorageEnum.DB.getStorage()))); | |
| 189 | - // 测试 createTime 不匹配 | |
| 190 | - fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setCreateTime(LocalDateTimeUtil.parse("2020-11-23", DatePattern.NORM_DATE_PATTERN)))); | |
| 191 | - // 准备参数 | |
| 192 | - FileConfigPageReqVO reqVO = new FileConfigPageReqVO(); | |
| 193 | - reqVO.setName("芋道"); | |
| 194 | - reqVO.setStorage(FileStorageEnum.LOCAL.getStorage()); | |
| 195 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 1, 1), | |
| 196 | - buildTime(2020, 1, 24)})); | |
| 197 | - | |
| 198 | - // 调用 | |
| 199 | - PageResult<FileConfigDO> pageResult = fileConfigService.getFileConfigPage(reqVO); | |
| 200 | - // 断言 | |
| 201 | - assertEquals(1, pageResult.getTotal()); | |
| 202 | - assertEquals(1, pageResult.getList().size()); | |
| 203 | - assertPojoEquals(dbFileConfig, pageResult.getList().get(0)); | |
| 181 | + // mock 数据 | |
| 182 | + FileConfigDO dbFileConfig = randomFileConfigDO().setName("芋道源码") | |
| 183 | + .setStorage(FileStorageEnum.LOCAL.getStorage()); | |
| 184 | + dbFileConfig.setCreateTime(LocalDateTimeUtil.parse("2020-01-23", DatePattern.NORM_DATE_PATTERN));// 等会查询到 | |
| 185 | + fileConfigMapper.insert(dbFileConfig); | |
| 186 | + // 测试 name 不匹配 | |
| 187 | + fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setName("源码"))); | |
| 188 | + // 测试 storage 不匹配 | |
| 189 | + fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setStorage(FileStorageEnum.DB.getStorage()))); | |
| 190 | + // 测试 createTime 不匹配 | |
| 191 | + fileConfigMapper.insert(cloneIgnoreId(dbFileConfig, o -> o.setCreateTime(LocalDateTimeUtil.parse("2020-11-23", DatePattern.NORM_DATE_PATTERN)))); | |
| 192 | + // 准备参数 | |
| 193 | + FileConfigPageReqVO reqVO = new FileConfigPageReqVO(); | |
| 194 | + reqVO.setName("芋道"); | |
| 195 | + reqVO.setStorage(FileStorageEnum.LOCAL.getStorage()); | |
| 196 | + reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 1, 1), | |
| 197 | + buildTime(2020, 1, 24)})); | |
| 198 | + | |
| 199 | + // 调用 | |
| 200 | + PageResult<FileConfigDO> pageResult = fileConfigService.getFileConfigPage(reqVO); | |
| 201 | + // 断言 | |
| 202 | + assertEquals(1, pageResult.getTotal()); | |
| 203 | + assertEquals(1, pageResult.getList().size()); | |
| 204 | + assertPojoEquals(dbFileConfig, pageResult.getList().get(0)); | |
| 204 | 205 | } |
| 205 | 206 | |
| 206 | 207 | @Test | ... | ... |