结合业务实际场景去除appCode校验

This commit is contained in:
tianliyong 2022-12-06 16:39:10 +08:00
parent 702959c6e0
commit 01f3bdf1ce
9 changed files with 18 additions and 51 deletions

View File

@ -101,10 +101,8 @@ public class WebFileController {
@SneakyThrows
@PostMapping("/v1/file/getUrl")
@CrossOrigin
public CommonResponse<List<FindFileUrlVo>> getUrl(@Valid @RequestParam String appCode,
@Valid @RequestParam List<String> fileKey) {
public CommonResponse<List<FindFileUrlVo>> getUrl(@Valid @RequestParam List<String> fileKey) {
FindFileUrlDto dto = FindFileUrlDto.builder()
.appCode(appCode)
.fileKey(fileKey)
.build();
List<FindFileUrlResponse> response = fileService.findFileUrl(dto);
@ -114,11 +112,8 @@ public class WebFileController {
@SneakyThrows
@GetMapping("/v1/file/download")
@CrossOrigin
public void download(@Valid @RequestParam String appCode,
@Valid @RequestParam String fileKey,
HttpServletResponse response) {
public void download(@Valid @RequestParam String fileKey, HttpServletResponse response) {
ServerFileDownloadDto dto = ServerFileDownloadDto.builder()
.appCode(appCode)
.fileKey(fileKey)
.build();
ServerFileDownloadResponse result = fileService.download(dto);

View File

@ -23,9 +23,9 @@ public interface FileDao extends IService<File> {
*/
File getByAppCodeAndUrlMd5(String appCode, String urlMd5);
File getByAppCodeAndFileUuid(String appCode, String fileKey);
File getByFileUuid(String fileKey);
List<File> getByAppCodeAndFileUuids(String appCode, List<String> fileKey);
List<File> getByFileUuids(List<String> fileKey);
List<File> getByAppCodeAndUrlMd5s(String appCode, List<String> urlMd5List);
List<File> getByUrlMd5s(List<String> urlMd5List);
}

View File

@ -29,25 +29,25 @@ public class FileDaoImpl extends ServiceImpl<FileMapper, File> implements FileDa
}
@Override
public File getByAppCodeAndFileUuid(String appCode, String fileKey) {
return lambdaQuery().eq(File::getAppCode, appCode).eq(File::getFileUuid, fileKey)
.eq(File::getStatus, FileStatus.SUCCESS).eq(File::getIsDelete, TableDelete.UN_DELETED)
.last("limit 1").one();
public File getByFileUuid(String fileKey) {
return lambdaQuery().eq(File::getFileUuid, fileKey)
.eq(File::getStatus, FileStatus.SUCCESS)
.eq(File::getIsDelete, TableDelete.UN_DELETED)
.last("limit 1")
.one();
}
@Override
public List<File> getByAppCodeAndFileUuids(String appCode, List<String> fileKey) {
return lambdaQuery().eq(File::getAppCode, appCode)
.in(File::getFileUuid, fileKey)
public List<File> getByFileUuids(List<String> fileKey) {
return lambdaQuery().in(File::getFileUuid, fileKey)
.eq(File::getStatus, FileStatus.SUCCESS)
.eq(File::getIsDelete, TableDelete.UN_DELETED)
.list();
}
@Override
public List<File> getByAppCodeAndUrlMd5s(String appCode, List<String> urlMd5List) {
return lambdaQuery().eq(File::getAppCode, appCode)
.in(File::getUrlMd5, urlMd5List)
public List<File> getByUrlMd5s(List<String> urlMd5List) {
return lambdaQuery().in(File::getUrlMd5, urlMd5List)
.eq(File::getStatus, FileStatus.SUCCESS)
.eq(File::getIsDelete, TableDelete.UN_DELETED)
.list();

View File

@ -14,9 +14,6 @@ import java.util.List;
@Data
public class FindFileKeyRequest {
@NotBlank(message = "appCode must not be null")
private String appCode;
@NotNull(message = "url must not be null")
private List<String> url;
}

View File

@ -14,9 +14,6 @@ import java.util.List;
@Data
public class FindFileUrlRequest {
@NotBlank(message = "appCode must not be null")
private String appCode;
@NotNull(message = "fileKey must not be null")
private List<String> fileKey;
}

View File

@ -18,11 +18,6 @@ import java.util.List;
@AllArgsConstructor
public class FindFileKeyDto {
/**
* 应用码
*/
private String appCode;
/**
* 文件url
*/

View File

@ -18,11 +18,6 @@ import java.util.List;
@AllArgsConstructor
public class FindFileUrlDto {
/**
* 应用码
*/
private String appCode;
/**
* 文件uuid
*/

View File

@ -16,11 +16,6 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class ServerFileDownloadDto {
/**
* 应用码
*/
private String appCode;
/**
* 文件uuid
*/

View File

@ -23,7 +23,6 @@ import cn.axzo.oss.manager.api.dto.request.*;
import cn.axzo.oss.manager.api.dto.response.*;
import cn.axzo.oss.service.api.FileService;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -141,10 +140,8 @@ public class FileServiceImpl implements FileService {
@Override
public ServerFileDownloadResponse download(ServerFileDownloadDto dto) {
log.info("file download dto = {}", JsonUtil.obj2Str(dto));
// 检查app code
checkAppCode(dto.getAppCode());
File file = fileDao.getByAppCodeAndFileUuid(dto.getAppCode(), dto.getFileKey());
File file = fileDao.getByFileUuid(dto.getFileKey());
if (Utility.objIsNull(file)) {
log.warn("file download is null, fileKey = {}", dto.getFileKey());
return null;
@ -217,8 +214,6 @@ public class FileServiceImpl implements FileService {
@Override
public List<FindFileUrlResponse> findFileUrl(FindFileUrlDto dto) {
log.info("find file url dto = {}", JsonUtil.obj2Str(dto));
// 检查app code
checkAppCode(dto.getAppCode());
// 做兼容处理如果List<String> fileKey如果存在url取出url不做查询处理
List<String> urlList = new ArrayList<>();
@ -231,7 +226,7 @@ public class FileServiceImpl implements FileService {
}
}
List<File> fileList = fileDao.getByAppCodeAndFileUuids(dto.getAppCode(), fileKeyList);
List<File> fileList = fileDao.getByFileUuids(fileKeyList);
if (CollectionUtil.isEmpty(fileList)) {
log.warn("find file url is null,key = {}", Arrays.toString(dto.getFileKey().toArray()));
return new ArrayList<>();
@ -242,14 +237,12 @@ public class FileServiceImpl implements FileService {
@Override
public List<FindFileKeyResponse> findFileKey(FindFileKeyDto dto) {
log.info("find file key dto = {}", JsonUtil.obj2Str(dto));
// 检查app code
checkAppCode(dto.getAppCode());
List<String> urlMd5List = dto.getUrl().stream()
.map(url -> Utility.getMd5(url))
.collect(Collectors.toList());
List<File> fileList = fileDao.getByAppCodeAndUrlMd5s(dto.getAppCode(), urlMd5List);
List<File> fileList = fileDao.getByUrlMd5s(urlMd5List);
if (CollectionUtil.isEmpty(fileList)) {
log.warn("find file key is null,url = {}", Arrays.toString(dto.getUrl().toArray()));
return new ArrayList<>();