完成这个地址替换

This commit is contained in:
super
2026-05-29 19:35:55 +08:00
parent e9b98908bb
commit eb7aa89f8b
9 changed files with 53 additions and 19 deletions
@@ -696,7 +696,7 @@ public class SimilarAsinTaskService {
scope.setCreatedAt(LocalDateTime.now());
}
scope.setChunkTotal(chunkTotal);
scope.setReceivedChunkCount(countChunks(taskId, scopeHash));
scope.setReceivedChunkCount(resolveReceivedChunkProgress(taskId, scopeHash, scope.getChunkTotal()));
scope.setLastChunkAt(LocalDateTime.now());
scope.setLastError(request.getError());
scope.setCompleted(Boolean.TRUE.equals(request.getDone()) ? 1 : 0);
@@ -1199,7 +1199,7 @@ public class SimilarAsinTaskService {
if (chunkTotal != null) {
scope.setChunkTotal(chunkTotal);
}
scope.setReceivedChunkCount(countChunks(taskId, scopeHash));
scope.setReceivedChunkCount(resolveReceivedChunkProgress(taskId, scopeHash, scope.getChunkTotal()));
scope.setLastChunkAt(now);
scope.setLastError(error);
scope.setCompleted(completed ? 1 : 0);
@@ -4822,6 +4822,36 @@ public class SimilarAsinTaskService {
return count == null ? 0 : count.intValue();
}
private int resolveReceivedChunkProgress(Long taskId, String scopeHash, Integer chunkTotal) {
int receivedCount = countChunks(taskId, scopeHash);
Integer maxChunkIndex = taskChunkMapper.selectObjs(new LambdaQueryWrapper<TaskChunkEntity>()
.select(TaskChunkEntity::getChunkIndex)
.eq(TaskChunkEntity::getTaskId, taskId)
.eq(TaskChunkEntity::getModuleType, MODULE_TYPE)
.eq(TaskChunkEntity::getScopeHash, scopeHash)
.orderByDesc(TaskChunkEntity::getChunkIndex)
.last("limit 1"))
.stream()
.filter(Objects::nonNull)
.map(value -> {
if (value instanceof Number number) {
return number.intValue();
}
try {
return Integer.parseInt(value.toString());
} catch (Exception ignored) {
return 0;
}
})
.findFirst()
.orElse(0);
int current = Math.max(receivedCount, maxChunkIndex == null ? 0 : maxChunkIndex);
if (chunkTotal != null && chunkTotal > 0) {
current = Math.min(current, chunkTotal);
}
return Math.max(0, current);
}
private SimilarAsinTaskItemVo toTaskItem(FileTaskEntity task) {
SimilarAsinTaskItemVo vo = new SimilarAsinTaskItemVo();
vo.setId(task.getId());
@@ -4938,7 +4968,7 @@ public class SimilarAsinTaskService {
PythonUploadProgress progress = resolvePythonUploadProgress(taskId);
int total = progress.total() > 0 ? progress.total() : Math.max(1, progress.current() + 1);
int current = Math.max(0, Math.min(progress.current(), total));
int percent = current <= 0 ? 1 : Math.min(95, (int) Math.floor(current * 100.0 / total));
int percent = current <= 0 ? 1 : Math.min(95, (int) Math.ceil(current * 100.0 / total));
vo.setFileProgressCurrent(current);
vo.setFileProgressTotal(total);
vo.setFileProgressPercent(percent);
@@ -4987,6 +5017,7 @@ public class SimilarAsinTaskService {
}
int stateTotal = state.getChunkTotal() == null ? 0 : state.getChunkTotal();
int stateCurrent = state.getReceivedChunkCount() == null ? 0 : state.getReceivedChunkCount();
stateCurrent = Math.max(stateCurrent, resolveReceivedChunkProgress(taskId, state.getScopeHash(), stateTotal));
if (stateTotal > total || total <= 0 && stateCurrent > current) {
total = stateTotal;
current = stateCurrent;
@@ -5010,6 +5041,9 @@ public class SimilarAsinTaskService {
}
String scopeHash = firstNonBlank(chunk.getScopeHash(), "");
receivedByScope.merge(scopeHash, 1, Integer::sum);
if (chunk.getChunkIndex() != null && chunk.getChunkIndex() > 0) {
receivedByScope.merge(scopeHash, chunk.getChunkIndex(), Math::max);
}
if (chunk.getChunkTotal() != null && chunk.getChunkTotal() > 0) {
totalByScope.merge(scopeHash, chunk.getChunkTotal(), Math::max);
}