diff --git a/src/main/java/club/joylink/rtss/services/voice/discriminate/VoiceDiscriminateService.java b/src/main/java/club/joylink/rtss/services/voice/discriminate/VoiceDiscriminateService.java index 65da7819b..386f2c972 100644 --- a/src/main/java/club/joylink/rtss/services/voice/discriminate/VoiceDiscriminateService.java +++ b/src/main/java/club/joylink/rtss/services/voice/discriminate/VoiceDiscriminateService.java @@ -77,26 +77,4 @@ public class VoiceDiscriminateService { replyParseService.doExec(result, simulation); // 回复执行 correctSourceService.doExec(result, simulation);// 原信息纠错 } - - /** - * 处理聊天信息 - * @param event 聊天事件信息 - */ - @EventListener - public void handleMessage(SimulationConversationGroupMessageEvent event) { - ConversationGroup conversationGroup = event.getConversationGroup(); - SimulationMember member = event.getMember(); - List memberList = conversationGroup.getMemberList().stream() - .filter(cm -> cm.isRobot() && !Objects.equals(cm.getMember(), member)) - .map(ConversationMember::getMember).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(memberList)) { // 人员全部为真实人员时直接返回 - return; - } - // 增加机器人已读操作 - memberList.forEach(m -> conversationGroupManagerService.readConversationGroup(event.getSimulation(), m, conversationGroup.getId())); - // 如果消息来源不为机器人,则执行语音识别,目前先不做语音识别回复 -// if (!event.getMessage().getMember().isRobot()) { -// doAnalysis(event.getSimulation(), conversationGroup.getId(), event.getMessage().getContent(), memberList); -// } - } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroup.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroup.java index c0294969d..1a370cdbc 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroup.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroup.java @@ -1,10 +1,8 @@ package club.joylink.rtss.simulation.cbtc.conversation; import club.joylink.rtss.simulation.cbtc.Simulation; -import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.vo.conversation.ConversationGroupVO; -import lombok.Data; import lombok.Getter; import org.springframework.util.CollectionUtils; @@ -80,9 +78,10 @@ public class ConversationGroup extends Chat { setMemberList(memberList); } - public ConversationGroup(Long id, String name, LocalDateTime time, SimulationMember leader, List simulationMembers){ + public ConversationGroup(Long id, String imageUrl, String name, LocalDateTime time, SimulationMember leader, List simulationMembers){ this.id = id; this.name = name; + this.imageUrl = imageUrl; setTime(time); setCreator(leader); int size = CollectionUtils.isEmpty(simulationMembers) ? 1 : simulationMembers.size() + 1; 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 6d7dfd4fd..2bcd4f193 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 @@ -11,16 +11,12 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.vo.AccountVO; -import club.joylink.rtss.vo.client.SocketMessageVO; -import club.joylink.rtss.vo.client.WebSocketMessageType; -import club.joylink.rtss.vo.client.factory.SocketMessageFactory; import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult; import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO; -import club.joylink.rtss.websocket.StompMessageService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -44,9 +40,6 @@ public class ConversationGroupHandlerService { @Autowired private ApplicationEventPublisher applicationEventPublisher; - @Autowired - private StompMessageService stompMessageService; - /** * 获取所有群组信息 * @param group 仿真ID @@ -68,17 +61,18 @@ public class ConversationGroupHandlerService { * * @param simulation 仿真 * @param member 用户 + * @param imageUrl 群头像 * @param name 群组名称 * @param memberIds 群组成员 */ - public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member, String name, List memberIds) { + public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member, String imageUrl, String name, List memberIds) { ConversationGroup conversationGroup = simulation.getConversationGroupByName(name); if (conversationGroup != null) { throw new SimulationException(SimulationExceptionType.Illegal_Argument, "【" + name + "】已存在"); } List simulationMembers = memberIds.stream().map(simulation::getSimulationMemberById).collect(Collectors.toList()); Long groupId = simulation.getMaxConversationGroupId(); - conversationGroup = new ConversationGroup(groupId, name, simulation.getCorrectSystemTime(), member, simulationMembers); + conversationGroup = new ConversationGroup(groupId, imageUrl, name, simulation.getCorrectSystemTime(), member, simulationMembers); simulation.addConversationGroup(conversationGroup); // 通知用户消息 applicationEventPublisher.publishEvent(new SimulationConversationGroupCreateEvent(this, simulation, conversationGroup)); @@ -90,7 +84,7 @@ public class ConversationGroupHandlerService { * * @param simulation 仿真 * @param member 用户 - * @param groupId 群组主键 + * @param id 群组主键 * @param name 群组名称 */ public void updateConversationGroupName(Simulation simulation, SimulationMember member, Long id, String name) { @@ -285,140 +279,31 @@ public class ConversationGroupHandlerService { } /** - * 处理创建群组事件 - * @param event 事件信息 + * 机器人批量已读信息 + * @param simulation 仿真 + * @param memberList 成员列表 + * @param id 用户群组ID */ - @EventListener - public void handleCreate(SimulationConversationGroupCreateEvent event) { - ConversationGroup conversationGroup = event.getConversationGroup(); - SimulationMember leader = conversationGroup.getLeader(); - ConversationGroupSocketMessageVO messageVO = ConversationGroupSocketMessageVO.MessageType.JOIN.generateMessageVO(conversationGroup, null); - if (!leader.isRobot()) { - doSendMessage(event.getSimulation(), Set.of(leader.getUserId()), messageVO); - } - Set userIds = conversationGroup.getMemberUserIdWithOutLeader(); - if (CollectionUtils.isEmpty(userIds)) { + 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; } - // 给非群主的群人员发送消息、添加tips信息 - messageVO.setMessageTips(String.format("你加入了【%s】", conversationGroup.getName())); - doSendMessage(event.getSimulation(), userIds, messageVO); - } - - /** - * 处理更新群组信息事件 - * @param event 事件信息 - */ - @EventListener - public void handleUpdate(SimulationConversationGroupUpdateEvent event) { - ConversationGroup conversationGroup = event.getConversationGroup(); - Set userIds = conversationGroup.getMemberUserId(); - if (CollectionUtils.isEmpty(userIds)) { - return; - } - ConversationGroupSocketMessageVO messageVO = event.getMessageType().generateMessageVO(conversationGroup, null); - doSendMessage(event.getSimulation(), userIds, messageVO); - } - - /** - * 处理邀请成员事件 - * @param event 事件信息 - */ - @EventListener - public void handleInvite(SimulationConversationGroupInviteEvent event) { - ConversationGroup conversationGroup = event.getConversationGroup(); - Set newUserIdSet = new HashSet<>(); // 发送加入信息的用户列表 - StringBuilder stringBuilder = new StringBuilder(); - event.getNewMemberList().forEach(m -> { - if (!m.isRobot()) { - newUserIdSet.add(m.getUserId()); + // 获取到所有没有读取的消息 + 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(); } - stringBuilder.append(m.getName()).append("、"); - }); - // 通知新成员 - if (!CollectionUtils.isEmpty(newUserIdSet)) { - ConversationGroupSocketMessageVO joinMessageVO = ConversationGroupSocketMessageVO.MessageType.JOIN.generateMessageVO(conversationGroup, null); - // 添加tips信息 - joinMessageVO.setMessageTips(String.format("你加入了【%s】", conversationGroup.getName())); - doSendMessage(event.getSimulation(), newUserIdSet, joinMessageVO); - } - Set oldUserIdSet = conversationGroup.getMemberUserId(event.getGroupMemberIds()); - // 通知老成员 - if (!CollectionUtils.isEmpty(oldUserIdSet)) { - ConversationGroupSocketMessageVO updateMessageVO = ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER.generateMessageVO(conversationGroup, null); - updateMessageVO.setMessageTips("欢迎【" + stringBuilder.substring(0, stringBuilder.length() - 1) + "】加入本群"); - doSendMessage(event.getSimulation(), conversationGroup.getMemberUserId(event.getGroupMemberIds()), updateMessageVO); - } - } - - /** - * 群组移除人员事件 - * - * @param event 事件信息 - */ - @EventListener - public void handleRemove(SimulationConversationGroupRemoveEvent event) { - ConversationGroup conversationGroup = event.getConversationGroup(); - Set removeUserIdSet = event.getRemoveGroupMember().stream().filter(m -> !m.isRobot()).map(SimulationMember::getUserId).collect(Collectors.toSet()); - // 通知移除 - if (!CollectionUtils.isEmpty(removeUserIdSet)) { - ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null); - // 添加tips信息 - exitMessageVO.setMessageTips(String.format("你被移出了【%s】", conversationGroup.getName())); - doSendMessage(event.getSimulation(), removeUserIdSet, exitMessageVO); - } - // 更新其他用户的成员列表 - Set userIdSet = conversationGroup.getMemberUserId(); - if (CollectionUtils.isEmpty(userIdSet)) { - return; - } - ConversationGroupSocketMessageVO updateMessageVO = ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER.generateMessageVO(conversationGroup, null); - doSendMessage(event.getSimulation(), userIdSet, updateMessageVO); - } - - /** - * 处理退出群组事件 - * @param event 事件信息 - */ - @EventListener - public void handleExit(SimulationConversationGroupExitEvent event) { - if (event.getMember().isRobot()) { - return; - } - ConversationGroup conversationGroup = event.getConversationGroup(); - ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null); - doSendMessage(event.getSimulation(), Set.of(event.getMember().getUserId()), exitMessageVO); - } - - /** - * 解散群主事件 - * @param event 事件信息 - */ - @EventListener - public void handleDissolve(SimulationConversationGroupDissolveEvent event) { - ConversationGroup conversationGroup = event.getConversationGroup(); - // 更新其他用户的成员列表 - Set userIdSet = conversationGroup.getMemberUserId(); - if (CollectionUtils.isEmpty(userIdSet)) { - return; - } - ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null); - exitMessageVO.setMessageTips(String.format("【%s】解散了", conversationGroup.getName())); - doSendMessage(event.getSimulation(), userIdSet, exitMessageVO); - } - - /** - * 处理消息状态 - * @param event - */ - @EventListener - public void handleMessageStatus(SimulationConversationGroupMessageStatusEvent event) { - ConversationGroup conversationGroup = event.getConversationGroup(); - event.getMessageList().stream().filter(m -> !m.getMember().isRobot()).forEach(message -> { - ConversationGroupSocketMessageVO messageStatusVO - = ConversationGroupSocketMessageVO.MessageType.MESSAGE_STATUS.generateMessageVO(conversationGroup, new ConversationGroupMessageVO(message)); - doSendMessage(event.getSimulation(), Set.of(message.getMember().getUserId()), messageStatusVO); }); + applicationEventPublisher.publishEvent(new SimulationConversationGroupMessageStatusEvent(this, simulation, conversationGroup, messageList)); } /** @@ -455,38 +340,16 @@ public class ConversationGroupHandlerService { throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员"); } VoiceRecognitionResult recognitionResult = handleSupplier.get(); - String upperCaseResult = recognitionResult.getResult().toUpperCase(); - String handledContent = simulationVoiceHandler.handle(upperCaseResult); + // 对语音信息进行消息文字处理 + String handledContent = StringUtils.isNotEmpty(recognitionResult.getFilePath()) ? + simulationVoiceHandler.handle(recognitionResult.getResult().toUpperCase()) : recognitionResult.getResult(); // 创建消息信息 String messageId = conversationGroup.generateMessageId(); ConversationGroupMessage message = new ConversationGroupMessage(messageId, member, simulation.getCorrectSystemTime(), handledContent, recognitionResult.getFilePath()); conversationGroup.addMessage(message); - // 发送消息 - ConversationGroupMessageVO messageVO = new ConversationGroupMessageVO(message); - Set userIdSet = conversationGroup.getMemberUserId(); - if (!CollectionUtils.isEmpty(userIdSet)) { - doSendMessage(simulation, userIdSet, ConversationGroupSocketMessageVO.MessageType.MESSAGE.generateMessageVO(conversationGroup, messageVO)); - } // 语音识别开始 - applicationEventPublisher.publishEvent(new SimulationConversationGroupMessageEvent(this, simulation, conversationGroup, member, message)); - return messageVO; + applicationEventPublisher.publishEvent(new SimulationConversationGroupMessageEvent(this, simulation, conversationGroup, message)); + return new ConversationGroupMessageVO(message); } - - /** - * 发送消息 - * - * @param simulation 仿真 - * @param userSet 用户列表 - * @param messageVO 消息体 - */ - private void doSendMessage(Simulation simulation, Set userSet, ConversationGroupSocketMessageVO messageVO) { - if (CollectionUtils.isEmpty(userSet)) { - return; - } - SocketMessageVO chatMessage = - SocketMessageFactory.build(WebSocketMessageType.Simulation_Conversation_Group, simulation.getId(), messageVO); - stompMessageService.sendToUser(userSet, chatMessage); - } - } 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 new file mode 100644 index 000000000..56675fdb4 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java @@ -0,0 +1,218 @@ +package club.joylink.rtss.simulation.cbtc.conversation; + +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO; +import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupSocketMessageVO; +import club.joylink.rtss.simulation.cbtc.event.conversation.*; +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; +import club.joylink.rtss.vo.client.SocketMessageVO; +import club.joylink.rtss.vo.client.WebSocketMessageType; +import club.joylink.rtss.vo.client.factory.SocketMessageFactory; +import club.joylink.rtss.websocket.StompMessageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * 用户群组事件监听器 + */ +@Component +public class ConversationGroupListener { + + @Autowired + private StompMessageService stompMessageService; + + @Autowired + private ConversationGroupHandlerService conversationGroupHandlerService; + + /** + * 处理创建群组事件 + * @param event 事件信息 + */ + @EventListener + public void handleCreate(SimulationConversationGroupCreateEvent event) { + ConversationGroup conversationGroup = event.getConversationGroup(); + SimulationMember leader = conversationGroup.getLeader(); + ConversationGroupSocketMessageVO messageVO = ConversationGroupSocketMessageVO.MessageType.JOIN.generateMessageVO(conversationGroup, null); + if (!leader.isRobot()) { + doSendMessage(event.getSimulation(), Set.of(leader.getUserId()), messageVO); + } + Set userIds = conversationGroup.getMemberUserIdWithOutLeader(); + if (CollectionUtils.isEmpty(userIds)) { + return; + } + // 给非群主的群人员发送消息、添加tips信息 + messageVO.setMessageTips(String.format("你加入了【%s】", conversationGroup.getName())); + doSendMessage(event.getSimulation(), userIds, messageVO); + } + + /** + * 处理更新群组信息事件 + * @param event 事件信息 + */ + @EventListener + public void handleUpdate(SimulationConversationGroupUpdateEvent event) { + ConversationGroup conversationGroup = event.getConversationGroup(); + Set userIds = conversationGroup.getMemberUserId(); + if (CollectionUtils.isEmpty(userIds)) { + return; + } + ConversationGroupSocketMessageVO messageVO = event.getMessageType().generateMessageVO(conversationGroup, null); + doSendMessage(event.getSimulation(), userIds, messageVO); + } + + /** + * 处理邀请成员事件 + * @param event 事件信息 + */ + @EventListener + public void handleInvite(SimulationConversationGroupInviteEvent event) { + ConversationGroup conversationGroup = event.getConversationGroup(); + Set newUserIdSet = new HashSet<>(); // 发送加入信息的用户列表 + StringBuilder stringBuilder = new StringBuilder(); + event.getNewMemberList().forEach(m -> { + if (!m.isRobot()) { + newUserIdSet.add(m.getUserId()); + } + stringBuilder.append(m.getMemberName()).append("、"); + }); + // 通知新成员 + if (!CollectionUtils.isEmpty(newUserIdSet)) { + ConversationGroupSocketMessageVO joinMessageVO = ConversationGroupSocketMessageVO.MessageType.JOIN.generateMessageVO(conversationGroup, null); + // 添加tips信息 + joinMessageVO.setMessageTips(String.format("你加入了【%s】", conversationGroup.getName())); + doSendMessage(event.getSimulation(), newUserIdSet, joinMessageVO); + } + Set oldUserIdSet = conversationGroup.getMemberUserId(event.getGroupMemberIds()); + // 通知老成员 + if (!CollectionUtils.isEmpty(oldUserIdSet)) { + ConversationGroupSocketMessageVO updateMessageVO = ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER.generateMessageVO(conversationGroup, null); + updateMessageVO.setMessageTips("欢迎【" + stringBuilder.substring(0, stringBuilder.length() - 1) + "】加入本群"); + doSendMessage(event.getSimulation(), conversationGroup.getMemberUserId(event.getGroupMemberIds()), updateMessageVO); + } + } + + /** + * 群组移除人员事件 + * + * @param event 事件信息 + */ + @EventListener + public void handleRemove(SimulationConversationGroupRemoveEvent event) { + ConversationGroup conversationGroup = event.getConversationGroup(); + Set removeUserIdSet = event.getRemoveGroupMember().stream().filter(m -> !m.isRobot()).map(SimulationMember::getUserId).collect(Collectors.toSet()); + // 通知移除 + if (!CollectionUtils.isEmpty(removeUserIdSet)) { + ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null); + // 添加tips信息 + exitMessageVO.setMessageTips(String.format("你被移出了【%s】", conversationGroup.getName())); + doSendMessage(event.getSimulation(), removeUserIdSet, exitMessageVO); + } + // 更新其他用户的成员列表 + Set userIdSet = conversationGroup.getMemberUserId(); + if (CollectionUtils.isEmpty(userIdSet)) { + return; + } + ConversationGroupSocketMessageVO updateMessageVO = ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER.generateMessageVO(conversationGroup, null); + doSendMessage(event.getSimulation(), userIdSet, updateMessageVO); + } + + /** + * 处理退出群组事件 + * @param event 事件信息 + */ + @EventListener + public void handleExit(SimulationConversationGroupExitEvent event) { + if (event.getMember().isRobot()) { + return; + } + ConversationGroup conversationGroup = event.getConversationGroup(); + ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null); + doSendMessage(event.getSimulation(), Set.of(event.getMember().getUserId()), exitMessageVO); + } + + /** + * 解散群主事件 + * @param event 事件信息 + */ + @EventListener + public void handleDissolve(SimulationConversationGroupDissolveEvent event) { + ConversationGroup conversationGroup = event.getConversationGroup(); + // 更新其他用户的成员列表 + Set userIdSet = conversationGroup.getMemberUserId(); + if (CollectionUtils.isEmpty(userIdSet)) { + return; + } + ConversationGroupSocketMessageVO exitMessageVO = ConversationGroupSocketMessageVO.MessageType.EXIT.generateMessageVO(conversationGroup, null); + exitMessageVO.setMessageTips(String.format("【%s】解散了", conversationGroup.getName())); + doSendMessage(event.getSimulation(), userIdSet, exitMessageVO); + } + + /** + * 处理消息状态 + * @param event + */ + @EventListener + public void handleMessageStatus(SimulationConversationGroupMessageStatusEvent event) { + ConversationGroup conversationGroup = event.getConversationGroup(); + event.getMessageList().stream().filter(m -> !m.getMember().isRobot()).forEach(message -> { + ConversationGroupSocketMessageVO messageStatusVO + = ConversationGroupSocketMessageVO.MessageType.MESSAGE_STATUS.generateMessageVO(conversationGroup, new ConversationGroupMessageVO(message)); + doSendMessage(event.getSimulation(), Set.of(message.getMember().getUserId()), messageStatusVO); + }); + } + + /** + * 处理聊天信息 + * @param event 聊天事件信息 + */ + @EventListener + public void handleMessage(SimulationConversationGroupMessageEvent event) { + Simulation simulation = event.getSimulation(); + ConversationGroup conversationGroup = event.getConversationGroup(); + ConversationGroupMessage message = event.getMessage(); + // 发送消息 + ConversationGroupMessageVO messageVO = new ConversationGroupMessageVO(message); + Set userIdSet = conversationGroup.getMemberUserId(); + if (!CollectionUtils.isEmpty(userIdSet)) { + doSendMessage(simulation, userIdSet, ConversationGroupSocketMessageVO.MessageType.MESSAGE.generateMessageVO(conversationGroup, messageVO)); + } + // 发送人员 + SimulationMember member = message.getMember(); + List memberList = conversationGroup.getMemberList().stream() + .filter(cm -> cm.isRobot() && !Objects.equals(cm.getMember(), member)) + .map(ConversationMember::getMember).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(memberList)) { // 人员全部为真实人员时直接返回 + return; + } + // 增加机器人已读操作(批量操作) + conversationGroupHandlerService.robotBatchRead(simulation, memberList, conversationGroup.getId()); + // 如果消息来源不为机器人,则执行语音识别,目前先不做语音识别回复 +// if (!event.getMessage().getMember().isRobot()) { +// VoiceDiscriminateService.doAnalysis(event.getSimulation(), conversationGroup.getId(), event.getMessage().getContent(), memberList); +// } + } + + /** + * 发送消息 + * + * @param simulation 仿真 + * @param userSet 用户列表 + * @param messageVO 消息体 + */ + private void doSendMessage(Simulation simulation, Set userSet, ConversationGroupSocketMessageVO messageVO) { + if (CollectionUtils.isEmpty(userSet)) { + return; + } + SocketMessageVO chatMessage = + SocketMessageFactory.build(WebSocketMessageType.Simulation_Conversation_Group, simulation.getId(), messageVO); + stompMessageService.sendToUser(userSet, chatMessage); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java index 98f4a7c0a..0410ffca8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java @@ -2,11 +2,9 @@ package club.joylink.rtss.simulation.cbtc.conversation; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import lombok.Getter; -import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.util.HashSet; -import java.util.List; import java.util.Set; /** diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupOperateHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupOperateHandler.java index 85ee6d288..0eb07f917 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupOperateHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupOperateHandler.java @@ -25,12 +25,13 @@ public class ConversationGroupOperateHandler { * 创建群组信息 * @param simulation 仿真 * @param member 创建人 - * @param name - * @param memberIds + * @param imageUrl 群图像 + * @param name 群名称 + * @param memberIds 群成员 */ @OperateHandlerMapping(type = Operation.Type.Conversation_Group_Create) - public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member, String name, List memberIds) { - return conversationGroupManagerService.createConversationGroup(simulation, member, name, memberIds); + public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member, String imageUrl, String name, List memberIds) { + return conversationGroupManagerService.createConversationGroup(simulation, member, imageUrl, name, memberIds); } /** diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/event/conversation/SimulationConversationGroupMessageEvent.java b/src/main/java/club/joylink/rtss/simulation/cbtc/event/conversation/SimulationConversationGroupMessageEvent.java index 80c4b158f..fa15465bb 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/event/conversation/SimulationConversationGroupMessageEvent.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/event/conversation/SimulationConversationGroupMessageEvent.java @@ -18,21 +18,15 @@ public class SimulationConversationGroupMessageEvent extends AbstractSimulationE */ private ConversationGroup conversationGroup; - /** - * 操作用户 - */ - private SimulationMember member; - /** * 消息内容 */ private ConversationGroupMessage message; public SimulationConversationGroupMessageEvent(Object source, Simulation simulation, ConversationGroup conversationGroup - , SimulationMember member, ConversationGroupMessage message) { + , ConversationGroupMessage message) { super(source, simulation); this.conversationGroup = conversationGroup; - this.member = member; this.message = message; } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/member/MemberManager.java b/src/main/java/club/joylink/rtss/simulation/cbtc/member/MemberManager.java index 5ce3f7ea0..f2cb66171 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/member/MemberManager.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/member/MemberManager.java @@ -92,6 +92,9 @@ public class MemberManager { // this.addRole(simulation, SimulationMember.Type.SCHEDULING); // 车务段段长 this.addRole(simulation, SimulationMember.Type.TRAIN_MASTER); + // NCC调度员 + this.addRole(simulation, SimulationMember.Type.NCC_DISPATCHER); + } /** diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/member/SimulationMember.java b/src/main/java/club/joylink/rtss/simulation/cbtc/member/SimulationMember.java index 01e293240..f61584315 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/member/SimulationMember.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/member/SimulationMember.java @@ -6,6 +6,7 @@ import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement; import club.joylink.rtss.simulation.vo.SimulationMemberVO; import lombok.Getter; import lombok.Setter; +import org.apache.commons.lang3.StringUtils; import javax.validation.constraints.NotNull; import java.util.Objects; @@ -120,6 +121,20 @@ public class SimulationMember extends club.joylink.rtss.simulation.SimulationMem return String.format("仿真成员[%s][%s][%s]", getId(), getType(), getName()); } + public String getMemberName() { + if (StringUtils.isNotEmpty(this.name)) { + return this.name; + } + StringBuilder memberName = new StringBuilder(); + if (device instanceof MapNamedElement) { + memberName.append(((MapNamedElement) device).getName()); + } + if (this.type != null) { + memberName.append(this.type.getDescription()); + } + return memberName.toString(); + } + @Override public String toString() { String deviceInfo = null; @@ -155,95 +170,103 @@ public class SimulationMember extends club.joylink.rtss.simulation.SimulationMem int TRAIN = 3; /** 大铁车务段 */ int TRAIN_DEPOT = 4; + /** */ + int NCC = 5; } /** * 仿真成员岗位 */ + @Getter public enum Type { /** * 值班主任 */ - SHIFT_MANAGER(Area.OCC), + SHIFT_MANAGER(Area.OCC, "值班主任"), /** * 中心调度员 */ - DISPATCHER(Area.OCC), + DISPATCHER(Area.OCC, "值班主任"), /** * 电力调度 */ - ELECTRIC_DISPATCHER(Area.OCC), + ELECTRIC_DISPATCHER(Area.OCC, "电力调度"), /** * 环控调度 */ - ENVIRONMENT_DISPATCHER(Area.OCC), + ENVIRONMENT_DISPATCHER(Area.OCC, "环控调度"), /** * 车辆段调度 */ - DEPOT_DISPATCHER(Area.VEHICLE_DEPOT), + DEPOT_DISPATCHER(Area.VEHICLE_DEPOT, "车辆段调度"), /** * 车站值班员 */ - STATION_SUPERVISOR(Area.STATION), + STATION_SUPERVISOR(Area.STATION, "车站值班员"), /** * 司机 */ - DRIVER(Area.TRAIN), + DRIVER(Area.TRAIN, "司机"), /** * 通号 */ - MAINTAINER(Area.STATION), + MAINTAINER(Area.STATION, "通号"), /** * 车辆段/停车场信号楼 */ - SIGNAL_BUILDING(Area.VEHICLE_DEPOT), + SIGNAL_BUILDING(Area.VEHICLE_DEPOT, "车辆段/停车场信号楼"), /** * 上级部门 */ @Deprecated(since = "2022-10-17", forRemoval = true) - PARENT_DEPARTMENT(Area.OCC), + PARENT_DEPARTMENT(Area.OCC, "上级部门"), /** * 派班员 */ @Deprecated(since = "2022-10-17", forRemoval = true) - SCHEDULING(Area.OCC), - - + SCHEDULING(Area.OCC, "派班员"), /** * 车务段段长 */ - TRAIN_MASTER(Area.TRAIN_DEPOT), + TRAIN_MASTER(Area.TRAIN_DEPOT, "车务段段长"), /** * 车站助理 */ - STATION_ASSISTANT(Area.STATION), - /*** 车站站长 */ - STATION_MASTER(Area.STATION), + STATION_ASSISTANT(Area.STATION, "车站助理"), + /** + * 车站站长 + * */ + STATION_MASTER(Area.STATION, "车站站长"), /** * 车站信号员 */ - STATION_SIGNALER(Area.STATION), + STATION_SIGNALER(Area.STATION, "车站信号员"), /** * 车站客运员 */ - STATION_PASSENGER(Area.STATION), + STATION_PASSENGER(Area.STATION, "车站客运员"), /** 车站扳道员 */ - STATION_SWITCH_MAN(Area.STATION), + STATION_SWITCH_MAN(Area.STATION, "车站扳道员"), /** 车站引导员 */ - STATION_FACILITATOR(Area.STATION), + STATION_FACILITATOR(Area.STATION, "车站引导员"), /** 车站工务工*/ - STATION_WORKER(Area.STATION), + STATION_WORKER(Area.STATION, "车站工务工"), /** 设备管理员 */ - DEVICE_MANAGER(Area.STATION), + DEVICE_MANAGER(Area.STATION, "设备管理员"), /** * 电力工务 */ - STATION_ELECTRIC_WORKER(Area.STATION); + STATION_ELECTRIC_WORKER(Area.STATION, "电力工务"), + + NCC_DISPATCHER(Area.NCC, "NCC调度员"); private final int area; - Type(int area) { + private final String description; + + Type(int area, String description) { this.area = area; + this.description = description; } }