diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/JwtUtils.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/JwtUtils.java index a7c00df..c9e317a 100644 --- a/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/JwtUtils.java +++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/JwtUtils.java @@ -80,7 +80,7 @@ public class JwtUtils { public Long getUidOrNull(String token) { return Optional.ofNullable(verifyToken(token)) .map(map -> map.get(UID_CLAIM)) - .map(Claim::asLong) + .map(Claim::asLong) .orElse(null); } diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/RedisUtils.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/RedisUtils.java index 5d1ce11..512c3c8 100644 --- a/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/RedisUtils.java +++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/utils/RedisUtils.java @@ -45,7 +45,7 @@ public class RedisUtils { public static Long inc(String key, int time, TimeUnit unit) { RedisScript redisScript = new DefaultRedisScript<>(LUA_INCR_EXPIRE, Long.class); - return stringRedisTemplate.execute(redisScript, Collections.singletonList(key), unit.toSeconds(time)); + return stringRedisTemplate.execute(redisScript, Collections.singletonList(key), String.valueOf(unit.toSeconds(time))); } /** diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java index 68b8f60..5e61c01 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java @@ -61,15 +61,16 @@ public class ChatController { @PostMapping("/msg") @ApiOperation("发送消息") - @FrequencyControl(time = 5,count = 2) - @FrequencyControl(time = 30,count = 5) - @FrequencyControl(time = 60,count = 10) + @FrequencyControl(time = 5,count = 2,target = FrequencyControl.Target.UID) + @FrequencyControl(time = 30,count = 5,target = FrequencyControl.Target.UID) + @FrequencyControl(time = 60,count = 10,target = FrequencyControl.Target.UID) public ApiResult sendMsg(@Valid @RequestBody ChatMessageReq request) { return ApiResult.success(IdRespVO.id(chatService.sendMsg(request, RequestHolder.get().getUid()))); } @PutMapping("/msg/mark") @ApiOperation("消息标记") + @FrequencyControl(time = 20,count = 3,target = FrequencyControl.Target.UID) public ApiResult setMsgMark(@Valid @RequestBody ChatMessageMarkReq request) {//分布式锁 chatService.setMsgMark(RequestHolder.get().getUid(),request); return ApiResult.success(); diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/LoginServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/LoginServiceImpl.java index 5182533..f995672 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/LoginServiceImpl.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/LoginServiceImpl.java @@ -77,6 +77,6 @@ public class LoginServiceImpl implements LoginService { @Override public Long getValidUid(String token) { - return verify(token) ? jwtUtils.getUidOrNull(token) : null; + return jwtUtils.getUidOrNull(token); } } diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/WebSocketServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/WebSocketServiceImpl.java index b1dbf49..f5a2e4f 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/WebSocketServiceImpl.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/WebSocketServiceImpl.java @@ -51,6 +51,9 @@ public class WebSocketServiceImpl implements WebSocketService { * 所有已连接的websocket连接列表和一些额外参数 */ private static final ConcurrentHashMap ONLINE_WS_MAP = new ConcurrentHashMap<>(); + public static ConcurrentHashMap getOnlineMap(){ + return ONLINE_WS_MAP; + } public static final int EXPIRE_SECONDS = 60 * 60; @Autowired diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/websocket/NettyWebSocketServer.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/websocket/NettyWebSocketServer.java index eda6742..41e3d68 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/websocket/NettyWebSocketServer.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/websocket/NettyWebSocketServer.java @@ -46,11 +46,11 @@ public class NettyWebSocketServer { * 销毁 */ @PreDestroy - public void destroy() throws InterruptedException { + public void destroy() { Future future = bossGroup.shutdownGracefully(); Future future1 = workerGroup.shutdownGracefully(); - future.sync(); - future1.sync(); + future.syncUninterruptibly(); + future1.syncUninterruptibly(); log.info("关闭 ws server 成功"); }