This commit is contained in:
杨建炊 2025-09-29 11:27:24 +08:00
parent ae77622325
commit 5cf48298f2
2 changed files with 35 additions and 21 deletions

View File

@ -142,6 +142,7 @@ public class CropController {
return saveData(messageList, maxSeq, config, mediaFileInfos, sdk, corpId);
}
/**
* 异步下载待处理的媒体文件
*
@ -164,6 +165,7 @@ public class CropController {
mf.setSeq(info.getSeq());
mf.setCropId(corpId);
mf.setStatus(0);
mf.setExt(info.getExt());
return mf;
}).collect(Collectors.toList());
@ -177,13 +179,15 @@ public class CropController {
}
return messageList;
}
/**
* 异步下载待处理的媒体文件
*/
private void downloadPendingFiles(List<CropFile> mediaFiles, Long sdk) {
for (CropFile mf : mediaFiles) {
try {
String url = downFile(mf.getSdkFileId(), mf.getMsgType(),sdk);
String msgType = getSuffixByMsgType(mf);
String url = downFile(mf.getSdkFileId(), msgType, sdk);
if (url != null && !url.isEmpty()) {
mf.setUrl(url);
mf.setStatus(1);
@ -201,6 +205,7 @@ public class CropController {
}
}
}
/**
* 提取所有需要下载的媒体文件信息
*/
@ -230,10 +235,17 @@ public class CropController {
if (msg.containsKey(msgType)) {
String sdkFileId = msg.getJSONObject(msgType).getString("sdkfileid");
if (sdkFileId != null && !sdkFileId.trim().isEmpty()) {
CropFile cropFile = new CropFile(); // 注意你写成了 CropConfig应为 CropFile
CropFile cropFile = new CropFile();
cropFile.setMsgType(msgType);
cropFile.setSeq(seq);
cropFile.setSdkFileId(sdkFileId);
cropFile.setSeq(seq);
cropFile.setExt(msgType);
if (msgType.equals("file")) {
String fileext = msg.getJSONObject(msgType).getString("fileext");
cropFile.setExt(fileext);
}
result.add(cropFile);
}
}
@ -248,7 +260,9 @@ public class CropController {
@GetMapping("/crop/downFile")
public String downFile(String sdkField, String msgType, Long sdk) throws IOException {
File tempFile = File.createTempFile(GlobalConstants.DOWNLOAD_TEMP_FILE_NAME_PREFIX,
getSuffixByMsgType(msgType), mediaContext.getTempMergeFileDir());
msgType, mediaContext.getTempMergeFileDir());
sdk = sdkManager.initSdk("ww64f47cd0afc456a5", "mEizahrSF6axdfWtSK_f73a3j6-sV02hhyGG7ogmTpM");
String indexbuf = null; // 初始化 indexbuf
try (FileOutputStream fileOutputStream = new FileOutputStream(tempFile)) {
while (true) {
@ -273,8 +287,8 @@ public class CropController {
return "";
}
public String getSuffixByMsgType(String msgType) {
switch (msgType) {
public String getSuffixByMsgType(CropFile cropFile) {
switch (cropFile.getMsgType()) {
case "image":
return ".jpg";
case "voice":
@ -282,7 +296,7 @@ public class CropController {
case "video":
return ".mp4";
case "file":
return ".bin";
return "." + cropFile.getExt(); // 取真实后缀
default:
return ".bin";
}

View File

@ -23,7 +23,7 @@ public class CropFile {
private String url; // 下载后上传 OSS 的地址
private String fileName; // 可选原始文件名后续可补充
private String ext; // 可选原始文件名后续可补充
private Integer status = 0; // 0 pending, 1 success, 2 failed