package com.cico.nest.lcdp.boot.core.qxsd.application.schedule.job;

import com.cico.nest.lcdp.boot.core.qxsd.application.service.TunnelService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 保存当前隧道流量数据
 * @author zws
 * @date 2024/8/12
 */

@Component
public class SaveTrafficFlowMetricJob  {
    @Resource
    private TunnelService tunnelService;

    @Value("${qxsd.tunnel.down-id}")
    private String tunnelDownId;

    @Value("${qxsd.tunnel.up-id}")
    private String tunnelUpId;

    private final ExecutorService service = Executors.newFixedThreadPool(5);
    @Scheduled(cron = "0 0,10,20,30,40,50 * * * ? " )
    public void execute(){
        tunnelService.saveTrafficFlowMetricByTunnelId(tunnelDownId);
        tunnelService.saveTrafficFlowMetricByTunnelId(tunnelUpId);
        /*List<String> tunnelIds = new ArrayList<>();
        tunnelIds.add(tunnelDownId);
        tunnelIds.add(tunnelUpId);
        for(String tunnelId : tunnelIds){
            service.submit(() -> tunnelService.saveTrafficFlowMetricByTunnelId(tunnelId));
        }*/
    }
}
