package cn.cecep.talroad.data.analyse.task.constant.impl;

import cn.cecep.talroad.data.analyse.task.constant.DataConstantAbstractService;
import cn.cecep.talroad.data.analyse.task.entity.DeviceSitVo;
import cn.cecep.talroad.data.analyse.task.real.device.impl.ElecDataDeviceRealService;
import cn.cecep.talroad.domain.BasDeviceSalAnalysis;
import cn.cecep.talroad.domain.MonElecReal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ElecDataConstantService extends DataConstantAbstractService<MonElecReal> {

    @Autowired
    private ElecDataDeviceRealService elecDataRealService;

    @Override
    protected List<String> queryDeviceIds() {
        return elecDataRealService.queryDeviceIds();
    }

    @Override
    protected Map<String, List<MonElecReal>> groupDeviceRealList(List<MonElecReal> dataReal,List<String> deviceIds) {
        return elecDataRealService.groupDeviceRealList(dataReal,deviceIds);
    }

    @Override
    protected List<MonElecReal> queryReal(List deviceIds, Date startTime, Date endTime) {
        return elecDataRealService.queryReal(deviceIds,startTime,endTime);
    }

    @Override
    protected String getLogicExceptionsDate(MonElecReal entity) {
        return elecDataRealService.getLogicExceptionsDate(entity);
    }

    @Override
    protected String getDeviceId(String deviceId) {
        return DeviceSitVo.parse(deviceId).getDeviceId();
    }

    @Override
    protected List<String> getOpenDeviceIds(List<String> deviceIds, List<BasDeviceSalAnalysis> basDeviceSalAnalyses) {
        List<DeviceSitVo> mainProductDeviceVos = DeviceSitVo.parse(deviceIds);
        mainProductDeviceVos = mainProductDeviceVos.stream().filter((mainProductDeviceVo) -> {
            for (BasDeviceSalAnalysis basDeviceSalAnalysis : basDeviceSalAnalyses) {
                if (basDeviceSalAnalysis.getDeviceId().equals(mainProductDeviceVo.getDeviceId())) {
                    return true;
                }
            }
            return false;
        }).collect(Collectors.toList());
        return DeviceSitVo.toJsonString(mainProductDeviceVos);
    }
}
