package cn.com.taiji.track.consumer;

import cn.com.taiji.track.service.IBeidouLocationService;
import cn.com.taiji.track.service.IBeidouTrackService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author wudskq
 * TODO 实时消费Kafka北斗船舶数据存入到redis图层
 */
@Component
@Slf4j
@ConditionalOnProperty(name = "taiji.kafka.consumer.beidou.enable",havingValue = "true")
public class BeidouShipTrackConsumer {

    @Autowired
    private IBeidouTrackService beidouTrackService;
    @Autowired
    private IBeidouLocationService beidouLocationService;

    @KafkaListener(
            groupId = "${taiji.kafka.consumer.beidou.group}",
            topics = {"${taiji.kafka.consumer.beidou.topic}"}
    )
    public void dynamicTrack(List<ConsumerRecord<?, ?>> records, Acknowledgment ack) {
        beidouTrackService.beidouDynamicShipToCache(records);
        beidouLocationService.beidouDynamicShipToCache(records);
        ack.acknowledge();
    }
}
