mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-22 20:43:42 +08:00
fix:前后端交互优化
This commit is contained in:
@@ -25,6 +25,7 @@ INSERT INTO `item_config` VALUES (2, 2, 'https://cdn-icons-png.flaticon.com/128/
|
|||||||
INSERT INTO `item_config` VALUES (3, 2, 'https://cdn-icons-png.flaticon.com/512/6198/6198527.png ', '抹茶聊天前10名注册的用户才能获得的专属徽章', '2023-05-07 17:50:31.100', '2023-05-07 18:12:01.448');
|
INSERT INTO `item_config` VALUES (3, 2, 'https://cdn-icons-png.flaticon.com/512/6198/6198527.png ', '抹茶聊天前10名注册的用户才能获得的专属徽章', '2023-05-07 17:50:31.100', '2023-05-07 18:12:01.448');
|
||||||
INSERT INTO `item_config` VALUES (4, 2, 'https://cdn-icons-png.flaticon.com/512/10232/10232583.png', '抹茶聊天前100名注册的用户才能获得的专属徽章', '2023-05-07 17:50:31.109', '2023-05-07 17:56:36.059');
|
INSERT INTO `item_config` VALUES (4, 2, 'https://cdn-icons-png.flaticon.com/512/10232/10232583.png', '抹茶聊天前100名注册的用户才能获得的专属徽章', '2023-05-07 17:50:31.109', '2023-05-07 17:56:36.059');
|
||||||
INSERT INTO `item_config` VALUES (5, 2, 'https://cdn-icons-png.flaticon.com/128/2909/2909937.png', '抹茶知识星球成员的专属徽章', '2023-05-07 17:50:31.109', '2023-05-07 17:56:36.059');
|
INSERT INTO `item_config` VALUES (5, 2, 'https://cdn-icons-png.flaticon.com/128/2909/2909937.png', '抹茶知识星球成员的专属徽章', '2023-05-07 17:50:31.109', '2023-05-07 17:56:36.059');
|
||||||
|
INSERT INTO `item_config` VALUES (6, 2, 'https://s2.loli.net/2023/06/15/O9FwjH4ciAuMSnL.png', '抹茶项目contributor专属徽章', '2023-05-07 17:50:31.109', '2023-05-07 17:56:36.059');
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for message
|
-- Table structure for message
|
||||||
@@ -181,4 +182,11 @@ CREATE TABLE `user_role` (
|
|||||||
KEY `idx_role_id` (`role_id`) USING BTREE,
|
KEY `idx_role_id` (`role_id`) USING BTREE,
|
||||||
KEY `idx_create_time` (`create_time`) USING BTREE,
|
KEY `idx_create_time` (`create_time`) USING BTREE,
|
||||||
KEY `idx_update_time` (`update_time`) USING BTREE
|
KEY `idx_update_time` (`update_time`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户角色关系表';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户角色关系表';
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `sensitive_word`;
|
||||||
|
CREATE TABLE `sensitive_word` (
|
||||||
|
`word` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '敏感词'
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='敏感词库';
|
||||||
|
INSERT INTO `sensitive_word` (`word`) VALUES ('TMD');
|
||||||
|
INSERT INTO `sensitive_word` (`word`) VALUES ('tmd');
|
||||||
14630
docs/sensitive_word.sql
14630
docs/sensitive_word.sql
File diff suppressed because it is too large
Load Diff
6
docs/version/2023-06-17.sql
Normal file
6
docs/version/2023-06-17.sql
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
DROP TABLE IF EXISTS `sensitive_word`;
|
||||||
|
CREATE TABLE `sensitive_word` (
|
||||||
|
`word` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '敏感词'
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='敏感词库';
|
||||||
|
INSERT INTO `sensitive_word` (`word`) VALUES ('TMD');
|
||||||
|
INSERT INTO `sensitive_word` (`word`) VALUES ('tmd');
|
||||||
@@ -19,9 +19,17 @@ import lombok.NoArgsConstructor;
|
|||||||
public class ItemInfoDTO {
|
public class ItemInfoDTO {
|
||||||
@ApiModelProperty(value = "徽章id")
|
@ApiModelProperty(value = "徽章id")
|
||||||
private Long itemId;
|
private Long itemId;
|
||||||
|
@ApiModelProperty(value = "是否需要刷新")
|
||||||
|
private Boolean needRefresh = Boolean.TRUE;
|
||||||
@ApiModelProperty("徽章图像")
|
@ApiModelProperty("徽章图像")
|
||||||
private String img;
|
private String img;
|
||||||
@ApiModelProperty("徽章说明")
|
@ApiModelProperty("徽章说明")
|
||||||
private String describe;
|
private String describe;
|
||||||
|
|
||||||
|
public static ItemInfoDTO skip(Long itemId) {
|
||||||
|
ItemInfoDTO dto = new ItemInfoDTO();
|
||||||
|
dto.setItemId(itemId);
|
||||||
|
dto.setNeedRefresh(Boolean.FALSE);
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import java.util.List;
|
|||||||
public class SummeryInfoDTO {
|
public class SummeryInfoDTO {
|
||||||
@ApiModelProperty(value = "用户id")
|
@ApiModelProperty(value = "用户id")
|
||||||
private Long uid;
|
private Long uid;
|
||||||
|
@ApiModelProperty(value = "是否需要刷新")
|
||||||
|
private Boolean needRefresh = Boolean.TRUE;
|
||||||
@ApiModelProperty(value = "用户昵称")
|
@ApiModelProperty(value = "用户昵称")
|
||||||
private String name;
|
private String name;
|
||||||
@ApiModelProperty(value = "用户头像")
|
@ApiModelProperty(value = "用户头像")
|
||||||
@@ -32,4 +34,10 @@ public class SummeryInfoDTO {
|
|||||||
@ApiModelProperty(value = "用户拥有的徽章id列表")
|
@ApiModelProperty(value = "用户拥有的徽章id列表")
|
||||||
List<Long> itemIds;
|
List<Long> itemIds;
|
||||||
|
|
||||||
|
public static SummeryInfoDTO skip(Long uid) {
|
||||||
|
SummeryInfoDTO dto = new SummeryInfoDTO();
|
||||||
|
dto.setUid(uid);
|
||||||
|
dto.setNeedRefresh(Boolean.FALSE);
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.abin.mallchat.custom.user.service.impl.UserServiceImpl;
|
|||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ import javax.validation.Valid;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -57,6 +59,20 @@ public class ChatController {
|
|||||||
return ApiResult.success(memberPage);
|
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")
|
@GetMapping("/member/list")
|
||||||
@ApiOperation("房间内的所有群成员列表-@专用")
|
@ApiOperation("房间内的所有群成员列表-@专用")
|
||||||
public ApiResult<List<ChatMemberListResp>> getMemberList(@Valid ChatMessageMemberReq chatMessageMemberReq) {
|
public ApiResult<List<ChatMemberListResp>> getMemberList(@Valid ChatMessageMemberReq chatMessageMemberReq) {
|
||||||
@@ -81,25 +97,30 @@ public class ChatController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserServiceImpl userService;
|
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")
|
@GetMapping("/public/msg/page")
|
||||||
@ApiOperation("消息列表")
|
@ApiOperation("消息列表")
|
||||||
@FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
@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);
|
// black(request);
|
||||||
CursorPageBaseResp<ChatMessageResp> msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
|
CursorPageBaseResp<ChatMessageResp> msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
|
||||||
filterBlackMsg(msgPage);
|
filterBlackMsg(msgPage);
|
||||||
return ApiResult.success(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) {
|
private void filterBlackMsg(CursorPageBaseResp<ChatMessageResp> memberPage) {
|
||||||
Set<String> blackMembers = getBlackUidSet();
|
Set<String> blackMembers = getBlackUidSet();
|
||||||
memberPage.getList().removeIf(a -> blackMembers.contains(a.getFromUser().getUid().toString()));
|
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());
|
List<Long> uidList = getNeedSyncUidList(req.getReqList());
|
||||||
//加载用户信息
|
//加载用户信息
|
||||||
Map<Long, SummeryInfoDTO> batch = userSummaryCache.getBatch(uidList);
|
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
|
@Override
|
||||||
@@ -151,7 +154,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
return req.getReqList().stream().map(a -> {
|
return req.getReqList().stream().map(a -> {
|
||||||
ItemConfig itemConfig = itemCache.getById(a.getItemId());
|
ItemConfig itemConfig = itemCache.getById(a.getItemId());
|
||||||
if (Objects.nonNull(a.getLastModifyTime()) && a.getLastModifyTime() >= itemConfig.getUpdateTime().getTime()) {
|
if (Objects.nonNull(a.getLastModifyTime()) && a.getLastModifyTime() >= itemConfig.getUpdateTime().getTime()) {
|
||||||
return null;
|
return ItemInfoDTO.skip(a.getItemId());
|
||||||
}
|
}
|
||||||
ItemInfoDTO dto = new ItemInfoDTO();
|
ItemInfoDTO dto = new ItemInfoDTO();
|
||||||
dto.setItemId(itemConfig.getId());
|
dto.setItemId(itemConfig.getId());
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ public class WebSocketServiceImpl implements WebSocketService {
|
|||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@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()")
|
@FrequencyControl(time = 100, count = 5, spEl = "T(com.abin.mallchat.common.common.utils.RequestHolder).get().getIp()")
|
||||||
public void handleLoginReq(Channel channel) {
|
public void handleLoginReq(Channel channel) {
|
||||||
//生成随机不重复的登录码
|
//生成随机不重复的登录码
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ public class NettyWebSocketServer {
|
|||||||
});
|
});
|
||||||
// 启动服务器,监听端口,阻塞直到启动成功
|
// 启动服务器,监听端口,阻塞直到启动成功
|
||||||
serverBootstrap.bind(WEB_SOCKET_PORT).sync();
|
serverBootstrap.bind(WEB_SOCKET_PORT).sync();
|
||||||
System.out.println("启动成功");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user