From e891167b6b774f7a69707315d72de02008557d59 Mon Sep 17 00:00:00 2001 From: zhongzb <972627721@qq.com> Date: Mon, 2 Oct 2023 15:28:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=9B=86=E7=BE=A4=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/common/domain/dto/PushMessageDTO.java | 12 ++++++++++-- .../mallchat/common/user/consumer/PushConsumer.java | 4 +++- .../common/user/service/impl/PushService.java | 4 +--- .../src/main/resources/application.yml | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/domain/dto/PushMessageDTO.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/domain/dto/PushMessageDTO.java index 06eeb90..cacf23a 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/domain/dto/PushMessageDTO.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/domain/dto/PushMessageDTO.java @@ -7,6 +7,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; +import java.util.Collections; +import java.util.List; /** * Description: 推送给用户的消息对象 @@ -24,7 +26,7 @@ public class PushMessageDTO implements Serializable { /** * 推送的uid */ - private Long uid; + private List uidList; /** * 推送类型 1个人 2全员 @@ -34,7 +36,13 @@ public class PushMessageDTO implements Serializable { private Integer pushType; public PushMessageDTO(Long uid, WSBaseResp wsBaseMsg) { - this.uid = uid; + this.uidList = Collections.singletonList(uid); + this.wsBaseMsg = wsBaseMsg; + this.pushType = WSPushTypeEnum.USER.getType(); + } + + public PushMessageDTO(List uidList, WSBaseResp wsBaseMsg) { + this.uidList = uidList; this.wsBaseMsg = wsBaseMsg; this.pushType = WSPushTypeEnum.USER.getType(); } diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/consumer/PushConsumer.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/consumer/PushConsumer.java index cff6fb5..e99ff20 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/consumer/PushConsumer.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/consumer/PushConsumer.java @@ -26,7 +26,9 @@ public class PushConsumer implements RocketMQListener { WSPushTypeEnum wsPushTypeEnum = WSPushTypeEnum.of(message.getPushType()); switch (wsPushTypeEnum) { case USER: - webSocketService.sendToUid(message.getWsBaseMsg(), message.getUid()); + message.getUidList().forEach(uid -> { + webSocketService.sendToUid(message.getWsBaseMsg(), uid); + }); break; case ALL: webSocketService.sendToAllOnline(message.getWsBaseMsg(), null); diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/service/impl/PushService.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/service/impl/PushService.java index 0eed34e..896b4e0 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/service/impl/PushService.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/user/service/impl/PushService.java @@ -20,9 +20,7 @@ public class PushService { private MQProducer mqProducer; public void sendPushMsg(WSBaseResp msg, List uidList) { - uidList.parallelStream().forEach(uid -> { - mqProducer.sendMsg(MQConstant.PUSH_TOPIC, new PushMessageDTO(uid, msg)); - }); + mqProducer.sendMsg(MQConstant.PUSH_TOPIC, new PushMessageDTO(uidList, msg)); } public void sendPushMsg(WSBaseResp msg, Long uid) { diff --git a/mallchat-chat-server/src/main/resources/application.yml b/mallchat-chat-server/src/main/resources/application.yml index ee78bd5..88a3e29 100644 --- a/mallchat-chat-server/src/main/resources/application.yml +++ b/mallchat-chat-server/src/main/resources/application.yml @@ -11,7 +11,7 @@ mybatis-plus: spring: profiles: #运行的环境 - active: my-prod + active: my-test application: name: mallchat datasource: