diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java index 0410ffca8..cf09ccd93 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java @@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.conversation; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import lombok.Getter; +import lombok.Setter; import java.time.LocalDateTime; import java.util.HashSet; @@ -15,7 +16,8 @@ public class ConversationGroupMessage extends ConversationMessage { /** * 已读角色的ID列表 */ - private final Set readerSet = new HashSet<>(); + @Setter + private Set readerSet = new HashSet<>(); /** * 是否全部已读 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/StorageSimulation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/StorageSimulation.java index 07712cd12..7349f026e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/StorageSimulation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/StorageSimulation.java @@ -2,8 +2,10 @@ package club.joylink.rtss.simulation.cbtc.data.storage; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.conversation.Conversation; +import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup; import club.joylink.rtss.simulation.cbtc.data.storage.ctc.StorageSimulationCtcDataRepository; import club.joylink.rtss.simulation.cbtc.data.storage.vo.StorageConversation; +import club.joylink.rtss.simulation.cbtc.data.storage.vo.StorageConversationGroup; import club.joylink.rtss.util.jsonSerialize.Boolean2NumDeserializer; import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -68,6 +70,8 @@ public class StorageSimulation { */ private List conversationList; + private List conversationGroupList; + public StorageSimulation(Simulation simulation, boolean script) { this.systemTime = simulation.getSystemTime(); this.planRunning = simulation.isPlanRunning(); @@ -82,6 +86,10 @@ public class StorageSimulation { this.conversationList = simulation.getSimulationConversationMap().values().stream() .map(StorageConversation::new).collect(Collectors.toList()); } + if (!CollectionUtils.isEmpty(simulation.getSimulationConversationGroupMap())) { + this.conversationGroupList = simulation.getSimulationConversationGroupMap().values().stream() + .map(StorageConversationGroup::new).collect(Collectors.toList()); + } } public void recover2Simulation(Simulation simulation) { @@ -98,5 +106,10 @@ public class StorageSimulation { simulation.getSimulationConversationMap().clear(); // 清空会话信息 this.conversationList.forEach(c -> simulation.addConversation(c.convert2SimulationObj(simulation))); } + if (!CollectionUtils.isEmpty(this.conversationGroupList)) { + Map conversationGroupMap = this.conversationGroupList.stream() + .map(g -> g.convert2SimulationObj(simulation)).collect(Collectors.toMap(ConversationGroup::getId, g -> g)); + simulation.initDefaultConversationGroupMap(conversationGroupMap); + } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationGroup.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationGroup.java new file mode 100644 index 000000000..150f50074 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationGroup.java @@ -0,0 +1,86 @@ +package club.joylink.rtss.simulation.cbtc.data.storage.vo; + +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.conversation.CommunicationObject; +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 lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +/** + * 背景会话信息 + */ +@Getter +@Setter +@NoArgsConstructor +public class StorageConversationGroup { + + private Long id; + + private String imageUrl; + + private String name; + + private String creatorId; + + private LocalDateTime time; + + private List memberList; + + private List messageList; + + private Integer messageId; + + /** + * 保存背景时会话群组消息 + */ + public StorageConversationGroup(ConversationGroup conversationGroup) { + this.id = conversationGroup.getId(); + this.imageUrl = conversationGroup.getImageUrl(); + this.name = conversationGroup.getName(); + if (conversationGroup.getCreator() != null) { + this.creatorId = conversationGroup.getCreator().getId(); + } + this.time = conversationGroup.getTime(); + if (!CollectionUtils.isEmpty(conversationGroup.getMemberList())) { + this.memberList = conversationGroup.getMemberList().stream().map(StorageConversationMember::new).collect(Collectors.toList()); + } + if (!CollectionUtils.isEmpty(conversationGroup.getMessageList())) { + this.messageList = conversationGroup.getMessageList().stream().map(StorageConversationGroupMessage::new).collect(Collectors.toList()); + } + this.messageId = conversationGroup.getMessageId().get(); + } + + /** + * 加载背景时会话信息 + * + * @param simulation 仿真 + * @return 会话信息 + */ + public ConversationGroup convert2SimulationObj(Simulation simulation) { + SimulationMember creator = StringUtils.hasText(this.creatorId) ? simulation.querySimulationMemberById(this.creatorId) : null; + List memberList = null; + if (!CollectionUtils.isEmpty(this.memberList)) { + memberList = this.memberList.stream().map(m -> simulation.querySimulationMemberById(m.getMemberId())).collect(Collectors.toList()); + } + ConversationGroup group = new ConversationGroup(this.id, this.imageUrl, this.name, this.time, creator, memberList); + if (this.messageId != null) { + group.getMessageId().set(this.messageId); + } + if (!CollectionUtils.isEmpty(this.messageList)) { + this.messageList.forEach(message -> group.addMessage(message.convert2SimulationObj(simulation))); + } + return group; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationGroupMessage.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationGroupMessage.java new file mode 100644 index 000000000..81f6ba9f8 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationGroupMessage.java @@ -0,0 +1,58 @@ +package club.joylink.rtss.simulation.cbtc.data.storage.vo; + +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroupMessage; +import club.joylink.rtss.simulation.cbtc.conversation.ConversationMessage; +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.springframework.util.CollectionUtils; + +import java.time.LocalDateTime; +import java.util.Set; + +@Setter +@Getter +@NoArgsConstructor +public class StorageConversationGroupMessage { + + private String id; + + private String memberId; + + private LocalDateTime time; + + private String content; + + private String audioPath; + + private Set readerSet; + + /** + * 是否全部已读 + */ + private Boolean allRead; + + public StorageConversationGroupMessage(ConversationGroupMessage conversationMessage) { + this.id = conversationMessage.getId(); + this.memberId = conversationMessage.getMember().getId(); + this.time = conversationMessage.getTime(); + this.content = conversationMessage.getContent(); + this.audioPath = conversationMessage.getAudioPath(); + this.readerSet = !CollectionUtils.isEmpty(readerSet) ? conversationMessage.getReaderSet() : null; + this.allRead = conversationMessage.isAllRead() ? true : null; + } + + public ConversationGroupMessage convert2SimulationObj(Simulation simulation) { + SimulationMember simulationMember = simulation.querySimulationMemberById(this.memberId); + ConversationGroupMessage message = new ConversationGroupMessage(id, simulationMember, time, content, audioPath); + if (!CollectionUtils.isEmpty(readerSet)) { + message.setReaderSet(readerSet); + } + if (allRead != null) { + message.finishRead(); + } + return message; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationMember.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationMember.java index 0c54ccd5b..c6bfa412a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationMember.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/vo/StorageConversationMember.java @@ -13,6 +13,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import org.springframework.util.CollectionUtils; +import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @@ -28,10 +29,24 @@ public class StorageConversationMember { private Boolean connect; + /** + * 加入时间 + */ + @Setter + private LocalDateTime time; + + /** + * 角色 + */ + @Setter + private ConversationMember.Role role; + public StorageConversationMember(ConversationMember conversationMember) { this.memberId = conversationMember.getMember().getId(); if (conversationMember.isConnect()) { this.connect = Boolean.TRUE; } + this.time = conversationMember.getTime(); + this.role = conversationMember.getRole(); } }