菜单修改优化
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ public class SimilarAsinHistoryItemVo {
|
||||
private String sourceFilename;
|
||||
@Schema(description = "最终结果文件名。任务完成并生成 xlsx 后返回。", example = "17-result.xlsx")
|
||||
private String resultFilename;
|
||||
@Schema(description = "最终结果文件下载地址。后端基于 MinIO objectKey 生成的公开直链 URL。", example = "http://47.110.241.161:9000/nanri-ai-images/result/similar_asin/xxx/17-result.xlsx")
|
||||
@Schema(description = "最终结果文件下载地址。后端基于 MinIO objectKey 生成的公开直链 URL。", example = "https://oss.aishufu.top/nanri-ai-images/result/similar_asin/xxx/17-result.xlsx")
|
||||
private String downloadUrl;
|
||||
private Long fileJobId;
|
||||
private String fileStatus;
|
||||
|
||||
+11
-1
@@ -4027,6 +4027,10 @@ public class SimilarAsinTaskService {
|
||||
int safeCompleted = Math.max(0, Math.min(completed, safeTotal));
|
||||
TaskProgressSnapshotEntity existing = taskProgressSnapshotService.find(task.getId(), MODULE_TYPE);
|
||||
int displayPercent = calculateDisplayProgressPercent(safeCompleted, safeTotal, job, LocalDateTime.now());
|
||||
boolean terminalProgress = isTerminalFileBuildProgress(task.getStatus(), safeCompleted, safeTotal);
|
||||
if (terminalProgress) {
|
||||
displayPercent = 100;
|
||||
}
|
||||
int previousDisplayPercent = calculateSnapshotDisplayPercent(existing, job);
|
||||
if (previousDisplayPercent > displayPercent && safeCompleted < safeTotal) {
|
||||
displayPercent = previousDisplayPercent;
|
||||
@@ -4034,7 +4038,7 @@ public class SimilarAsinTaskService {
|
||||
taskProgressSnapshotService.save(
|
||||
task.getId(),
|
||||
MODULE_TYPE,
|
||||
STATUS_RUNNING,
|
||||
terminalProgress ? task.getStatus() : STATUS_RUNNING,
|
||||
safeTotal,
|
||||
safeCompleted,
|
||||
0,
|
||||
@@ -4044,6 +4048,12 @@ public class SimilarAsinTaskService {
|
||||
);
|
||||
}
|
||||
|
||||
static boolean isTerminalFileBuildProgress(String taskStatus, int completed, int total) {
|
||||
return total > 0
|
||||
&& completed >= total
|
||||
&& (STATUS_SUCCESS.equals(taskStatus) || STATUS_FAILED.equals(taskStatus));
|
||||
}
|
||||
|
||||
private int calculateDisplayProgressPercent(int current,
|
||||
int total,
|
||||
TaskFileJobEntity job,
|
||||
|
||||
+18
-7
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.similarasin.util;
|
||||
|
||||
import com.nanri.aiimage.config.SimilarAsinProperties;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.Dns;
|
||||
@@ -39,6 +40,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletionService;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
@@ -102,12 +104,14 @@ public class SimilarAsinImageEmbedder {
|
||||
private final int downloadPoolSize;
|
||||
private final OkHttpClient httpClient;
|
||||
private final ExecutorService downloadPool;
|
||||
private final OssStorageService ossStorageService;
|
||||
|
||||
public SimilarAsinImageEmbedder(SimilarAsinProperties properties) {
|
||||
public SimilarAsinImageEmbedder(SimilarAsinProperties properties, OssStorageService ossStorageService) {
|
||||
int rawTimeout = properties == null ? DEFAULT_DOWNLOAD_TIMEOUT_SECONDS : properties.getImageDownloadTimeoutSeconds();
|
||||
int rawPool = properties == null ? DEFAULT_DOWNLOAD_POOL_SIZE : properties.getImageDownloadPoolSize();
|
||||
this.downloadTimeoutSeconds = rawTimeout > 0 ? rawTimeout : DEFAULT_DOWNLOAD_TIMEOUT_SECONDS;
|
||||
this.downloadPoolSize = rawPool > 0 ? rawPool : DEFAULT_DOWNLOAD_POOL_SIZE;
|
||||
this.ossStorageService = Objects.requireNonNull(ossStorageService, "ossStorageService must not be null");
|
||||
this.httpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(Duration.ofSeconds(downloadTimeoutSeconds))
|
||||
.readTimeout(Duration.ofSeconds(downloadTimeoutSeconds))
|
||||
@@ -178,8 +182,9 @@ public class SimilarAsinImageEmbedder {
|
||||
if (taskImageCache.containsKey(url)) {
|
||||
return;
|
||||
}
|
||||
byte[] raw = doFetch(url);
|
||||
ResizedImage thumb = resizeImage(url, raw);
|
||||
String downloadUrl = normalizeAndValidateDownloadUrl(url);
|
||||
byte[] raw = doFetch(downloadUrl);
|
||||
ResizedImage thumb = resizeImage(downloadUrl, raw);
|
||||
taskImageCache.putIfAbsent(url, thumb);
|
||||
} catch (Exception ex) {
|
||||
// 预下载失败不抛出:embed() 时同 url 会再次尝试并走原有兜底链路。
|
||||
@@ -345,8 +350,8 @@ public class SimilarAsinImageEmbedder {
|
||||
}
|
||||
|
||||
private byte[] downloadWithRetry(String url) throws IOException, TimeoutException {
|
||||
validateHttpsUrl(url);
|
||||
List<String> candidates = downloadCandidates(url);
|
||||
String downloadUrl = normalizeAndValidateDownloadUrl(url);
|
||||
List<String> candidates = downloadCandidates(downloadUrl);
|
||||
IOException last = null;
|
||||
TimeoutException lastTimeout = null;
|
||||
long waitSeconds = downloadTimeoutSeconds * 2L;
|
||||
@@ -355,9 +360,9 @@ public class SimilarAsinImageEmbedder {
|
||||
Future<byte[]> future = downloadPool.submit(() -> doFetch(attemptUrl));
|
||||
try {
|
||||
byte[] bytes = future.get(waitSeconds, TimeUnit.SECONDS);
|
||||
if (!attemptUrl.equals(url)) {
|
||||
if (!attemptUrl.equals(downloadUrl)) {
|
||||
log.info("[similar-asin][image] download-fallback-success originalUrl={} usedUrl={} attempt={}/{}",
|
||||
url, attemptUrl, attempt + 1, DOWNLOAD_MAX_RETRY + 1);
|
||||
downloadUrl, attemptUrl, attempt + 1, DOWNLOAD_MAX_RETRY + 1);
|
||||
}
|
||||
return bytes;
|
||||
} catch (java.util.concurrent.ExecutionException ee) {
|
||||
@@ -396,6 +401,12 @@ public class SimilarAsinImageEmbedder {
|
||||
throw last != null ? last : new IOException("image download failed without cause");
|
||||
}
|
||||
|
||||
String normalizeAndValidateDownloadUrl(String url) {
|
||||
String downloadUrl = ossStorageService.normalizeManagedPublicUrl(url);
|
||||
validateHttpsUrl(downloadUrl);
|
||||
return downloadUrl;
|
||||
}
|
||||
|
||||
static List<String> downloadCandidates(String url) {
|
||||
List<String> single = List.of(url);
|
||||
URI uri;
|
||||
|
||||
Reference in New Issue
Block a user