This commit is contained in:
杨建炊 2025-10-11 14:20:42 +08:00
parent a43017f3ab
commit 62dbe1cd20

View File

@ -3,6 +3,7 @@ package org.shop.crop;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tencent.wework.Finance;
import lombok.extern.slf4j.Slf4j;
import org.shop.crop.constant.GlobalConstants;
@ -55,15 +56,17 @@ public class CropController {
@GetMapping("/crop/chatData")
public List<CropMessage> chatData(Long startSeq, String corpId) throws IOException {
LambdaQueryWrapper<CropConfig> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CropConfig::getCropid, corpId);
CropConfig config = cropConfigMapper.selectOne(wrapper);
synchronized (SDK_LOCK) {
long limit = 50;
long slice = Finance.NewSlice();
long sdk = 0;
try {
sdk = sdkManager.initSdk(corpId, "mEizahrSF6axdfWtSK_f73a3j6-sV02hhyGG7ogmTpM");
int ret = Finance.GetChatData(sdk, startSeq, limit, "", "", 1000, slice);
sdk = sdkManager.initSdk(corpId, config.getMessageSecret());
int ret = Finance.GetChatData(sdk, config.getLastSeq(), limit, "", "", 2000, slice);
if (ret != 0) {
System.out.println("调用sdk拉取消息接口失败,失败消息为 ret = " + ret);
//Finance.FreeSlice(slice);
@ -212,13 +215,11 @@ public class CropController {
cropFileService.saveBatch(mediaFiles);
// 异步触发下载任务可以轮询数据库
CompletableFuture.runAsync(() -> {
try {
downloadPendingFiles(mediaFiles, sdk); // 也可以不传参改为查数据库
} catch (Exception e) {
log.error("异步下载任务异常", e);
}
});
}
return messageList;
}
@ -305,7 +306,8 @@ public class CropController {
File tempFile = File.createTempFile(GlobalConstants.DOWNLOAD_TEMP_FILE_NAME_PREFIX,
msgType, mediaContext.getTempMergeFileDir());
String indexbuf = null; // 初始化 indexbuf
String indexbuf = ""; // 初始化 indexbuf
try (FileOutputStream fileOutputStream = new FileOutputStream(tempFile)) {
while (true) {
long mediaData = Finance.NewMediaData();