diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java index afba7c0dd..c1c108900 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java @@ -282,6 +282,34 @@ public class ConversationGroupHandlerService { return ConversationGroupMessageVO.convert2VO(messageList); } + /** + * 机器人批量已读信息 + * @param simulation 仿真 + * @param memberList 成员列表 + * @param id 用户群组ID + */ + public void robotBatchRead(Simulation simulation, List memberList, Long id) { + // 查找群组 + ConversationGroup conversationGroup = simulation.getConversationGroup(id); + Set robotMemberIds = memberList.stream().map(SimulationMember::getId).collect(Collectors.toSet()); + Set allMemberIds = conversationGroup.getMemberList().stream().map(m -> m.getMember().getId()).collect(Collectors.toSet()); + // 是否全部是群成员 + if (!allMemberIds.containsAll(robotMemberIds)) { + return; + } + // 获取到所有没有读取的消息 + List messageList = conversationGroup.getMessageList().stream() + .filter(m -> !m.isAllRead()).collect(Collectors.toList()); + messageList.forEach(message -> { + message.getReaderSet().addAll(robotMemberIds); + if (allMemberIds.stream().filter(mid -> !Objects.equals(message.getMember().getId(), mid)) + .allMatch(mid -> message.getReaderSet().contains(mid))) { // 除发送用户外全部已读 + message.finishRead(); + } + }); + applicationEventPublisher.publishEvent(new SimulationConversationGroupMessageStatusEvent(this, simulation, conversationGroup, messageList)); + } + /** * 对群组操作时基础判断 * diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java index e53aec4e8..56675fdb4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java @@ -192,8 +192,8 @@ public class ConversationGroupListener { if (CollectionUtils.isEmpty(memberList)) { // 人员全部为真实人员时直接返回 return; } - // 增加机器人已读操作 - memberList.forEach(m -> conversationGroupHandlerService.readConversationGroup(simulation, m, conversationGroup.getId())); + // 增加机器人已读操作(批量操作) + conversationGroupHandlerService.robotBatchRead(simulation, memberList, conversationGroup.getId()); // 如果消息来源不为机器人,则执行语音识别,目前先不做语音识别回复 // if (!event.getMessage().getMember().isRobot()) { // VoiceDiscriminateService.doAnalysis(event.getSimulation(), conversationGroup.getId(), event.getMessage().getContent(), memberList);