package com.muyu.carData.listener;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.muyu.carData.event.EsSaveEvent;
import com.muyu.carData.event.EventListener;
import com.muyu.carData.util.CacheUtil;
import com.muyu.domain.FaultCodeCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/** 判断故障信息
 * @Author：张腾
 * @Package：com.muyu.carData.listener
 * @Project：cloud-server-8
 * @name：IdentifyingFailuresListener
 * @Date：2024/10/8 11:22
 */
@Component
@Slf4j
public class IdentifyingFailuresListener implements EventListener {


    @Autowired
    private CacheUtil cacheUtil;

    @Override
    public void onEvent(EsSaveEvent event) {
        log.info("规则预警事件开始...");
        JSONObject data = event.getData();
        String vin = (String) data.get("vin");
        String str = cacheUtil.get(vin).toString();
        FaultCodeCache faultCodeCache = JSON.parseObject(str, FaultCodeCache.class);
        log.info("规则预警事件结束...");
    }

    @Override
    public void onApplicationEvent(EsSaveEvent event) {
        onEvent(event);
    }
}
