package com.xinda.mq.redischannel.consumer;

import com.xinda.common.constant.XinDaConstant;
import com.xinda.common.core.mq.DeviceReportBo;
import com.xinda.mq.service.IDeviceReportMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 设备消息回复
 *
 * @author gsb
 * @date 2022/10/10 11:12
 */
@Component
@Slf4j
public class DeviceReplyMsgConsumer {


    @Resource
    private IDeviceReportMessageService deviceReportMessageService;


    /*设备回调消息，统一用上报model*/
    @Async(XinDaConstant.TASK.DEVICE_REPLY_MESSAGE_TASK)
    public void consume(DeviceReportBo bo) {
        try {
            String topicName = bo.getTopicName();

            if (topicName.endsWith(XinDaConstant.TOPIC.MSG_REPLY)) {
                //普通设备回复消息
                deviceReportMessageService.parseReplyMsg(bo);
            } else if (topicName.endsWith(XinDaConstant.TOPIC.UPGRADE_REPLY)) {
                //OTA升级的回复消息
                deviceReportMessageService.parseOTAUpdateReply(bo);
            }
        } catch (Exception e) {
            log.error("=>设备回复消息消费异常", e);
        }
    }
}
