package com.xjrsoft.module.mqtt.face.service;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.xjrsoft.common.mqtt.MqttSubscribe;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.mqttv5.client.IMqttMessageListener;
import org.eclipse.paho.mqttv5.common.MqttMessage;
import org.springframework.stereotype.Component;

/**
 * 人员图片删除回调
 */
@Component
@MqttSubscribe(topic = "/face/device/personnel/delete/reply")
@Slf4j
public class FaceDelete implements IMqttMessageListener {
    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        try {
            // 获取回复数据
            JSONObject jsonObject = JSONUtil.parseObj(message.toString());

            // 判断回复结果是否成功
            int code = jsonObject.getInt("code");
            if (code != 0) {
                log.error("删除人脸失败:", jsonObject.get("msg"), new String(message.getProperties().getCorrelationData()));
            }
        } catch (Exception e) {
            log.error(this.getClass().getName(), e.getMessage());
        }
    }
}
