package com.lutao.cloud.oil.runner;//package com.lutao.cloud.oil.runner;
//
//import com.lutao.cloud.oil.mapper.*;
//import com.lutao.cloud.oil.service.PerceptionMonitorFireInfoService;
//import com.lutao.entity.*;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.core.annotation.Order;
//import org.springframework.data.redis.connection.RedisConnection;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.BoundHashOperations;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Component;
//
//import java.nio.charset.StandardCharsets;
//import java.Timestamp;
//import java.util.List;
//
//@Component
//@Order(1)
//@AllArgsConstructor
//@Slf4j
//public class InitFireMonitor implements CommandLineRunner {
//
//    private final PerceptionMonitorFireInfoMapper fireInfoMapper;
//
//    private final PerceptionMonitorGasInfoMapper gasInfoMapper;
//
//    private final PerceptionMonitorHazardousGasInfoMapper hazardousGasInfoMapper;
//
//    private final PerceptionMonitorInfoMapper monitorInfoMapper;
//
//    private final AtmosphereMonitorInfoMapper atmosphereMonitorInfoMapper;
//
//    private final RedisTemplate redisTemplate;
//
//    @Override
//    public void run(String... args) throws Exception {
//        Integer recordSize = 20;
//
//        RedisConnectionFactory connectionFactory = redisTemplate.getConnectionFactory();
//        assert connectionFactory != null;
//        RedisConnection connection = connectionFactory.getConnection();
//        connection.openPipeline();
//        // 初始化 火气动态数据
//        List<PerceptionMonitorFireInfo> fireInfos = fireInfoMapper.selectNewRecore(recordSize);
//        log.info("初始化火气动态数据 begin....");
//        fireInfos.forEach(fire -> {
//            byte[] keyByte = redisTemplate.getKeySerializer().serialize(String.format("perception_monitor_fire_info:%s",fire.getPlatformCode()));
//            byte[] valueByte = redisTemplate.getValueSerializer().serialize(fire);
//            connection.zAdd(keyByte, Timestamp.valueOf(fire.getCollectTime()).getTime(),valueByte);
//        });
//        connection.closePipeline();
//        log.info("初始化火气动态数据 end....");
//
//        List<PerceptionMonitorGasInfo> gasInfos = gasInfoMapper.selectNewRecore(recordSize);
//        log.info("初始化天然气动态数据 begin....");
//        gasInfos.forEach(gas -> {
//            byte[] keyByte = redisTemplate.getKeySerializer().serialize(String.format("perception_monitor_gas_info:%s",gas.getPlatformCode()));
//            byte[] valueByte = redisTemplate.getValueSerializer().serialize(gas);
//            connection.zAdd(keyByte, Timestamp.valueOf(gas.getCollectTime()).getTime(),valueByte);
//        });
//        connection.closePipeline();
//        log.info("初始化天然气动态数据 end....");
//
//        List<PerceptionMonitorHazardousGasInfo> hazardousGasInfos = hazardousGasInfoMapper.selectNewRecore(recordSize);
//        log.info("初始化有毒有害动态数据 begin....");
//        hazardousGasInfos.forEach(hazardousGasInfo -> {
//            byte[] keyByte = redisTemplate.getKeySerializer().serialize(String.format("perception_monitor_hazardous_gas_info:%s",hazardousGasInfo.getPlatformCode()));
//            byte[] valueByte = redisTemplate.getValueSerializer().serialize(hazardousGasInfo);
//            connection.zAdd(keyByte, Timestamp.valueOf(hazardousGasInfo.getCollectTime()).getTime(),valueByte);
//        });
//        connection.closePipeline();
//        log.info("初始化有毒有害动态数据 end....");
//
//        List<PerceptionMonitorInfo> monitorInfos = monitorInfoMapper.selectNewRecore(recordSize);
//        log.info("初始化其他动态数据 begin....");
//        monitorInfos.forEach(monitorInfo -> {
//            byte[] keyByte = redisTemplate.getKeySerializer().serialize(String.format("perception_monitor_info:%s",monitorInfo.getPlatformCode()));
//            byte[] valueByte = redisTemplate.getValueSerializer().serialize(monitorInfo);
//            connection.zAdd(keyByte, Timestamp.valueOf(monitorInfo.getCollectTime()).getTime(),valueByte);
//        });
//        connection.closePipeline();
//        log.info("初始化其他动态数据 end....");
//
//        List<AtmosphereMonitorInfo> atmosphereMonitorInfos = atmosphereMonitorInfoMapper.selectNewRecore(recordSize);
//        log.info("初始化天气动态数据 begin....");
//        atmosphereMonitorInfos.forEach(atmosphere -> {
//            byte[] keyByte = redisTemplate.getKeySerializer().serialize(String.format("atmosphere_monitor_info:%s",atmosphere.getPlatformCode()));
//            byte[] valueByte = redisTemplate.getValueSerializer().serialize(atmosphere);
//            connection.zAdd(keyByte, Timestamp.valueOf(atmosphere.getDetectionTime()).getTime(),valueByte);
//        });
//        connection.closePipeline();
//        log.info("初始化天气动态数据 end....");
//    }
//
//}
