package com.gyee.frame.common.websocket;

import com.alibaba.fastjson.JSON;
import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.util.StringUtils;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component
public class WebsocketMessageService
{

    @Resource
    private SimpMessagingTemplate simpMessagingTemplate;


    public void SendAlertToAll(String destination, Object sendData)
    {
        if (StringUtils.notEmp(sendData)) {
            simpMessagingTemplate.convertAndSend(destination, AjaxResult.successData(AjaxStatus.success.code, JSON.toJSONString(sendData)));
        } else {
            simpMessagingTemplate.convertAndSend(destination, AjaxResult.successData(AjaxStatus.error.code, "数据传输错误"));
        }

    }
}
