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.RuleUtils;
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.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);

    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));
        log.info(String.format("接收规则返回数据: %s", JSON.toJSONString(msgObj)));
        if (!ValidationUtil.isEmpty(messageModel)) {
            try {
                Systemctl.messageClient.create(messageModel);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}


