package com.mosty.yjzl.remote;

import com.alibaba.fastjson.JSON;
import com.mosty.base.feign.service.MostyWebSocketFeignService;
import com.mosty.base.model.dto.websocket.WebSocketObject;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author dw
 * @since 2022/7/23
 * websocket外部调用基础管理接口
 **/
@Service
@Slf4j
public class TbWebSocketAdaptRemoteService {

    @Resource
    private MostyWebSocketFeignService mostyWebSocketFeignService;

    // 发送websocket信息
    public void sendMessage(WebSocketObject obj) {
        ResponseResult<Void> responseResult = this.mostyWebSocketFeignService.sendMessage(obj);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("发送websocket信息异常 Result = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("发送websocket信息异常");
        }
    }

}
