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

import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.tzs.biz.utils.RedisUtil;
import com.yeejoin.amos.feign.privilege.Privilege;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqxListener;
import org.typroject.tyboot.core.foundation.context.RequestContext;

@Component
@Slf4j
public class PrivilegeCompanyDeleteListener extends EmqxListener {

    @Autowired
    RedisUtil redisUtil;

    @Value("${admin.product}")
    String product;

    @Value("${admin.appkey}")
    String appkey;


    @Override
    public void processMessage(String s, MqttMessage message) throws Exception {
        System.out.println(message);
        JSONObject object = null;
        try {
            object = JSONObject.parseObject(message.toString());
        } catch (Exception e) {
            throw new Exception("公司同步消息解析失败");
        }
        RequestContext.setAppKey(appkey);
        RequestContext.setProduct(product);
        RequestContext.setToken(String.valueOf(redisUtil.get("platform_token")));

        //通过sequence_nbr删除企业
        Privilege.companyClient.deleteCompany(object.getString("sequence_nbr"));
    }
}
