场景实训中非用户的文字聊天操作会被替换为语音聊天,且车次号会被替换为专业发音
This commit is contained in:
parent
5eac7cc9be
commit
6b14090431
|
@ -6,9 +6,11 @@ import club.joylink.rtss.entity.training2.DraftTraining2WithBLOBs;
|
|||
import club.joylink.rtss.entity.training2.PublishedTraining2WithBLOBs;
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.services.training2.index.IndexAlgorithmService;
|
||||
import club.joylink.rtss.services.voice.VoiceService;
|
||||
import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher;
|
||||
import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher;
|
||||
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
|
||||
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation.Type;
|
||||
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
|
||||
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
|
@ -28,6 +30,7 @@ import club.joylink.rtss.simulation.cbtc.member.MemberManager;
|
|||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||
import club.joylink.rtss.simulation.cbtc.script.ScriptBO;
|
||||
import club.joylink.rtss.simulation.cbtc.training2.Operation2;
|
||||
import club.joylink.rtss.simulation.cbtc.training2.Operation2.SimCommand2;
|
||||
import club.joylink.rtss.simulation.cbtc.training2.Step2;
|
||||
import club.joylink.rtss.simulation.cbtc.training2.Training2;
|
||||
import club.joylink.rtss.simulation.cbtc.training2.index.Index;
|
||||
|
@ -38,6 +41,8 @@ import club.joylink.rtss.vo.LoginUserInfoVO;
|
|||
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.BaseVoiceSynthesisVO;
|
||||
import club.joylink.rtss.vo.client.voice.VoiceCompose;
|
||||
import club.joylink.rtss.vo.paper.PaperTrainAnswerDetail;
|
||||
import club.joylink.rtss.websocket.StompMessageService;
|
||||
import java.util.Arrays;
|
||||
|
@ -49,6 +54,8 @@ import java.util.Set;
|
|||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -79,7 +86,8 @@ public class Training2Service {
|
|||
Operation.Type.Conversation_Group_Text_Chat.name(),
|
||||
Operation.Type.Conversation_Group_Audio_Base64.name(),
|
||||
Operation.Type.Conversation_Group_Private_Text_Chat.name(),
|
||||
Operation.Type.Conversation_Group_Private_Audio_Base64.name()
|
||||
Operation.Type.Conversation_Group_Private_Audio_Base64.name(),
|
||||
Type.Conversation_Group_Private_Audio_Chat.name()
|
||||
);
|
||||
|
||||
private static final List<String> CONVERSATION_TEXT_LIST = Arrays.asList(
|
||||
|
@ -129,6 +137,8 @@ public class Training2Service {
|
|||
|
||||
@Autowired
|
||||
private SimulationService simulationService;
|
||||
@Autowired
|
||||
private VoiceService voiceService;
|
||||
|
||||
/**
|
||||
* 完成步骤接口信号量
|
||||
|
@ -744,32 +754,97 @@ public class Training2Service {
|
|||
return simCommand2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试操作动作
|
||||
*/
|
||||
private boolean tryDoOperation(Simulation simulation, Step2 step, Operation2.SimCommand2 operation2) {
|
||||
boolean isRobot = step.getSimulationMember().isRobot(); // 角色是否是机器人
|
||||
long simCurTime = simulation.getCorrectSystemTimeStamp();
|
||||
// 未操作过
|
||||
if (Step2.StepStatus.isUndo(operation2.getStatus())) {
|
||||
boolean isExec = true; // 是否要执行
|
||||
if (operation2.getSimTime() != null && simulation.getTraining2().isScene()) {
|
||||
isExec = (simCurTime == operation2.getSimTime() || operation2.getSimTime() < simCurTime);
|
||||
}
|
||||
if (isExec) {
|
||||
if (isRobot || operation2.isSpecial() || simulation.getTraining2().isJumpStep(step)) { // 特殊操作直接执行
|
||||
atsOperationDispatcher.execute(simulation, step.getSimulationMember(), operation2.getOperationType().name()
|
||||
, operation2.getParams());
|
||||
return true;
|
||||
} else { // 非机器人,暂停仿真等待用户操作
|
||||
simulation.onlyPause();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 尝试操作动作
|
||||
*/
|
||||
private boolean tryDoOperation(Simulation simulation, Step2 step,
|
||||
Operation2.SimCommand2 operation2) {
|
||||
boolean isRobot = step.getSimulationMember().isRobot(); // 角色是否是机器人
|
||||
long simCurTime = simulation.getCorrectSystemTimeStamp();
|
||||
// 未操作过
|
||||
if (Step2.StepStatus.isUndo(operation2.getStatus())) {
|
||||
boolean isExec = true; // 是否要执行
|
||||
if (operation2.getSimTime() != null && simulation.getTraining2().isScene()) {
|
||||
isExec = (simCurTime == operation2.getSimTime() || operation2.getSimTime() < simCurTime);
|
||||
}
|
||||
if (isExec) {
|
||||
if (isRobot || operation2.isSpecial() || simulation.getTraining2()
|
||||
.isJumpStep(step)) { // 特殊操作直接执行
|
||||
executeOperation(simulation, step, operation2);
|
||||
return true;
|
||||
} else { // 非机器人,暂停仿真等待用户操作
|
||||
simulation.onlyPause();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeOperation(Simulation simulation, Step2 step, SimCommand2 operation2) {
|
||||
Type operateType = operation2.getOperationType();
|
||||
Map<String, Object> params = operation2.getParams();
|
||||
boolean isTextChat = false;
|
||||
if (operateType.equals(Type.Conversation_Group_Private_Text_Chat)) {
|
||||
operateType = Type.Conversation_Group_Private_Audio_Chat;
|
||||
isTextChat = true;
|
||||
} else if (operateType.equals(Type.Conversation_Group_Text_Chat)) {
|
||||
operateType = Type.Conversation_Group_Audio_Chat;
|
||||
isTextChat = true;
|
||||
} else if (operateType.equals(Type.Conversation_Chat_Text)) {
|
||||
operateType = Type.Conversation_Chat_Audio;
|
||||
isTextChat = true;
|
||||
}
|
||||
if (isTextChat) {
|
||||
//将车次号替换为标准读音
|
||||
String content = (String) operation2.getParams().get("content");
|
||||
Pattern pattern = Pattern.compile("([0-9]+)次");
|
||||
Matcher matcher = pattern.matcher(content);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int index = 0;
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
int start = matcher.start(1);
|
||||
sb.append(content, index, start);
|
||||
sb.append(convertPronunciation(group));
|
||||
sb.append("次");
|
||||
index = sb.length();
|
||||
}
|
||||
sb.append(content.substring(index));
|
||||
VoiceCompose compose = voiceService.synthesis(new BaseVoiceSynthesisVO(sb.toString()));
|
||||
params = new HashMap<>(params);
|
||||
params.put("audioPath", compose.getFilePath());
|
||||
}
|
||||
atsOperationDispatcher.execute(simulation,
|
||||
step.getSimulationMember(), operateType.name(), params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字转语音
|
||||
*/
|
||||
private String convertPronunciation(String content) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : content.split("")) {
|
||||
switch (s) {
|
||||
case "0":
|
||||
sb.append("洞");
|
||||
break;
|
||||
case "1":
|
||||
sb.append("幺");
|
||||
break;
|
||||
case "2":
|
||||
sb.append("两");
|
||||
break;
|
||||
case "7":
|
||||
sb.append("拐");
|
||||
break;
|
||||
default:
|
||||
sb.append(s);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试完成操作
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,13 +6,28 @@ 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.data.vo.ConversationGroupVO;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.*;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupCreateEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupDissolveEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupExitEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupInviteEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupMessageEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupMessageStatusEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupPrivateChatEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupRemoveEvent;
|
||||
import club.joylink.rtss.simulation.cbtc.event.conversation.SimulationConversationGroupUpdateEvent;
|
||||
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.voice.VoiceRecognitionResult;
|
||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -20,390 +35,450 @@ import org.springframework.context.ApplicationEventPublisher;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ConversationGroupHandlerService {
|
||||
|
||||
@Autowired
|
||||
private GroupSimulationCache groupSimulationCache;
|
||||
@Autowired
|
||||
private GroupSimulationCache groupSimulationCache;
|
||||
|
||||
@Autowired
|
||||
private VoiceService iVoiceService;
|
||||
@Autowired
|
||||
private VoiceService iVoiceService;
|
||||
|
||||
@Autowired
|
||||
private SimulationVoiceHandler simulationVoiceHandler;
|
||||
@Autowired
|
||||
private SimulationVoiceHandler simulationVoiceHandler;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
/**
|
||||
* 获取所有群组信息
|
||||
* @param group 仿真ID
|
||||
* @return 群组信息
|
||||
*/
|
||||
public List<ConversationGroupVO> getAllConversationsGroup(String group, AccountVO user) {
|
||||
Simulation simulation = groupSimulationCache.getSimulationByGroup(group);
|
||||
List<ConversationGroup> allGroup = simulation.queryAllConversationGroup();
|
||||
SimulationMember member = simulation.querySimulationMemberByUserId(user.getId());
|
||||
if (member == null) {
|
||||
return List.of();
|
||||
} else {
|
||||
return allGroup.stream().filter(g -> g.isConversationMember(member))
|
||||
.map(g -> new ConversationGroupVO(g, member)).collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 获取所有群组信息
|
||||
*
|
||||
* @param group 仿真ID
|
||||
* @return 群组信息
|
||||
*/
|
||||
public List<ConversationGroupVO> getAllConversationsGroup(String group, AccountVO user) {
|
||||
Simulation simulation = groupSimulationCache.getSimulationByGroup(group);
|
||||
List<ConversationGroup> allGroup = simulation.queryAllConversationGroup();
|
||||
SimulationMember member = simulation.querySimulationMemberByUserId(user.getId());
|
||||
if (member == null) {
|
||||
return List.of();
|
||||
} else {
|
||||
return allGroup.stream().filter(g -> g.isConversationMember(member))
|
||||
.map(g -> new ConversationGroupVO(g, member)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建群组会话
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param imageUrl 群头像
|
||||
* @param name 群组名称
|
||||
* @param memberIds 群组成员
|
||||
*/
|
||||
public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member, String imageUrl, String name, List<String> memberIds) {
|
||||
List<SimulationMember> simulationMembers = memberIds.stream().map(simulation::getSimulationMemberById).collect(Collectors.toList());
|
||||
Long groupId = simulation.getMaxConversationGroupId();
|
||||
ConversationGroup conversationGroup = new ConversationGroup(groupId, imageUrl, name, simulation.getCorrectSystemTime(), member, simulationMembers);
|
||||
conversationGroup.initGroupType();
|
||||
simulation.addConversationGroup(conversationGroup);
|
||||
// 通知用户消息
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupCreateEvent(this, simulation, conversationGroup));
|
||||
return new ConversationGroupVO(conversationGroup);
|
||||
/**
|
||||
* 创建群组会话
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param imageUrl 群头像
|
||||
* @param name 群组名称
|
||||
* @param memberIds 群组成员
|
||||
*/
|
||||
public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member,
|
||||
String imageUrl, String name, List<String> memberIds) {
|
||||
List<SimulationMember> simulationMembers = memberIds.stream()
|
||||
.map(simulation::getSimulationMemberById).collect(Collectors.toList());
|
||||
Long groupId = simulation.getMaxConversationGroupId();
|
||||
ConversationGroup conversationGroup = new ConversationGroup(groupId, imageUrl, name,
|
||||
simulation.getCorrectSystemTime(), member, simulationMembers);
|
||||
conversationGroup.initGroupType();
|
||||
simulation.addConversationGroup(conversationGroup);
|
||||
// 通知用户消息
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupCreateEvent(this, simulation, conversationGroup));
|
||||
return new ConversationGroupVO(conversationGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会话群组名称
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
* @param name 群组名称
|
||||
*/
|
||||
public void updateConversationGroupName(Simulation simulation, SimulationMember member, Long id,
|
||||
String name) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
|
||||
conversationGroup.setName(name);
|
||||
// 通知其他用户群名变更
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup,
|
||||
ConversationGroupSocketMessageVO.MessageType.UPDATE_NAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置会话群群主
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
* @param memberId 目标用户
|
||||
*/
|
||||
public void updateConversationGroupLeader(Simulation simulation, SimulationMember member, Long id,
|
||||
String memberId) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
|
||||
SimulationMember simulationMember = simulation.getSimulationMemberById(memberId);
|
||||
if (!conversationGroup.isConversationMember(simulationMember)) {
|
||||
conversationGroup.addSimulationMember(simulationMember, simulation.getCorrectSystemTime());
|
||||
}
|
||||
// 设置群组
|
||||
conversationGroup.setLeader(simulationMember);
|
||||
// 发送通知消息
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup,
|
||||
ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会话群组名称
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
* @param name 群组名称
|
||||
*/
|
||||
public void updateConversationGroupName(Simulation simulation, SimulationMember member, Long id, String name) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
|
||||
conversationGroup.setName(name);
|
||||
// 通知其他用户群名变更
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup, ConversationGroupSocketMessageVO.MessageType.UPDATE_NAME));
|
||||
/**
|
||||
* 邀请用户进群
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
* @param memberIds 角色ID
|
||||
*/
|
||||
public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member,
|
||||
Long id, List<String> memberIds) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, id);
|
||||
if (!conversationGroup.isConversationMember(member)) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument,
|
||||
"非本组成员,不能邀请用户");
|
||||
}
|
||||
List<String> groupMemberIds = conversationGroup.getSimulationMemberIds();
|
||||
List<String> newMemberIds = memberIds.stream().filter(mid -> !groupMemberIds.contains(mid))
|
||||
.collect(Collectors.toList());
|
||||
List<SimulationMember> newSimulationMemberList = new ArrayList<>(newMemberIds.size());
|
||||
newMemberIds.forEach(memberId -> {
|
||||
SimulationMember newMember = simulation.getSimulationMemberById(memberId);
|
||||
newSimulationMemberList.add(newMember);
|
||||
conversationGroup.addSimulationMember(newMember, simulation.getCorrectSystemTime());
|
||||
});
|
||||
// 给新加入的用户发送消息
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupInviteEvent(this, simulation, conversationGroup,
|
||||
groupMemberIds, newSimulationMemberList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置会话群群主
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
* @param memberId 目标用户
|
||||
*/
|
||||
public void updateConversationGroupLeader(Simulation simulation, SimulationMember member, Long id, String memberId) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
|
||||
SimulationMember simulationMember = simulation.getSimulationMemberById(memberId);
|
||||
if (!conversationGroup.isConversationMember(simulationMember)) {
|
||||
conversationGroup.addSimulationMember(simulationMember, simulation.getCorrectSystemTime());
|
||||
}
|
||||
// 设置群组
|
||||
conversationGroup.setLeader(simulationMember);
|
||||
// 发送通知消息
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup, ConversationGroupSocketMessageVO.MessageType.UPDATE_MEMBER));
|
||||
/**
|
||||
* 移除群组用户
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
* @param memberIds 角色ID
|
||||
*/
|
||||
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long id,
|
||||
List<String> memberIds) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
|
||||
if (memberIds.contains(conversationGroup.getLeader().getId())) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "群主不能移除");
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请用户进群
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
* @param memberIds 角色ID
|
||||
*/
|
||||
public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member, Long id, List<String> memberIds) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, id);
|
||||
if (!conversationGroup.isConversationMember(member)) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员,不能邀请用户");
|
||||
}
|
||||
List<String> groupMemberIds = conversationGroup.getSimulationMemberIds();
|
||||
List<String> newMemberIds = memberIds.stream().filter(mid -> !groupMemberIds.contains(mid)).collect(Collectors.toList());
|
||||
List<SimulationMember> newSimulationMemberList = new ArrayList<>(newMemberIds.size());
|
||||
newMemberIds.forEach(memberId -> {
|
||||
SimulationMember newMember = simulation.getSimulationMemberById(memberId);
|
||||
newSimulationMemberList.add(newMember);
|
||||
conversationGroup.addSimulationMember(newMember, simulation.getCorrectSystemTime());
|
||||
List<SimulationMember> removeSimulationMemberList = new ArrayList<>(memberIds.size());
|
||||
conversationGroup.getSimulationMemberList().stream().filter(m -> memberIds.contains(m.getId()))
|
||||
.forEach(m -> {
|
||||
removeSimulationMemberList.add(m);
|
||||
conversationGroup.exit(m);
|
||||
});
|
||||
// 给新加入的用户发送消息
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupInviteEvent(this, simulation, conversationGroup, groupMemberIds, newSimulationMemberList));
|
||||
}
|
||||
// 给新加入的用户发送消息
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupRemoveEvent(this, simulation, conversationGroup,
|
||||
removeSimulationMemberList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除群组用户
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
* @param memberIds 角色ID
|
||||
*/
|
||||
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long id, List<String> memberIds) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
|
||||
if (memberIds.contains(conversationGroup.getLeader().getId())) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "群主不能移除");
|
||||
}
|
||||
List<SimulationMember> removeSimulationMemberList = new ArrayList<>(memberIds.size());
|
||||
conversationGroup.getSimulationMemberList().stream().filter(m -> memberIds.contains(m.getId()))
|
||||
.forEach(m -> {
|
||||
removeSimulationMemberList.add(m);
|
||||
conversationGroup.exit(m);
|
||||
});
|
||||
// 给新加入的用户发送消息
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupRemoveEvent(this, simulation, conversationGroup, removeSimulationMemberList));
|
||||
/**
|
||||
* 退出群组
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
*/
|
||||
public void exitConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, id);
|
||||
if (!conversationGroup.isConversationMember(member)) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument,
|
||||
"非本组成员,不能邀请用户");
|
||||
}
|
||||
if (conversationGroup.isLeader(member)) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "请先变更群主");
|
||||
}
|
||||
conversationGroup.exit(member);
|
||||
// 发送退群消息
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupExitEvent(this, simulation, conversationGroup, member));
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出群组
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
*/
|
||||
public void exitConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, id);
|
||||
if (!conversationGroup.isConversationMember(member)) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员,不能邀请用户");
|
||||
}
|
||||
if (conversationGroup.isLeader(member)) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "请先变更群主");
|
||||
}
|
||||
conversationGroup.exit(member);
|
||||
// 发送退群消息
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupExitEvent(this, simulation, conversationGroup, member));
|
||||
}
|
||||
/**
|
||||
* 解散群组
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
*/
|
||||
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
|
||||
simulation.removeConversionGroup(conversationGroup);
|
||||
// 发送解散消息
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupDissolveEvent(this, simulation, conversationGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解散群组
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组主键
|
||||
*/
|
||||
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
|
||||
simulation.removeConversionGroup(conversationGroup);
|
||||
// 发送解散消息
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupDissolveEvent(this, simulation, conversationGroup));
|
||||
}
|
||||
/**
|
||||
* 语音文件聊天
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 用户组
|
||||
* @param audioPath 文件路径
|
||||
* @param content 文件内容
|
||||
* @return 消息信息实体
|
||||
*/
|
||||
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member,
|
||||
Long id, String audioPath, String content) {
|
||||
return sendMessage(simulation, member, id, () -> {
|
||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||
recognitionResult.setFilePath(audioPath);
|
||||
recognitionResult.setResult(content);
|
||||
return recognitionResult;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 语音文件聊天
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 用户组
|
||||
* @param audioPath 文件路径
|
||||
* @param content 文件内容
|
||||
* @return 消息信息实体
|
||||
*/
|
||||
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long id, String audioPath, String content) {
|
||||
return sendMessage(simulation, member, id, () -> {
|
||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||
recognitionResult.setFilePath(audioPath);
|
||||
recognitionResult.setResult(content);
|
||||
return recognitionResult;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 文字聊天
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 用户组
|
||||
* @param content 文字信息
|
||||
* @return 消息信息实体
|
||||
*/
|
||||
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member,
|
||||
Long id, String content) {
|
||||
return sendMessage(simulation, member, id, () -> {
|
||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||
recognitionResult.setResult(content);
|
||||
return recognitionResult;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字聊天
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 用户组
|
||||
* @param content 文字信息
|
||||
* @return 消息信息实体
|
||||
*/
|
||||
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long id, String content) {
|
||||
return sendMessage(simulation, member, id, () -> {
|
||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||
recognitionResult.setResult(content);
|
||||
return recognitionResult;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 发送Base64文件消息
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 成员
|
||||
* @param id 用户群组ID
|
||||
* @param fileBase64Str base64文件内容
|
||||
* @return 消息信息实体
|
||||
*/
|
||||
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member,
|
||||
Long id, String fileBase64Str) {
|
||||
return sendMessage(simulation, member, id, () -> {
|
||||
VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str);
|
||||
return iVoiceService.voiceRecognition(vo);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送Base64文件消息
|
||||
* @param simulation 仿真
|
||||
* @param member 成员
|
||||
* @param id 用户群组ID
|
||||
* @param fileBase64Str base64文件内容
|
||||
* @return 消息信息实体
|
||||
*/
|
||||
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long id, String fileBase64Str) {
|
||||
return sendMessage(simulation, member, id, () -> {
|
||||
VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str);
|
||||
return iVoiceService.voiceRecognition(vo);
|
||||
});
|
||||
/**
|
||||
* 群组用户读取消息
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 群组成员
|
||||
* @param id 群组ID
|
||||
* @return 未读的消息列表
|
||||
*/
|
||||
public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation,
|
||||
SimulationMember member, Long id) {
|
||||
ConversationGroup conversationGroup = simulation.getConversationGroup(id);
|
||||
// 没有消息,不是本群人员
|
||||
List<ConversationGroupMessage> messageList = conversationGroup.getUnreadMessages(member);
|
||||
if (CollectionUtils.isEmpty(messageList)) {
|
||||
return List.of();
|
||||
}
|
||||
List<String> memberIds = conversationGroup.getSimulationMemberIds();
|
||||
messageList.forEach(message -> {
|
||||
message.read(member);
|
||||
if (memberIds.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));
|
||||
return ConversationGroupMessageVO.convert2VO(messageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 群组用户读取消息
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 群组成员
|
||||
* @param id 群组ID
|
||||
* @return 未读的消息列表
|
||||
*/
|
||||
public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
ConversationGroup conversationGroup = simulation.getConversationGroup(id);
|
||||
// 没有消息,不是本群人员
|
||||
List<ConversationGroupMessage> messageList = conversationGroup.getUnreadMessages(member);
|
||||
if (CollectionUtils.isEmpty(messageList)) {
|
||||
return List.of();
|
||||
}
|
||||
List<String> memberIds = conversationGroup.getSimulationMemberIds();
|
||||
messageList.forEach(message -> {
|
||||
message.read(member);
|
||||
if (memberIds.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));
|
||||
return ConversationGroupMessageVO.convert2VO(messageList);
|
||||
/**
|
||||
* 机器人批量已读信息
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param memberList 成员列表
|
||||
* @param id 用户群组ID
|
||||
*/
|
||||
public void robotBatchRead(Simulation simulation, List<SimulationMember> memberList, Long id) {
|
||||
// 查找群组
|
||||
ConversationGroup conversationGroup = simulation.getConversationGroup(id);
|
||||
Set<String> robotMemberIds = memberList.stream().map(SimulationMember::getId)
|
||||
.collect(Collectors.toSet());
|
||||
Set<String> allMemberIds = conversationGroup.getMemberList().stream()
|
||||
.map(m -> m.getMember().getId()).collect(Collectors.toSet());
|
||||
// 是否全部是群成员
|
||||
if (!allMemberIds.containsAll(robotMemberIds)) {
|
||||
return;
|
||||
}
|
||||
// 获取到所有没有读取的消息
|
||||
List<ConversationGroupMessage> 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 机器人批量已读信息
|
||||
* @param simulation 仿真
|
||||
* @param memberList 成员列表
|
||||
* @param id 用户群组ID
|
||||
*/
|
||||
public void robotBatchRead(Simulation simulation, List<SimulationMember> memberList, Long id) {
|
||||
// 查找群组
|
||||
ConversationGroup conversationGroup = simulation.getConversationGroup(id);
|
||||
Set<String> robotMemberIds = memberList.stream().map(SimulationMember::getId).collect(Collectors.toSet());
|
||||
Set<String> allMemberIds = conversationGroup.getMemberList().stream().map(m -> m.getMember().getId()).collect(Collectors.toSet());
|
||||
// 是否全部是群成员
|
||||
if (!allMemberIds.containsAll(robotMemberIds)) {
|
||||
return;
|
||||
}
|
||||
// 获取到所有没有读取的消息
|
||||
List<ConversationGroupMessage> 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));
|
||||
}
|
||||
/**
|
||||
* 文字私聊
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param memberId 指定用户
|
||||
* @param content 消息内容
|
||||
* @return 消息信息
|
||||
*/
|
||||
public ConversationGroupMessageVO privateTextChat(Simulation simulation, SimulationMember member,
|
||||
String memberId, String content) {
|
||||
ConversationGroup conversationGroup = getPrivateConversation(simulation, member, memberId);
|
||||
return sendMessage(simulation, member, conversationGroup.getId(), () -> {
|
||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||
recognitionResult.setResult(content);
|
||||
return recognitionResult;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字私聊
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param memberId 指定用户
|
||||
* @param content 消息内容
|
||||
* @return 消息信息
|
||||
*/
|
||||
public ConversationGroupMessageVO privateTextChat(Simulation simulation, SimulationMember member, String memberId, String content) {
|
||||
ConversationGroup conversationGroup = getPrivateConversation(simulation, member, memberId);
|
||||
return sendMessage(simulation, member, conversationGroup.getId(), () -> {
|
||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||
recognitionResult.setResult(content);
|
||||
return recognitionResult;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 语音私聊
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param memberId 指定用户
|
||||
* @param fileBase64Str 语音消息
|
||||
* @return 消息信息
|
||||
*/
|
||||
public ConversationGroupMessageVO privateAudioChat(Simulation simulation, SimulationMember member,
|
||||
String memberId, String fileBase64Str) {
|
||||
ConversationGroup conversationGroup = getPrivateConversation(simulation, member, memberId);
|
||||
return sendMessage(simulation, member, conversationGroup.getId(), () -> {
|
||||
VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str);
|
||||
return iVoiceService.voiceRecognition(vo);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 语音私聊
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param memberId 指定用户
|
||||
* @param fileBase64Str 语音消息
|
||||
* @return 消息信息
|
||||
*/
|
||||
public ConversationGroupMessageVO privateAudioChat(Simulation simulation, SimulationMember member, String memberId, String fileBase64Str) {
|
||||
ConversationGroup conversationGroup = getPrivateConversation(simulation, member, memberId);
|
||||
return sendMessage(simulation, member, conversationGroup.getId(), () -> {
|
||||
VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str);
|
||||
return iVoiceService.voiceRecognition(vo);
|
||||
});
|
||||
/**
|
||||
* 获取私聊会话
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 发起人
|
||||
* @param memberId 对话人
|
||||
* @return 会话
|
||||
*/
|
||||
private ConversationGroup getPrivateConversation(Simulation simulation, SimulationMember member,
|
||||
String memberId) {
|
||||
SimulationMember communicator = simulation.getSimulationMemberById(memberId);
|
||||
ConversationGroup conversationGroup = simulation.getSimulationConversationGroupMap().values()
|
||||
.stream().filter(group -> {
|
||||
if (Objects.equals(member.getId(), memberId)) {
|
||||
return group.getMemberList().size() == 1 && group.isPrivate() && group.contains(
|
||||
communicator);
|
||||
} else {
|
||||
return group.getMemberList().size() == 2 && group.isPrivate() && group.contains(
|
||||
communicator) && group.contains(member);
|
||||
}
|
||||
}).findFirst().orElse(null);
|
||||
if (conversationGroup == null) {
|
||||
Long groupId = simulation.getMaxConversationGroupId();
|
||||
conversationGroup = new ConversationGroup(groupId, null, null,
|
||||
simulation.getCorrectSystemTime(),
|
||||
member, Collections.singletonList(communicator));
|
||||
conversationGroup.getMemberList().forEach(ConversationMember::setLeader);
|
||||
conversationGroup.initPrivateType();
|
||||
simulation.addConversationGroup(conversationGroup);
|
||||
// 语音识别开始
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupPrivateChatEvent(this, simulation, conversationGroup));
|
||||
}
|
||||
return conversationGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取私聊会话
|
||||
* @param simulation 仿真
|
||||
* @param member 发起人
|
||||
* @param memberId 对话人
|
||||
* @return 会话
|
||||
*/
|
||||
private ConversationGroup getPrivateConversation(Simulation simulation, SimulationMember member, String memberId) {
|
||||
SimulationMember communicator = simulation.getSimulationMemberById(memberId);
|
||||
ConversationGroup conversationGroup = simulation.getSimulationConversationGroupMap().values()
|
||||
.stream().filter(group -> {
|
||||
if (Objects.equals(member.getId(), memberId)) {
|
||||
return group.getMemberList().size() == 1 && group.isPrivate() && group.contains(communicator);
|
||||
} else {
|
||||
return group.getMemberList().size() == 2 && group.isPrivate() && group.contains(communicator) && group.contains(member);
|
||||
}
|
||||
}).findFirst().orElse(null);
|
||||
if (conversationGroup == null) {
|
||||
Long groupId = simulation.getMaxConversationGroupId();
|
||||
conversationGroup = new ConversationGroup(groupId, null, null, simulation.getCorrectSystemTime(),
|
||||
member, Collections.singletonList(communicator));
|
||||
conversationGroup.getMemberList().forEach(ConversationMember::setLeader);
|
||||
conversationGroup.initPrivateType();
|
||||
simulation.addConversationGroup(conversationGroup);
|
||||
// 语音识别开始
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupPrivateChatEvent(this, simulation, conversationGroup));
|
||||
}
|
||||
return conversationGroup;
|
||||
/**
|
||||
* 对群组操作时基础判断
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 操作人员
|
||||
* @param id 群组ID
|
||||
* @return 群组信息
|
||||
*/
|
||||
private ConversationGroup checkGroupIdAndReturn(Simulation simulation, SimulationMember member,
|
||||
Long id) {
|
||||
ConversationGroup conversationGroup = simulation.getConversationGroup(id);
|
||||
if (conversationGroup == null) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "群组不存在");
|
||||
}
|
||||
if (member != null && !Objects.equals(member.getId(), conversationGroup.getLeader().getId())) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "您无操作权限");
|
||||
}
|
||||
return conversationGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对群组操作时基础判断
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 操作人员
|
||||
* @param id 群组ID
|
||||
* @return 群组信息
|
||||
*/
|
||||
private ConversationGroup checkGroupIdAndReturn(Simulation simulation, SimulationMember member, Long id) {
|
||||
ConversationGroup conversationGroup = simulation.getConversationGroup(id);
|
||||
if (conversationGroup == null) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "群组不存在");
|
||||
}
|
||||
if (member != null && !Objects.equals(member.getId(), conversationGroup.getLeader().getId())) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "您无操作权限");
|
||||
}
|
||||
return conversationGroup;
|
||||
/**
|
||||
* 处理并发送消息方法
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 操作人
|
||||
* @param id 用户组
|
||||
* @param handleSupplier 处理消息方法
|
||||
* @return 用户组消息
|
||||
*/
|
||||
private ConversationGroupMessageVO sendMessage(Simulation simulation, SimulationMember member,
|
||||
Long id
|
||||
, Supplier<VoiceRecognitionResult> handleSupplier) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, id);
|
||||
if (!conversationGroup.isConversationMember(member)) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员");
|
||||
}
|
||||
VoiceRecognitionResult recognitionResult = handleSupplier.get();
|
||||
// 对语音信息进行消息文字处理
|
||||
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);
|
||||
// 语音识别开始
|
||||
applicationEventPublisher.publishEvent(
|
||||
new SimulationConversationGroupMessageEvent(this, simulation, conversationGroup, message));
|
||||
return new ConversationGroupMessageVO(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理并发送消息方法
|
||||
* @param simulation 仿真
|
||||
* @param member 操作人
|
||||
* @param id 用户组
|
||||
* @param handleSupplier 处理消息方法
|
||||
* @return 用户组消息
|
||||
*/
|
||||
private ConversationGroupMessageVO sendMessage(Simulation simulation, SimulationMember member, Long id
|
||||
, Supplier<VoiceRecognitionResult> handleSupplier) {
|
||||
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, id);
|
||||
if (!conversationGroup.isConversationMember(member)) {
|
||||
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员");
|
||||
}
|
||||
VoiceRecognitionResult recognitionResult = handleSupplier.get();
|
||||
// 对语音信息进行消息文字处理
|
||||
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);
|
||||
// 语音识别开始
|
||||
applicationEventPublisher.publishEvent(new SimulationConversationGroupMessageEvent(this, simulation, conversationGroup, message));
|
||||
return new ConversationGroupMessageVO(message);
|
||||
}
|
||||
public ConversationGroupMessageVO privateAudioChat(Simulation simulation,
|
||||
SimulationMember member, String targetMemberId, String audioPath, String content) {
|
||||
ConversationGroup conversationGroup = getPrivateConversation(simulation, member,
|
||||
targetMemberId);
|
||||
return sendMessage(simulation, member, conversationGroup.getId(), () -> {
|
||||
VoiceRecognitionResult recognitionResult = new VoiceRecognitionResult();
|
||||
recognitionResult.setFilePath(audioPath);
|
||||
recognitionResult.setResult(content);
|
||||
return recognitionResult;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,141 +7,176 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
|
|||
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO;
|
||||
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO;
|
||||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 群组会话操作
|
||||
*/
|
||||
@OperateHandler
|
||||
@Slf4j
|
||||
public class ConversationGroupOperateHandler {
|
||||
@Autowired
|
||||
private ConversationGroupHandlerService conversationGroupManagerService;
|
||||
|
||||
/**
|
||||
* 创建群组信息
|
||||
* @param simulation 仿真
|
||||
* @param member 创建人
|
||||
* @param imageUrl 群图像
|
||||
* @param name 群名称
|
||||
* @param memberIds 群成员
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Create)
|
||||
public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member, String imageUrl, String name, List<String> memberIds) {
|
||||
return conversationGroupManagerService.createConversationGroup(simulation, member, imageUrl, name, memberIds);
|
||||
}
|
||||
@Autowired
|
||||
private ConversationGroupHandlerService conversationGroupManagerService;
|
||||
|
||||
/**
|
||||
* 修改群组名称等基本信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Name)
|
||||
public void updateConversationGroup(Simulation simulation, SimulationMember member, Long id, String name) {
|
||||
conversationGroupManagerService.updateConversationGroupName(simulation, member, id, name);
|
||||
}
|
||||
/**
|
||||
* 创建群组信息
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 创建人
|
||||
* @param imageUrl 群图像
|
||||
* @param name 群名称
|
||||
* @param memberIds 群成员
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Create)
|
||||
public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member,
|
||||
String imageUrl, String name, List<String> memberIds) {
|
||||
return conversationGroupManagerService.createConversationGroup(simulation, member, imageUrl,
|
||||
name, memberIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设定群组群主
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组ID
|
||||
* @param memberId 用户ID
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Leader)
|
||||
public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long id, String memberId) {
|
||||
conversationGroupManagerService.updateConversationGroupLeader(simulation, member, id, memberId);
|
||||
}
|
||||
/**
|
||||
* 修改群组名称等基本信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Name)
|
||||
public void updateConversationGroup(Simulation simulation, SimulationMember member, Long id,
|
||||
String name) {
|
||||
conversationGroupManagerService.updateConversationGroupName(simulation, member, id, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请角色进群组
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Invite_Member)
|
||||
public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member, Long id, List<String> memberIds) {
|
||||
conversationGroupManagerService.inviteMembersInConversationGroup(simulation, member, id, memberIds);
|
||||
}
|
||||
/**
|
||||
* 设定群组群主
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 用户
|
||||
* @param id 群组ID
|
||||
* @param memberId 用户ID
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Leader)
|
||||
public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long id,
|
||||
String memberId) {
|
||||
conversationGroupManagerService.updateConversationGroupLeader(simulation, member, id, memberId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 踢人
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Remove_Member)
|
||||
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long id, List<String> memberIds) {
|
||||
conversationGroupManagerService.removeMemberConversationGroup(simulation, member, id, memberIds);
|
||||
}
|
||||
/**
|
||||
* 邀请角色进群组
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Invite_Member)
|
||||
public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member,
|
||||
Long id, List<String> memberIds) {
|
||||
conversationGroupManagerService.inviteMembersInConversationGroup(simulation, member, id,
|
||||
memberIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出群组信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Exit)
|
||||
public void exitConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
conversationGroupManagerService.exitConversationGroup(simulation, member, id);
|
||||
}
|
||||
/**
|
||||
* 踢人
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Remove_Member)
|
||||
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long id,
|
||||
List<String> memberIds) {
|
||||
conversationGroupManagerService.removeMemberConversationGroup(simulation, member, id,
|
||||
memberIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解散群组
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Dissolve)
|
||||
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
conversationGroupManagerService.dissolveConversationGroup(simulation, member, id);
|
||||
}
|
||||
/**
|
||||
* 退出群组信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Exit)
|
||||
public void exitConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
conversationGroupManagerService.exitConversationGroup(simulation, member, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送语音信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Audio_Chat)
|
||||
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long id, String audioPath, String content) {
|
||||
return conversationGroupManagerService.audioChat(simulation, member, id, audioPath, content);
|
||||
}
|
||||
/**
|
||||
* 解散群组
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Dissolve)
|
||||
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
conversationGroupManagerService.dissolveConversationGroup(simulation, member, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文字信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Text_Chat)
|
||||
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long id, String content) {
|
||||
return conversationGroupManagerService.textChat(simulation, member, id, content);
|
||||
}
|
||||
/**
|
||||
* 发送语音信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Audio_Chat)
|
||||
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member,
|
||||
Long id, String audioPath, String content) {
|
||||
return conversationGroupManagerService.audioChat(simulation, member, id, audioPath, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送Base64音频文件
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Audio_Base64)
|
||||
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long id, String fileBase64Str) {
|
||||
return conversationGroupManagerService.audioBase64(simulation, member, id, fileBase64Str);
|
||||
}
|
||||
/**
|
||||
* 发送文字信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Text_Chat)
|
||||
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member,
|
||||
Long id, String content) {
|
||||
return conversationGroupManagerService.textChat(simulation, member, id, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跟指定用户文字私聊
|
||||
* @param simulation 仿真
|
||||
* @param member 发起用户
|
||||
* @param memberId 指定用户
|
||||
* @param content 文字信息
|
||||
* @return 消息信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Private_Text_Chat)
|
||||
public ConversationGroupMessageVO privateTextChat(Simulation simulation, SimulationMember member, String memberId, String content) {
|
||||
return conversationGroupManagerService.privateTextChat(simulation, member, memberId, content);
|
||||
}
|
||||
/**
|
||||
* 发送Base64音频文件
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Audio_Base64)
|
||||
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member,
|
||||
Long id, String fileBase64Str) {
|
||||
return conversationGroupManagerService.audioBase64(simulation, member, id, fileBase64Str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跟指定用户发语音信息
|
||||
* @param simulation 仿真信息
|
||||
* @param member 发起用户
|
||||
* @param memberId 指定用户
|
||||
* @param fileBase64Str 语音消息
|
||||
* @return 消息内容
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Private_Audio_Base64)
|
||||
public ConversationGroupMessageVO privateAudioChat(Simulation simulation, SimulationMember member, String memberId, String fileBase64Str) {
|
||||
return conversationGroupManagerService.privateAudioChat(simulation, member, memberId, fileBase64Str);
|
||||
}
|
||||
/**
|
||||
* 跟指定用户文字私聊
|
||||
*
|
||||
* @param simulation 仿真
|
||||
* @param member 发起用户
|
||||
* @param memberId 指定用户
|
||||
* @param content 文字信息
|
||||
* @return 消息信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Private_Text_Chat)
|
||||
public ConversationGroupMessageVO privateTextChat(Simulation simulation, SimulationMember member,
|
||||
String memberId, String content) {
|
||||
return conversationGroupManagerService.privateTextChat(simulation, member, memberId, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 阅读群组信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Read_Message)
|
||||
public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation, SimulationMember member, Long id) {
|
||||
return conversationGroupManagerService.readConversationGroup(simulation, member, id);
|
||||
}
|
||||
/**
|
||||
* 跟指定用户发语音信息
|
||||
*
|
||||
* @param simulation 仿真信息
|
||||
* @param member 发起用户
|
||||
* @param memberId 指定用户
|
||||
* @param fileBase64Str 语音消息
|
||||
* @return 消息内容
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Private_Audio_Base64)
|
||||
public ConversationGroupMessageVO privateAudioChat(Simulation simulation, SimulationMember member,
|
||||
String memberId, String fileBase64Str) {
|
||||
return conversationGroupManagerService.privateAudioChat(simulation, member, memberId,
|
||||
fileBase64Str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定用户发送(已上传的)语音消息
|
||||
*
|
||||
* @param simulation 仿真信息
|
||||
* @param member 发起用户
|
||||
* @param memberId 指定用户
|
||||
* @param audioPath 文件路径
|
||||
* @param content 语音内容
|
||||
* @return 消息内容
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Private_Audio_Chat)
|
||||
public ConversationGroupMessageVO privateAudioChat(Simulation simulation, SimulationMember member,
|
||||
String memberId, String audioPath, String content) {
|
||||
return conversationGroupManagerService.privateAudioChat(simulation, member, memberId,
|
||||
audioPath, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 阅读群组信息
|
||||
*/
|
||||
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Read_Message)
|
||||
public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation,
|
||||
SimulationMember member, Long id) {
|
||||
return conversationGroupManagerService.readConversationGroup(simulation, member, id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue