This commit is contained in:
tiger_zhou 2023-04-26 15:16:04 +08:00
commit c209942286
12 changed files with 211 additions and 14 deletions

View File

@ -1632,6 +1632,16 @@ public class Operation {
* 会话群组获取未读消息 * 会话群组获取未读消息
*/ */
Conversation_Group_Read_Message(new Label[]{Label.CLIENT}, true), Conversation_Group_Read_Message(new Label[]{Label.CLIENT}, true),
/**
* 跟指定用户文字私聊
*/
Conversation_Group_Private_Text_Chat(new Label[]{Label.CLIENT}, true),
/**
* 跟指定用户发语音信息
*/
Conversation_Group_Private_Audio_Base64(new Label[]{Label.CLIENT}, true),
//---------------------------- PSL ------------------------------ //---------------------------- PSL ------------------------------
/** /**
* PSL盘按下按钮 * PSL盘按下按钮

View File

@ -58,6 +58,14 @@ public class SimulationIdGenerator {
return String.valueOf(memberId.incrementAndGet()); return String.valueOf(memberId.incrementAndGet());
} }
public Long getCurrentMemberId() {
return memberId.get();
}
public void setMemberId(Long id) {
this.memberId.set(id);
}
/** /**
* 剧本编制/预览/演出时更新成员id基础值 * 剧本编制/预览/演出时更新成员id基础值
*/ */

View File

@ -383,8 +383,11 @@ public class SimulationServiceImpl implements SimulationService {
if (CollectionUtils.isEmpty(conversationGroupVOList)) { if (CollectionUtils.isEmpty(conversationGroupVOList)) {
return; return;
} }
Map<Long, ConversationGroup> groupMap = conversationGroupVOList.stream().map(g -> new ConversationGroup(simulation, g)) Map<Long, ConversationGroup> groupMap = conversationGroupVOList.stream().map(g ->{
.collect(Collectors.toMap(ConversationGroup::getId, group -> group)); ConversationGroup group = new ConversationGroup(simulation, g);
group.initGroupType();
return group;
}).collect(Collectors.toMap(ConversationGroup::getId, group -> group));
simulation.initDefaultConversationGroupMap(groupMap); simulation.initDefaultConversationGroupMap(groupMap);
} }
} }

View File

