mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-21 19:43:46 +08:00
代码优化
This commit is contained in:
@@ -80,7 +80,7 @@ public class JwtUtils {
|
|||||||
public Long getUidOrNull(String token) {
|
public Long getUidOrNull(String token) {
|
||||||
return Optional.ofNullable(verifyToken(token))
|
return Optional.ofNullable(verifyToken(token))
|
||||||
.map(map -> map.get(UID_CLAIM))
|
.map(map -> map.get(UID_CLAIM))
|
||||||
.map(Claim::asLong)
|
.map(Claim::asLong)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class RedisUtils {
|
|||||||
|
|
||||||
public static Long inc(String key, int time, TimeUnit unit) {
|
public static Long inc(String key, int time, TimeUnit unit) {
|
||||||
RedisScript<Long> redisScript = new DefaultRedisScript<>(LUA_INCR_EXPIRE, Long.class);
|
RedisScript<Long> 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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,15 +61,16 @@ public class ChatController {
|
|||||||
|
|
||||||
@PostMapping("/msg")
|
@PostMapping("/msg")
|
||||||
@ApiOperation("发送消息")
|
@ApiOperation("发送消息")
|
||||||
@FrequencyControl(time = 5,count = 2)
|
@FrequencyControl(time = 5,count = 2,target = FrequencyControl.Target.UID)
|
||||||
@FrequencyControl(time = 30,count = 5)
|
@FrequencyControl(time = 30,count = 5,target = FrequencyControl.Target.UID)
|
||||||
@FrequencyControl(time = 60,count = 10)
|
@FrequencyControl(time = 60,count = 10,target = FrequencyControl.Target.UID)
|
||||||
public ApiResult<IdRespVO> sendMsg(@Valid @RequestBody ChatMessageReq request) {
|
public ApiResult<IdRespVO> sendMsg(@Valid @RequestBody ChatMessageReq request) {
|
||||||
return ApiResult.success(IdRespVO.id(chatService.sendMsg(request, RequestHolder.get().getUid())));
|
return ApiResult.success(IdRespVO.id(chatService.sendMsg(request, RequestHolder.get().getUid())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/msg/mark")
|
@PutMapping("/msg/mark")
|
||||||
@ApiOperation("消息标记")
|
@ApiOperation("消息标记")
|
||||||
|
@FrequencyControl(time = 20,count = 3,target = FrequencyControl.Target.UID)
|
||||||
public ApiResult<Void> setMsgMark(@Valid @RequestBody ChatMessageMarkReq request) {//分布式锁
|
public ApiResult<Void> setMsgMark(@Valid @RequestBody ChatMessageMarkReq request) {//分布式锁
|
||||||
chatService.setMsgMark(RequestHolder.get().getUid(),request);
|
chatService.setMsgMark(RequestHolder.get().getUid(),request);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
|
|||||||
@@ -77,6 +77,6 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getValidUid(String token) {
|
public Long getValidUid(String token) {
|
||||||
return verify(token) ? jwtUtils.getUidOrNull(token) : null;
|
return jwtUtils.getUidOrNull(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ public class WebSocketServiceImpl implements WebSocketService {
|
|||||||
* 所有已连接的websocket连接列表和一些额外参数
|
* 所有已连接的websocket连接列表和一些额外参数
|
||||||
*/
|
*/
|
||||||
private static final ConcurrentHashMap<Channel, WSChannelExtraDTO> ONLINE_WS_MAP = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<Channel, WSChannelExtraDTO> ONLINE_WS_MAP = new ConcurrentHashMap<>();
|
||||||
|
public static ConcurrentHashMap<Channel, WSChannelExtraDTO> getOnlineMap(){
|
||||||
|
return ONLINE_WS_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
public static final int EXPIRE_SECONDS = 60 * 60;
|
public static final int EXPIRE_SECONDS = 60 * 60;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -46,11 +46,11 @@ public class NettyWebSocketServer {
|
|||||||
* 销毁
|
* 销毁
|
||||||
*/
|
*/
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void destroy() throws InterruptedException {
|
public void destroy() {
|
||||||
Future<?> future = bossGroup.shutdownGracefully();
|
Future<?> future = bossGroup.shutdownGracefully();
|
||||||
Future<?> future1 = workerGroup.shutdownGracefully();
|
Future<?> future1 = workerGroup.shutdownGracefully();
|
||||||
future.sync();
|
future.syncUninterruptibly();
|
||||||
future1.sync();
|
future1.syncUninterruptibly();
|
||||||
log.info("关闭 ws server 成功");
|
log.info("关闭 ws server 成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user