Jelajahi Sumber

fix : Websocket客服系统优化处理02

bilingfeng 1 tahun lalu
induk
melakukan
fdfd239876

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 <Websocket客服系统优化处理01> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <Websocket客服系统优化处理02> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 13 - 3
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/websocket/KfMsgWebsocketHandler.java

@@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 import org.springframework.web.socket.*;
 import reactor.util.function.Tuple2;
@@ -68,6 +69,9 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
     @Autowired
     private IKfQuickReplyService kfQuickReplyService;
 
+    @Autowired
+    private RedisTemplate<String, String> redisTemplate;
+
     /**
      * websocket连接建立成功
      */
@@ -408,8 +412,8 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
                 .build());
         //发送消息, 给所有在线客服推送完整待接入列表
         List<KfWebSocketMsgDTO.WaitUserBean> waitUserList = kfSessionUserService.getWaitUserList(param.getGameId());
-        this.sendMessage(session, KfWebSocketMsgDTO.builder()
-                .webSocketMsgType(param.getWebSocketMsgType())
+        this.pushMessage(KfWebSocketMsgDTO.builder()
+                .webSocketMsgType(KfWebSocketMsgEnum.WEBSOCKET_MSG_WAIT_LIST)
                 .gameId(param.getGameId())
                 .waitUserList(waitUserList)
                 .build());
@@ -499,8 +503,14 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
     private void sendMessage(WebSocketSession session, KfWebSocketMsgDTO kfWebSocketMsgDTO) {
         try {
             session.sendMessage(new TextMessage(JsonUtil.toString(kfWebSocketMsgDTO)));
-            log.error("发送消息给客服 kfUserId : {}, msg : {}", SecurityUtil.getUserId(), JsonUtil.toString(kfWebSocketMsgDTO));
         } catch (IOException ignored) {
         }
     }
+
+    /**
+     * 消息发送到redis广播
+     */
+    private void pushMessage(KfWebSocketMsgDTO kfWebSocketMsgDTO) {
+        redisTemplate.convertAndSend(RedisKeyConstant.KF_MSG_REDIS_LISTEN_TOPIC, JsonUtil.toString(kfWebSocketMsgDTO));
+    }
 }