package com.yeejoin.amos.boot.biz.common.rule.action;//package com.yeejoin.amos.latentdanger.business.rule.action;

import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.biz.common.utils.RuleUtils;
import com.yeejoin.amos.boot.biz.common.utils.SnowFlake;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.MessageModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;

/**
 * @Author: xl
 * @Description: 消息规则动作
 * @Date: 2021/11/10 11:49
 */
@Component
public class MessageAction {

    public static final Logger log = LoggerFactory.getLogger(MessageAction.class);
    @Autowired
    private SnowFlake snowFlake;
    public void sendMessage(Object msgObj, String title, String content) {
        MessageModel messageModel = JSON.parseObject(JSON.toJSONString(msgObj), MessageModel.class);
        messageModel.setTitle(title);
        messageModel.setBody(RuleUtils.instedParams(content, msgObj));
        messageModel.setSequenceNbr(snowFlake.nextId());

        log.info(String.format("接收规则返回数据: %s", msgObj));
        if (!ValidationUtil.isEmpty(messageModel)) {
            try {
                log.info("调用平台消息接口参数: {}", messageModel);
                Systemctl.messageClient.create(messageModel);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}


