package com.muyu.processing.listener;

import com.alibaba.fastjson.JSONObject;
import com.muyu.domain.FenceGroup;
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.awt.*;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 电子围栏判定
 * @Author：杨鹏
 * @Package：com.muyu.processing.listener
 * @Project：cloud-vehicle
 * @name：FenceListener
 * @Date：2024/10/9 11:17
 */
@Log4j2
public class FenceListener 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码");
            Double longitude = (Double) data.get("longitude");
            Double latitude = (Double) data.get("latitude");
            HashMap<String, Object> map  = (HashMap<String, Object>) cacheUtil.get(vin);
            if (map != null) {
                ArrayList<Point> points = new ArrayList<>();
                FenceGroup fenceGroup = new FenceGroup();
                Point testPoint = new Point(); // 应该在第一个围栏内
            }
        } catch (NumberFormatException e) {
            log.error("事件发送错误",e);
            throw new RuntimeException(e);
        }
    }

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