package com.tievd.jyz.mqtt; import com.alibaba.fastjson.JSONObject; import com.tievd.jyz.handler.BaseDataSyncHandler; import com.tievd.jyz.handler.DeviceStatusHandler; import com.tievd.jyz.handler.EventInfoHandler; import com.tievd.jyz.handler.PatrolConfigHandler; import com.tievd.jyz.mqtt.dto.MqttParamDTO; import com.tievd.jyz.service.IDeviceService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; /** * mqtt消息接收分发者 * @author timi */ @Component @Slf4j public class MqttMsgReceiver { /** 一体机注册 */ public static final String REGISTER = "register"; /** aibox按定时周期上报状态数据,状态数据均为周期内的平均值 */ public static final String HEARTBEAT = "heartbeat"; /** aibox初始化完成后,上报终端和加油位的修改时间 */ public static final String BASE_UPDATE_CHECK = "baseUpdateCheck"; /** aibox上报终端/加油位信息至业务平台 */ public static final String BASE_UPDATE = "baseUpdate"; /** aaibox上报检测事件到业务平台 */ public static final String EVENT_INFO = "eventInfo"; /** aaibox检测卸油事件到业务平台 */ public static final String OIL_OUT_EVENT = "oilOutEventInfo"; /** 业务平台根据业务流转需求,获取事件相关资源 */ public static final String EVENT_RESOURCE = "eventResource"; /** 业务平台根据业务流转需求,获取事件相关资源 */ public static final String CUT_VIDEO = "cutVideo"; /** aobox上报巡查配置 */ public static final String PATROL_CONFIG = "patrolConfig"; @Autowired private IDeviceService deviceService; @Autowired private BaseDataSyncHandler baseDataSyncHandler; @Autowired private EventInfoHandler eventInfoHandler; @Autowired private PatrolConfigHandler patrolConfigHandler; /** * 处理mqtt接收到的指令消息 * * @param message */ @Async("commandTaskAsyncPool") public void dealCommandMsg(String message) { MqttParamDTO mqttParamDTO = JSONObject.parseObject(message, MqttParamDTO.class); String type = mqttParamDTO.getType(); switch (type) { case REGISTER: log.info("接收到一体机注册信息,msg:{}",message); deviceService.register(mqttParamDTO); break; case HEARTBEAT: log.info("接收到一体机心跳信息,msg:{}", message.length() > 100 ? message.substring(0, 100) : message); DeviceStatusHandler.heartbeat(mqttParamDTO); break; case BASE_UPDATE_CHECK: log.info("aibox初始化完成后,上报终端和加油位的修改时间,msg:{}",message); baseDataSyncHandler.baseUpdateCheck(mqttParamDTO); break; case BASE_UPDATE: log.info("aibox上报终端/加油位信息至业务平台,msg:{}",message); baseDataSyncHandler.baseInfoUpdate(mqttParamDTO); break; case EVENT_RESOURCE: log.info("接收事件相关资源,msg:{}",message); eventInfoHandler.resource(mqttParamDTO); break; case PATROL_CONFIG: log.info("接收巡查配置,msg:{}",message); patrolConfigHandler.configPatrol(mqttParamDTO); break; case CUT_VIDEO: log.info("获取截取的视频录像"); //TODimgUidO break; default: break; } } /** * 处理mqtt接收到的事件消息 * * @param message */ @Async("eventTaskAsyncPool") public void dealEventMsg(String message) { log.info("------------------> 接受到事件信息:{}", message); MqttParamDTO mqttParamDTO = JSONObject.parseObject(message, MqttParamDTO.class); String type = mqttParamDTO.getType(); switch (type) { case EVENT_INFO: eventInfoHandler.event(mqttParamDTO); break; default: break; } } }