添加文件md5检测
This commit is contained in:
parent
7f71d6b2cf
commit
505f440af8
|
@ -139,6 +139,7 @@ tenant:
|
|||
- sys_user_post
|
||||
- sys_user_role
|
||||
- sys_client
|
||||
- sys_oss
|
||||
- sys_oss_config
|
||||
- sys_oss_resource
|
||||
- sys_oss_textbook
|
||||
|
|
|
@ -64,6 +64,7 @@ public interface CacheNames {
|
|||
* OSS内容
|
||||
*/
|
||||
String SYS_OSS = "sys_oss#30d";
|
||||
String SYS_OSS_IDENTIFIER = "sys_oss_identifier#30d";
|
||||
|
||||
/**
|
||||
* OSS配置
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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<Long> identifier(@NotEmpty(message = "MD5不能为空") String md5) {
|
||||
Long ossId = ossService.getIdByMd5(md5);
|
||||
return R.ok(ossId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 原名
|
||||
*/
|
||||
|
|
|
@ -26,6 +26,11 @@ public class SysOssBo extends BaseEntity {
|
|||
*/
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* md5
|
||||
*/
|
||||
private String fileMd5;
|
||||
|
||||
/**
|
||||
* 原名
|
||||
*/
|
||||
|
|
|
@ -78,5 +78,14 @@ public interface ISysOssService {
|
|||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
|
||||
/**
|
||||
* 根据 md5 从缓存或数据库中获取 SysOssVo 对象
|
||||
*
|
||||
* @param md5 文件在数据库中的唯一标识
|
||||
* @return SysOssVo 对象,包含文件信息
|
||||
*/
|
||||
Long getIdByMd5(String md5);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<SysDept> selectAllDept() {
|
||||
return baseMapper.selectList();
|
||||
|
|
|
@ -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<SysOss>().eq(SysOss::getFileMd5, md5));
|
||||
if (ObjectUtil.isNotNull(sysOss)) {
|
||||
return sysOss.getOssId();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue