【群组发送消息】

This commit is contained in:
weizhihong 2023-04-17 16:58:12 +08:00
parent c88ae2b17b
commit 1eb4e2c6cf

View File

@ -210,13 +210,12 @@ public class ConversationGroupHandlerService {
* @return 消息信息实体
*/
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long groupId, String audioPath, String content) {
ConversationGroupMessage message = sendMessage(simulation, member, groupId, () -> {
return sendMessage(simulation, member, groupId, () -> {
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
recognitionResult.setFilePath(audioPath);
recognitionResult.setResult(content);
return recognitionResult;
});
return new ConversationGroupMessageVO(message);
}
/**
@ -229,12 +228,11 @@ public class ConversationGroupHandlerService {
* @return 消息信息实体
*/
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long groupId, String content) {
ConversationGroupMessage message = sendMessage(simulation, member, groupId, () -> {
return sendMessage(simulation, member, groupId, () -> {
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
recognitionResult.setResult(content);
return recognitionResult;
});
return new ConversationGroupMessageVO(message);
}
/**
@ -246,11 +244,10 @@ public class ConversationGroupHandlerService {
* @return 消息信息实体
*/
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) {
ConversationGroupMessage message = sendMessage(simulation, member, groupId, () -> {
return sendMessage(simulation, member, groupId, () -> {
VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str);
return iVoiceService.voiceRecognition(vo);
});
return new ConversationGroupMessageVO(message);
}
/**
@ -428,27 +425,27 @@ public class ConversationGroupHandlerService {
* @param handleSupplier 处理消息方法
* @return 用户组消息
*/
private ConversationGroupMessage sendMessage(Simulation simulation, SimulationMember member, Long groupId
private ConversationGroupMessageVO sendMessage(Simulation simulation, SimulationMember member, Long groupId
, Supplier<VoiceRecognitionResult> handleSupplier) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, groupId);
if (!conversationGroup.isConversationMember(member)) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员,不能邀请用户");
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员");
}
VoiceRecognitionResult recognitionResult = handleSupplier.get();
String upperCaseResult = recognitionResult.getResult().toUpperCase();
String handledContent = simulationVoiceHandler.handle(upperCaseResult);
// 创建消息信息
String messageId = conversationGroup.generateMessageId();
ConversationGroupMessage message = new ConversationGroupMessage(messageId, member,
simulation.getCorrectSystemTime(), handledContent, recognitionResult.getFilePath());
conversationGroup.addMessage(message);
// 发送消息
return message;
ConversationGroupMessageVO messageVO = new ConversationGroupMessageVO(message);
Set<String> userIdSet = conversationGroup.getMemberUserId();
if (!CollectionUtils.isEmpty(userIdSet)) {
doSendMessage(simulation, userIdSet, ConversationGroupSocketMessageVO.MessageType.MESSAGE.generateMessageVO(conversationGroup, messageVO));
}
return messageVO;
}
/**