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

import cn.cecep.talroad.data.analyse.task.entity.MainProductDeviceVo;
import cn.cecep.talroad.data.analyse.task.missing.DataMissingAbstractService;
import cn.cecep.talroad.data.analyse.task.real.device.impl.OdsMeShingWeiDeviceRealService;
import cn.cecep.talroad.domain.BasDeviceSalAnalysis;
import cn.cecep.talroad.domain.OdsMeshingWeiStationHourI;
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 OdsMeShingWeiStationService extends DataMissingAbstractService<OdsMeshingWeiStationHourI> {

    @Autowired
    private OdsMeShingWeiDeviceRealService odsMeShingWeiRealService;

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

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

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

    @Override
    protected String getLogicExceptionsDate(OdsMeshingWeiStationHourI entity) {
//        return gasDataRealService.getLogicExceptionsDate(entity);
        return "";
    }

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

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