소스 검색

优化系统登录时间,超过一小时没有心跳的直接登出

hurugang 2 년 전
부모
커밋
611461da01

+ 3 - 3
src/main/java/cn/hnthyy/thmz/Utils/DateUtil.java

@@ -66,12 +66,12 @@ public class DateUtil {
     /**
      * 获取与当前时间相隔多少个小时数后的时间
      *
-     * @param time 间隔小时数
+     * @param hour 间隔小时数
      * @return
      */
-    public static Date getDate(int time) {
+    public static Date getDate(int hour) {
         Calendar calendar = Calendar.getInstance();
-        calendar.add(Calendar.HOUR, time);
+        calendar.add(Calendar.HOUR, hour);
         return calendar.getTime();
     }
 

+ 88 - 88
src/main/java/cn/hnthyy/thmz/common/Constants.java

@@ -7,16 +7,16 @@ public class Constants {
     /**
      * 默认密码的MD%值 实际值1
      */
-    public static final String DEFAULT_PASSWORD="xMpCOKC5I4INzFCab3WEmw==";
+    public static final String DEFAULT_PASSWORD = "xMpCOKC5I4INzFCab3WEmw==";
     /**
      * 默认用户id
      */
-    public static final Long DEFAULT_USER_ID=-1L;
+    public static final Long DEFAULT_USER_ID = -1L;
 
     /**
      * 默认用户名称
      */
-    public static final String DEFAULT_USER_NAME="泰和门诊系统";
+    public static final String DEFAULT_USER_NAME = "泰和门诊系统";
 
     /**
      * token id
@@ -29,7 +29,7 @@ public class Constants {
     /**
      * token最大有效时间 小时数
      */
-    public static final int JWT_TTL = 5;
+    public static final int JWT_TTL = 24;
     /**
      * 挂号时段的上午编码
      */
@@ -41,11 +41,11 @@ public class Constants {
     /**
      * 挂号时段的全天编码
      */
-    public static final String  DAY= "d";
+    public static final String DAY = "d";
     /**
      * 口服的用药方式
      */
-    public static final String KOU_FU_SUPPLY_CODE="001";
+    public static final String KOU_FU_SUPPLY_CODE = "001";
 //    /**
 //     * 本院记账收款方式
 //     */
@@ -54,187 +54,187 @@ public class Constants {
     /**
      * 挂号费
      */
-    public static final String GHF="001";
+    public static final String GHF = "001";
     /**
      * 床位费
      */
-    public static final String CWF="002";
+    public static final String CWF = "002";
     /**
      * 诊查费
      */
-    public static final String ZCF="003";
+    public static final String ZCF = "003";
     /**
      * 检查费
      */
-    public static final String JCF="004";
+    public static final String JCF = "004";
     /**
      * 治疗费
      */
-    public static final String ZLF="005";
+    public static final String ZLF = "005";
     /**
      * 护理费
      */
-    public static final String HLF="006";
+    public static final String HLF = "006";
     /**
      * 手术费
      */
-    public static final String SSF="007";
+    public static final String SSF = "007";
     /**
      * 化验费
      */
-    public static final String HYF="008";
+    public static final String HYF = "008";
     /**
      * 其他
      */
-    public static final String QTF="009";
+    public static final String QTF = "009";
     /**
      * 西药费
      */
-    public static final String XYF="010";
+    public static final String XYF = "010";
     /**
      * 中成药费
      */
-    public static final String ZCYF="011";
+    public static final String ZCYF = "011";
     /**
      * 中草药费
      */
-    public static final String CYF="012";
+    public static final String CYF = "012";
     /**
      * 特殊材料费
      */
-    public static final String TSCLF="013";
+    public static final String TSCLF = "013";
     /**
      * 输血费
      */
-    public static final String SXF="014";
+    public static final String SXF = "014";
     /**
      * 鉴定费
      */
-    public static final String JDF="015";
+    public static final String JDF = "015";
     /**
      * 消毒费
      */
-    public static final String XDF="016";
+    public static final String XDF = "016";
     /**
      * 手术器械使用费
      */
-    public static final String SSQXSSF="017";
+    public static final String SSQXSSF = "017";
     /**
      * 材料费
      */
-    public static final String CLF="018";
+    public static final String CLF = "018";
     /**
      * 麻醉费
      */
-    public static final String MZF="019";
+    public static final String MZF = "019";
     /**
      * 四舍五入
      */
-    public static final String SSWRF="020";
+    public static final String SSWRF = "020";
 
 
     /**
      * 套餐
      */
-    public static final String TC="TC";
+    public static final String TC = "TC";
 
 
     /**
      * 默认付款方式 现金
      */
-    public static final String CASH="1";
+    public static final String CASH = "1";
 
 
     /**
      * 本院记账付款方式
      */
-    public static final String BYJZ="Y";
+    public static final String BYJZ = "Y";
 
     /**
      * 本院记账付款方式名称
      */
-    public static final String BYJZ_NAME="本院记账";
+    public static final String BYJZ_NAME = "本院记账";
 
     /**
      * 自助微信缴费
      */
-    public static final String ZZWX="W";
+    public static final String ZZWX = "W";
 
     /**
      * 自助支付宝缴费
      */
-    public static final String ZZZFB="M";
+    public static final String ZZZFB = "M";
 
     /**
      * 微信缴费
      */
-    public static final String WX="E";
+    public static final String WX = "E";
 
     /**
      * 支付宝缴费
      */
-    public static final String ZFB="F";
+    public static final String ZFB = "F";
 
     /**
      * 医保记账缴费
      */
-    public static final String YBJZ="2";
+    public static final String YBJZ = "2";
 
     /**
      * 市医保卡缴费
      */
-    public static final String SSHIYBK="6";
+    public static final String SSHIYBK = "6";
 
     /**
      * 省医保卡缴费
      */
-    public static final String SHENYBK="7";
+    public static final String SHENYBK = "7";
 
     /**
      * 市医保卡个账
      */
-    public static final String SSHIYBGZ="T";
+    public static final String SSHIYBGZ = "T";
 
     /**
      * 省医保卡个账
      */
-    public static final String SHENYGZ="P";
+    public static final String SHENYGZ = "P";
 
     /**
      * 医技分组编号
      */
-    public static final String YJ_GROUP_NO="00";
+    public static final String YJ_GROUP_NO = "00";
 
     /**
      * 静脉采血编码
      */
-    public static final String JM_CAI_XUE_CODE="008910";
+    public static final String JM_CAI_XUE_CODE = "008910";
 
     /**
      * 静脉采血名称
      */
-    public static final String JM_CAI_XUE_NAME="静脉采血";
+    public static final String JM_CAI_XUE_NAME = "静脉采血";
 
     /**
      * 病人自助缴费编码
      */
-    public static final String BRZZJF_CODE="99999";
+    public static final String BRZZJF_CODE = "99999";
 
     /**
      * 全院账号编码
      */
-    public static final String QYZH_CODE="00000";
+    public static final String QYZH_CODE = "00000";
 
     /**
      * 病人自助缴费编码
      */
-    public static final String BRZZJF_NAME="自助缴费";
+    public static final String BRZZJF_NAME = "自助缴费";
 
 
     /**
      * 单病种收费员编码
      */
-    public static final String DBZJF_CODE="99998";
+    public static final String DBZJF_CODE = "99998";
 
     /**
      * 核酸检测混检收费员编码  (因为核酸混检是在每个人的时候收费,然后再集中一次去进行医技申请,
@@ -242,103 +242,103 @@ public class Constants {
      * 改变了处方状态吗,又不进行日结,就不会影响报表)
      * 在患者缴费的时候,收费员是自助或者实际收费员,但是在需要开申请单的时候,是混检收费员
      */
-    public static final String HSJCHJSFY_CODE="99997";
+    public static final String HSJCHJSFY_CODE = "99997";
 
     /**
      * 互联网医院收费员编码
      */
-    public static final String HLWYY_CODE="99996";
+    public static final String HLWYY_CODE = "99996";
 
     /**
      * 单病种收费员编码
      */
-    public static final String DBZJF_NAME="单病种收费员";
+    public static final String DBZJF_NAME = "单病种收费员";
 
     /**
      * 120卡号
      */
-    public static final String JZ_IC_CARD="120";
+    public static final String JZ_IC_CARD = "120";
 
 
     /**
      * 西药和中成药的药品组
      */
-    public static final String XY_ZCY_GROUP_NO="71";
+    public static final String XY_ZCY_GROUP_NO = "71";
 
     /**
      * 中草药药的药品组
      */
-    public static final String ZY_GROUP_NO="81";
+    public static final String ZY_GROUP_NO = "81";
 
     /**
      * 颗粒剂中药药品组
      */
-    public static final String GRANULA_GROUP_NO="82";
+    public static final String GRANULA_GROUP_NO = "82";
 
     /**
      * 医材的药品组
      */
-    public static final String YC_GROUP_NO="91";
+    public static final String YC_GROUP_NO = "91";
 
     /**
      * 颗粒剂类型
      */
-    public static final String GRANULA_DRUG_KIND="0007";
+    public static final String GRANULA_DRUG_KIND = "0007";
 
     /**
      * 西药和中成药的执行科室 门诊西药房
      */
-    public static final String XY_ZCY_EXEC_CODE="2060400";
+    public static final String XY_ZCY_EXEC_CODE = "2060400";
 
     /**
      * 中草药药的执行科室 门诊中药房
      */
-    public static final String ZY_EXEC_CODE="2060500";
+    public static final String ZY_EXEC_CODE = "2060500";
 
     /**
      * 中草药药的执行科室 门诊颗粒剂药房
      */
-    public static final String GRANULA_EXEC_CODE="2060501";
+    public static final String GRANULA_EXEC_CODE = "2060501";
 
     /**
      * 急诊科编码
      */
-    public static final String EMERGENCY_WARD_CODE="1070000";
+    public static final String EMERGENCY_WARD_CODE = "1070000";
 
     /**
      * 医学检验科编码
      */
-    public static final String MEDICAL_LABORATORY_CODE="2010000";
+    public static final String MEDICAL_LABORATORY_CODE = "2010000";
     /**
      * 超声影像科编码
      */
-    public static final String CSYXK_CODE="2020300";
+    public static final String CSYXK_CODE = "2020300";
     /**
      * 放射科编码
      */
-    public static final String FSK_CODE="2020100";
+    public static final String FSK_CODE = "2020100";
     /**
      * 医材药房
      */
-    public static final String YC_EXEC_CODE="2060999";
+    public static final String YC_EXEC_CODE = "2060999";
     /**
      * 简易门诊编码
      */
-    public static final String JY_EXEC_CODE="3110000";
+    public static final String JY_EXEC_CODE = "3110000";
     /**
      * 四舍五入 收费编码
      */
-    public static final String SSWR_CHARGE_ITEM_CODE="BILL99";
+    public static final String SSWR_CHARGE_ITEM_CODE = "BILL99";
 
     /**
      * 四舍五入 收费类型码
      */
-    public static final String SSWR_BILL_ITEM_CODE="BILL20";
+    public static final String SSWR_BILL_ITEM_CODE = "BILL20";
 
     /**
      * 收费类型编码前缀
      */
-    public static final String  BILL_ITEM_CODE_prev= "BILL";
+    public static final String BILL_ITEM_CODE_prev = "BILL";
 
 //    /**
 //     * 收费窗口号KEY
@@ -349,105 +349,105 @@ public class Constants {
     /**
      * 触发号表告警的最小号数配置的key
      */
-    public static final String  ALARM_NUM_KEY= "alarm_num";
+    public static final String ALARM_NUM_KEY = "alarm_num";
     /**
      * 号表告警的人员配置的key
      */
-    public static final String  ALARM_USER_KEY= "alarm_user";
+    public static final String ALARM_USER_KEY = "alarm_user";
     /**
      * 缴费成功的提示信息
      */
-    public static final String  MESSAGE_TO_PHONE= "message_to_phone";
+    public static final String MESSAGE_TO_PHONE = "message_to_phone";
     /**
      * 核酸混采时间配置的key
      */
-    public static final String  HYBIRD_TIME_KEY= "hybird_time";
+    public static final String HYBIRD_TIME_KEY = "hybird_time";
 
     /**
      * 医生的人员类型
      */
-    public static final Integer  DOCTOR_TIT_GRADE= 1;
+    public static final Integer DOCTOR_TIT_GRADE = 1;
 
     /**
      * 驾驶员体检中心编码
      */
-    public static final String JSYTJJX="1500010";
+    public static final String JSYTJJX = "1500010";
 
     /**
      * 财务部编码
      */
-    public static final String CWBBM="3060000";
+    public static final String CWBBM = "3060000";
 
     /**
      * 自助部编码
      */
-    public static final String ZZBM="1400004";
+    public static final String ZZBM = "1400004";
     /**
      * 核酸检测(单人单管)项目编码
      */
-    public static final String NUCLEIC_ORDER_CODE ="003585";
+    public static final String NUCLEIC_ORDER_CODE = "003585";
 
     /**
      * 核酸检测项目(混检)编码
      */
-    public static final String HYBRID_TEST_ORDER_CODE ="003680";
+    public static final String HYBRID_TEST_ORDER_CODE = "003680";
 
     /**
      * 核酸检测收费项目(混检)编码
      */
-    public static final String HYBRID_TEST_CHARGE_CODE ="019103";
+    public static final String HYBRID_TEST_CHARGE_CODE = "019103";
 
     /**
      * 核酸检测项目的检验物
      */
-    public static final String NUCLEIC_INSPECT_STUFF ="0027";
+    public static final String NUCLEIC_INSPECT_STUFF = "0027";
 
     /**
      * 皮试给药方式
      */
-    public static final String SUPPLY_TYPE_PS="007";
+    public static final String SUPPLY_TYPE_PS = "007";
 
 
     /**
      * 住院DR核算码
      */
-    public static final String AUDIT_ITEM_DR="02";
+    public static final String AUDIT_ITEM_DR = "02";
 
     /**
      * 门诊DR核算码
      */
-    public static final String MZ_AUDIT_ITEM_DR="07";
+    public static final String MZ_AUDIT_ITEM_DR = "07";
 
     /**
      * 检查的分类码
      */
-    public static final String JC_CLASS_CODE="D";
+    public static final String JC_CLASS_CODE = "D";
 
 
     /**
      * 重新匹配合同
      */
-    public static final String CONTRACT_RE_MATCH="contract_re_match";
+    public static final String CONTRACT_RE_MATCH = "contract_re_match";
 
 
     /**
      * 简易门诊编码
      */
-    public static final String SIMPLE_OUTPATIENT_CODE="10";
+    public static final String SIMPLE_OUTPATIENT_CODE = "10";
 
     /**
      * 免挂号编码
      */
-    public static final String FREE_TO_REGISTER_CODE="16";
+    public static final String FREE_TO_REGISTER_CODE = "16";
 
     /**
      * 自费病人身份
      */
-    public static final String SELF_PAYING_RESPONCE_TYPE="01";
+    public static final String SELF_PAYING_RESPONCE_TYPE = "01";
     /**
      * 急诊号别分类码
      */
-    public static final String JZ_CODE="03";
+    public static final String JZ_CODE = "03";
 
 
 }

+ 34 - 17
src/main/java/cn/hnthyy/thmz/socket/EvaluationWebSocket.java

@@ -14,6 +14,7 @@ import javax.websocket.OnOpen;
 import javax.websocket.Session;
 import javax.websocket.server.PathParam;
 import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -98,13 +99,14 @@ public class EvaluationWebSocket {
     @OnMessage
     public void onMessage(String message) {
         log.debug("[WebSocket] 收到消息:{}", message);
-        //判断是否需要指定发送,具体规则自定义
-        if (message.indexOf("TOUSER") == 0) {
-            String name = message.substring(message.indexOf("TOUSER") + 6, message.indexOf(";"));
-            appointSending(name, message.substring(message.indexOf(";") + 1, message.length()));
-        } else {
-            groupSending(message);
-        }
+        appointSending(this.clientIp, message);
+//        //判断是否需要指定发送,具体规则自定义
+//        if (message.indexOf("TOUSER") == 0) {
+//            String name = message.substring(message.indexOf("TOUSER") + 6, message.indexOf(";"));
+//            appointSending(name, message.substring(message.indexOf(";") + 1, message.length()));
+//        } else {
+//            groupSending(message);
+//        }
 
     }
 
@@ -116,7 +118,7 @@ public class EvaluationWebSocket {
     public void groupSending(String message) {
         for (String name : webSocketSet.keySet()) {
             try {
-                lastSendMessageDate.put(name,new Date());
+                lastSendMessageDate.put(name, new Date());
                 webSocketSet.get(name).session.getBasicRemote().sendText(message);
             } catch (Exception e) {
                 //e.printStackTrace();
@@ -135,7 +137,7 @@ public class EvaluationWebSocket {
         try {
             Session session = webSocketSet.get(clientIp).session;
             synchronized (session) {
-                lastSendMessageDate.put(clientIp,new Date());
+                lastSendMessageDate.put(clientIp, new Date());
                 session.getBasicRemote().sendText(message);
             }
         } catch (Exception e) {
@@ -156,11 +158,12 @@ public class EvaluationWebSocket {
 
     /**
      * 评价器客户端登录
+     *
      * @param clientIp
      * @param tokenUser
      */
-    public void login(String clientIp,User tokenUser) {
-        userMap.put(clientIp,tokenUser);
+    public void login(String clientIp, User tokenUser) {
+        userMap.put(clientIp, tokenUser);
         if (isLogin(clientIp)) {
             return;
         }
@@ -173,6 +176,7 @@ public class EvaluationWebSocket {
 
     /**
      * 评价器登出
+     *
      * @param clientIpAddress
      */
     public void loginOut(String clientIpAddress) {
@@ -183,14 +187,26 @@ public class EvaluationWebSocket {
         userMap.remove(clientIpAddress);
         welcomeSet.remove(clientIpAddress);
         lastSendMessageDate.remove(clientIpAddress);
+        EvaluationWebSocket evaluationWebSocket = webSocketSet.get(clientIpAddress);
+        try {
+            if (evaluationWebSocket != null) {
+                evaluationWebSocket.session.close();
+                webSocketSet.remove(clientIpAddress);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            webSocketSet.remove(clientIpAddress);
+            log.error("关闭连接失败");
+        }
     }
 
     /**
      * 获取当前评价器登录的用户信息
+     *
      * @param requestIp
      * @return
      */
-    public User getUser(String requestIp){
+    public User getUser(String requestIp) {
         return userMap.get(requestIp);
     }
 //    /**
@@ -207,17 +223,18 @@ public class EvaluationWebSocket {
     /**
      * 每分钟检查一次客户端是否有超过4分钟没有消息推送,如果没有消息推送就关闭客户端
      */
-    @Scheduled(cron="0 0/1 * * * ?")
+    @Scheduled(cron = "0 0/1 * * * ?")
     private void closeClientSession() {
         Date now = new Date();
-        for (String clientIp:lastSendMessageDate.keySet()) {
-            if(StringUtils.isBlank(clientIp)){
+        for (String clientIp : lastSendMessageDate.keySet()) {
+            if (StringUtils.isBlank(clientIp)) {
                 continue;
             }
             Date lastDate = lastSendMessageDate.get(clientIp);
-            Long intervalMinutes =DateUtil.getIntervalMinutes(lastDate,now);
-            if(intervalMinutes>=4L){
+            Long intervalMinutes = DateUtil.getIntervalMinutes(lastDate, now);
+            if (intervalMinutes >= 4L) {
                 loginOut(clientIp);
+
             }
         }
     }

+ 65 - 11
src/main/java/cn/hnthyy/thmz/socket/NoticeWebSocket.java

@@ -1,9 +1,12 @@
 package cn.hnthyy.thmz.socket;
 
+import cn.hnthyy.thmz.Utils.DateUtil;
 import cn.hnthyy.thmz.Utils.SpringBeanUtils;
 import cn.hnthyy.thmz.service.thmz.NoticeSinkService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.json.JSONObject;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.websocket.OnClose;
@@ -12,6 +15,8 @@ import javax.websocket.OnOpen;
 import javax.websocket.Session;
 import javax.websocket.server.PathParam;
 import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
+import java.util.Date;
 import java.util.concurrent.ConcurrentHashMap;
 
 
@@ -44,13 +49,30 @@ public class NoticeWebSocket {
      * 用于存所有的连接服务的客户端,这个对象存储是安全的
      */
     private static ConcurrentHashMap<String, NoticeWebSocket> webSocketSet = new ConcurrentHashMap<>();
+    /**
+     * 用于存所有的连接最后一次发送消息的时间
+     */
+    private static ConcurrentHashMap<String, Date> lastSendMessageDate = new ConcurrentHashMap<>();
+
 
     @OnOpen
     public void onOpen(Session session, @PathParam(value = "userIdCode") String userIdCode) {
         this.session = session;
         this.userIdCode = userIdCode;
+
         // userIdCode是用来表示唯一客户端,如果需要指定发送,需要指定发送通过clientIp来区分
         webSocketSet.put(userIdCode, this);
+        Date lastDate = lastSendMessageDate.get(userIdCode);
+        if (lastDate != null) {
+            //超过一小时没有心跳,说明浏览器关闭一个小时,这个时候强制登录
+            Date now = new Date();
+            Long intervalMinutes = DateUtil.getIntervalMinutes(lastDate, now);
+            if (intervalMinutes >= 60L) {
+                lastSendMessageDate.remove(userIdCode);
+                appointSending(userIdCode, "loginOut");
+                return;
+            }
+        }
         if (noticeSinkService == null) {
             //这里通过spring 上下文来获取我想要的对象
             noticeSinkService = SpringBeanUtils.getBean(NoticeSinkService.class);
@@ -69,13 +91,15 @@ public class NoticeWebSocket {
     @OnMessage
     public void onMessage(String message) {
         log.debug("[WebSocket] 收到消息:{}", message);
-        //判断是否需要指定发送,具体规则自定义
-        if (message.indexOf("TOUSER") == 0) {
-            String name = message.substring(message.indexOf("TOUSER") + 6, message.indexOf(";"));
-            appointSending(name, message.substring(message.indexOf(";") + 1, message.length()));
-        } else {
-            groupSending(message);
-        }
+        lastSendMessageDate.put(this.userIdCode, new Date());
+        appointSending(this.userIdCode, message);
+//        //判断是否需要指定发送,具体规则自定义
+//        if (message.indexOf("TOUSER") == 0) {
+//            String name = message.substring(message.indexOf("TOUSER") + 6, message.indexOf(";"));
+//            appointSending(name, message.substring(message.indexOf(";") + 1, message.length()));
+//        } else {
+//            groupSending(message);
+//        }
 
     }
 
@@ -85,9 +109,9 @@ public class NoticeWebSocket {
      * @param message
      */
     public void groupSending(String message) {
-        for (String name : webSocketSet.keySet()) {
+        for (String userIdCode : webSocketSet.keySet()) {
             try {
-                webSocketSet.get(name).session.getBasicRemote().sendText(message);
+                webSocketSet.get(userIdCode).session.getBasicRemote().sendText(message);
             } catch (Exception e) {
                 //e.printStackTrace();
                 log.info("通道关闭,消息推送失败");
@@ -115,11 +139,41 @@ public class NoticeWebSocket {
 
     /**
      * 判断当前连接是否是开启的
+     *
      * @param userIdCode
      * @return
      */
-    public boolean isOpen(String userIdCode){
+    public boolean isOpen(String userIdCode) {
         NoticeWebSocket noticeWebSocket = webSocketSet.get(userIdCode);
-        return noticeWebSocket!=null;
+        return noticeWebSocket != null;
+    }
+
+
+    /**
+     * 每分钟检查一次客户端是否有超过4分钟没有消息推送,如果没有消息推送就关闭客户端
+     */
+    @Scheduled(cron = "0 0/1 * * * ?")
+    private void closeClientSession() {
+        Date now = new Date();
+        for (String userIdCode : lastSendMessageDate.keySet()) {
+            if (StringUtils.isBlank(userIdCode)) {
+                continue;
+            }
+            Date lastDate = lastSendMessageDate.get(userIdCode);
+            Long intervalMinutes = DateUtil.getIntervalMinutes(lastDate, now);
+            if (intervalMinutes >= 4L) {
+                NoticeWebSocket noticeWebSocket = webSocketSet.get(userIdCode);
+                try {
+                    if (noticeWebSocket != null) {
+                        noticeWebSocket.session.close();
+                        webSocketSet.remove(userIdCode);
+                    }
+                } catch (IOException e) {
+                    e.printStackTrace();
+                    webSocketSet.remove(userIdCode);
+                    log.error("关闭连接失败");
+                }
+            }
+        }
     }
 }

+ 4 - 0
src/main/resources/static/js/common/notice-websocket.js

@@ -74,6 +74,10 @@ function initEventHandle() {
         heartCheck.reset().start();
         if (event.data == "HeartBeat") {
             //忽略心跳的信息,因为只要有消息进来,断线重连就会重置不会触发
+        } else  if (event.data == "loginOut") {
+            //超过一小时没有发送消息,系统默认登出
+            localStorage.removeItem("token");
+            window.location.href = '/thmz/login/view';
         } else {
             var data = JSON.parse(event.data);
             fitNoticeList(data);

+ 2 - 1
src/main/resources/static/js/menu.js

@@ -148,6 +148,7 @@ function loginOut() {
         headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
         success: function (result) {
             if (result == '401' || result == 401 || result.code == 0) {
+                localStorage.removeItem("token");
                 window.location.href = '/thmz/login/view'
                 return;
             }
@@ -586,4 +587,4 @@ function getAge(mzPatientMi) {
         age = age + "岁";
     }
     return age;
-}
+}