@ -4,6 +4,7 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.vo.conversation.ConversationGroupVO; import club.joylink.rtss.vo.conversation.ConversationGroupVO;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -45,6 +46,11 @@ public class ConversationGroup extends Chat {
*/ */
private AtomicInteger messageId = new AtomicInteger(0); private AtomicInteger messageId = new AtomicInteger(0);
/**
* 群组类型
*/
private ConversationType type;
/** /**
* 用户组信息 * 用户组信息
* *
@ -223,4 +229,24 @@ public class ConversationGroup extends Chat {
} }
return member.getMember(); return member.getMember();
} }
public void initGroupType() {
if (this.type == null) {
this.type = ConversationType.GROUP_CHAT;
}
}
public void initPrivateType() {
if (this.type == null) {
this.type = ConversationType.PRIVATE_CHAT;
}
}
public boolean isGroup() {
return Objects.equals(this.type, ConversationType.GROUP_CHAT);
}
public boolean isPrivate() {
return Objects.equals(this.type, ConversationType.PRIVATE_CHAT);
}
} }

View File

@ -52,7 +52,8 @@ public class ConversationGroupHandlerService {
if (member == null) { if (member == null) {
return List.of(); return List.of();
} else { } else {
return allGroup.stream().filter(g -> g.isConversationMember(member)).map(ConversationGroupVO::new).collect(Collectors.toList()); return allGroup.stream().filter(g -> g.isConversationMember(member))
.map(g -> new ConversationGroupVO(g, member)).collect(Collectors.toList());
} }
} }
@ -73,6 +74,7 @@ public class ConversationGroupHandlerService {
List<SimulationMember> simulationMembers = memberIds.stream().map(simulation::getSimulationMemberById).collect(Collectors.toList()); List<SimulationMember> simulationMembers = memberIds.stream().map(simulation::getSimulationMemberById).collect(Collectors.toList());
Long groupId = simulation.getMaxConversationGroupId(); Long groupId = simulation.getMaxConversationGroupId();
conversationGroup = new ConversationGroup(groupId, imageUrl, name, simulation.getCorrectSystemTime(), member, simulationMembers); conversationGroup = new ConversationGroup(groupId, imageUrl, name, simulation.getCorrectSystemTime(), member, simulationMembers);
conversationGroup.initGroupType();
simulation.addConversationGroup(conversationGroup); simulation.addConversationGroup(conversationGroup);
// 通知用户消息 // 通知用户消息
applicationEventPublisher.publishEvent(new SimulationConversationGroupCreateEvent(this, simulation, conversationGroup)); applicationEventPublisher.publishEvent(new SimulationConversationGroupCreateEvent(this, simulation, conversationGroup));
@ -306,6 +308,63 @@ public class ConversationGroupHandlerService {
applicationEventPublisher.publishEvent(new SimulationConversationGroupMessageStatusEvent(this, simulation, conversationGroup, messageList)); 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 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 -> group.isPrivate() && group.contains(communicator)).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;
}
/** /**
* 对群组操作时基础判断 * 对群组操作时基础判断
* *

View File

@ -3,6 +3,7 @@ package club.joylink.rtss.simulation.cbtc.conversation;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO; 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.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.*;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.vo.client.SocketMessageVO; import club.joylink.rtss.vo.client.SocketMessageVO;
@ -32,6 +33,20 @@ public class ConversationGroupListener {
@Autowired @Autowired
private ConversationGroupHandlerService conversationGroupHandlerService; private ConversationGroupHandlerService conversationGroupHandlerService;
@EventListener
public void handlePrivateChat(SimulationConversationGroupPrivateChatEvent event) {
ConversationGroup conversationGroup = event.getConversationGroup();
ConversationGroupSocketMessageVO messageVO = ConversationGroupSocketMessageVO.MessageType.JOIN.generateMessageVO(conversationGroup, null);
conversationGroup.getSimulationMemberList().forEach(member -> {
if (!member.isRobot()) {
String name = ConversationGroupVO.getGroupName(conversationGroup, member);
messageVO.setName(name);
doSendMessage(event.getSimulation(), Set.of(member.getUserId()), messageVO);
}
});
}
/** /**
* 处理创建群组事件 * 处理创建群组事件
* @param event 事件信息 * @param event 事件信息

View File

@ -111,6 +111,32 @@ public class ConversationGroupOperateHandler {
return conversationGroupManagerService.audioBase64(simulation, member, id, fileBase64Str); return conversationGroupManagerService.audioBase64(simulation, member, id, 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);
}
/**
* 跟指定用户发语音信息
* @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);
}
/** /**
* 阅读群组信息 * 阅读群组信息
*/ */

View File

@ -1,10 +1,7 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vo; package club.joylink.rtss.simulation.cbtc.data.storage.vo;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.CommunicationObject; import club.joylink.rtss.simulation.cbtc.conversation.*;
import club.joylink.rtss.simulation.cbtc.conversation.Conversation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroupMessage;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -15,6 +12,7 @@ import org.springframework.util.StringUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -42,6 +40,8 @@ public class StorageConversationGroup {
private Integer messageId; private Integer messageId;
private ConversationType type;
/** /**
* 保存背景时会话群组消息 * 保存背景时会话群组消息
*/ */
@ -49,6 +49,7 @@ public class StorageConversationGroup {
this.id = conversationGroup.getId(); this.id = conversationGroup.getId();
this.imageUrl = conversationGroup.getImageUrl(); this.imageUrl = conversationGroup.getImageUrl();
this.name = conversationGroup.getName(); this.name = conversationGroup.getName();
this.type = conversationGroup.getType();
if (conversationGroup.getCreator() != null) { if (conversationGroup.getCreator() != null) {
this.creatorId = conversationGroup.getCreator().getId(); this.creatorId = conversationGroup.getCreator().getId();
} }
@ -81,6 +82,11 @@ public class StorageConversationGroup {
if (!CollectionUtils.isEmpty(this.messageList)) { if (!CollectionUtils.isEmpty(this.messageList)) {
this.messageList.forEach(message -> group.addMessage(message.convert2SimulationObj(simulation))); this.messageList.forEach(message -> group.addMessage(message.convert2SimulationObj(simulation)));
} }
if (Objects.equals(this.type, ConversationType.PRIVATE_CHAT)) {
group.initPrivateType();
} else {
group.initGroupType();
}
return group; return group;
} }
} }

