This commit is contained in:
tiger_zhou 2023-04-20 14:13:22 +08:00
commit 90d6a1200a
7 changed files with 105 additions and 68 deletions

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.services.voice.discriminate;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroupHandlerService;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationManagerService;
import club.joylink.rtss.simulation.cbtc.discriminate.*;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
@ -18,7 +19,7 @@ import java.util.List;
public class ReplyParseServiceImpl implements VoiceTransactionalService {
@Autowired
private ConversationManagerService conversationManagerService;
private ConversationGroupHandlerService conversationGroupHandlerService;
@Override
@Async("voiceDiscriminateExecutor")
@ -55,7 +56,7 @@ public class ReplyParseServiceImpl implements VoiceTransactionalService {
replyResult.getParamList().toArray(objArr);
replyResult.setContent(String.format(replyRule.getMessageFormat(), objArr));
// 执行回复
simulationMemberList.forEach(member -> conversationManagerService.conversationChat(simulation, member, replyResult.getContent(), null));
simulationMemberList.forEach(member -> conversationGroupHandlerService.textChat(simulation, member, result.getConversionGroupId(), replyResult.getContent()));
}
/**

View File

@ -69,8 +69,9 @@ public class VoiceDiscriminateService {
/**
* 接受语音文件资源等必要条件解析开始
*/
public void doAnalysis(Simulation simulation, String content, List<SimulationMember> memberList) {
public void doAnalysis(Simulation simulation, Long id, String content, List<SimulationMember> memberList) {
VoiceDiscriminateResult result = voiceParseService.doParse(simulation, content);
result.setConversionGroupId(id);
result.setSimulationMemberList(memberList); // 匹配到人员集合
operateParseService.doExec(result, simulation); // 指令执行
replyParseService.doExec(result, simulation); // 回复执行
@ -93,7 +94,8 @@ public class VoiceDiscriminateService {
}
// 增加机器人已读操作
memberList.forEach(m -> conversationGroupManagerService.readConversationGroup(event.getSimulation(), m, conversationGroup.getId()));
// 执行语音识别
doAnalysis(event.getSimulation(), event.getMessage().getContent(), memberList);
if (!event.getMessage().getMember().isRobot()) { // 如果消息来源不为机器人则执行语音识别
doAnalysis(event.getSimulation(), conversationGroup.getId(), event.getMessage().getContent(), memberList);
}
}
}

View File

@ -73,6 +73,26 @@ public class StationDirectionService {
}
};
/**
* 改方按钮抬起验证
*/
private final ButtonValidInterface turnDirectionPressUpValid = (simulation, stationDirection) -> {
// 原接车站无发车进路锁闭
boolean isDeliverConflict = stationDirection.getDeliverRouteList().stream().anyMatch(Route::isLock);
if (isDeliverConflict) {
throw new SimulationException(SimulationExceptionType.Operation_Cannot_handed, "操作异常:存在发车进路");
}
// 原发车站无发车进路锁闭
StationDirection relativeDirection = getRelativeStationDirection(simulation, stationDirection);
boolean isReceiverConflict = relativeDirection != null;
if (isReceiverConflict) {
isReceiverConflict = relativeDirection.getReceiveRouteList().stream().anyMatch(Route::isLock);
}
if (isReceiverConflict) {
throw new SimulationException(SimulationExceptionType.Operation_Cannot_handed, "操作异常:相对方向存在接车进路");
}
};
/**
* 总辅助校验
*/
@ -311,6 +331,8 @@ public class StationDirectionService {
this.operationButtonValidMap = new HashMap<>();
// 改方按下验证函数
this.operationButtonValidMap.put(Operation.Type.ASSIST_PRESS_DOWN_TURN_DIRECTION, this.turnDirectionPressDownValid);
// 改方抬起验证函数
this.operationButtonValidMap.put(Operation.Type.ASSIST_PRESS_UP_TURN_DIRECTION, this.turnDirectionPressUpValid);
// 总辅助按下验证函数
this.operationButtonValidMap.put(Operation.Type.ASSIST_PRESS_MAIN_ASSIST, this.turnAssistValid);
// 接辅助按下验证函数

View File

@ -57,7 +57,8 @@ public class ConversationGroup extends Chat {
this.id = info.getId();
this.name = info.getName();
this.imageUrl = info.getImageUrl();
setTime(simulation.getCorrectSystemTime());
LocalDateTime time = simulation.getCorrectSystemTime();
setTime(time);
// 成员中放入群主
SimulationMember leader = simulation.getSimulationMemberById(info.getLeaderId());
setCreator(leader);
@ -65,12 +66,16 @@ public class ConversationGroup extends Chat {
List<ConversationMember> memberList = new ArrayList<>(size);
ConversationMember conversationLeader = new ConversationMember(leader);
conversationLeader.setLeader();
conversationLeader.setTime(time);
memberList.add(conversationLeader);
// 处理群成员
if (size > 1) {
info.getMemberIds().stream().filter(id -> !Objects.equals(id, info.getLeaderId())).distinct()
.map(simulation::getSimulationMemberById)
.forEach(member -> memberList.add(new ConversationMember(member)));
.map(simulation::getSimulationMemberById).forEach(member -> {
ConversationMember conversationMember = new ConversationMember(member);
conversationMember.setTime(time);
memberList.add(conversationMember);
});
}
setMemberList(memberList);
}
@ -88,7 +93,11 @@ public class ConversationGroup extends Chat {
// 处理群成员
if (size > 1) {
simulationMembers.stream().filter(member -> !Objects.equals(member.getId(), leader.getId())).distinct()
.forEach(member -> memberList.add(new ConversationMember(member)));
.forEach(member -> {
ConversationMember conversationMember = new ConversationMember(member);
conversationMember.setTime(time);
memberList.add(conversationMember);
});
}
setMemberList(memberList);
}

View File

@ -1,7 +1,6 @@
package club.joylink.rtss.simulation.cbtc.conversation;
import club.joylink.rtss.services.voice.VoiceService;
import club.joylink.rtss.services.voice.discriminate.VoiceDiscriminateService;
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO;
@ -19,7 +18,6 @@ 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;
@ -95,13 +93,13 @@ public class ConversationGroupHandlerService {
* @param groupId 群组主键
* @param name 群组名称
*/
public void updateConversationGroupName(Simulation simulation, SimulationMember member, Long groupId, String name) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
public void updateConversationGroupName(Simulation simulation, SimulationMember member, Long id, String name) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, id);
// 查找名称是否已存在
ConversationGroup nameConversationGroup = simulation.getConversationGroupByName(name);
if (nameConversationGroup != null && !Objects.equals(groupId, nameConversationGroup.getId())) {
if (nameConversationGroup != null && !Objects.equals(id, nameConversationGroup.getId())) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "" + name + "】已存在");
} else if (nameConversationGroup != null && Objects.equals(groupId, nameConversationGroup.getId())) {
} else if (nameConversationGroup != null && Objects.equals(id, nameConversationGroup.getId())) {
return;
}
conversationGroup.setName(name);
@ -114,11 +112,11 @@ public class ConversationGroupHandlerService {
*
* @param simulation 仿真
* @param member 用户
* @param groupId 群组主键
* @param id 群组主键
* @param memberId 目标用户
*/
public void updateConversationGroupLeader(Simulation simulation, SimulationMember member, Long groupId, String memberId) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
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());
@ -133,11 +131,11 @@ public class ConversationGroupHandlerService {
* 邀请用户进群
* @param simulation 仿真
* @param member 用户
* @param groupId 群组主键
* @param id 群组主键
* @param memberIds 角色ID
*/
public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member, Long groupId, List<String> memberIds) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, groupId);
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, "非本组成员,不能邀请用户");
}
@ -157,11 +155,11 @@ public class ConversationGroupHandlerService {
* 移除群组用户
* @param simulation 仿真
* @param member 用户
* @param groupId 群组主键
* @param id 群组主键
* @param memberIds 角色ID
*/
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long groupId, List<String> memberIds) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
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, "群主不能移除");
}
@ -181,8 +179,8 @@ public class ConversationGroupHandlerService {
* @param simulation 仿真
* @param member 用户
*/
public void exitConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, groupId);
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, "非本组成员,不能邀请用户");
}
@ -198,10 +196,10 @@ public class ConversationGroupHandlerService {
* 解散群组
* @param simulation 仿真
* @param member 用户
* @param groupId 群组主键
* @param id 群组主键
*/
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
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));
@ -212,13 +210,13 @@ public class ConversationGroupHandlerService {
*
* @param simulation 仿真
* @param member 用户
* @param groupId 用户组
* @param id 用户组
* @param audioPath 文件路径
* @param content 文件内容
* @return 消息信息实体
*/
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long groupId, String audioPath, String content) {
return sendMessage(simulation, member, groupId, () -> {
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);
@ -231,12 +229,12 @@ public class ConversationGroupHandlerService {
*
* @param simulation 仿真
* @param member 用户
* @param groupId 用户组
* @param id 用户组
* @param content 文字信息
* @return 消息信息实体
*/
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long groupId, String content) {
return sendMessage(simulation, member, groupId, () -> {
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;
@ -247,12 +245,12 @@ public class ConversationGroupHandlerService {
* 发送Base64文件消息
* @param simulation 仿真
* @param member 成员
* @param groupId 用户群组ID
* @param id 用户群组ID
* @param fileBase64Str base64文件内容
* @return 消息信息实体
*/
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) {
return sendMessage(simulation, member, groupId, () -> {
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);
});
@ -263,11 +261,11 @@ public class ConversationGroupHandlerService {
*
* @param simulation 仿真
* @param member 群组成员
* @param groupId 群组ID
* @param id 群组ID
* @return 未读的消息列表
*/
public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
ConversationGroup conversationGroup = simulation.getConversationGroup(groupId);
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)) {
@ -428,11 +426,11 @@ public class ConversationGroupHandlerService {
*
* @param simulation 仿真
* @param member 操作人员
* @param groupId 群组ID
* @param id 群组ID
* @return 群组信息
*/
private ConversationGroup checkGroupIdAndReturn(Simulation simulation, SimulationMember member, Long groupId) {
ConversationGroup conversationGroup = simulation.getConversationGroup(groupId);
private ConversationGroup checkGroupIdAndReturn(Simulation simulation, SimulationMember member, Long id) {
ConversationGroup conversationGroup = simulation.getConversationGroup(id);
if (conversationGroup == null) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "群组不存在");
}
@ -446,13 +444,13 @@ public class ConversationGroupHandlerService {
* 处理并发送消息方法
* @param simulation 仿真
* @param member 操作人
* @param groupId 用户组
* @param id 用户组
* @param handleSupplier 处理消息方法
* @return 用户组消息
*/
private ConversationGroupMessageVO sendMessage(Simulation simulation, SimulationMember member, Long groupId
private ConversationGroupMessageVO sendMessage(Simulation simulation, SimulationMember member, Long id
, Supplier<VoiceRecognitionResult> handleSupplier) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, groupId);
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, null, id);
if (!conversationGroup.isConversationMember(member)) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员");
}

View File

@ -37,8 +37,8 @@ public class ConversationGroupOperateHandler {
* 修改群组名称等基本信息
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Name)
public void updateConversationGroup(Simulation simulation, SimulationMember member, Long groupId, String name) {
conversationGroupManagerService.updateConversationGroupName(simulation, member, groupId, name);
public void updateConversationGroup(Simulation simulation, SimulationMember member, Long id, String name) {
conversationGroupManagerService.updateConversationGroupName(simulation, member, id, name);
}
/**
@ -46,75 +46,75 @@ public class ConversationGroupOperateHandler {
*
* @param simulation 仿真
* @param member 用户
* @param groupId 群组ID
* @param id 群组ID
* @param memberId 用户ID
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Leader)
public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long groupId, String memberId) {
conversationGroupManagerService.updateConversationGroupLeader(simulation, member, groupId, memberId);
public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long id, String memberId) {
conversationGroupManagerService.updateConversationGroupLeader(simulation, member, id, memberId);
}
/**
* 邀请角色进群组
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Invite_Member)
public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member, Long groupId, List<String> memberIds) {
conversationGroupManagerService.inviteMembersInConversationGroup(simulation, member, groupId, memberIds);
public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member, Long id, List<String> memberIds) {
conversationGroupManagerService.inviteMembersInConversationGroup(simulation, member, id, memberIds);
}
/**
* 踢人
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Remove_Member)
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long groupId, List<String> memberIds) {
conversationGroupManagerService.removeMemberConversationGroup(simulation, member, groupId, memberIds);
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long id, List<String> memberIds) {
conversationGroupManagerService.removeMemberConversationGroup(simulation, member, id, memberIds);
}
/**
* 退出群组信息
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Exit)
public void exitConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
conversationGroupManagerService.exitConversationGroup(simulation, member, groupId);
public void exitConversationGroup(Simulation simulation, SimulationMember member, Long id) {
conversationGroupManagerService.exitConversationGroup(simulation, member, id);
}
/**
* 解散群组
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Dissolve)
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
conversationGroupManagerService.dissolveConversationGroup(simulation, member, groupId);
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long id) {
conversationGroupManagerService.dissolveConversationGroup(simulation, member, id);
}
/**
* 发送语音信息
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Audio_Chat)
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long groupId, String audioPath, String content) {
return conversationGroupManagerService.audioChat(simulation, member, groupId, audioPath, content);
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_Text_Chat)
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long groupId, String content) {
return conversationGroupManagerService.textChat(simulation, member, groupId, content);
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long id, String content) {
return conversationGroupManagerService.textChat(simulation, member, id, content);
}
/**
* 发送Base64音频文件
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Audio_Base64)
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) {
return conversationGroupManagerService.audioBase64(simulation, member, groupId, fileBase64Str);
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long id, String fileBase64Str) {
return conversationGroupManagerService.audioBase64(simulation, member, id, fileBase64Str);
}
/**
* 阅读群组信息
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Get_Unread_Message)
public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
return conversationGroupManagerService.readConversationGroup(simulation, member, groupId);
public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation, SimulationMember member, Long id) {
return conversationGroupManagerService.readConversationGroup(simulation, member, id);
}
}

View File

@ -52,6 +52,11 @@ public class VoiceDiscriminateResult {
*/
private List<ParamExtractResult> paramExtractResultList;
/**
* 会话的ID用于回复
*/
private Long conversionGroupId;
/**
* 匹配人员集合
*/