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.MainProductDeviceVo;
import cn.cecep.talroad.data.analyse.task.real.device.impl.WaterDataDeviceRealService;
import cn.cecep.talroad.domain.BasDeviceSalAnalysis;
import cn.cecep.talroad.domain.SEnvWaterMonReal;
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 WaterDataConstantService extends DataConstantAbstractService<SEnvWaterMonReal> {

    @Autowired
    private WaterDataDeviceRealService waterRealService;

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

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

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

    @Override
    protected String getLogicExceptionsDate(SEnvWaterMonReal entity) {
        return waterRealService.getLogicExceptionsDate(entity);
    }

    @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();
    }
}
