package org.sxkj.resource.download.mode;
|
|
import lombok.AllArgsConstructor;
|
import lombok.Data;
|
import lombok.NoArgsConstructor;
|
|
import java.time.LocalDateTime;
|
import java.util.concurrent.Future;
|
|
/**
|
* @Description TODO 下载任务相关
|
* @Author AIX
|
* @Date 2025/8/5 13:46
|
* @Version 1.0
|
*/
|
@Data
|
@AllArgsConstructor
|
@NoArgsConstructor
|
public class DownloadTask {
|
|
private String taskId;
|
private String userId;
|
/**
|
* 待定:PENDING, 处理:PROCESSING, 完成:COMPLETED, 失败:FAILED, 取消:CANCELLED
|
*/
|
private String status;
|
private int totalFiles;
|
private int processedFiles;
|
private String downloadUrl;
|
private String errorMessage;
|
/**
|
* 下载类型,sjzx:数据中心,aisb:ai识别,htsjzx:后台数据中心
|
*/
|
private String type;
|
private LocalDateTime startTime;
|
private LocalDateTime endTime;
|
/**
|
* 用于取消任务
|
*/
|
private Future<?> future;
|
|
public boolean isCompleted() {
|
return "COMPLETED".equals(status) || "FAILED".equals(status) || "CANCELLED".equals(status);
|
}
|
|
public int getProgress() {
|
if (totalFiles <= 0) return 0;
|
return Math.min(100, Math.max(0, (processedFiles * 100) / totalFiles));
|
}
|
|
public void cancel() {
|
if (future != null && !future.isDone()) {
|
future.cancel(true);
|
}
|
status = "CANCELLED";
|
endTime = LocalDateTime.now();
|
}
|
|
}
|