package com.gic.haoban.manage.service.service.message;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.haoban.manage.service.service.notify.out.NoticeMessageApiServiceImpl;
import com.gic.message.center.api.subscribe.model.NoticeMessageForm;
import com.gic.mq.sdk.GicMQClient;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import static org.slf4j.LoggerFactory.getLogger;

/**
 * @description: 企业微信通知消息发送处理类
 * @author: 巴弗
 * @createDate: 2023/4/21 14:03
 */
@Service
public class NoticeMessageHandler {
    private static final Logger logger = getLogger(NoticeMessageHandler.class);

    /**
     * 发送小程序消息
     */
    public void sendMessage(NoticeMessageForm noticeMessageForm){
        logger.info("消息中心发送消息实体:{}", JSONObject.toJSONString(noticeMessageForm));

        if (ObjectUtil.isEmpty(noticeMessageForm.getMessageCode()) || ObjectUtil.isEmpty(noticeMessageForm.getMqRouterCode())) {
            logger.info("消息中心发送消息实体 messageCode 或 mqRouterCode 不存在");
        }
        GicMQClient client = GICMQClientUtil.getClientInstance();
        try {
            client.sendMessage(noticeMessageForm.getMqRouterCode(), JSONObject.toJSONString(noticeMessageForm));
        } catch (Exception e) {
            logger.error("消息中心发送消息实体发送异常 ", e);
        }
    }
}
