添加文件md5检测

This commit is contained in:
cjw 2024-06-04 15:00:44 +08:00
parent 7f71d6b2cf
commit 505f440af8
10 changed files with 92 additions and 8 deletions

View File

@ -139,6 +139,7 @@ tenant:
- sys_user_post - sys_user_post
- sys_user_role - sys_user_role
- sys_client - sys_client
- sys_oss
- sys_oss_config - sys_oss_config
- sys_oss_resource - sys_oss_resource
- sys_oss_textbook - sys_oss_textbook

View File

@ -64,6 +64,7 @@ public interface CacheNames {
* OSS内容 * OSS内容
*/ */
String SYS_OSS = "sys_oss#30d"; String SYS_OSS = "sys_oss#30d";
String SYS_OSS_IDENTIFIER = "sys_oss_identifier#30d";
/** /**
* OSS配置 * OSS配置

View File

@ -4,8 +4,8 @@ import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.file.service.IFileService; import org.dromara.file.service.IFileService;
import org.springframework.validation.annotation.Validated; 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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -32,7 +32,7 @@ public class FileController {
* @param ossId OSS对象ID * @param ossId OSS对象ID
*/ */
//@SaCheckPermission("system:oss:download") //@SaCheckPermission("system:oss:download")
@GetMapping("/preview/{ossId}") @PostMapping("/preview/{ossId}")
public void preview(@PathVariable Long ossId, HttpServletResponse response) throws Exception { public void preview(@PathVariable Long ossId, HttpServletResponse response) throws Exception {
fileService.preview(ossId, response); fileService.preview(ossId, response);
} }

View File

@ -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;
/**
* <p>TODO<p>
*
* @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;
}

View File

@ -105,4 +105,16 @@ public class SysOssController extends BaseController {
return toAjax(ossService.deleteWithValidByIds(List.of(ossIds), true)); return toAjax(ossService.deleteWithValidByIds(List.of(ossIds), true));
} }
/**
* 查询OSS对象基于md5
*
* @param md5 OSS对象md5
*/
@SaCheckPermission("system:oss:identifier")
@GetMapping("/identifier")
public R<Long> identifier(@NotEmpty(message = "MD5不能为空") String md5) {
Long ossId = ossService.getIdByMd5(md5);
return R.ok(ossId);
}
} }

View File

@ -2,9 +2,9 @@ package org.dromara.system.domain;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import org.dromara.common.tenant.core.TenantEntity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
/** /**
* OSS对象存储对象 * OSS对象存储对象
@ -14,7 +14,7 @@ import lombok.EqualsAndHashCode;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName("sys_oss") @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; private String fileName;
/**
* md5
*/
private String fileMd5;
/** /**
* 原名 * 原名
*/ */

View File

@ -26,6 +26,11 @@ public class SysOssBo extends BaseEntity {
*/ */
private String fileName; private String fileName;
/**
* md5
*/
private String fileMd5;
/** /**
* 原名 * 原名
*/ */

View File

@ -78,5 +78,14 @@ public interface ISysOssService {
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid); Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 根据 md5 从缓存或数据库中获取 SysOssVo 对象
*
* @param md5 文件在数据库中的唯一标识
* @return SysOssVo 对象包含文件信息
*/
Long getIdByMd5(String md5);
} }

View File

@ -291,7 +291,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Caching(evict = { @Caching(evict = {
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId"), @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId"),
@CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT) @CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT, key = "all")
}) })
@Override @Override
public int updateDept(SysDeptBo bo) { public int updateDept(SysDeptBo bo) {
@ -362,14 +362,14 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
*/ */
@Caching(evict = { @Caching(evict = {
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"), @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"),
@CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT) @CacheEvict(cacheNames = CacheNames.SYS_TENANT_DEPT, key = "all")
}) })
@Override @Override
public int deleteDeptById(Long deptId) { public int deleteDeptById(Long deptId) {
return baseMapper.deleteById(deptId); return baseMapper.deleteById(deptId);
} }
@Cacheable(cacheNames = CacheNames.SYS_TENANT_DEPT) @Cacheable(cacheNames = CacheNames.SYS_TENANT_DEPT, key = "all")
@Override @Override
public List<SysDept> selectAllDept() { public List<SysDept> selectAllDept() {
return baseMapper.selectList(); return baseMapper.selectList();

View File

@ -251,7 +251,6 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
} }
/** /**
* 桶类型为 private 的URL 修改为临时URL时长为120s * 桶类型为 private 的URL 修改为临时URL时长为120s
* *
@ -266,4 +265,21 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
} }
return oss; 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<SysOss>().eq(SysOss::getFileMd5, md5));
if (ObjectUtil.isNotNull(sysOss)) {
return sysOss.getOssId();
} else {
return null;
}
}
} }