From b39a1bdf0c79a2e8ca38436a912df563acd066a0 Mon Sep 17 00:00:00 2001
From: zhongzb <972627721@qq.com>
Date: Sun, 7 May 2023 20:22:06 +0800
Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=BE=BD=E7=AB=A0=E4=BD=A9?=
=?UTF-8?q?=E6=88=B4=E5=92=8C=E5=8F=91=E6=94=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../chat/domain/dto/ChatMessageMarkDTO.java | 29 +++++++++++
.../common/aspect/RedissonLockAspect.java | 2 +
.../common/common/event/ItemReceiveEvent.java | 17 +++++++
.../common/common/event/MessageMarkEvent.java | 15 ++++++
.../common/event/MessageSendEvent.java | 2 +-
.../common/event/UserOfflineEvent.java | 2 +-
.../common}/common/event/UserOnlineEvent.java | 2 +-
.../common/event/UserRegisterEvent.java | 2 +-
.../common/user/domain/enums/ItemEnum.java | 4 +-
.../service/impl/UserBackpackServiceImpl.java | 8 +++
.../chat/controller/ChatController.java | 19 ++++---
.../custom/chat/service/ChatService.java | 7 +++
.../chat/service/impl/ChatServiceImpl.java | 34 ++++++++-----
.../custom/common/event/MessageMarkEvent.java | 15 ------
.../event/listener/ItemReceiveListener.java | 49 +++++++++++++++++++
.../event/listener/MessageMarkListener.java | 14 +++---
.../event/listener/MessageSendListener.java | 2 +-
.../event/listener/UserOfflineListener.java | 3 +-
.../event/listener/UserOnlineListener.java | 7 +--
.../event/listener/UserRegisterListener.java | 18 +++----
.../user/service/impl/UserServiceImpl.java | 3 +-
.../service/impl/WebSocketServiceImpl.java | 4 +-
22 files changed, 187 insertions(+), 71 deletions(-)
create mode 100644 mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/dto/ChatMessageMarkDTO.java
create mode 100644 mallchat-common/src/main/java/com/abin/mallchat/common/common/event/ItemReceiveEvent.java
create mode 100644 mallchat-common/src/main/java/com/abin/mallchat/common/common/event/MessageMarkEvent.java
rename {mallchat-custom-server/src/main/java/com/abin/mallchat/custom => mallchat-common/src/main/java/com/abin/mallchat/common}/common/event/MessageSendEvent.java (87%)
rename {mallchat-custom-server/src/main/java/com/abin/mallchat/custom => mallchat-common/src/main/java/com/abin/mallchat/common}/common/event/UserOfflineEvent.java (87%)
rename {mallchat-custom-server/src/main/java/com/abin/mallchat/custom => mallchat-common/src/main/java/com/abin/mallchat/common}/common/event/UserOnlineEvent.java (88%)
rename {mallchat-custom-server/src/main/java/com/abin/mallchat/custom => mallchat-common/src/main/java/com/abin/mallchat/common}/common/event/UserRegisterEvent.java (87%)
delete mode 100644 mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/MessageMarkEvent.java
create mode 100644 mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/ItemReceiveListener.java
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/dto/ChatMessageMarkDTO.java b/mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/dto/ChatMessageMarkDTO.java
new file mode 100644
index 0000000..5288aa1
--- /dev/null
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/chat/domain/dto/ChatMessageMarkDTO.java
@@ -0,0 +1,29 @@
+package com.abin.mallchat.common.chat.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * Description: 消息标记请求
+ * Author: abin
+ * Date: 2023-03-29
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class ChatMessageMarkDTO {
+ @ApiModelProperty("消息id")
+ private Long msgId;
+
+ @ApiModelProperty("标记类型 1点赞 2举报")
+ private Integer markType;
+
+ @ApiModelProperty("动作类型 1确认 2取消")
+ private Integer actType;
+}
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/aspect/RedissonLockAspect.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/aspect/RedissonLockAspect.java
index 4c5b9c4..4e69769 100644
--- a/mallchat-common/src/main/java/com/abin/mallchat/common/common/aspect/RedissonLockAspect.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/aspect/RedissonLockAspect.java
@@ -17,6 +17,7 @@ import org.aspectj.lang.reflect.MethodSignature;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.DefaultParameterNameDiscoverer;
+import org.springframework.core.annotation.Order;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
@@ -35,6 +36,7 @@ import java.util.*;
@Slf4j
@Aspect
@Component
+@Order(0)//确保比事务注解先执行,分布式锁在事务外
public class RedissonLockAspect {
@Autowired
private LockService lockService;
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/ItemReceiveEvent.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/ItemReceiveEvent.java
new file mode 100644
index 0000000..00bb601
--- /dev/null
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/ItemReceiveEvent.java
@@ -0,0 +1,17 @@
+package com.abin.mallchat.common.common.event;
+
+import com.abin.mallchat.common.user.domain.entity.User;
+import com.abin.mallchat.common.user.domain.entity.UserBackpack;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+@Getter
+public class ItemReceiveEvent extends ApplicationEvent {
+ private UserBackpack userBackpack;
+
+ public ItemReceiveEvent(Object source, UserBackpack userBackpack) {
+ super(source);
+ this.userBackpack = userBackpack;
+ }
+
+}
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/MessageMarkEvent.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/MessageMarkEvent.java
new file mode 100644
index 0000000..5cd7906
--- /dev/null
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/MessageMarkEvent.java
@@ -0,0 +1,15 @@
+package com.abin.mallchat.common.common.event;
+
+import com.abin.mallchat.common.chat.domain.dto.ChatMessageMarkDTO;
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+@Getter
+public class MessageMarkEvent extends ApplicationEvent {
+ private ChatMessageMarkDTO dto;
+
+ public MessageMarkEvent(Object source, ChatMessageMarkDTO dto) {
+ super(source);
+ this.dto = dto;
+ }
+}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/MessageSendEvent.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/MessageSendEvent.java
similarity index 87%
rename from mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/MessageSendEvent.java
rename to mallchat-common/src/main/java/com/abin/mallchat/common/common/event/MessageSendEvent.java
index ace9788..02bcddb 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/MessageSendEvent.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/MessageSendEvent.java
@@ -1,4 +1,4 @@
-package com.abin.mallchat.custom.common.event;
+package com.abin.mallchat.common.common.event;
import com.abin.mallchat.common.chat.domain.entity.Message;
import lombok.Getter;
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserOfflineEvent.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserOfflineEvent.java
similarity index 87%
rename from mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserOfflineEvent.java
rename to mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserOfflineEvent.java
index 8a295af..affe673 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserOfflineEvent.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserOfflineEvent.java
@@ -1,4 +1,4 @@
-package com.abin.mallchat.custom.common.event;
+package com.abin.mallchat.common.common.event;
import com.abin.mallchat.common.user.domain.entity.User;
import lombok.Getter;
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserOnlineEvent.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserOnlineEvent.java
similarity index 88%
rename from mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserOnlineEvent.java
rename to mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserOnlineEvent.java
index 9ac1bb5..87c18c4 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserOnlineEvent.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserOnlineEvent.java
@@ -1,4 +1,4 @@
-package com.abin.mallchat.custom.common.event;
+package com.abin.mallchat.common.common.event;
import com.abin.mallchat.common.user.domain.entity.User;
import lombok.Getter;
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserRegisterEvent.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserRegisterEvent.java
similarity index 87%
rename from mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserRegisterEvent.java
rename to mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserRegisterEvent.java
index f3242f0..4f82b3b 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/UserRegisterEvent.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/event/UserRegisterEvent.java
@@ -1,4 +1,4 @@
-package com.abin.mallchat.custom.common.event;
+package com.abin.mallchat.common.common.event;
import com.abin.mallchat.common.user.domain.entity.User;
import lombok.Getter;
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/user/domain/enums/ItemEnum.java b/mallchat-common/src/main/java/com/abin/mallchat/common/user/domain/enums/ItemEnum.java
index 8a917a2..5966fce 100644
--- a/mallchat-common/src/main/java/com/abin/mallchat/common/user/domain/enums/ItemEnum.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/user/domain/enums/ItemEnum.java
@@ -18,8 +18,8 @@ import java.util.stream.Collectors;
public enum ItemEnum {
MODIFY_NAME_CARD(1L, ItemTypeEnum.MODIFY_NAME_CARD, "改名卡"),
LIKE_BADGE(2L, ItemTypeEnum.BADGE, "爆赞徽章"),
- REG_TOP10_BADGE(2L, ItemTypeEnum.BADGE, "爆赞徽章"),
- REG_TOP100_BADGE(2L, ItemTypeEnum.BADGE, "爆赞徽章"),
+ REG_TOP10_BADGE(3L, ItemTypeEnum.BADGE, "前十注册徽章"),
+ REG_TOP100_BADGE(4L, ItemTypeEnum.BADGE, "前100注册徽章"),
;
private final Long id;
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/user/service/impl/UserBackpackServiceImpl.java b/mallchat-common/src/main/java/com/abin/mallchat/common/user/service/impl/UserBackpackServiceImpl.java
index db1c47a..03bc00b 100644
--- a/mallchat-common/src/main/java/com/abin/mallchat/common/user/service/impl/UserBackpackServiceImpl.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/user/service/impl/UserBackpackServiceImpl.java
@@ -3,6 +3,7 @@ package com.abin.mallchat.common.user.service.impl;
import com.abin.mallchat.common.common.annotation.RedissonLock;
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
+import com.abin.mallchat.common.common.event.ItemReceiveEvent;
import com.abin.mallchat.common.user.dao.ItemConfigDao;
import com.abin.mallchat.common.user.dao.UserBackpackDao;
import com.abin.mallchat.common.user.domain.entity.ItemConfig;
@@ -11,7 +12,10 @@ import com.abin.mallchat.common.user.domain.enums.ItemTypeEnum;
import com.abin.mallchat.common.user.service.IUserBackpackService;
import com.abin.mallchat.common.user.service.cache.ItemCache;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.event.SpringApplicationEvent;
+import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.util.Objects;
@@ -31,6 +35,8 @@ public class UserBackpackServiceImpl implements IUserBackpackService {
private ItemConfigDao itemConfigDao;
@Autowired
private ItemCache itemCache;
+ @Autowired
+ private ApplicationEventPublisher applicationEventPublisher;
@Override
@RedissonLock(key = "#uid")
@@ -56,6 +62,8 @@ public class UserBackpackServiceImpl implements IUserBackpackService {
.idempotent(idempotent)
.build();
userBackpackDao.save(insert);
+ //用户收到物品的事件
+ applicationEventPublisher.publishEvent(new ItemReceiveEvent(this, insert));
}
private String getIdempotent(Long itemId, IdempotentEnum idempotentEnum, String businessId) {
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 5e61c01..e9e22b9 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
@@ -36,11 +36,13 @@ import javax.validation.Valid;
public class ChatController {
@Autowired
private ChatService chatService;
+
@GetMapping("/public/room/page")
@ApiOperation("会话列表")
public ApiResult> getRoomPage(CursorPageBaseReq request) {
return ApiResult.success(chatService.getRoomPage(request, RequestHolder.get().getUid()));
}
+
@GetMapping("/public/member/page")
@ApiOperation("群成员列表")
public ApiResult> getMemberPage(CursorPageBaseReq request) {
@@ -61,19 +63,22 @@ public class ChatController {
@PostMapping("/msg")
@ApiOperation("发送消息")
- @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())));
+ @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) {
+ Long msgId = chatService.sendMsg(request, RequestHolder.get().getUid());
+ //返回完整消息格式,方便前展示
+ return ApiResult.success(chatService.getMsgResp(msgId, RequestHolder.get().getUid()));
}
@PutMapping("/msg/mark")
@ApiOperation("消息标记")
- @FrequencyControl(time = 20,count = 3,target = FrequencyControl.Target.UID)
+ @FrequencyControl(time = 20, count = 3, target = FrequencyControl.Target.UID)
public ApiResult setMsgMark(@Valid @RequestBody ChatMessageMarkReq request) {//分布式锁
- chatService.setMsgMark(RequestHolder.get().getUid(),request);
+ chatService.setMsgMark(RequestHolder.get().getUid(), request);
return ApiResult.success();
+
}
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/ChatService.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/ChatService.java
index ad67b41..de2080f 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/ChatService.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/ChatService.java
@@ -39,6 +39,13 @@ public interface ChatService {
* @return
*/
ChatMessageResp getMsgResp(Message message,Long receiveUid);
+ /**
+ * 根据消息获取消息前端展示的物料
+ * @param msgId
+ * @param receiveUid 接受消息的uid,可null
+ * @return
+ */
+ ChatMessageResp getMsgResp(Long msgId,Long receiveUid);
/**
* 获取群成员列表
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java
index 1838c79..fee3473 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java
@@ -6,6 +6,7 @@ import cn.hutool.core.lang.Pair;
import com.abin.mallchat.common.chat.dao.MessageDao;
import com.abin.mallchat.common.chat.dao.MessageMarkDao;
import com.abin.mallchat.common.chat.dao.RoomDao;
+import com.abin.mallchat.common.chat.domain.dto.ChatMessageMarkDTO;
import com.abin.mallchat.common.chat.domain.entity.Message;
import com.abin.mallchat.common.chat.domain.entity.MessageMark;
import com.abin.mallchat.common.chat.domain.entity.Room;
@@ -28,11 +29,12 @@ import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
import com.abin.mallchat.custom.chat.service.adapter.MemberAdapter;
import com.abin.mallchat.custom.chat.service.adapter.RoomAdapter;
import com.abin.mallchat.custom.chat.service.helper.ChatMemberHelper;
-import com.abin.mallchat.custom.common.event.MessageMarkEvent;
-import com.abin.mallchat.custom.common.event.MessageSendEvent;
+import com.abin.mallchat.common.common.event.MessageMarkEvent;
+import com.abin.mallchat.common.common.event.MessageSendEvent;
import com.abin.mallchat.custom.chat.service.ChatService;
import com.abin.mallchat.custom.chat.service.adapter.MessageAdapter;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
@@ -76,19 +78,19 @@ public class ChatServiceImpl implements ChatService {
@Transactional
public Long sendMsg(ChatMessageReq request, Long uid) {
//校验下回复消息
- Message replyMsg =null;
- if(Objects.nonNull(request.getReplyMsgId())){
+ Message replyMsg = null;
+ if (Objects.nonNull(request.getReplyMsgId())) {
replyMsg = messageDao.getById(request.getReplyMsgId());
- AssertUtil.isNotEmpty(replyMsg,"回复消息不存在");
- AssertUtil.equal(replyMsg.getRoomId(),request.getRoomId(),"只能回复相同会话内的消息");
+ AssertUtil.isNotEmpty(replyMsg, "回复消息不存在");
+ AssertUtil.equal(replyMsg.getRoomId(), request.getRoomId(), "只能回复相同会话内的消息");
}
Message insert = MessageAdapter.buildMsgSave(request, uid);
messageDao.save(insert);
//如果有回复消息
- if(Objects.nonNull(replyMsg)){
+ if (Objects.nonNull(replyMsg)) {
Integer gapCount = messageDao.getGapCount(request.getRoomId(), replyMsg.getId(), insert.getId());
- messageDao.updateGapCount(insert.getId(),gapCount);
+ messageDao.updateGapCount(insert.getId(), gapCount);
}
//发布消息发送事件
applicationEventPublisher.publishEvent(new MessageSendEvent(this, insert.getId()));
@@ -100,6 +102,12 @@ public class ChatServiceImpl implements ChatService {
return CollUtil.getFirst(getMsgRespBatch(Collections.singletonList(message), receiveUid));
}
+ @Override
+ public ChatMessageResp getMsgResp(Long msgId, Long receiveUid) {
+ Message msg = messageDao.getById(msgId);
+ return getMsgResp(msg, receiveUid);
+ }
+
@Override
public CursorPageBaseResp getMemberPage(CursorPageBaseReq request) {
Pair pair = ChatMemberHelper.getCursorPair(request.getCursor());
@@ -108,10 +116,10 @@ public class ChatServiceImpl implements ChatService {
List resultList = new ArrayList<>();//最终列表
Boolean isLast = Boolean.FALSE;
if (activeStatusEnum == ChatActiveStatusEnum.ONLINE) {//在线列表
- CursorPageBaseResp> cursorPage = userCache.getOnlineCursorPage(new CursorPageBaseReq(request.getPageSize(), timeCursor));
+ CursorPageBaseResp> cursorPage = userCache.getOnlineCursorPage(new CursorPageBaseReq(request.getPageSize(), timeCursor));
resultList.addAll(memberAdapter.buildMember(cursorPage.getList(), ChatActiveStatusEnum.ONLINE));//添加在线列表
if (cursorPage.getIsLast()) {//如果是最后一页,从离线列表再补点数据
- Integer leftSize = request.getPageSize() - cursorPage.getList().size();
+ Integer leftSize = request.getPageSize() - cursorPage.getList().size();
cursorPage = userCache.getOfflineCursorPage(new CursorPageBaseReq(leftSize, null));
resultList.addAll(memberAdapter.buildMember(cursorPage.getList(), ChatActiveStatusEnum.OFFLINE));//添加离线线列表
activeStatusEnum = ChatActiveStatusEnum.OFFLINE;
@@ -179,7 +187,9 @@ public class ChatServiceImpl implements ChatService {
.build();
messageMarkDao.save(insert);
//发布消息标记事件
- applicationEventPublisher.publishEvent(new MessageMarkEvent(this,request));
+ ChatMessageMarkDTO dto = new ChatMessageMarkDTO();
+ BeanUtils.copyProperties(request, dto);
+ applicationEventPublisher.publishEvent(new MessageMarkEvent(this, dto));
}
private Integer transformAct(Integer actType) {
@@ -207,7 +217,7 @@ public class ChatServiceImpl implements ChatService {
userMap = userCache.getUserInfoBatch(uidSet);
//查询消息标志
List msgMark = messageMarkDao.getValidMarkByMsgIdBatch(messages.stream().map(Message::getId).collect(Collectors.toList()));
- return MessageAdapter.buildMsgResp(messages, replyMap, userMap,msgMark,receiveUid);
+ return MessageAdapter.buildMsgResp(messages, replyMap, userMap, msgMark, receiveUid);
}
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/MessageMarkEvent.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/MessageMarkEvent.java
deleted file mode 100644
index 6bd4f8b..0000000
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/MessageMarkEvent.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.abin.mallchat.custom.common.event;
-
-import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
-import lombok.Getter;
-import org.springframework.context.ApplicationEvent;
-
-@Getter
-public class MessageMarkEvent extends ApplicationEvent {
- private ChatMessageMarkReq req;
-
- public MessageMarkEvent(Object source, ChatMessageMarkReq req) {
- super(source);
- this.req = req;
- }
-}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/ItemReceiveListener.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/ItemReceiveListener.java
new file mode 100644
index 0000000..eb6721e
--- /dev/null
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/ItemReceiveListener.java
@@ -0,0 +1,49 @@
+package com.abin.mallchat.custom.common.event.listener;
+
+import com.abin.mallchat.common.user.dao.UserDao;
+import com.abin.mallchat.common.user.domain.entity.ItemConfig;
+import com.abin.mallchat.common.user.domain.entity.User;
+import com.abin.mallchat.common.user.domain.entity.UserBackpack;
+import com.abin.mallchat.common.user.domain.enums.ItemTypeEnum;
+import com.abin.mallchat.common.user.service.cache.ItemCache;
+import com.abin.mallchat.common.common.event.ItemReceiveEvent;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+import java.util.Objects;
+
+/**
+ * 用户收到物品监听器
+ *
+ * @author zhongzb create on 2022/08/26
+ */
+@Slf4j
+@Component
+public class ItemReceiveListener {
+ @Autowired
+ private UserDao userDao;
+ @Autowired
+ private ItemCache itemCache;
+
+ /**
+ * 徽章类型,帮忙默认佩戴
+ *
+ * @param event
+ */
+ @Async
+ @EventListener(classes = ItemReceiveEvent.class)
+ public void wear(ItemReceiveEvent event) {
+ UserBackpack userBackpack = event.getUserBackpack();
+ ItemConfig itemConfig = itemCache.getById(userBackpack.getItemId());
+ if (ItemTypeEnum.BADGE.getType().equals(itemConfig.getType())) {
+ User user = userDao.getById(userBackpack.getUid());
+ if (Objects.isNull(user.getItemId())) {
+ userDao.wearingBadge(userBackpack.getUid(), userBackpack.getItemId());
+ }
+ }
+ }
+
+}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/MessageMarkListener.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/MessageMarkListener.java
index 96710d3..9f82034 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/MessageMarkListener.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/MessageMarkListener.java
@@ -2,14 +2,14 @@ package com.abin.mallchat.custom.common.event.listener;
import com.abin.mallchat.common.chat.dao.MessageDao;
import com.abin.mallchat.common.chat.dao.MessageMarkDao;
+import com.abin.mallchat.common.chat.domain.dto.ChatMessageMarkDTO;
import com.abin.mallchat.common.chat.domain.entity.Message;
import com.abin.mallchat.common.chat.domain.enums.MessageMarkTypeEnum;
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
import com.abin.mallchat.common.user.service.IUserBackpackService;
-import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
-import com.abin.mallchat.custom.common.event.MessageMarkEvent;
+import com.abin.mallchat.common.common.event.MessageMarkEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
@@ -36,19 +36,19 @@ public class MessageMarkListener {
@Async
@EventListener(classes = MessageMarkEvent.class)
public void changeMsgType(MessageMarkEvent event) {
- ChatMessageMarkReq req = event.getReq();
- Message msg = messageDao.getById(req.getMsgId());
+ ChatMessageMarkDTO dto = event.getDto();
+ Message msg = messageDao.getById(dto.getMsgId());
if (!Objects.equals(msg, MessageTypeEnum.NORMAL.getType())) {//普通消息才需要升级
return;
}
//消息被标记次数
- Integer markCount = messageMarkDao.getMarkCount(req.getMsgId(), req.getMarkType());
- MessageMarkTypeEnum markTypeEnum = MessageMarkTypeEnum.of(req.getMarkType());
+ Integer markCount = messageMarkDao.getMarkCount(dto.getMsgId(), dto.getMarkType());
+ MessageMarkTypeEnum markTypeEnum = MessageMarkTypeEnum.of(dto.getMarkType());
if (markCount < markTypeEnum.getRiseNum()) {
return;
}
boolean updateSuccess = messageDao.riseOptimistic(msg.getId(), msg.getType(), markTypeEnum.getRiseEnum().getType());
- if (MessageMarkTypeEnum.LIKE.getType().equals(req.getMarkType()) && updateSuccess) {//尝试给用户发送一张徽章
+ if (MessageMarkTypeEnum.LIKE.getType().equals(dto.getMarkType()) && updateSuccess) {//尝试给用户发送一张徽章
iUserBackpackService.acquireItem(msg.getFromUid(), ItemEnum.LIKE_BADGE.getId(), IdempotentEnum.MSG_ID, msg.getId().toString());
}
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/MessageSendListener.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/MessageSendListener.java
index 45fc314..ce9a803 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/MessageSendListener.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/MessageSendListener.java
@@ -3,7 +3,7 @@ package com.abin.mallchat.custom.common.event.listener;
import com.abin.mallchat.common.chat.dao.MessageDao;
import com.abin.mallchat.common.chat.domain.entity.Message;
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
-import com.abin.mallchat.custom.common.event.MessageSendEvent;
+import com.abin.mallchat.common.common.event.MessageSendEvent;
import com.abin.mallchat.custom.chat.service.ChatService;
import com.abin.mallchat.custom.user.service.WebSocketService;
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserOfflineListener.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserOfflineListener.java
index 077c5c7..d67f0c5 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserOfflineListener.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserOfflineListener.java
@@ -3,8 +3,7 @@ package com.abin.mallchat.custom.common.event.listener;
import com.abin.mallchat.common.user.dao.UserDao;
import com.abin.mallchat.common.user.domain.entity.User;
import com.abin.mallchat.common.user.service.cache.UserCache;
-import com.abin.mallchat.custom.common.event.UserOfflineEvent;
-import com.abin.mallchat.custom.common.event.UserOnlineEvent;
+import com.abin.mallchat.common.common.event.UserOfflineEvent;
import com.abin.mallchat.custom.user.service.WebSocketService;
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
import lombok.extern.slf4j.Slf4j;
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserOnlineListener.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserOnlineListener.java
index aa4469b..32ca3bb 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserOnlineListener.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserOnlineListener.java
@@ -1,15 +1,10 @@
package com.abin.mallchat.custom.common.event.listener;
-import com.abin.mallchat.common.chat.dao.MessageDao;
-import com.abin.mallchat.common.chat.domain.entity.Message;
import com.abin.mallchat.common.user.dao.UserDao;
import com.abin.mallchat.common.user.domain.entity.User;
import com.abin.mallchat.common.user.service.IpService;
import com.abin.mallchat.common.user.service.cache.UserCache;
-import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
-import com.abin.mallchat.custom.chat.service.ChatService;
-import com.abin.mallchat.custom.common.event.MessageSendEvent;
-import com.abin.mallchat.custom.common.event.UserOnlineEvent;
+import com.abin.mallchat.common.common.event.UserOnlineEvent;
import com.abin.mallchat.custom.user.service.WebSocketService;
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
import lombok.extern.slf4j.Slf4j;
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserRegisterListener.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserRegisterListener.java
index 34217ac..4f3c32c 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserRegisterListener.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/event/listener/UserRegisterListener.java
@@ -5,11 +5,8 @@ import com.abin.mallchat.common.user.dao.UserDao;
import com.abin.mallchat.common.user.domain.entity.User;
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
import com.abin.mallchat.common.user.service.IUserBackpackService;
-import com.abin.mallchat.common.user.service.cache.UserCache;
-import com.abin.mallchat.custom.common.event.UserOnlineEvent;
-import com.abin.mallchat.custom.common.event.UserRegisterEvent;
-import com.abin.mallchat.custom.user.service.WebSocketService;
-import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
+import com.abin.mallchat.common.common.event.UserOnlineEvent;
+import com.abin.mallchat.common.common.event.UserRegisterEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
@@ -24,15 +21,9 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class UserRegisterListener {
- @Autowired
- private WebSocketService webSocketService;
@Autowired
private UserDao userDao;
@Autowired
- private UserCache userCache;
- @Autowired
- private WSAdapter wsAdapter;
- @Autowired
private IUserBackpackService iUserBackpackService;
@Async
@@ -48,6 +39,11 @@ public class UserRegisterListener {
public void sendBadge(UserOnlineEvent event) {
User user = event.getUser();
int count = userDao.count();
+ if (count <= 10) {
+ iUserBackpackService.acquireItem(user.getId(), ItemEnum.REG_TOP10_BADGE.getId(), IdempotentEnum.UID, user.getId().toString());
+ } else if (count <= 100) {
+ iUserBackpackService.acquireItem(user.getId(), ItemEnum.REG_TOP100_BADGE.getId(), IdempotentEnum.UID, user.getId().toString());
+ }
}
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserServiceImpl.java
index d39dc85..b5358b3 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserServiceImpl.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserServiceImpl.java
@@ -1,6 +1,5 @@
package com.abin.mallchat.custom.user.service.impl;
-import com.abin.mallchat.common.common.domain.enums.IdempotentEnum;
import com.abin.mallchat.common.common.utils.AssertUtil;
import com.abin.mallchat.common.user.dao.ItemConfigDao;
import com.abin.mallchat.common.user.dao.UserBackpackDao;
@@ -13,7 +12,7 @@ import com.abin.mallchat.common.user.domain.enums.ItemTypeEnum;
import com.abin.mallchat.common.user.service.IUserBackpackService;
import com.abin.mallchat.common.user.service.cache.ItemCache;
import com.abin.mallchat.common.user.service.cache.UserCache;
-import com.abin.mallchat.custom.common.event.UserRegisterEvent;
+import com.abin.mallchat.common.common.event.UserRegisterEvent;
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.response.user.BadgeResp;
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 f5a2e4f..6422a94 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
@@ -6,11 +6,11 @@ import cn.hutool.json.JSONUtil;
import com.abin.mallchat.common.common.config.ThreadPoolConfig;
import com.abin.mallchat.common.user.dao.UserDao;
import com.abin.mallchat.common.user.domain.entity.User;
-import com.abin.mallchat.custom.common.event.UserOfflineEvent;
+import com.abin.mallchat.common.common.event.UserOfflineEvent;
import com.abin.mallchat.custom.user.domain.dto.ws.WSChannelExtraDTO;
import com.abin.mallchat.custom.user.domain.vo.request.ws.WSAuthorize;
import com.abin.mallchat.custom.user.domain.vo.response.ws.WSBaseResp;
-import com.abin.mallchat.custom.common.event.UserOnlineEvent;
+import com.abin.mallchat.common.common.event.UserOnlineEvent;
import com.abin.mallchat.custom.user.service.LoginService;
import com.abin.mallchat.custom.user.service.WebSocketService;
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;