Bladeren bron

token 冻结校验bug修复

chejianzheng 2 maanden geleden
bovenliggende
commit
c32c4b5b42

+ 21 - 4
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/UserGatewayImpl.java

@@ -4,6 +4,7 @@ package com.hfln.portal.infrastructure.gateway.impl;
 import cn.dev33.satoken.session.SaSession;
 import cn.dev33.satoken.stp.SaTokenInfo;
 import cn.dev33.satoken.stp.StpUtil;
+import cn.dev33.satoken.stp.parameter.SaLoginParameter;
 import cn.hfln.framework.extension.BizException;
 import cn.hfln.framework.redis.util.RedisUtil;
 import com.alibaba.fastjson2.JSON;
@@ -105,7 +106,11 @@ public class UserGatewayImpl implements UserGateway {
     @Autowired
     private OssFileService ossFileService;
 
-//    public static String WXX_CX_ACCESS_TOKEN = "";
+    @Value("${sa-token.wx.timeout}")
+    private long wxTimeout;
+
+    @Value("${sa-token.wx.active-timeout}")
+    private long wxActiveTimeout;
 
     @Autowired
     private WxOfficeAccountClient wxOfficeAccountClient;
@@ -193,7 +198,11 @@ public class UserGatewayImpl implements UserGateway {
             // 先清除之前登录信息
             StpUtil.logout(RedisCacheConstant.WX_USER_PRE + userInfo.getUserId(), DeviceType.WX.getCode());
 
-            StpUtil.login(RedisCacheConstant.WX_USER_PRE + userInfo.getUserId(), DeviceType.WX.getCode());
+            StpUtil.login(RedisCacheConstant.WX_USER_PRE + userInfo.getUserId(),
+                    SaLoginParameter.create()
+                    .setDeviceType(DeviceType.WX.getCode())
+                    .setTimeout(wxTimeout)
+                    .setActiveTimeout(wxActiveTimeout));
             // 这里可以考虑 在session 中插入信息
             // 同账户多设备 登录共享信息
             // 当前 token session 独享信息
@@ -290,7 +299,11 @@ public class UserGatewayImpl implements UserGateway {
         redisService.del(redisKey);
 
         // 登录
-        StpUtil.login(RedisCacheConstant.WX_USER_PRE + user.getUserId(), DeviceType.WX.getCode());
+        StpUtil.login(RedisCacheConstant.WX_USER_PRE + user.getUserId(),
+                SaLoginParameter.create()
+                        .setDeviceType(DeviceType.WX.getCode())
+                        .setTimeout(wxTimeout)
+                        .setActiveTimeout(wxActiveTimeout));
         SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
 
         // 构造返回对象
@@ -571,7 +584,11 @@ public class UserGatewayImpl implements UserGateway {
         }
 
         if (!StpUtil.isLogin()) {
-            StpUtil.login(RedisCacheConstant.WX_USER_PRE + userInfo.getUserId(), DeviceType.WX.getCode());
+            StpUtil.login(RedisCacheConstant.WX_USER_PRE + userInfo.getUserId(),
+                    SaLoginParameter.create()
+                            .setDeviceType(DeviceType.WX.getCode())
+                            .setTimeout(wxTimeout)
+                            .setActiveTimeout(wxActiveTimeout));
         }
     }
 

+ 1 - 13
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/gateway/impl/WebGatewayImpl.java

@@ -3,7 +3,6 @@ package com.hfln.portal.infrastructure.gateway.impl;
 import cn.dev33.satoken.session.SaSession;
 import cn.dev33.satoken.stp.SaTokenInfo;
 import cn.dev33.satoken.stp.StpUtil;
-import cn.dev33.satoken.stp.parameter.SaLoginParameter;
 import cn.hfln.framework.extension.BizException;
 import cn.hfln.framework.redis.util.RedisUtil;
 import com.alibaba.excel.EasyExcel;
@@ -37,7 +36,6 @@ import com.hfln.portal.infrastructure.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -80,12 +78,6 @@ public class WebGatewayImpl implements WebGateway {
 
     @Autowired
     private TblRoleMenuMapService tblRoleMenuMapService;
-
-    @Value("${sa-token.admin.timeout}")
-    private long adminTimeout;
-
-    @Value("${sa-token.admin.active-timeout}")
-    private long adminActiveTimeout;
     @Autowired
     private TblDicService tblDicService;
     @Autowired
@@ -189,11 +181,7 @@ public class WebGatewayImpl implements WebGateway {
         // 1 需要保证 userId 和 adminUserId 不能一样
         // 2 可以在 stputil.login 的 loginId 参数前加前缀 user_ or admin_
         // 3 添加 SptAdminUtil,不过在不同地方,需要注意对 stputil sptadminutil 的不同引用
-        StpUtil.login(RedisCacheConstant.WEB_USER_PRE + adminUser.getUserId(),
-                SaLoginParameter.create()
-                        .setDeviceType(DeviceType.WEB.getCode())
-                        .setTimeout(adminTimeout)
-                        .setActiveTimeout(adminActiveTimeout));
+        StpUtil.login(RedisCacheConstant.WEB_USER_PRE + adminUser.getUserId(), DeviceType.WEB.getCode());
 
         // 用户登录后,保存用户信息到 session
         SaSession saSession = StpUtil.getSession();

+ 17 - 17
portal-service-infrastructure/src/main/java/com/hfln/portal/infrastructure/mqtt/MqttSubHandle.java

@@ -162,24 +162,24 @@ public class MqttSubHandle {
             log.warn("Device not found for clientId: {}", clientId);
             return;
         }
-        if (!targetPointsStr.equals(dev.getTargetPoints())) {
-            //  存储跌倒事件
-            if (messageType == 3) {
-
-                event = obj.getString("event");
-                if (event.equals("fall_confirmed")) {
-                    EventList eventListVO = new EventList();
-                    eventListVO.setDevId(dev.getDevId());
-                    eventListVO.setPose(pose);
-                    eventListVO.setIsHandle(0);
-                    eventListVO.setTargetPoints(targetPointsStr);
-                    eventListVO.setEventType(messageType);
-                    eventService.save(eventListVO);
-                }
+        //  存储跌倒事件
+        if (messageType == 3) {
+
+            event = obj.getString("event");
+            if (event.equals("fall_confirmed")) {
+                EventList eventListVO = new EventList();
+                eventListVO.setDevId(dev.getDevId());
+                eventListVO.setPose(pose);
+                eventListVO.setIsHandle(0);
+                eventListVO.setTargetPoints(targetPointsStr);
+                eventListVO.setEventType(messageType);
+                eventService.save(eventListVO);
             }
-        } else {
-            log.info("此次targetPoints与上次相同!");
         }
+//        if (!targetPointsStr.equals(dev.getTargetPoints())) {
+//        } else {
+//            log.info("此次targetPoints与上次相同!");
+//        }
 
         //向前端发送数据
         JSONObject msg = new JSONObject();
@@ -330,13 +330,13 @@ public class MqttSubHandle {
 
     public void subDasRealtimePos(String topic, String payload) {
 
-        log.debug("Received device message: topic={}, payload={}", topic, payload);
         JSONObject obj = JSONObject.parseObject(payload);
         String clientId = obj.getString("dev_id");
         byte messageType = obj.getByteValue("message_type");
         byte pose = obj.getByteValue("pose");
         JSONArray targetPointArray = obj.getJSONArray("target_point");
         if (targetPointArray == null || targetPointArray.isEmpty()) {
+            log.info("Received device message: topic={}, payload={}", topic, payload);
             log.info("mqttsub target_point is Empty, do nothing");
             return;
         }

+ 6 - 6
portal-service-server/src/main/resources/bootstrap-dev.yml

@@ -83,21 +83,21 @@ sa-token:
   # token 名称(同时也是 cookie 名称)
   token-name: token
   # token 有效期(单位:秒) 默认30天,-1 代表永久有效
-  timeout: 2592000
+  timeout: 36000
   # token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
-  active-timeout: -1
+  active-timeout: 1800
   # 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
-  is-concurrent: true
+  is-concurrent: false
   # 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
   is-share: false
   # token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
   token-style: uuid
   # 是否输出操作日志
   is-log: true
-  admin:
-    timeout: 36000
-    active-timeout: 1800
   dynamic-active-timeout: true
+  wx:
+    timeout: 2592000
+    active-timeout: -1
 
 # mqtt相关
 mqtt:

+ 5 - 5
portal-service-server/src/main/resources/bootstrap-local.yml

@@ -83,9 +83,9 @@ sa-token:
   # token 名称(同时也是 cookie 名称)
   token-name: token
   # token 有效期(单位:秒) 默认30天,-1 代表永久有效
-  timeout: 2592000
+  timeout: 36000
   # token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
-  active-timeout: -1
+  active-timeout: 1800
   # 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
   is-concurrent: false
   # 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
@@ -95,9 +95,9 @@ sa-token:
   # 是否输出操作日志
   is-log: true
   dynamic-active-timeout: true
-  admin:
-    timeout: 36000
-    active-timeout: 1800
+  wx:
+    timeout: 2592000
+    active-timeout: -1
 
 # mqtt相关
 mqtt:

+ 20 - 0
portal-service-server/src/main/resources/bootstrap-prod.yml

@@ -57,3 +57,23 @@ lnxx:
 wechat:
   appid: wx1a783618d97d999d
   secret: db43538fbd86e946c9798fed18a91df1
+
+sa-token:
+  # token 名称(同时也是 cookie 名称)
+  token-name: token
+  # token 有效期(单位:秒) 默认30天,-1 代表永久有效
+  timeout: 36000
+  # token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
+  active-timeout: 1800
+  # 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
+  is-concurrent: false
+  # 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
+  is-share: false
+  # token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
+  token-style: uuid
+  # 是否输出操作日志
+  is-log: true
+  dynamic-active-timeout: true
+  wx:
+    timeout: 2592000
+    active-timeout: -1

+ 6 - 5
portal-service-server/src/main/resources/bootstrap-test.yml

@@ -83,9 +83,9 @@ sa-token:
   # token 名称(同时也是 cookie 名称)
   token-name: token
   # token 有效期(单位:秒) 默认30天,-1 代表永久有效
-  timeout: 2592000
+  timeout: 36000
   # token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
-  active-timeout: -1
+  active-timeout: 1800
   # 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
   is-concurrent: false
   # 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
@@ -94,9 +94,10 @@ sa-token:
   token-style: uuid
   # 是否输出操作日志
   is-log: true
-  admin:
-    timeout: 36000
-    active-timeout: 1800
+  dynamic-active-timeout: true
+  wx:
+    timeout: 2592000
+    active-timeout: -1
 
 # mqtt相关
 mqtt: