package com.muyu.processing.listener;

import com.alibaba.fastjson.JSONObject;
import com.muyu.domain.resp.WarnRuleResp;
import com.muyu.processing.basic.EventCustom;
import com.muyu.processing.basic.EventListener;
import com.muyu.processing.utils.CacheUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 警告规则响应事件
 * @Author：杨鹏
 * @Package：com.muyu.processing.listener
 * @Project：cloud-vehicle
 * @name：WarnRuleRespListener
 * @Date：2024/10/9 18:41
 */
@Log4j2
@Component
public class WarnRuleRespListener implements EventListener {

    @Resource
    private CacheUtil cacheUtil;

    /**
     * 事件处理
     */
    @Override
    public void onEvent(EventCustom event) {
        // 获得数据
        JSONObject jsonObject = event.getData();
        // 获得VIN码
        String vin = (String) jsonObject.get("VIN码");
        // 获得本地缓存数据
        Map<String, Object> map = (Map<String, Object>) cacheUtil.get(vin);
        if (map != null){
            log.info("本地缓存数据为: {}",map);
            WarnRuleResp warnRuleResp = (WarnRuleResp) map.get("warnRuleResp");
        }
    }

    @Override
    public void onApplicationEvent(EventCustom event) {

    }
}
