package com.yeejoin.amos.boot.module.tcm.biz.listener;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.tcm.api.service.IEquipmentCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqxListener;

/**
 * @author Administrator
 */
@Component
@Slf4j
public class AmosMqttListener extends EmqxListener {

    @Autowired
    IEquipmentCategoryService equipmentCategoryService;

    @Override
    public void processMessage(String topic, MqttMessage mqttMessage) {
        log.info(topic + "已收到：准备生成监管码或96333电梯识别码");
        byte[] payload = mqttMessage.getPayload();
        String str = new String(payload);
        String msg = JSON.parse(str).toString();
        JSONObject jsonObject = JSONObject.parseObject(msg);
        String id = jsonObject.get("id").toString();
//        equipmentCategoryService.createSupervisorCode(null, id);
        // 更新ES
        equipmentCategoryService.checkEsData(id);
        // 更新一码通总览数据统计表
//        equipmentCategoryService.updateEquipmentCategoryData(id);
    }
}
