|
@@ -4,9 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -21,7 +19,6 @@ import shop.alien.util.common.safe.TextModerationResultVO;
|
|
|
import shop.alien.util.common.safe.TextModerationUtil;
|
|
import shop.alien.util.common.safe.TextModerationUtil;
|
|
|
import shop.alien.util.common.safe.TextReviewServiceEnum;
|
|
import shop.alien.util.common.safe.TextReviewServiceEnum;
|
|
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
|
import javax.websocket.*;
|
|
import javax.websocket.*;
|
|
|
import javax.websocket.server.PathParam;
|
|
import javax.websocket.server.PathParam;
|
|
|
import javax.websocket.server.ServerEndpoint;
|
|
import javax.websocket.server.ServerEndpoint;
|
|
@@ -128,6 +125,9 @@ public class WebSocketProcess implements ApplicationContextAware {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ log.info("websocketVo----------------{}",JSONObject.from(websocketVo).toJSONString());
|
|
|
|
|
+ log.info("concurrentHashMap----------{}",concurrentHashMap.keySet());
|
|
|
|
|
+
|
|
|
// 保存消息记录
|
|
// 保存消息记录
|
|
|
LifeMessage lifeMessage = new LifeMessage();
|
|
LifeMessage lifeMessage = new LifeMessage();
|
|
|
lifeMessage.setSenderId(websocketVo.getSenderId());
|
|
lifeMessage.setSenderId(websocketVo.getSenderId());
|
|
@@ -157,7 +157,7 @@ public class WebSocketProcess implements ApplicationContextAware {
|
|
|
sendMessage(websocketVo.getSenderId(), JSONObject.from(websocketVo).toJSONString());
|
|
sendMessage(websocketVo.getSenderId(), JSONObject.from(websocketVo).toJSONString());
|
|
|
sendMessage(websocketVo.getReceiverId(), JSONObject.from(websocketVo).toJSONString());
|
|
sendMessage(websocketVo.getReceiverId(), JSONObject.from(websocketVo).toJSONString());
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- log.error("WebSocketProcess.onMessage() Error Mgs={}", e.getMessage());
|
|
|
|
|
|
|
+ log.error("WebSocketProcess.onMessage()----error----Msg={}", e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -184,23 +184,19 @@ public class WebSocketProcess implements ApplicationContextAware {
|
|
|
* 发送消息到指定客户端
|
|
* 发送消息到指定客户端
|
|
|
*/
|
|
*/
|
|
|
public void sendMessage(String id, String message) throws Exception {
|
|
public void sendMessage(String id, String message) throws Exception {
|
|
|
- log.info("-------------sendMessage----------------");
|
|
|
|
|
- log.info("-------------sendMessage {} {}----------------", id, message);
|
|
|
|
|
|
|
+ log.info("WebSocketProcess.sendMessage()--ready----id={},message={}", id, message);
|
|
|
//根据id,从map中获取存储的webSocket对象
|
|
//根据id,从map中获取存储的webSocket对象
|
|
|
WebSocketProcess webSocketProcess = concurrentHashMap.get(id);
|
|
WebSocketProcess webSocketProcess = concurrentHashMap.get(id);
|
|
|
- log.info("-------------webSocketProcess----------------");
|
|
|
|
|
- System.out.println(concurrentHashMap);
|
|
|
|
|
- log.info("-------------concurrentHashMap----------------");
|
|
|
|
|
- System.out.println(webSocketProcess);
|
|
|
|
|
if (!ObjectUtils.isEmpty(webSocketProcess)) {
|
|
if (!ObjectUtils.isEmpty(webSocketProcess)) {
|
|
|
//当客户端是Open状态时,才能发送消息
|
|
//当客户端是Open状态时,才能发送消息
|
|
|
if (webSocketProcess.session.isOpen()) {
|
|
if (webSocketProcess.session.isOpen()) {
|
|
|
webSocketProcess.session.getBasicRemote().sendText(message);
|
|
webSocketProcess.session.getBasicRemote().sendText(message);
|
|
|
|
|
+ log.info("WebSocketProcess.sendMessage()---success---id={},message={}", id, message);
|
|
|
} else {
|
|
} else {
|
|
|
- log.error("WebSocketProcess.sendMessage() websocket session={} is closed ", id);
|
|
|
|
|
|
|
+ log.error("WebSocketProcess.sendMessage()---error----websocket session:{} is closed ", id);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- log.error("WebSocketProcess.sendMessage() websocket session={} is not exit ", id);
|
|
|
|
|
|
|
+ log.error("WebSocketProcess.sendMessage()---error----websocket session:{} is not exit ", id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|