package com.muyu.carData.consumer;

import com.muyu.carData.util.CacheUtil;
import com.muyu.domain.FaultCodeCache;
import com.muyu.enterprise.cache.car.VehicleCacheCarInformationAddService;
import com.muyu.enterprise.cache.car.VehicleCacheCarInformationFenceRespService;
import com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**车辆上线消费者
 * @Author：张腾
 * @Package：com.muyu.carData.consumer
 * @Project：cloud-server-8
 * @name：CarOnlineConsumer
 * @Date：2024/10/4 14:27
 */
@Log4j2
@Component
public class CarOnlineConsumer {

    @Autowired
    private CacheUtil cacheUtil;

    @Autowired
    private VehicleCacheFaultCodeAddService vehicleCacheCarInformationAddService;




    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "CAR_ONLINE",durable = "true"),
            exchange = @Exchange(value = "ONLINE_EXCHANGE",type = "fanout")
    ))
    public void online(String vin){
        log.info("车辆vin:{},已上线,开始消费",vin);
        FaultCodeCache faultCodeCache = vehicleCacheCarInformationAddService
                .get(vehicleCacheCarInformationAddService.keyPre()+vin);
        cacheUtil.put(vin,faultCodeCache);
    }
}
