package cn.wise.sc.energy.power.plant.business.task.async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * 执行耗时任务
 *
 * @author neo.shu
 * @since 2020/10/07 08:30
 */
@Service
public class ReportParamsTask {

    @Async
    public Future<String> executeTimeConsumingOperation(TimeConsumingOperation operation, Object... args) {
        Future<String> future;
        try {
            operation.operate(args);
            return new AsyncResult<>("0");
        } catch (Exception e) {
            future = new AsyncResult<>(e.getMessage());
            e.printStackTrace();
            return future;
        }
    }

}
