package com.ho.datacollect.component;

import com.ho.datacollect.api.vo.req.add.DataSetParam;
import com.ho.datacollect.service.DataCollectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author fancl
 * @desc: 数据采集处理类
 * @date 2022/8/31
 */
@Component
@Slf4j
public class DCStrategy {

    @Autowired
    Map<String, DataCollectService> dcStrategy;

    //异步调用方法,并指定 数据采集模块的线程池
    @Async("dataCollectThreadPoolExecutor")
    public void strategy(String typeName, DataSetParam dataSetParam){
        log.info("DCStrategy.strategy, typeName:{},dataSetParam:{} ", typeName, null);
/*        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        if(dcStrategy.containsKey(typeName)){
            dcStrategy.get(typeName).doService(dataSetParam);
        }else{
            log.error("Not found this strategy:{}",typeName );
            log.error("=====================================");
        }
    }

}
