获取filekey接口兼容处理请求参数不是url情况
This commit is contained in:
parent
1cd40155ae
commit
2e571f6bab
@ -6,6 +6,7 @@ import cn.azxo.framework.common.utils.LogUtil;
|
|||||||
import com.aliyun.oss.ClientException;
|
import com.aliyun.oss.ClientException;
|
||||||
import com.aliyun.oss.OSS;
|
import com.aliyun.oss.OSS;
|
||||||
import com.aliyun.oss.OSSException;
|
import com.aliyun.oss.OSSException;
|
||||||
|
import com.aliyun.oss.model.GetObjectRequest;
|
||||||
import com.aliyun.oss.model.OSSObject;
|
import com.aliyun.oss.model.OSSObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -89,6 +90,10 @@ public class AliOssServiceImpl implements AliOssService {
|
|||||||
@Override
|
@Override
|
||||||
public InputStream downloadFile(String bucket, String tgtFileKey) {
|
public InputStream downloadFile(String bucket, String tgtFileKey) {
|
||||||
OSS client = aliOssClient.getClient();
|
OSS client = aliOssClient.getClient();
|
||||||
|
// TODO: 2022/12/9 支持图片样式
|
||||||
|
/*GetObjectRequest request = new GetObjectRequest(bucket, tgtFileKey);
|
||||||
|
request.setProcess("");
|
||||||
|
client.getObject(request);*/
|
||||||
OSSObject ossObject = client.getObject(bucket, tgtFileKey);
|
OSSObject ossObject = client.getObject(bucket, tgtFileKey);
|
||||||
return ossObject.getObjectContent();
|
return ossObject.getObjectContent();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,6 +54,8 @@ public class FileServiceImpl implements FileService {
|
|||||||
private static String APPCODE_BANKCARD = "bankcard";
|
private static String APPCODE_BANKCARD = "bankcard";
|
||||||
private static String SCENE_BANKCARD = "bankcard";
|
private static String SCENE_BANKCARD = "bankcard";
|
||||||
|
|
||||||
|
private static String IS_URL = "http://";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FileManager fileManager;
|
private FileManager fileManager;
|
||||||
|
|
||||||
@ -225,7 +227,7 @@ public class FileServiceImpl implements FileService {
|
|||||||
List<String> fileKeyList = new ArrayList<>();
|
List<String> fileKeyList = new ArrayList<>();
|
||||||
Map<String, String> fileKeyStyleMap = new HashMap<>();
|
Map<String, String> fileKeyStyleMap = new HashMap<>();
|
||||||
for (String fileKey : dto.getFileKey()) {
|
for (String fileKey : dto.getFileKey()) {
|
||||||
if (fileKey.contains("http")) {
|
if (fileKey.contains(IS_URL)) {
|
||||||
urlList.add(fileKey);
|
urlList.add(fileKey);
|
||||||
} else {
|
} else {
|
||||||
//对fileKey带图片样式进行处理
|
//对fileKey带图片样式进行处理
|
||||||
@ -238,13 +240,9 @@ public class FileServiceImpl implements FileService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (urlList.size() == dto.getFileKey().size()) {
|
List<File> fileList = new ArrayList<>();
|
||||||
return setFileUrlRes(urlList);
|
if (CollectionUtil.isNotEmpty(fileKeyList)) {
|
||||||
}
|
fileList = fileDao.getByFileUuids(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<>();
|
|
||||||
}
|
}
|
||||||
return setFileUrlRes(urlList, fileKeyStyleMap, fileList);
|
return setFileUrlRes(urlList, fileKeyStyleMap, fileList);
|
||||||
}
|
}
|
||||||
@ -265,6 +263,7 @@ public class FileServiceImpl implements FileService {
|
|||||||
private List<FindFileUrlResponse> setFileUrlRes(List<String> urlList, Map<String, String> fileKeyStyleMap, List<File> fileList) {
|
private List<FindFileUrlResponse> setFileUrlRes(List<String> urlList, Map<String, String> fileKeyStyleMap, List<File> fileList) {
|
||||||
List<FindFileUrlResponse> resList = setFileUrlRes(urlList);
|
List<FindFileUrlResponse> resList = setFileUrlRes(urlList);
|
||||||
|
|
||||||
|
if (CollectionUtil.isNotEmpty(fileList)) {
|
||||||
fileList.stream().forEach(file -> {
|
fileList.stream().forEach(file -> {
|
||||||
FindFileUrlResponse response = new FindFileUrlResponse();
|
FindFileUrlResponse response = new FindFileUrlResponse();
|
||||||
response.setUrl(file.getFileUrl());
|
response.setUrl(file.getFileUrl());
|
||||||
@ -276,6 +275,7 @@ public class FileServiceImpl implements FileService {
|
|||||||
}
|
}
|
||||||
resList.add(response);
|
resList.add(response);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return resList;
|
return resList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,23 +284,52 @@ public class FileServiceImpl implements FileService {
|
|||||||
log.info("find file key dto = {}", JsonUtil.obj2Str(dto));
|
log.info("find file key dto = {}", JsonUtil.obj2Str(dto));
|
||||||
|
|
||||||
List<String> urlList = dto.getUrl();
|
List<String> urlList = dto.getUrl();
|
||||||
List<String> urlMd5List = urlList.stream()
|
//用于对请求参数中为fileKey的兼容处理
|
||||||
.map(url -> Utility.getMd5(url))
|
List<String> fileKeyList = new ArrayList<>();
|
||||||
.collect(Collectors.toList());
|
List<String> urlMd5List = new ArrayList<>();
|
||||||
|
urlList.stream().forEach(url -> {
|
||||||
List<File> fileList = fileDao.getByUrlMd5s(urlMd5List);
|
if (url.contains(IS_URL)) {
|
||||||
|
urlMd5List.add(Utility.getMd5(url));
|
||||||
|
} else {
|
||||||
|
fileKeyList.add(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
List<File> fileList = new ArrayList<>();
|
||||||
|
List<FindFileKeyResponse> resList = new ArrayList<>();
|
||||||
|
if (CollectionUtil.isNotEmpty(urlMd5List)) {
|
||||||
|
fileList = fileDao.getByUrlMd5s(urlMd5List);
|
||||||
//处理app端历史数据不在file表中的情况
|
//处理app端历史数据不在file表中的情况
|
||||||
if (urlMd5List.size() > fileList.size()) {
|
if (urlMd5List.size() > fileList.size()) {
|
||||||
List<String> existUrlList = fileList.stream().map(File::getFileUrl).collect(Collectors.toList());
|
List<String> existUrlList = fileList.stream().map(File::getFileUrl).collect(Collectors.toList());
|
||||||
urlList.removeAll(existUrlList);
|
urlList.removeAll(existUrlList);
|
||||||
List<FindFileKeyResponse> resList = setFileKeyResByUrl(urlList);
|
resList = setFileKeyResByUrl(urlList);
|
||||||
// 异步新增file数据
|
// 异步新增file数据
|
||||||
asyncSaveFile(resList);
|
asyncSaveFile(resList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resList.addAll(setFileKeyRes(fileKeyList, fileList));
|
||||||
return resList;
|
return resList;
|
||||||
}
|
}
|
||||||
|
|
||||||
return setFileKeyResByFile(fileList);
|
private List<FindFileKeyResponse> setFileKeyRes(List<String> fileKeyList, List<File> fileList) {
|
||||||
|
List<FindFileKeyResponse> resList = new ArrayList<>();
|
||||||
|
if (CollectionUtil.isNotEmpty(fileKeyList)) {
|
||||||
|
fileKeyList.forEach(fileKey -> {
|
||||||
|
FindFileKeyResponse response = new FindFileKeyResponse();
|
||||||
|
response.setUrl(fileKey);
|
||||||
|
response.setFileKey(fileKey);
|
||||||
|
resList.add(response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (CollectionUtil.isNotEmpty(fileList)) {
|
||||||
|
fileList.forEach(file -> {
|
||||||
|
FindFileKeyResponse response = new FindFileKeyResponse();
|
||||||
|
response.setUrl(file.getFileUrl());
|
||||||
|
response.setFileKey(file.getFileUuid());
|
||||||
|
resList.add(response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return resList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void asyncSaveFile(List<FindFileKeyResponse> resList) {
|
private void asyncSaveFile(List<FindFileKeyResponse> resList) {
|
||||||
@ -372,17 +401,6 @@ public class FileServiceImpl implements FileService {
|
|||||||
return resList;
|
return resList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<FindFileKeyResponse> setFileKeyResByFile(List<File> fileList) {
|
|
||||||
List<FindFileKeyResponse> resList = new ArrayList<>();
|
|
||||||
fileList.forEach(file -> {
|
|
||||||
FindFileKeyResponse response = new FindFileKeyResponse();
|
|
||||||
response.setUrl(file.getFileUrl());
|
|
||||||
response.setFileKey(file.getFileUuid());
|
|
||||||
resList.add(response);
|
|
||||||
});
|
|
||||||
return resList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断文件是否符合要求
|
* 判断文件是否符合要求
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user