package net.lab1024.sa.admin.module.business.wms.excel;

import jakarta.servlet.ServletOutputStream;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Service
@Slf4j
public class ExportTaskService {
    private final ConcurrentMap<String, Long> progressMap = new ConcurrentHashMap<>();

    public String createTask() {
        String taskId = System.currentTimeMillis() + "-" + new Random().nextInt(1000000);
        progressMap.put(taskId, 0L);
        return taskId;
    }

    public void updateProgress(String taskId, long progress) {
        progressMap.put(taskId, progress);
    }

    public Long getProgress(String taskId) {
        return progressMap.getOrDefault(taskId, 0L);
    }

    public void cleanupTask(String taskId) {
        progressMap.remove(taskId);
    }
}
