package com.muyu.processing.listener;

import com.alibaba.fastjson.JSONObject;
import com.muyu.domain.WarnRule;
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.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.HashMap;

/**
 * 判断故障信息
 * @Author：杨鹏
 * @Package：com.muyu.processing.listener
 * @Project：cloud-vehicle
 * @name：IdentifyingFailuresListener
 * @Date：2024/10/9 11:20
 */
@Log4j2
public class IdentifyingFailuresListener implements EventListener {

    @Autowired
    private CacheUtil cacheUtil;

    @Override
    public void onEvent(EventCustom event) {
        try {
            log.info("规则预警事件开始");
            JSONObject data = event.getData();
            String vin = (String) data.get("VIN码");
            HashMap<String, Object> map = (HashMap<String, Object>) cacheUtil.get(vin);
            if (map != null) {
                WarnRule faultCondition = (WarnRule) map.get("warnRule");
            }
        } catch (Exception e) {
            log.error("事件发生错误",e);
            throw new RuntimeException(e);
        }

    }

    @Override
    public void onApplicationEvent(EventCustom event) {
        this.onEvent(event);
    }

}
