package com.gci.boot.modules.task.gps;

import cn.hutool.json.JSONUtil;
import com.gci.boot.common.util.RedisKey;
import com.gci.boot.modules.gis.service.GpsConsumerService;
import com.gci.boot.modules.gis.vo.FenceSpeedBeanVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author lyz
 * @date 2023/9/14 15:37
 */
@Configuration
@EnableScheduling
@Slf4j
public class SpeedingAndFenceAlarmTask {


    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private GpsConsumerService gpsConsumerService;

    @Scheduled(fixedRate = 10000)
    public void consumeActSafetyFileData() {
        String data = redisTemplate.opsForList().rightPop(RedisKey.FENCE_SPEED_ALARM_BEAN);
        if (data != null) {
            log.info("开始消费数据-{}", data);
            try {
                FenceSpeedBeanVO vo = JSONUtil.toBean(data, FenceSpeedBeanVO.class);
                gpsConsumerService.saveHandle(vo);
            } catch (Exception e) {
                log.error("获取GPS告警（围栏告警、超速告警）数据消息失败 ， data = {}， msg = {}", JSONUtil.formatJsonStr(data), e.getMessage());
            }
        }
    }
}