View File

@ -1,10 +1,12 @@
package club.joylink.rtss.simulation.cbtc.data.vo; package club.joylink.rtss.simulation.cbtc.data.vo;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup; import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -18,6 +20,7 @@ public class ConversationGroupSocketMessageVO {
/** /**
* 群组名称 * 群组名称
*/ */
@Setter
private String name; private String name;
/** /**

View File

@ -1,6 +1,8 @@
package club.joylink.rtss.simulation.cbtc.data.vo; package club.joylink.rtss.simulation.cbtc.data.vo;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup; import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationType;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -8,6 +10,7 @@ import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
@Getter @Getter
@Setter @Setter
@ -28,6 +31,8 @@ public class ConversationGroupVO {
private List<ConversationGroupMessageVO> messageList; private List<ConversationGroupMessageVO> messageList;
private ConversationType type;
public ConversationGroupVO(ConversationGroup conversation) { public ConversationGroupVO(ConversationGroup conversation) {
this.id = conversation.getId(); this.id = conversation.getId();
this.name = conversation.getName(); this.name = conversation.getName();
@ -36,15 +41,25 @@ public class ConversationGroupVO {
this.leaderId = conversation.getLeader() != null ? conversation.getLeader().getId() : null; this.leaderId = conversation.getLeader() != null ? conversation.getLeader().getId() : null;
this.memberList = ConversationMemberVO.convert2VOList(conversation.getMemberList()); this.memberList = ConversationMemberVO.convert2VOList(conversation.getMemberList());
this.messageList = ConversationGroupMessageVO.convert2VO(conversation.getMessageList()); this.messageList = ConversationGroupMessageVO.convert2VO(conversation.getMessageList());
this.type = conversation.getType();
} }
public static List<ConversationGroupVO> convert2VOList(List<ConversationGroup> list) { public ConversationGroupVO(ConversationGroup conversation, SimulationMember member) {
List<ConversationGroupVO> voList = new ArrayList<>(); this(conversation);
if (!CollectionUtils.isEmpty(list)) { this.name = getGroupName(conversation, member);
for (ConversationGroup conversation : list) { }
voList.add(new ConversationGroupVO(conversation));
} /**
* 私聊的时候名称使用对方的
* @param conversation 会话
* @param member 成员
* @return 名称
*/
public static String getGroupName(ConversationGroup conversation, SimulationMember member) {
if (conversation.isPrivate()) {
return conversation.getMemberList().stream().filter(c -> !Objects.equals(c.getMember(), member))
.map(c -> c.getMember().getMemberName()).findFirst().orElse(conversation.getName());
} }
return voList; return conversation.getName();
} }
} }

View File

@ -0,0 +1,20 @@
package club.joylink.rtss.simulation.cbtc.event.conversation;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
import lombok.Getter;
/**
* 私聊会话事件
*/
@Getter
public class SimulationConversationGroupPrivateChatEvent extends AbstractSimulationEvent {
private ConversationGroup conversationGroup;
public SimulationConversationGroupPrivateChatEvent(Object source, Simulation simulation, ConversationGroup conversationGroup) {
super(source, simulation);
this.conversationGroup = conversationGroup;
}
}

View File

@ -13,6 +13,7 @@ import club.joylink.rtss.simulation.cbtc.event.SimulationUserPlayChangeEvent;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -179,6 +180,11 @@ public class MemberManager {
} }
if (id == null) { if (id == null) {
id = simulation.getIdGenerator().nextMemberId(); id = simulation.getIdGenerator().nextMemberId();
} else {
Long generatorId = simulation.getIdGenerator().getCurrentMemberId();
if (NumberUtils.isCreatable(id) && generatorId < Long.parseLong(id)) { // 如果ID大于当前记录ID则将ID置于当前大小 防止ID重复导致出错
simulation.getIdGenerator().setMemberId(Long.parseLong(id));
}
} }
SimulationMember member = new SimulationMember(id, type, device); SimulationMember member = new SimulationMember(id, type, device);
member.setName(name); member.setName(name);