package com.xydl.cac.task;

import com.xydl.cac.config.BizConfig;
import com.xydl.cac.entity.*;
import com.xydl.cac.iec.IEDCollectService;
import com.xydl.cac.repository.*;
import com.xydl.cac.service.DataService;
import com.xydl.cac.service.IedDlRecordService;
import com.xydl.cac.socket.WebSocketServer;
import com.xydl.cac.spectrogram.SpectrogramHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AsyncTask {
    @Value("${cac.61850.warning:true}")
    public boolean warning;
    @Resource
    IcdConfigTypeRepository configRepository;
    @Resource
    IcdConfigTypeAttRepository attRepository;
    @Resource
    IcdConfigTypeInstRepository instRepository;
    @Resource
    RptparamindexRepository rptparamindexRepository;
    @Resource
    IedDlRecordService dlRecordService;
    @Resource
    DataService dataService;
    @Resource
    WebSocketServer webSocketServer;
    @Resource
    BizConfig bizConfig;
    @Resource
    WarningRepository warningRepository;
    @Resource
    SpectrogramHandler spectrogramHandler;

    @Async
    public void collectIed(String xml, IcdIed ied, List<Rptparamindex> rptList, List<IedDlConfig> dlList) {
        IEDCollectService iedService = new IEDCollectService(configRepository, attRepository,
                instRepository, rptparamindexRepository,
                dlRecordService, dataService,
                xml, ied,
                webSocketServer, bizConfig, warning,
                warningRepository, spectrogramHandler);
        iedService.collectAndSave(rptList, dlList);
    }
}
