mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-15 15:13:43 +08:00
feat:
1.前后端交互改版 2.艾特成员功能 3.用户名片卡功能
This commit is contained in:
@@ -8,15 +8,8 @@ import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
|
||||
import com.abin.mallchat.common.common.utils.RequestHolder;
|
||||
import com.abin.mallchat.common.user.domain.enums.BlackTypeEnum;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageBaseReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessagePageReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.msg.TextMsgReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberStatisticResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.*;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.*;
|
||||
import com.abin.mallchat.custom.chat.service.ChatService;
|
||||
import com.abin.mallchat.custom.user.service.impl.UserServiceImpl;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -27,7 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -56,14 +49,20 @@ public class ChatController {
|
||||
|
||||
@GetMapping("/public/member/page")
|
||||
@ApiOperation("群成员列表")
|
||||
@FrequencyControl(time = 120, count = 10, target = FrequencyControl.Target.IP)
|
||||
@FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
||||
public ApiResult<CursorPageBaseResp<ChatMemberResp>> getMemberPage(@Valid CursorPageBaseReq request) {
|
||||
black(request);
|
||||
// black(request);
|
||||
CursorPageBaseResp<ChatMemberResp> memberPage = chatService.getMemberPage(request);
|
||||
filterBlackMember(memberPage);
|
||||
return ApiResult.success(memberPage);
|
||||
}
|
||||
|
||||
@GetMapping("/member/list")
|
||||
@ApiOperation("房间内的所有群成员列表-@专用")
|
||||
public ApiResult<List<ChatMemberListResp>> getMemberList(@Valid ChatMessageMemberReq chatMessageMemberReq) {
|
||||
return ApiResult.success(chatService.getMemberList(chatMessageMemberReq));
|
||||
}
|
||||
|
||||
private void filterBlackMember(CursorPageBaseResp<ChatMemberResp> memberPage) {
|
||||
Set<String> blackMembers = getBlackUidSet();
|
||||
memberPage.getList().removeIf(a -> blackMembers.contains(a.getUid().toString()));
|
||||
@@ -84,9 +83,9 @@ public class ChatController {
|
||||
|
||||
@GetMapping("/public/msg/page")
|
||||
@ApiOperation("消息列表")
|
||||
@FrequencyControl(time = 120, count = 10, target = FrequencyControl.Target.IP)
|
||||
@FrequencyControl(time = 120, count = 20, target = FrequencyControl.Target.IP)
|
||||
public ApiResult<CursorPageBaseResp<ChatMessageResp>> getMsgPage(@Valid ChatMessagePageReq request) {
|
||||
black(request);
|
||||
// black(request);
|
||||
CursorPageBaseResp<ChatMessageResp> msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
|
||||
filterBlackMsg(msgPage);
|
||||
return ApiResult.success(msgPage);
|
||||
@@ -113,10 +112,6 @@ public class ChatController {
|
||||
@FrequencyControl(time = 30, count = 5, target = FrequencyControl.Target.UID)
|
||||
@FrequencyControl(time = 60, count = 10, target = FrequencyControl.Target.UID)
|
||||
public ApiResult<ChatMessageResp> sendMsg(@Valid @RequestBody ChatMessageReq request) {
|
||||
if (Objects.isNull(request.getBody())) {
|
||||
TextMsgReq req = new TextMsgReq(request.getContent(), request.getReplyMsgId());//todo 消息兼容之后删了
|
||||
request.setBody(req);
|
||||
}
|
||||
Long msgId = chatService.sendMsg(request, RequestHolder.get().getUid());
|
||||
//返回完整消息格式,方便前端展示
|
||||
return ApiResult.success(chatService.getMsgResp(msgId, RequestHolder.get().getUid()));
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.abin.mallchat.custom.chat.domain.vo.request;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Description: 消息列表请求
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-03-29
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChatMessageMemberReq {
|
||||
@NotNull
|
||||
@ApiModelProperty("会话id")
|
||||
private Long roomId;
|
||||
}
|
||||
@@ -30,11 +30,4 @@ public class ChatMessageReq {
|
||||
@ApiModelProperty("消息内容,类型不同传值不同,见https://www.yuque.com/snab/mallcaht/rkb2uz5k1qqdmcmd")
|
||||
private Object body;
|
||||
|
||||
@ApiModelProperty("消息内容")
|
||||
@Deprecated
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty("回复的消息id,如果没有别传就好")
|
||||
@Deprecated
|
||||
private Long replyMsgId;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description: 文本消息入参
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
@@ -22,4 +24,7 @@ public class TextMsgReq {
|
||||
|
||||
@ApiModelProperty("回复的消息id,如果没有别传就好")
|
||||
private Long replyMsgId;
|
||||
|
||||
@ApiModelProperty("艾特的uid")
|
||||
private List<Long> atUidList;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Description: 群成员列表的成员信息
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-03-23
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChatMemberListResp {
|
||||
@ApiModelProperty("uid")
|
||||
private Long uid;
|
||||
@ApiModelProperty("用户名称")
|
||||
private String name;
|
||||
@ApiModelProperty("头像")
|
||||
private String avatar;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,8 @@ public class TextMsgResp {
|
||||
private String content;
|
||||
@ApiModelProperty("消息链接映射")
|
||||
private Map<String, String> urlTitleMap;
|
||||
@ApiModelProperty("艾特的uid")
|
||||
private List<Long> atUidList;
|
||||
@ApiModelProperty("父消息,如果没有父消息,返回的是null")
|
||||
private TextMsgResp.ReplyMsg reply;
|
||||
|
||||
|
||||
@@ -3,16 +3,11 @@ package com.abin.mallchat.custom.chat.service;
|
||||
import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||
import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageBaseReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessagePageReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberStatisticResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.*;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description: 消息处理类
|
||||
@@ -76,4 +71,6 @@ public interface ChatService {
|
||||
void setMsgMark(Long uid, ChatMessageMarkReq request);
|
||||
|
||||
void recallMsg(Long uid, ChatMessageBaseReq request);
|
||||
|
||||
List<ChatMemberListResp> getMemberList(ChatMessageMemberReq chatMessageMemberReq);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.abin.mallchat.common.chat.domain.entity.msg.MessageExtra;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageMarkTypeEnum;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum;
|
||||
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
||||
import com.abin.mallchat.common.common.utils.discover.PrioritizedUrlTitleDiscover;
|
||||
import com.abin.mallchat.common.user.domain.entity.IpDetail;
|
||||
import com.abin.mallchat.common.user.domain.entity.IpInfo;
|
||||
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
|
||||
@@ -27,7 +26,6 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class MessageAdapter {
|
||||
public static final int CAN_CALLBACK_GAP_COUNT = 100;
|
||||
private static final PrioritizedUrlTitleDiscover URL_TITLE_DISCOVER = new PrioritizedUrlTitleDiscover();
|
||||
|
||||
public static Message buildMsgSave(ChatMessageReq request, Long uid) {
|
||||
|
||||
@@ -35,16 +33,10 @@ public class MessageAdapter {
|
||||
.fromUid(uid)
|
||||
.roomId(request.getRoomId())
|
||||
.status(MessageStatusEnum.NORMAL.getStatus())
|
||||
.extra(buildExtra(request))
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
private static MessageExtra buildExtra(ChatMessageReq request) {
|
||||
Map<String, String> contentTitleMap = URL_TITLE_DISCOVER.getContentTitleMap(request.getContent());
|
||||
return MessageExtra.builder().urlTitleMap(contentTitleMap).build();
|
||||
}
|
||||
|
||||
public static List<ChatMessageResp> buildMsgResp(List<Message> messages, Map<Long, Message> replyMap, Map<Long, User> userMap, List<MessageMark> msgMark, Long receiveUid, Map<Long, ItemConfig> itemMap) {
|
||||
Map<Long, List<MessageMark>> markMap = msgMark.stream().collect(Collectors.groupingBy(MessageMark::getMsgId));
|
||||
return messages.stream().map(a -> {
|
||||
|
||||
@@ -26,14 +26,8 @@ import com.abin.mallchat.common.user.domain.enums.RoleEnum;
|
||||
import com.abin.mallchat.common.user.service.IRoleService;
|
||||
import com.abin.mallchat.common.user.service.cache.ItemCache;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageBaseReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessagePageReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberStatisticResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.*;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.*;
|
||||
import com.abin.mallchat.custom.chat.service.ChatService;
|
||||
import com.abin.mallchat.custom.chat.service.adapter.MemberAdapter;
|
||||
import com.abin.mallchat.custom.chat.service.adapter.MessageAdapter;
|
||||
@@ -45,7 +39,9 @@ import com.abin.mallchat.custom.chat.service.strategy.msg.AbstractMsgHandler;
|
||||
import com.abin.mallchat.custom.chat.service.strategy.msg.MsgHandlerFactory;
|
||||
import com.abin.mallchat.custom.chat.service.strategy.msg.RecallMsgHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -92,7 +88,7 @@ public class ChatServiceImpl implements ChatService {
|
||||
@Transactional
|
||||
public Long sendMsg(ChatMessageReq request, Long uid) {
|
||||
AbstractMsgHandler msgHandler = MsgHandlerFactory.getStrategyNoNull(request.getMsgType());//todo 这里先不扩展,后续再改
|
||||
msgHandler.checkMsg(request);
|
||||
msgHandler.checkMsg(request, uid);
|
||||
//同步获取消息的跳转链接标题
|
||||
Message insert = MessageAdapter.buildMsgSave(request, uid);
|
||||
messageDao.save(insert);
|
||||
@@ -196,6 +192,22 @@ public class ChatServiceImpl implements ChatService {
|
||||
recallMsgHandler.recall(uid, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "member", key = "'memberList.'+#req.roomId")
|
||||
public List<ChatMemberListResp> getMemberList(ChatMessageMemberReq req) {
|
||||
if (Objects.equals(1L, req.getRoomId())) {//大群聊可看见所有人
|
||||
return userDao.getMemberList()
|
||||
.stream()
|
||||
.map(a -> {
|
||||
ChatMemberListResp resp = new ChatMemberListResp();
|
||||
BeanUtils.copyProperties(a, resp);
|
||||
resp.setUid(a.getId());
|
||||
return resp;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void checkRecall(Long uid, Message message) {
|
||||
AssertUtil.isNotEmpty(message, "消息有误");
|
||||
AssertUtil.notEqual(message.getType(), MessageTypeEnum.RECALL, "消息无法撤回");
|
||||
|
||||
@@ -20,7 +20,7 @@ public abstract class AbstractMsgHandler {
|
||||
|
||||
abstract MessageTypeEnum getMsgTypeEnum();
|
||||
|
||||
public abstract void checkMsg(ChatMessageReq req);
|
||||
public abstract void checkMsg(ChatMessageReq req, Long uid);
|
||||
|
||||
public abstract void saveMsg(Message msg, ChatMessageReq req);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class RecallMsgHandler extends AbstractMsgHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkMsg(ChatMessageReq request) {
|
||||
public void checkMsg(ChatMessageReq request, Long uid) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,15 +9,22 @@ import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import com.abin.mallchat.common.chat.service.cache.MsgCache;
|
||||
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.common.common.utils.discover.PrioritizedUrlTitleDiscover;
|
||||
import com.abin.mallchat.common.user.domain.entity.User;
|
||||
import com.abin.mallchat.common.user.domain.enums.RoleEnum;
|
||||
import com.abin.mallchat.common.user.service.IRoleService;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import com.abin.mallchat.common.user.service.cache.UserInfoCache;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.msg.TextMsgReq;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.response.msg.TextMsgResp;
|
||||
import com.abin.mallchat.custom.chat.service.adapter.MessageAdapter;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -34,6 +41,12 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
||||
private MsgCache msgCache;
|
||||
@Autowired
|
||||
private UserCache userCache;
|
||||
@Autowired
|
||||
private UserInfoCache userInfoCache;
|
||||
@Autowired
|
||||
private IRoleService iRoleService;
|
||||
@Autowired
|
||||
private static final PrioritizedUrlTitleDiscover URL_TITLE_DISCOVER = new PrioritizedUrlTitleDiscover();
|
||||
|
||||
@Override
|
||||
MessageTypeEnum getMsgTypeEnum() {
|
||||
@@ -41,7 +54,7 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkMsg(ChatMessageReq request) {
|
||||
public void checkMsg(ChatMessageReq request, Long uid) {
|
||||
TextMsgReq body = BeanUtil.toBean(request.getBody(), TextMsgReq.class);
|
||||
AssertUtil.isNotEmpty(body.getContent(), "内容不能为空");
|
||||
AssertUtil.isTrue(body.getContent().length() < 500, "消息内容过长,服务器扛不住啊,兄dei");
|
||||
@@ -51,14 +64,26 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
||||
AssertUtil.isNotEmpty(replyMsg, "回复消息不存在");
|
||||
AssertUtil.equal(replyMsg.getRoomId(), request.getRoomId(), "只能回复相同会话内的消息");
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(body.getAtUidList())) {
|
||||
AssertUtil.isTrue(body.getAtUidList().size() > 10, "一次别艾特这么多人");
|
||||
List<Long> atUidList = body.getAtUidList();
|
||||
Map<Long, User> batch = userInfoCache.getBatch(atUidList);
|
||||
AssertUtil.equal(atUidList.size(), batch.values().size(), "@用户不存在");
|
||||
boolean atAll = body.getAtUidList().contains(0L);
|
||||
if (atAll) {
|
||||
AssertUtil.isTrue(iRoleService.hasPower(uid, RoleEnum.CHAT_MANAGER), "没有权限");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveMsg(Message msg, ChatMessageReq request) {//插入文本内容
|
||||
TextMsgReq body = BeanUtil.toBean(request.getBody(), TextMsgReq.class);
|
||||
MessageExtra extra = Optional.ofNullable(msg.getExtra()).orElse(new MessageExtra());
|
||||
Message update = new Message();
|
||||
update.setId(msg.getId());
|
||||
update.setContent(body.getContent());
|
||||
update.setExtra(extra);
|
||||
//如果有回复消息
|
||||
if (Objects.nonNull(body.getReplyMsgId())) {
|
||||
Integer gapCount = messageDao.getGapCount(request.getRoomId(), body.getReplyMsgId(), msg.getId());
|
||||
@@ -66,6 +91,15 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
||||
update.setReplyMsgId(body.getReplyMsgId());
|
||||
|
||||
}
|
||||
//判断消息url跳转
|
||||
Map<String, String> urlTitleMap = URL_TITLE_DISCOVER.getContentTitleMap(body.getContent());
|
||||
extra.setUrlTitleMap(urlTitleMap);
|
||||
//艾特功能
|
||||
if (CollectionUtils.isNotEmpty(body.getAtUidList())) {
|
||||
extra.setAtUidList(body.getAtUidList());
|
||||
|
||||
}
|
||||
|
||||
messageDao.updateById(update);
|
||||
}
|
||||
|
||||
@@ -74,6 +108,7 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
||||
TextMsgResp resp = new TextMsgResp();
|
||||
resp.setContent(msg.getContent());
|
||||
resp.setUrlTitleMap(Optional.ofNullable(msg.getExtra()).map(MessageExtra::getUrlTitleMap).orElse(null));
|
||||
resp.setAtUidList(Optional.ofNullable(msg.getExtra()).map(MessageExtra::getAtUidList).orElse(null));
|
||||
//回复消息
|
||||
Optional<Message> reply = Optional.ofNullable(msg.getReplyMsgId())
|
||||
.map(msgCache::getMsg)
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ItemReceiveListener {
|
||||
User user = userDao.getById(userBackpack.getUid());
|
||||
if (Objects.isNull(user.getItemId())) {
|
||||
userDao.wearingBadge(userBackpack.getUid(), userBackpack.getItemId());
|
||||
userCache.delUserInfo(userBackpack.getUid());
|
||||
userCache.userInfoChange(userBackpack.getUid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ package com.abin.mallchat.custom.user.controller;
|
||||
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.common.common.utils.RequestHolder;
|
||||
import com.abin.mallchat.common.user.domain.dto.ItemInfoDTO;
|
||||
import com.abin.mallchat.common.user.domain.dto.SummeryInfoDTO;
|
||||
import com.abin.mallchat.common.user.domain.enums.RoleEnum;
|
||||
import com.abin.mallchat.common.user.service.IRoleService;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.BlackReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.ModifyNameReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.WearingBadgeReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.*;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.BadgeResp;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.UserInfoResp;
|
||||
import com.abin.mallchat.custom.user.service.UserService;
|
||||
@@ -43,6 +43,18 @@ public class UserController {
|
||||
return ApiResult.success(userService.getUserInfo(RequestHolder.get().getUid()));
|
||||
}
|
||||
|
||||
@PostMapping("/public/summary/userInfo/batch")
|
||||
@ApiOperation("用户聚合信息-返回的代表需要刷新的")
|
||||
public ApiResult<List<SummeryInfoDTO>> getSummeryUserInfo(@Valid @RequestBody SummeryInfoReq req) {
|
||||
return ApiResult.success(userService.getSummeryUserInfo(req));
|
||||
}
|
||||
|
||||
@PostMapping("/public/badges/batch")
|
||||
@ApiOperation("徽章聚合信息-返回的代表需要刷新的")
|
||||
public ApiResult<List<ItemInfoDTO>> getItemInfo(@Valid @RequestBody ItemInfoReq req) {
|
||||
return ApiResult.success(userService.getItemInfo(req));
|
||||
}
|
||||
|
||||
@PutMapping("/name")
|
||||
@ApiOperation("修改用户名")
|
||||
public ApiResult<Void> modifyName(@Valid @RequestBody ModifyNameReq req) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.abin.mallchat.custom.user.domain.vo.request.user;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Description: 批量查询徽章详情
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-03-23
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ItemInfoReq {
|
||||
@ApiModelProperty(value = "徽章信息入参")
|
||||
@Size(max = 50)
|
||||
private List<infoReq> reqList;
|
||||
|
||||
@Data
|
||||
public static class infoReq {
|
||||
@ApiModelProperty(value = "徽章id")
|
||||
private Long itemId;
|
||||
@ApiModelProperty(value = "最近一次更新徽章信息时间")
|
||||
private Long lastModifyTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.abin.mallchat.custom.user.domain.vo.request.user;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Description: 批量查询用户汇总详情
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-03-23
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SummeryInfoReq {
|
||||
@ApiModelProperty(value = "用户信息入参")
|
||||
@Size(max = 50)
|
||||
private List<infoReq> reqList;
|
||||
|
||||
@Data
|
||||
public static class infoReq {
|
||||
@ApiModelProperty(value = "uid")
|
||||
private Long uid;
|
||||
@ApiModelProperty(value = "最近一次更新用户信息时间")
|
||||
private Long lastModifyTime;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.abin.mallchat.custom.user.service;
|
||||
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.BlackReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.ModifyNameReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.WearingBadgeReq;
|
||||
import com.abin.mallchat.common.user.domain.dto.ItemInfoDTO;
|
||||
import com.abin.mallchat.common.user.domain.dto.SummeryInfoDTO;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.*;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.BadgeResp;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.UserInfoResp;
|
||||
|
||||
@@ -57,4 +57,14 @@ public interface UserService {
|
||||
void register(String openId);
|
||||
|
||||
void black(BlackReq req);
|
||||
|
||||
/**
|
||||
* 获取用户汇总信息
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
List<SummeryInfoDTO> getSummeryUserInfo(SummeryInfoReq req);
|
||||
|
||||
List<ItemInfoDTO> getItemInfo(ItemInfoReq req);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.abin.mallchat.common.user.dao.BlackDao;
|
||||
import com.abin.mallchat.common.user.dao.ItemConfigDao;
|
||||
import com.abin.mallchat.common.user.dao.UserBackpackDao;
|
||||
import com.abin.mallchat.common.user.dao.UserDao;
|
||||
import com.abin.mallchat.common.user.domain.dto.ItemInfoDTO;
|
||||
import com.abin.mallchat.common.user.domain.dto.SummeryInfoDTO;
|
||||
import com.abin.mallchat.common.user.domain.entity.Black;
|
||||
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
|
||||
import com.abin.mallchat.common.user.domain.entity.User;
|
||||
@@ -17,9 +19,8 @@ import com.abin.mallchat.common.user.domain.enums.ItemEnum;
|
||||
import com.abin.mallchat.common.user.domain.enums.ItemTypeEnum;
|
||||
import com.abin.mallchat.common.user.service.cache.ItemCache;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.BlackReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.ModifyNameReq;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.WearingBadgeReq;
|
||||
import com.abin.mallchat.common.user.service.cache.UserSummaryCache;
|
||||
import com.abin.mallchat.custom.user.domain.vo.request.user.*;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.BadgeResp;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.user.UserInfoResp;
|
||||
import com.abin.mallchat.custom.user.service.UserService;
|
||||
@@ -30,7 +31,10 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -56,6 +60,8 @@ public class UserServiceImpl implements UserService {
|
||||
private ItemCache itemCache;
|
||||
@Autowired
|
||||
private BlackDao blackDao;
|
||||
@Autowired
|
||||
private UserSummaryCache userSummaryCache;
|
||||
|
||||
@Override
|
||||
public UserInfoResp getUserInfo(Long uid) {
|
||||
@@ -79,7 +85,7 @@ public class UserServiceImpl implements UserService {
|
||||
//改名
|
||||
userDao.modifyName(uid, req.getName());
|
||||
//删除缓存
|
||||
userCache.delUserInfo(uid);
|
||||
userCache.userInfoChange(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +111,7 @@ public class UserServiceImpl implements UserService {
|
||||
//佩戴徽章
|
||||
userDao.wearingBadge(uid, req.getBadgeId());
|
||||
//删除用户缓存
|
||||
userCache.delUserInfo(uid);
|
||||
userCache.userInfoChange(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,6 +134,43 @@ public class UserServiceImpl implements UserService {
|
||||
applicationEventPublisher.publishEvent(new UserBlackEvent(this, byId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SummeryInfoDTO> getSummeryUserInfo(SummeryInfoReq req) {
|
||||
//需要前端同步的uid
|
||||
List<Long> uidList = getNeedSyncUidList(req.getReqList());
|
||||
//加载用户信息
|
||||
Map<Long, SummeryInfoDTO> batch = userSummaryCache.getBatch(uidList);
|
||||
return new ArrayList<>(batch.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemInfoDTO> getItemInfo(ItemInfoReq req) {//简单做,更新时间可判断被修改
|
||||
return req.getReqList().stream().map(a -> {
|
||||
ItemConfig itemConfig = itemCache.getById(a.getItemId());
|
||||
if (Objects.nonNull(a.getLastModifyTime()) && a.getLastModifyTime() >= itemConfig.getUpdateTime().getTime()) {
|
||||
return null;
|
||||
}
|
||||
ItemInfoDTO dto = new ItemInfoDTO();
|
||||
dto.setItemId(itemConfig.getId());
|
||||
dto.setImg(itemConfig.getImg());
|
||||
dto.setDescribe(itemConfig.getDescribe());
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<Long> getNeedSyncUidList(List<SummeryInfoReq.infoReq> reqList) {
|
||||
List<Long> result = new ArrayList<>();
|
||||
List<Long> userModifyTime = userCache.getUserModifyTime(reqList.stream().map(SummeryInfoReq.infoReq::getUid).collect(Collectors.toList()));
|
||||
for (int i = 0; i < reqList.size(); i++) {
|
||||
SummeryInfoReq.infoReq infoReq = reqList.get(i);
|
||||
Long modifyTime = userModifyTime.get(i);
|
||||
if (Objects.isNull(infoReq.getLastModifyTime()) || (Objects.nonNull(modifyTime) && modifyTime > infoReq.getLastModifyTime())) {
|
||||
result.add(infoReq.getUid());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void blackIp(String ip) {
|
||||
if (StrUtil.isBlank(ip)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user