提交接口进度完善
This commit is contained in:
@@ -17,4 +17,7 @@ public class DeleteBrandTaskDetailVo {
|
||||
|
||||
@Schema(description = "任务结果项快照")
|
||||
private List<DeleteBrandResultItemVo> items = new ArrayList<>();
|
||||
|
||||
@Schema(description = "文件级进度快照")
|
||||
private List<DeleteBrandTaskFileProgressVo> fileProgress = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.nanri.aiimage.modules.deletebrand.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "删除品牌任务中的文件级进度")
|
||||
public class DeleteBrandTaskFileProgressVo {
|
||||
|
||||
@Schema(description = "文件标识(优先 fileKey)")
|
||||
private String fileKey;
|
||||
|
||||
@Schema(description = "源文件名")
|
||||
private String sourceFilename;
|
||||
|
||||
@Schema(description = "已处理行数")
|
||||
private Integer processedRows;
|
||||
|
||||
@Schema(description = "总行数")
|
||||
private Integer totalRows;
|
||||
|
||||
@Schema(description = "百分比(0-100)")
|
||||
private Integer percent;
|
||||
|
||||
@Schema(description = "文件状态:PENDING/RUNNING/COMPLETED/FAILED")
|
||||
private String status;
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.nanri.aiimage.modules.deletebrand.model.vo.DeleteBrandResultItemVo;
|
||||
import com.nanri.aiimage.modules.deletebrand.model.vo.DeleteBrandRunVo;
|
||||
import com.nanri.aiimage.modules.deletebrand.model.vo.DeleteBrandTaskDeletionStatusVo;
|
||||
import com.nanri.aiimage.modules.deletebrand.model.vo.DeleteBrandTaskDetailVo;
|
||||
import com.nanri.aiimage.modules.deletebrand.model.vo.DeleteBrandTaskFileProgressVo;
|
||||
import com.nanri.aiimage.modules.deletebrand.model.vo.DeleteBrandTaskItemVo;
|
||||
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
@@ -569,9 +570,11 @@ public class DeleteBrandRunService {
|
||||
DeleteBrandLineProgressVo progressVo = buildLineProgress(task.getId(), progress);
|
||||
|
||||
DeleteBrandTaskDetailVo detail = new DeleteBrandTaskDetailVo();
|
||||
List<DeleteBrandResultItemVo> taskItems = resolveTaskResultItems(task);
|
||||
detail.setTask(taskVo);
|
||||
detail.setLine_progress(progressVo);
|
||||
detail.setItems(resolveTaskResultItems(task));
|
||||
detail.setItems(taskItems);
|
||||
detail.setFileProgress(buildFileProgress(task, taskItems, progressVo));
|
||||
return detail;
|
||||
}
|
||||
|
||||
@@ -602,6 +605,73 @@ public class DeleteBrandRunService {
|
||||
}
|
||||
}
|
||||
|
||||
private List<DeleteBrandTaskFileProgressVo> buildFileProgress(FileTaskEntity task,
|
||||
List<DeleteBrandResultItemVo> taskItems,
|
||||
DeleteBrandLineProgressVo progressVo) {
|
||||
if (taskItems == null || taskItems.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
String taskStatus = task == null ? null : task.getStatus();
|
||||
DeleteBrandLineProgressInfoVo info = progressVo == null ? null : progressVo.getInfo();
|
||||
Integer finishedFiles = info == null ? null : info.getFinished_files();
|
||||
String runningFileName = info == null ? null : info.getFile_name();
|
||||
Integer currentLine = info == null ? null : info.getCurrent_line();
|
||||
Integer totalLines = info == null ? null : info.getTotal_lines();
|
||||
|
||||
List<DeleteBrandTaskFileProgressVo> fileProgress = new ArrayList<>();
|
||||
int completedAssigned = 0;
|
||||
int normalizedFinished = finishedFiles == null ? 0 : Math.max(0, finishedFiles);
|
||||
|
||||
for (DeleteBrandResultItemVo item : taskItems) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DeleteBrandTaskFileProgressVo fp = new DeleteBrandTaskFileProgressVo();
|
||||
fp.setFileKey(item.getFileKey());
|
||||
fp.setSourceFilename(item.getSourceFilename());
|
||||
|
||||
Integer itemTotalRows = item.getTotalRows() == null ? 0 : Math.max(item.getTotalRows(), 0);
|
||||
fp.setTotalRows(itemTotalRows);
|
||||
|
||||
String status = "PENDING";
|
||||
int processedRows = 0;
|
||||
int percent = 0;
|
||||
|
||||
if ("SUCCESS".equals(taskStatus)) {
|
||||
status = "COMPLETED";
|
||||
processedRows = itemTotalRows;
|
||||
percent = 100;
|
||||
} else if ("FAILED".equals(taskStatus)) {
|
||||
status = "FAILED";
|
||||
processedRows = Math.min(itemTotalRows, Math.max(0, currentLine == null ? 0 : currentLine));
|
||||
percent = itemTotalRows > 0 ? Math.min(100, (int) Math.round(processedRows * 100.0 / itemTotalRows)) : 0;
|
||||
} else {
|
||||
if (completedAssigned < normalizedFinished) {
|
||||
status = "COMPLETED";
|
||||
processedRows = itemTotalRows;
|
||||
percent = 100;
|
||||
completedAssigned++;
|
||||
} else if (runningFileName != null && runningFileName.equals(item.getSourceFilename())) {
|
||||
status = "RUNNING";
|
||||
processedRows = Math.min(itemTotalRows, Math.max(0, currentLine == null ? 0 : currentLine));
|
||||
if (totalLines != null && totalLines > 0) {
|
||||
percent = Math.min(100, Math.max(0, (int) Math.round(processedRows * 100.0 / totalLines)));
|
||||
} else if (itemTotalRows > 0) {
|
||||
percent = Math.min(100, Math.max(0, (int) Math.round(processedRows * 100.0 / itemTotalRows)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fp.setProcessedRows(processedRows);
|
||||
fp.setPercent(percent);
|
||||
fp.setStatus(status);
|
||||
fileProgress.add(fp);
|
||||
}
|
||||
return fileProgress;
|
||||
}
|
||||
|
||||
private FileTaskEntity refreshIndexedMatchesIfNeeded(FileTaskEntity task) {
|
||||
if (task == null || task.getResultJson() == null || task.getResultJson().isBlank()) {
|
||||
return task;
|
||||
|
||||
Reference in New Issue
Block a user