package com.lutao.cloud.oil.service.impl;

import com.lutao.cloud.common.core.util.MessageInfo;
import com.lutao.cloud.oil.service.IBusinessDynamicDataAlarmService;
import com.lutao.entity.*;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

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

@Service
public class BusinessDynamicDataAlarmServiceImpl implements IBusinessDynamicDataAlarmService {

    @Resource
    private RedisTemplate redisTemplate;


    @Override
    public MessageInfo<List<AtmosphereMonitorInfo>> queryAtmosphereMonitorInfo() {
        BoundZSetOperations atmosphereMonitorInfo = redisTemplate.boundZSetOps("atmosphere_monitor_info");
        Set set = atmosphereMonitorInfo.reverseRange(0, 20);
        List<AtmosphereMonitorInfo> atmosphereMonitorInfos = new ArrayList<>(set);
        return MessageInfo.ok(atmosphereMonitorInfos);
    }

    @Override
    public MessageInfo<List<PerceptionMonitorInfo>> queryPerceptionMonitorInfo() {
        BoundZSetOperations perceptionMonitorInfo = redisTemplate.boundZSetOps("perception_monitor_info");
        Set set = perceptionMonitorInfo.reverseRange(0, 20);
        List<PerceptionMonitorInfo> perceptionMonitorInfos = new ArrayList<>(set);
        return MessageInfo.ok(perceptionMonitorInfos);
    }

    @Override
    public MessageInfo<List<PerceptionMonitorFireInfo>> queryPerceptionMonitorFireInfo() {
        BoundZSetOperations perceptionMonitorFireInfo = redisTemplate.boundZSetOps("perception_monitor_fire_info");
        Set set = perceptionMonitorFireInfo.reverseRange(0, 20);
        List<PerceptionMonitorFireInfo> perceptionMonitorFireInfos = new ArrayList<>(set);
        return MessageInfo.ok(perceptionMonitorFireInfos);
    }

    @Override
    public MessageInfo<List<PerceptionMonitorGasInfo>> queryPerceptionMonitorGasInfo() {
        BoundZSetOperations perceptionMonitorGasInfo = redisTemplate.boundZSetOps("perception_monitor_gas_info");
        Set set = perceptionMonitorGasInfo.reverseRange(0, 20);
        List<PerceptionMonitorGasInfo> perceptionMonitorGasInfos = new ArrayList<>(set);
        return MessageInfo.ok(perceptionMonitorGasInfos);
    }

    @Override
    public MessageInfo<List<PerceptionMonitorHazardousGasInfo>> queryPerceptionMonitorHazardousGasInfo() {
        BoundZSetOperations perceptionMonitorHazardousGasInfo = redisTemplate.boundZSetOps("perception_monitor_hazardous_gas_info");
        Set set = perceptionMonitorHazardousGasInfo.reverseRange(0, 20);
        List<PerceptionMonitorHazardousGasInfo> perceptionMonitorHazardousGasInfos = new ArrayList<>(set);
        return MessageInfo.ok(perceptionMonitorHazardousGasInfos);
    }
}
