提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.infra.api.websocket; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.StrUtil; |
|
4 |
import com.iailab.framework.common.pojo.CommonResult; |
|
5 |
import com.iailab.framework.websocket.core.sender.WebSocketMessageSender; |
|
6 |
import com.iailab.module.infra.api.websocket.dto.WebSocketSendReqDTO; |
|
7 |
import org.springframework.validation.annotation.Validated; |
|
8 |
import org.springframework.web.bind.annotation.RestController; |
|
9 |
|
|
10 |
import javax.annotation.Resource; |
|
11 |
|
|
12 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
13 |
|
|
14 |
@RestController // 提供 RESTful API 接口,给 Feign 调用 |
|
15 |
@Validated |
|
16 |
public class WebSocketSenderApiImpl implements WebSocketSenderApi { |
|
17 |
|
|
18 |
@Resource |
|
19 |
private WebSocketMessageSender webSocketMessageSender; |
|
20 |
|
|
21 |
@Override |
|
22 |
public CommonResult<Boolean> send(WebSocketSendReqDTO message) { |
|
23 |
if (StrUtil.isNotEmpty(message.getSessionId())) { |
|
24 |
webSocketMessageSender.send(message.getSessionId(), |
|
25 |
message.getMessageType(), message.getMessageContent()); |
|
26 |
} else if (message.getUserType() != null && message.getUserId() != null) { |
|
27 |
webSocketMessageSender.send(message.getUserType(), message.getUserId(), |
|
28 |
message.getMessageType(), message.getMessageContent()); |
|
29 |
} else if (message.getUserType() != null) { |
|
30 |
webSocketMessageSender.send(message.getUserType(), |
|
31 |
message.getMessageType(), message.getMessageContent()); |
|
32 |
} |
|
33 |
return success(true); |
|
34 |
} |
|
35 |
|
|
36 |
} |