diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index ac4b9da..ae60083 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -139,6 +139,7 @@ tenant: - sys_user_post - sys_user_role - sys_client + - sys_oss - sys_oss_config - sys_oss_resource - sys_oss_textbook diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java index 08c5fe8..fe6f0c7 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java @@ -64,6 +64,7 @@ public interface CacheNames { * OSS内容 */ String SYS_OSS = "sys_oss#30d"; + String SYS_OSS_IDENTIFIER = "sys_oss_identifier#30d"; /** * OSS配置 diff --git a/ruoyi-modules/ruoyi-file/src/main/java/org/dromara/file/controller/FileController.java b/ruoyi-modules/ruoyi-file/src/main/java/org/dromara/file/controller/FileController.java index 1898250..827e661 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/org/dromara/file/controller/FileController.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/org/dromara/file/controller/FileController.java @@ -4,8 +4,8 @@ import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.dromara.file.service.IFileService; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -32,7 +32,7 @@ public class FileController { * @param ossId OSS对象ID */ //@SaCheckPermission("system:oss:download") - @GetMapping("/preview/{ossId}") + @PostMapping("/preview/{ossId}") public void preview(@PathVariable Long ossId, HttpServletResponse response) throws Exception { fileService.preview(ossId, response); } diff --git a/ruoyi-modules/ruoyi-file/src/main/java/org/dromara/file/domain/bo/OssFileBo.java b/ruoyi-modules/ruoyi-file/src/main/java/org/dromara/file/domain/bo/OssFileBo.java new file mode 100644 index 0000000..7347d2b --- /dev/null +++ b/ruoyi-modules/ruoyi-file/src/main/java/org/dromara/file/domain/bo/OssFileBo.java @@ -0,0 +1,35 @@ +package org.dromara.file.domain.bo; + +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMappers; +import org.dromara.file.domain.SysOssResource; +import org.dromara.file.domain.SysOssTextbook; + +/** + *

TODO

+ * + * @author cjw + * @version V1.0.0 + * @date 2024/6/3 16:45 + */ +@AutoMappers({ + @AutoMapper(target = SysOssResource.class, reverseConvertGenerate = false), + @AutoMapper(target = SysOssTextbook.class, reverseConvertGenerate = false) +}) +public class OssFileBo { + + /** + * + */ + private Long ossId; + + /** + * + */ + private Long catalogId; + + /** + * 1课件,2课堂,3作业,4试卷 + */ + private Integer type; +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java index 73ada3b..b17a516 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java @@ -105,4 +105,16 @@ public class SysOssController extends BaseController { return toAjax(ossService.deleteWithValidByIds(List.of(ossIds), true)); } + /** + * 查询OSS对象基于md5 + * + * @param md5 OSS对象md5 + */ + @SaCheckPermission("system:oss:identifier") + @GetMapping("/identifier") + public R identifier(@NotEmpty(message = "MD5不能为空") String md5) { + Long ossId = ossService.getIdByMd5(md5); + return R.ok(ossId); + } + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysOss.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysOss.java index af88898..027f3ed 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysOss.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysOss.java @@ -2,9 +2,9 @@ package org.dromara.system.domain; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import org.dromara.common.tenant.core.TenantEntity; import lombok.Data; import lombok.EqualsAndHashCode; +import org.dromara.common.mybatis.core.domain.BaseEntity; /** * OSS对象存储对象 @@ -14,7 +14,7 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = true) @TableName("sys_oss") -public class SysOss extends TenantEntity { +public class SysOss extends BaseEntity { /** * 对象存储主键 @@ -27,6 +27,11 @@ public class SysOss extends TenantEntity { */ private String fileName; + /** + * md5 + */ + private String fileMd5; + /** * 原名 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysOssBo.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysOssBo.java index 7cb3104..175c3b3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysOssBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysOssBo.java @@ -26,6 +26,11 @@ public class SysOssBo extends BaseEntity { */ private String fileName; + /** + * md5 + */ + private String fileMd5; + /** * 原名 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java index bb37ca3..aab7097 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java @@ -78,5 +78,14 @@ public interface ISysOssService { Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + /** + * 根据 md5 从缓存或数据库中获取 SysOssVo 对象 + * + * @param md5 文件在数据库中的唯一标识 + * @return SysOssVo 对象,包含文件信息 + */ + Long getIdByMd5(String md5); + + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java index 18cf1f4..edc067e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java @@ -291,7 +291,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { @Caching(evict = { @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId"), - @CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT) + @CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT, key = "all") }) @Override public int updateDept(SysDeptBo bo) { @@ -362,14 +362,14 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { */ @Caching(evict = { @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"), - @CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT) + @CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT, key = "all") }) @Override public int deleteDeptById(Long deptId) { return baseMapper.deleteById(deptId); } - @Cacheable(cacheNames = CacheNames.SYS_TENANT_DEPT) + @Cacheable(cacheNames = CacheNames.SYS_TENANT_DEPT, key = "all") @Override public List selectAllDept() { return baseMapper.selectList(); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java index eadd009..4b0faba 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java @@ -251,7 +251,6 @@ public class SysOssServiceImpl implements ISysOssService, OssService { } - /** * 桶类型为 private 的URL 修改为临时URL时长为120s * @@ -266,4 +265,21 @@ public class SysOssServiceImpl implements ISysOssService, OssService { } return oss; } + + /** + * 根据 md5 从缓存或数据库中获取 SysOssVo 对象 + * + * @param md5 文件在数据库中的唯一标识 + * @return SysOssVo 对象,包含文件信息 + */ + @Cacheable(cacheNames = CacheNames.SYS_OSS_IDENTIFIER, key = "#md5") + @Override + public Long getIdByMd5(String md5) { + SysOss sysOss = baseMapper.selectOne(new LambdaQueryWrapper().eq(SysOss::getFileMd5, md5)); + if (ObjectUtil.isNotNull(sysOss)) { + return sysOss.getOssId(); + } else { + return null; + } + } }