package com.ruoyi.common.websocket.service;

import com.ruoyi.common.websocket.dto.WebSocketMessageDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.common.websocket.utils.WebSocketUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;


/**
 * 短信服务
 *
 * @author Lion Li
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class RemoteMessageService {

    /**
     * 发布订阅的消息
     *
     * @param sessionKey session主键 一般为用户id
     * @param message    消息文本
     */
    public void publishMessage(Long sessionKey, String message) {
        WebSocketMessageDto webSocketMessageDto = new WebSocketMessageDto();
        webSocketMessageDto.setSessionKeys(Collections.singletonList(sessionKey));
        webSocketMessageDto.setMessage(message);
        WebSocketUtils.publishMessage(webSocketMessageDto);
    }

    /**
     * 发布订阅的消息(群发)
     *
     * @param message 消息内容
     */
    public void publishAll(String message) {
        WebSocketUtils.publishAll(message);
    }

}
