package cn.cecep.talroad.data.analyse.task.real;

import cn.cecep.talroad.domain.AmProblemFi;
import cn.cecep.talroad.domain.BasDevice;
import cn.cecep.talroad.domain.SEnvWaterMonReal;
import cn.cecep.talroad.enums.EnIndustry;
import cn.cecep.talroad.mapper.BasDeviceMapper;
import cn.cecep.talroad.vo.BasDeviceParamListVo;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;

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

public abstract class RealService<T> {

    @Autowired
    private BasDeviceMapper basDeviceMapper;

    /**
     * 获取实时数据
     */
    public abstract List<T> queryReal(List<String> deviceIds, Date startTime, Date endTime);

    /**
     * 获取设备id
     */
    public abstract List<String> queryDeviceIds();

    /**
     * 数据分组
     */
    public abstract Map<String, List<T>> groupDeviceRealList(List<T> dataReal,List<String> deviceIds);

    /**
     * 获取报警时间
     */
    public abstract String getLogicExceptionsDate(T entity);


    protected List<String> queryDeviceIds(EnIndustry enIndustry){
        if (enIndustry == null){
            throw new RuntimeException("queryDeviceIds is null!");
        }
        LambdaQueryWrapper<BasDevice> wrapper = Wrappers.<BasDevice>lambdaQuery()
                .select(BasDevice::getDeviceId)
                .eq(BasDevice::getIndustry, enIndustry.id());
        List<BasDevice> basDevices = basDeviceMapper.selectList(wrapper);
        return basDevices.stream().map(BasDevice::getDeviceId).collect(Collectors.toList());
    }

}
