package com.ningdatech.carapi.radar.task;

import java.util.List;

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

import com.ningdatech.carapi.radar.helper.RadarDataHelper;
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;
    private final RadarDataHelper radarDataHelper;

    //@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.getHsYwRadarArmIp(),properties.getHsYwRadarArmPort()));
        radarInfoList.add(new RadarInfoDTO(properties.getHsDyRadarArmIp(),properties.getHsDyRadarArmPort()));
        radarInfoList.add(new RadarInfoDTO(properties.getHlRadarArmIp(),properties.getHlRadarArmPort()));
        MultiRadarServer server = new MultiRadarServer(radarDataService,radarInfoList,radarDataHelper);
        server.startServers(radarInfoList);
    }
}
