All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.schoolwow.download.module.progress.flow.GetDownloadTaskProgressFlow Maven / Gradle / Ivy

package cn.schoolwow.download.module.progress.flow;

import cn.schoolwow.download.domain.progress.DownloadProgress;
import cn.schoolwow.download.domain.task.DownloadTask;
import cn.schoolwow.download.module.pool.domain.PoolContext;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.domain.FlowDataFeature;
import cn.schoolwow.quickflow.dto.FlowContextDataRange;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.instanceList.QueryInstanceList;

public class GetDownloadTaskProgressFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        DownloadTask downloadTask = flowContext.checkInstanceData(DownloadTask.class);
        PoolContext poolContext = flowContext.checkInstanceData(PoolContext.class);

        if(poolContext.downloadProgressList.isEmpty()){
            return;
        }
        DownloadProgress downloadProgress = QueryInstanceList.newQuery(poolContext.downloadProgressList)
                .addQuery("downloadTask", downloadTask)
                .execute()
                .getOne();
        if(null==downloadProgress){
            return;
        }

        synchronized (poolContext.downloadProgressList){
            if("下载中".equals(downloadProgress.state)){
                downloadProgress.currentFileSize = downloadProgress.getFileDownloadedSize.getFileDownloadedSize();
                int m3u8SuccessCount = downloadProgress.getFileDownloadedSize.getM3u8SuccessCount();
                if(downloadProgress.m3u8){
                    downloadProgress.currentFileSizeFormat = m3u8SuccessCount+"("+String.format("%.2fMB",downloadProgress.currentFileSize/1.0/1024/1024)+")";
                }else{
                    downloadProgress.currentFileSizeFormat = String.format("%.2fMB",downloadProgress.currentFileSize/1.0/1024/1024);
                }
                if(downloadProgress.m3u8){
                    int m3u8SegmentSize = downloadProgress.getFileDownloadedSize.getM3u8SegmentSize();
                    downloadProgress.percent = m3u8SuccessCount*100/m3u8SegmentSize;
                }else if(downloadProgress.totalFileSize>0){
                    downloadProgress.percent = (int) (downloadProgress.currentFileSize*100/downloadProgress.totalFileSize);
                }
            }
        }
        flowContext.putInstanceData(downloadProgress, FlowContextDataRange.Flow, FlowDataFeature.ReturnData);
    }

    @Override
    public String name() {
        return "获取下载进度列表";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy