mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
fix:前后端交互优化
This commit is contained in:
@@ -15,6 +15,7 @@ import com.abin.mallchat.custom.user.service.impl.UserServiceImpl;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -22,6 +23,7 @@ import javax.validation.Valid;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -57,6 +59,20 @@ public class ChatController {
|
||||
return ApiResult.success(memberPage);
|
||||
}
|
||||
|
||||
@GetMapping("/public/member/page/v1")
|
||||
@ApiOperation("群成员列表/v1")
|
||||
@FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
||||
public ApiResult<CursorPageBaseResp<ChatMemberRespV1>> getMemberPage1(@Valid CursorPageBaseReq request) {
|
||||
CursorPageBaseResp<ChatMemberResp> memberPage = chatService.getMemberPage(request);
|
||||
filterBlackMember(memberPage);
|
||||
List<ChatMemberRespV1> collect = memberPage.getList().stream().map(a -> {
|
||||
ChatMemberRespV1 v1 = new ChatMemberRespV1();
|
||||
BeanUtils.copyProperties(a, v1);
|
||||
return v1;
|
||||
}).collect(Collectors.toList());
|
||||
return ApiResult.success(CursorPageBaseResp.init(memberPage, collect));
|
||||
}
|
||||
|
||||
@GetMapping("/member/list")
|
||||
@ApiOperation("房间内的所有群成员列表-@专用")
|
||||
public ApiResult<List<ChatMemberListResp>> getMemberList(@Valid ChatMessageMemberReq chatMessageMemberReq) {
|
||||
@@ -81,25 +97,30 @@ public class ChatController {
|
||||
@Autowired
|
||||
private UserServiceImpl userService;
|
||||
|
||||
@GetMapping("/public/msg/page/v1")
|
||||
@ApiOperation("消息列表/v1")
|
||||
@FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
||||
public ApiResult<CursorPageBaseResp<ChatMessageRespV1>> getMsgPage(@Valid ChatMessagePageReq request) {
|
||||
CursorPageBaseResp<ChatMessageResp> msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
|
||||
filterBlackMsg(msgPage);
|
||||
List<ChatMessageRespV1> collect = msgPage.getList().stream().map(a -> {
|
||||
ChatMessageRespV1 v1 = new ChatMessageRespV1();
|
||||
BeanUtils.copyProperties(a, v1);
|
||||
return v1;
|
||||
}).collect(Collectors.toList());
|
||||
return ApiResult.success(CursorPageBaseResp.init(msgPage, collect));
|
||||
}
|
||||
|
||||
@GetMapping("/public/msg/page")
|
||||
@ApiOperation("消息列表")
|
||||
@FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
||||
public ApiResult<CursorPageBaseResp<ChatMessageResp>> getMsgPage(@Valid ChatMessagePageReq request) {
|
||||
public ApiResult<CursorPageBaseResp<ChatMessageResp>> getMsgPage1(@Valid ChatMessagePageReq request) {
|
||||
// black(request);
|
||||
CursorPageBaseResp<ChatMessageResp> msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
|
||||
filterBlackMsg(msgPage);
|
||||
return ApiResult.success(msgPage);
|
||||
}
|
||||
|
||||
private void black(CursorPageBaseReq baseReq) {
|
||||
if (baseReq.getPageSize() > 50) {
|
||||
log.info("limit request:{}", baseReq);
|
||||
baseReq.setPageSize(10);
|
||||
userService.blackIp(RequestHolder.get().getIp());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void filterBlackMsg(CursorPageBaseResp<ChatMessageResp> memberPage) {
|
||||
Set<String> blackMembers = getBlackUidSet();
|
||||
memberPage.getList().removeIf(a -> blackMembers.contains(a.getFromUser().getUid().toString()));
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.abin.mallchat.custom.chat.domain.vo.response;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Description: 群成员列表的成员信息
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-03-23
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChatMemberRespV1 {
|
||||
@ApiModelProperty("uid")
|
||||
private Long uid;
|
||||
/**
|
||||
* @see com.abin.mallchat.common.user.domain.enums.ChatActiveStatusEnum
|
||||
*/
|
||||
@ApiModelProperty("在线状态 1在线 2离线")
|
||||
private Integer activeStatus;
|
||||
@ApiModelProperty("最后一次上下线时间")
|
||||
private Date lastOptTime;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.abin.mallchat.custom.chat.domain.vo.response;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Description: 消息
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-03-23
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChatMessageRespV1 {
|
||||
|
||||
@ApiModelProperty("发送者信息")
|
||||
private UserInfo fromUser;
|
||||
@ApiModelProperty("消息详情")
|
||||
private Message message;
|
||||
|
||||
@Data
|
||||
public static class UserInfo {
|
||||
@ApiModelProperty("用户id")
|
||||
private Long uid;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Message {
|
||||
@ApiModelProperty("消息id")
|
||||
private Long id;
|
||||
@ApiModelProperty("消息发送时间")
|
||||
private Date sendTime;
|
||||
@ApiModelProperty("消息类型 1正常文本 2.撤回消息")
|
||||
private Integer type;
|
||||
@ApiModelProperty("消息内容不同的消息类型,内容体不同,见https://www.yuque.com/snab/mallcaht/rkb2uz5k1qqdmcmd")
|
||||
private Object body;
|
||||
@ApiModelProperty("消息标记")
|
||||
private MessageMark messageMark;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class MessageMark {
|
||||
@ApiModelProperty("点赞数")
|
||||
private Integer likeCount;
|
||||
@ApiModelProperty("该用户是否已经点赞 0否 1是")
|
||||
private Integer userLike;
|
||||
@ApiModelProperty("举报数")
|
||||
private Integer dislikeCount;
|
||||
@ApiModelProperty("该用户是否已经举报 0否 1是")
|
||||
private Integer userDislike;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -143,7 +143,10 @@ public class UserServiceImpl implements UserService {
|
||||
List<Long> uidList = getNeedSyncUidList(req.getReqList());
|
||||
//加载用户信息
|
||||
Map<Long, SummeryInfoDTO> batch = userSummaryCache.getBatch(uidList);
|
||||
return new ArrayList<>(batch.values());
|
||||
return req.getReqList()
|
||||
.stream()
|
||||
.map(a -> batch.containsKey(a.getUid()) ? batch.get(a.getUid()) : SummeryInfoDTO.skip(a.getUid()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,7 +154,7 @@ public class UserServiceImpl implements UserService {
|
||||
return req.getReqList().stream().map(a -> {
|
||||
ItemConfig itemConfig = itemCache.getById(a.getItemId());
|
||||
if (Objects.nonNull(a.getLastModifyTime()) && a.getLastModifyTime() >= itemConfig.getUpdateTime().getTime()) {
|
||||
return null;
|
||||
return ItemInfoDTO.skip(a.getItemId());
|
||||
}
|
||||
ItemInfoDTO dto = new ItemInfoDTO();
|
||||
dto.setItemId(itemConfig.getId());
|
||||
|
||||
@@ -90,7 +90,6 @@ public class WebSocketServiceImpl implements WebSocketService {
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
@FrequencyControl(time = 10, count = 2, spEl = "T(com.abin.mallchat.common.common.utils.RequestHolder).get().getIp()")
|
||||
@FrequencyControl(time = 100, count = 5, spEl = "T(com.abin.mallchat.common.common.utils.RequestHolder).get().getIp()")
|
||||
public void handleLoginReq(Channel channel) {
|
||||
//生成随机不重复的登录码
|
||||
|
||||
@@ -96,7 +96,6 @@ public class NettyWebSocketServer {
|
||||
});
|
||||
// 启动服务器,监听端口,阻塞直到启动成功
|
||||
serverBootstrap.bind(WEB_SOCKET_PORT).sync();
|
||||
System.out.println("启动成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user