jingyuanchao il y a 10 mois
Parent
commit
080ce63f64

+ 17 - 6
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/north/controller/HostController.java

@@ -15,9 +15,11 @@ import com.xunmei.system.api.Eto.SubSystemControlEto;
 import com.xunmei.system.api.util.LogUtils;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.socket.WebSocketSession;
 
 import javax.annotation.Resource;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
@@ -53,6 +55,7 @@ public class HostController {
         websocketService.getDevices();
         return AjaxResult.success();
     }
+
     @ApiOperation("布撤防控制")
     @PostMapping({"/subSystemControl"})
     public AjaxResult subSystemControl(@RequestBody SubSystemControlEto eto) {
@@ -78,10 +81,9 @@ public class HostController {
     }*/
 
 
-
     @ApiOperation("关闭iot链接")
     @GetMapping({"/closeSession"})
-    public AjaxResult closeSession(String iotCode){
+    public AjaxResult closeSession(String iotCode) {
         //集群环境下 此功能不稳地,暂时取消
         //WebSocketSessionHolder.closeServe(iotCode);
         return AjaxResult.success();
@@ -144,14 +146,23 @@ public class HostController {
     }
 
     @GetMapping("/deletedRetryMsg/{date}")
-    AjaxResult deletedRetryMsg(@PathVariable("date") String date){
+    AjaxResult deletedRetryMsg(@PathVariable("date") String date) {
         websocketMsgService.deletedRetryMsg(date);
         return AjaxResult.success();
     }
 
     @GetMapping("/hostInfo")
-    AjaxResult hostInfo(){
-        final Set<String> sessionsAll = WebSocketSessionHolder.getSessionsAll();
-        return AjaxResult.success(sessionsAll);
+    AjaxResult hostInfo() {
+        Set<String> set = WebSocketSessionHolder.getSessionsAll();
+        List<String> list = new ArrayList<>();
+        for (String token : set) {
+            WebSocketSession sessions = WebSocketSessionHolder.getSessions(token);
+            if (sessions != null && sessions.isOpen()) {
+                list.add(token);
+            } else {
+                WebSocketSessionHolder.removeSession(token);
+            }
+        }
+        return AjaxResult.success(list);
     }
 }

+ 4 - 1
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/websocket/handler/SocWebSocketHandler.java

@@ -292,9 +292,12 @@ public class SocWebSocketHandler extends AbstractWebSocketHandler {
         if (StringUtils.isNotEmpty(token)) {
             IotServerInfo serverInfo = iotServerInfoService.selectByToken(token);
             serverInfo.setIotStatus(IotServerConnectStatus.OFFLINE.getIdx());
+            serverInfo.setUpdateTime(LocalDateTime.now());
             iotServerInfoService.updateByToken(serverInfo);
+            LogUtils.WEBSOCKET_MSG.warn("服务 {},状态:{}, 断开链接,{}", serverInfo.getIotName(), status, status.getReason());
+
         }
-        LogUtils.WEBSOCKET_MSG.info("[断开连接],ip:{}", WebSocketUtils.getIp(session));
+        LogUtils.WEBSOCKET_MSG.info("[断开连接],ip:{},{}", WebSocketUtils.getIp(session), status.getReason());
     }
 
     /**