package com.ningdatech.carapi.radar.task;

import java.util.List;

import javax.annotation.PostConstruct;

import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Component;

import com.ningdatech.carapi.radar.model.dto.RadarInfoDTO;
import com.ningdatech.carapi.radar.properties.RadarDataTaskProperties;
import com.ningdatech.carapi.radar.server.MultiRadarServer;
import com.ningdatech.carapi.radar.service.IRadarDataService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author CMM
 * 雷达数据接收定时任务
 * @since 2024/09/27 14:36
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class RadarDataTask {

    private final RadarDataTaskProperties properties;
    private final IRadarDataService radarDataService;

    @PostConstruct
    public void initTask() {
        if (!properties.getEnable()) {
            log.warn("雷达数据同步已关闭……");
            return;
        }
        //initRadarDataTaskByStart();
    }

    /**
     * 项目重启之后重新初始化雷达接收定时任务
     */
    private void initRadarDataTaskByStart() {
        log.info("雷达数据接收任务已启动……");
        List<RadarInfoDTO> radarInfoList = Lists.newArrayList();
        radarInfoList.add(new RadarInfoDTO(properties.getHsYwComeRadarIp(),properties.getHsYwComeRadarPort()));
        radarInfoList.add(new RadarInfoDTO(properties.getHsYwGoRadarIp(),properties.getHsYwGoRadarPort()));
        radarInfoList.add(new RadarInfoDTO(properties.getHsDyComeRadarIp(),properties.getHsDyComeRadarPort()));
        radarInfoList.add(new RadarInfoDTO(properties.getHsDyGoRadarIp(),properties.getHsDyGoRadarPort()));
        radarInfoList.add(new RadarInfoDTO(properties.getHlYwRadarIp(),properties.getHlYwRadarPort()));
        radarInfoList.add(new RadarInfoDTO(properties.getHlLxRadarIp(),properties.getHlLxRadarPort()));
        MultiRadarServer server = new MultiRadarServer(radarDataService,radarInfoList);
        server.startServers(radarInfoList);
    }
}
