From 0d1f5bf56b6710fd0e803388b3ca072f5bb860fe Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 14 Apr 2023 16:25:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=BE=A4=E7=BB=84=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=EF=BC=8C=E4=BB=BF=E7=9C=9F=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=BE=A4=E7=BB=84=E6=8E=A5=E5=8F=A3=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/20230413-wei-training.sql | 2 +- sql/20230414-wei-conversation-group.sql | 13 +++ .../ConversationGroupController.java | 4 +- .../SimulationConversationController.java | 11 ++ .../RtsConversationGroupInfo.java | 4 +- .../RtsConversationGroupInfoExample.java | 20 ++-- .../ConversationGroupService.java | 10 +- .../ConversationGroupServiceImpl.java | 12 +- .../rtss/simulation/cbtc/Simulation.java | 29 +++++ .../cbtc/SimulationServiceImpl.java | 27 +++++ .../simulation/cbtc/conversation/Chat.java | 70 ++++++++++++ .../cbtc/conversation/Conversation.java | 77 ++----------- .../cbtc/conversation/ConversationGroup.java | 107 ++++++++++++++++++ .../ConversationGroupMessage.java | 44 +++++++ .../ConversationManagerService.java | 13 +++ .../data/vo/ConversationGroupMessageVO.java | 40 +++++++ .../cbtc/data/vo/ConversationGroupVO.java | 41 +++++++ .../vo/conversation/ConversationGroupVO.java | 8 +- .../mapper/RtsConversationGroupInfoMapper.xml | 18 +-- 19 files changed, 454 insertions(+), 96 deletions(-) create mode 100644 sql/20230414-wei-conversation-group.sql create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/conversation/Chat.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroup.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ConversationGroupMessageVO.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ConversationGroupVO.java diff --git a/sql/20230413-wei-training.sql b/sql/20230413-wei-training.sql index 46797ee1b..b9f75f232 100644 --- a/sql/20230413-wei-training.sql +++ b/sql/20230413-wei-training.sql @@ -1,3 +1,3 @@ ALTER TABLE `joylink`.`rts_published_training2` ADD COLUMN `shared` int NULL DEFAULT 0 COMMENT '0 不共享,1共享' AFTER `client`; -update rts_published_training2 SET shared = 1 WHERE creator_id = 0 ; \ No newline at end of file +update rts_published_training2 SET shared = 1,org_id = null WHERE creator_id = 0 ; \ No newline at end of file diff --git a/sql/20230414-wei-conversation-group.sql b/sql/20230414-wei-conversation-group.sql new file mode 100644 index 000000000..0868e40bb --- /dev/null +++ b/sql/20230414-wei-conversation-group.sql @@ -0,0 +1,13 @@ +CREATE TABLE `rts_conversation_group_info` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '群组名称', + `map_id` bigint DEFAULT NULL COMMENT '所属地图ID', + `project_code` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '所属项目', + `leader_id` varchar(12) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '群主角色ID', + `member_ids` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '群组用户角色ID', + `create_time` datetime DEFAULT NULL, + `update_time` datetime DEFAULT NULL, + `creator_id` bigint DEFAULT NULL, + `status` int DEFAULT NULL COMMENT '状态0=编辑,1=使用', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='群组信息设置'; \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/controller/conversation/ConversationGroupController.java b/src/main/java/club/joylink/rtss/controller/conversation/ConversationGroupController.java index 2ef837da9..d30d2a293 100644 --- a/src/main/java/club/joylink/rtss/controller/conversation/ConversationGroupController.java +++ b/src/main/java/club/joylink/rtss/controller/conversation/ConversationGroupController.java @@ -21,8 +21,8 @@ public class ConversationGroupController { private ConversationGroupServiceImpl conversationGroupService; @GetMapping("/list") - public List queryList(ConversationGroupQueryVO queryVO, @RequestAttribute AccountVO user) { - return conversationGroupService.queryList(queryVO, user); + public List queryList(ConversationGroupQueryVO queryVO) { + return conversationGroupService.queryList(queryVO); } @GetMapping("/page/users") diff --git a/src/main/java/club/joylink/rtss/controller/simulation/SimulationConversationController.java b/src/main/java/club/joylink/rtss/controller/simulation/SimulationConversationController.java index 2214a52e1..4cfc27309 100644 --- a/src/main/java/club/joylink/rtss/controller/simulation/SimulationConversationController.java +++ b/src/main/java/club/joylink/rtss/controller/simulation/SimulationConversationController.java @@ -4,6 +4,7 @@ import club.joylink.rtss.controller.advice.AuthenticateInterceptor; import club.joylink.rtss.simulation.cbtc.conversation.CommunicationObject; import club.joylink.rtss.simulation.cbtc.conversation.ConversationManagerService; import club.joylink.rtss.simulation.cbtc.conversation.ConversationText; +import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO; import club.joylink.rtss.simulation.cbtc.data.vo.ConversationVO; import club.joylink.rtss.vo.AccountVO; import org.springframework.beans.factory.annotation.Autowired; @@ -100,4 +101,14 @@ public class SimulationConversationController { this.conversationManagerService.textChat(group, id, text, user); } + /** + * 获取本仿真的用户群组信息 + * + * @param group 仿真ID + * @return 用户群组 + */ + @GetMapping("/group/list") + public List groupList(@PathVariable String group) { + return conversationManagerService.getAllConversationsGroup(group); + } } diff --git a/src/main/java/club/joylink/rtss/entity/conversation/RtsConversationGroupInfo.java b/src/main/java/club/joylink/rtss/entity/conversation/RtsConversationGroupInfo.java index eb3335757..5d4ea20a8 100644 --- a/src/main/java/club/joylink/rtss/entity/conversation/RtsConversationGroupInfo.java +++ b/src/main/java/club/joylink/rtss/entity/conversation/RtsConversationGroupInfo.java @@ -43,7 +43,7 @@ public class RtsConversationGroupInfo { /** * 创建者 */ - private Long creatorId; + private String creatorId; /** * 状态,1为有效 @@ -53,7 +53,7 @@ public class RtsConversationGroupInfo { /** * 群组ID */ - private Long leaderId; + private String leaderId; /** * 成员ID diff --git a/src/main/java/club/joylink/rtss/entity/conversation/RtsConversationGroupInfoExample.java b/src/main/java/club/joylink/rtss/entity/conversation/RtsConversationGroupInfoExample.java index 080407c31..a1a7d5b34 100644 --- a/src/main/java/club/joylink/rtss/entity/conversation/RtsConversationGroupInfoExample.java +++ b/src/main/java/club/joylink/rtss/entity/conversation/RtsConversationGroupInfoExample.java @@ -625,52 +625,52 @@ public class RtsConversationGroupInfoExample { return (Criteria) this; } - public Criteria andLeaderIdEqualTo(Long value) { + public Criteria andLeaderIdEqualTo(String value) { addCriterion("leader_id =", value, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdNotEqualTo(Long value) { + public Criteria andLeaderIdNotEqualTo(String value) { addCriterion("leader_id <>", value, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdGreaterThan(Long value) { + public Criteria andLeaderIdGreaterThan(String value) { addCriterion("leader_id >", value, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdGreaterThanOrEqualTo(Long value) { + public Criteria andLeaderIdGreaterThanOrEqualTo(String value) { addCriterion("leader_id >=", value, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdLessThan(Long value) { + public Criteria andLeaderIdLessThan(String value) { addCriterion("leader_id <", value, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdLessThanOrEqualTo(Long value) { + public Criteria andLeaderIdLessThanOrEqualTo(String value) { addCriterion("leader_id <=", value, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdIn(List values) { + public Criteria andLeaderIdIn(List values) { addCriterion("leader_id in", values, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdNotIn(List values) { + public Criteria andLeaderIdNotIn(List values) { addCriterion("leader_id not in", values, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdBetween(Long value1, Long value2) { + public Criteria andLeaderIdBetween(String value1, String value2) { addCriterion("leader_id between", value1, value2, "leaderId"); return (Criteria) this; } - public Criteria andLeaderIdNotBetween(Long value1, Long value2) { + public Criteria andLeaderIdNotBetween(String value1, String value2) { addCriterion("leader_id not between", value1, value2, "leaderId"); return (Criteria) this; } diff --git a/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupService.java b/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupService.java index 82ac50ac7..677de85b2 100644 --- a/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupService.java +++ b/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupService.java @@ -19,7 +19,7 @@ public interface ConversationGroupService { * @param user 用户 * @return 群组列表 */ - List queryList(ConversationGroupQueryVO queryVO, AccountVO user); + List queryList(ConversationGroupQueryVO queryVO); /** * 查询带参数的会话群组列表 @@ -59,4 +59,12 @@ public interface ConversationGroupService { * @param id 主键 */ void delete(Long id); + + /** + * 通过地图获取会话群组信息 + * + * @param mapId 地图信息 + * @return 群组列表 + */ + List getConversationGroupByMapId(Long mapId); } diff --git a/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupServiceImpl.java b/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupServiceImpl.java index 26340ef57..8d98137a8 100644 --- a/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -33,9 +34,8 @@ public class ConversationGroupServiceImpl implements ConversationGroupService { @Autowired private RtsConversationGroupInfoMapper conversationGroupInfoMapper; - @Override - public List queryList(ConversationGroupQueryVO queryVO, AccountVO user) { + public List queryList(ConversationGroupQueryVO queryVO) { List conversationGroupInfoList = conversationGroupInfoMapper.selectByExampleWithBLOBs(getExample(queryVO)); return conversationGroupInfoList.stream().map(ConversationGroupVO::new).collect(Collectors.toList()); } @@ -81,6 +81,14 @@ public class ConversationGroupServiceImpl implements ConversationGroupService { conversationGroupInfoMapper.deleteByPrimaryKey(id); } + @Override + public List getConversationGroupByMapId(Long mapId) { + ConversationGroupQueryVO queryVO = new ConversationGroupQueryVO(); + queryVO.setMapIds(Arrays.asList(mapId)); + return queryList(queryVO); + } + + /** * 获取查询条件 * diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java index c76aa68a6..8a721098b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java @@ -10,6 +10,7 @@ import club.joylink.rtss.simulation.cbtc.command.VoiceCommandBO; import club.joylink.rtss.simulation.cbtc.competition.CompetitionBO; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.conversation.Conversation; +import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup; import club.joylink.rtss.simulation.cbtc.conversation.ConversationMember; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationIscsDataRepository; @@ -148,6 +149,13 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation simulationConversationMap = new ConcurrentHashMap<>(); + /** + * 用户组会话 + * key-用户组ID + * val-仿真用户组信息 + */ + private Map simulationConversationGroupMap = new ConcurrentHashMap<>(); + /** * 地图数据是否异常 */ @@ -308,6 +316,27 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation(this.simulationConversationMap.values()); } + public void addConversationGroup(ConversationGroup group) { + this.simulationConversationGroupMap.put(group.getId(), group); + } + + public void addConversationGroupMap(Map map) { + this.simulationConversationGroupMap.putAll(map); + } + + public ConversationGroup getConversationGroup(Long id) { + ConversationGroup group = this.simulationConversationGroupMap.get(id); + if (Objects.isNull(group)) { + throw new SimulationException(SimulationExceptionType.Simulation_Conversation_Not_Exist, + String.format("id[%s]的群组不存在", id)); + } + return group; + } + + public List queryAllConversationGroup(){ + return new ArrayList<>(this.simulationConversationGroupMap.values()); + } + public RealDeviceConfig getRealDeviceById(Long id) { for (RealDeviceConfig realDevice : this.realDeviceList) { if (Objects.equals(realDevice.getProjectDevice().getId(), id)) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java index fbe80ff43..9a506eeb4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java @@ -3,9 +3,11 @@ package club.joylink.rtss.simulation.cbtc; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.ISysUserService; import club.joylink.rtss.services.RunPlanDraftService; +import club.joylink.rtss.services.conversation.ConversationGroupService; import club.joylink.rtss.services.mapFunction.RtsMapFunctionService; import club.joylink.rtss.services.permission.PermissionSubjectService; import club.joylink.rtss.simulation.SimulationManager; +import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup; import club.joylink.rtss.simulation.cbtc.discriminate.IVoiceDiscriminateRule; import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateRule; import club.joylink.rtss.simulation.cbtc.event.SimulationCreateSuccessEvent; @@ -23,6 +25,7 @@ import club.joylink.rtss.vo.client.factory.SocketMessageFactory; import club.joylink.rtss.vo.client.mapFunction.MapFunctionVO; import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam; +import club.joylink.rtss.vo.conversation.ConversationGroupVO; import club.joylink.rtss.vo.permission.PermissionSubjectTypeEnum; import club.joylink.rtss.vo.permission.PermissionSystemAbilityVO; import club.joylink.rtss.vo.permission.subject.PermissionSubjectVO; @@ -71,6 +74,10 @@ public class SimulationServiceImpl implements SimulationService { @Autowired private IVoiceDiscriminateRule discriminateRule; + + @Autowired + private ConversationGroupService conversationGroupService; + @Override public String createSimulation(long mapId, Long mapFunctionId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO,Map createUserType) { return createSimulationPojo(mapId, mapFunctionId, workParamVO, loginUserInfoVO, createUserType).getId(); @@ -305,6 +312,9 @@ public class SimulationServiceImpl implements SimulationService { List ruleList = this.discriminateRule.findRuleByMapId(mapId); simulation.setVoiceRuleList(ruleList); + // 群组配置信息 + initConversationGroup(simulation); + simulation.setMapFunctionId(mapFunctionId); simulation.setCreateUserType(createUserType); LoginUserInfoVO loginUserInfo = simulation.getBuildParams().getLoginUserInfo(); @@ -365,4 +375,21 @@ public class SimulationServiceImpl implements SimulationService { this.simulationLifeCycleService.reloadRunPlan(simulation, runPlanVO, null); simulation.getRepository().clearChangeTrips(); //清除掉之前的车次计划变化信息 } + + + /** + * 初始化地图的群组信息 + * + * @param simulation 仿真对象 + */ + private void initConversationGroup(Simulation simulation) { + List conversationGroupVOList = + conversationGroupService.getConversationGroupByMapId(simulation.getBuildParams().getMap().getId()); + if (CollectionUtils.isEmpty(conversationGroupVOList)) { + return; + } + Map groupMap = conversationGroupVOList.stream().map(g -> new ConversationGroup(simulation, g)) + .collect(Collectors.toMap(ConversationGroup::getId, group -> group)); + simulation.addConversationGroupMap(groupMap); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/Chat.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/Chat.java new file mode 100644 index 000000000..6110020a1 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/Chat.java @@ -0,0 +1,70 @@ +package club.joylink.rtss.simulation.cbtc.conversation; + +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; +import lombok.Data; +import org.springframework.util.CollectionUtils; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * 谈话 + */ +@Data +public abstract class Chat { + + private SimulationMember creator; + + private LocalDateTime time; + + private List memberList = new ArrayList<>(); + + /** + * 获取会话中所有仿真成员 + */ + public List getSimulationMemberList() { + return this.memberList.stream().map(ConversationMember::getMember).collect(Collectors.toList()); + } + + /** + * 获取会话中的所有仿真成员的id + */ + public List getSimulationMemberIds() { + return this.memberList.stream().map(conversationMember -> conversationMember.getMember().getId()).collect(Collectors.toList()); + } + + public boolean isConversationMember(SimulationMember member) { + for (ConversationMember conversationMember : this.memberList) { + if (Objects.equals(conversationMember.getMember(), member)) { + return true; + } + } + return false; + } + + public boolean isCreator(SimulationMember member) { + return Objects.equals(member, this.creator); + } + + public boolean contains(SimulationMember member) { + for (ConversationMember conversationMember : this.memberList) { + if (Objects.equals(member, conversationMember.getMember())) { + return true; + } + } + return false; + } + + /** + * 该成员退出会话 + */ + public void exit(SimulationMember member) { + if (CollectionUtils.isEmpty(this.memberList)) { + return; + } + this.memberList.removeIf(conversationMember -> Objects.equals(conversationMember.getMember().getId(), member.getId())); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/Conversation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/Conversation.java index ce54020b9..b12798aff 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/Conversation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/Conversation.java @@ -13,16 +13,10 @@ import java.util.Objects; import java.util.stream.Collectors; @Getter -public class Conversation { +public class Conversation extends Chat { private String id; - private SimulationMember creator; - - private LocalDateTime time; - - private List memberList = new ArrayList<>(); - private List messageList = new ArrayList<>(); private CommunicationObject object; @@ -31,53 +25,29 @@ public class Conversation { public Conversation(String id, SimulationMember creator, LocalDateTime systemTime, List memberList, CommunicationObject object) { this.id = id; - this.creator = creator; - this.time = systemTime; + setCreator(creator); + setTime(systemTime); if (creator != null) { ConversationMember member1 = new ConversationMember(creator); member1.connect(); - this.memberList.add(member1); + getMemberList().add(member1); } if (memberList != null) { for (SimulationMember member : memberList) { - this.memberList.add(new ConversationMember(member)); + getMemberList().add(new ConversationMember(member)); } } - this.over = false; this.object = object; } - /** - * 获取会话中所有仿真成员 - */ - public List getSimulationMemberList() { - return this.memberList.stream().map(ConversationMember::getMember).collect(Collectors.toList()); - } - - /** - * 获取会话中的所有仿真成员的id - */ - public List getSimulationMemberIds() { - return this.memberList.stream().map(conversationMember -> conversationMember.getMember().getId()).collect(Collectors.toList()); - } - - public boolean isConversationMember(SimulationMember member) { - for (ConversationMember conversationMember : this.memberList) { - if (Objects.equals(conversationMember.getMember(), member)) { - return true; - } - } - return false; - } - public void memberConnect(SimulationMember member) { ConversationMember conversationMember = this.getConversationMember(member); conversationMember.connect(); } public boolean hasMemberConnect() { - for (ConversationMember conversationMember : this.memberList) { + for (ConversationMember conversationMember : getMemberList()) { if (conversationMember.isConnect()) { return true; } @@ -86,8 +56,8 @@ public class Conversation { } public boolean hasOtherMemberConnect() { - for (ConversationMember conversationMember : this.memberList) { - if (!Objects.equals(conversationMember.getMember(), creator) && conversationMember.isConnect()) { + for (ConversationMember conversationMember : getMemberList()) { + if (!Objects.equals(conversationMember.getMember(), getCreator()) && conversationMember.isConnect()) { return true; } } @@ -95,7 +65,7 @@ public class Conversation { } private ConversationMember getConversationMember(SimulationMember member) { - for (ConversationMember conversationMember : this.memberList) { + for (ConversationMember conversationMember : getMemberList()) { if (Objects.equals(conversationMember.getMember(), member)) { return conversationMember; } @@ -103,42 +73,19 @@ public class Conversation { throw new SimulationException(SimulationExceptionType.System_Fault); } - public boolean isCreator(SimulationMember member) { - return Objects.equals(member, this.creator); + public void addMessage(ConversationMessage conversationMessage) { + this.messageList.add(conversationMessage); } public void over() { this.over = true; } - public void addMessage(ConversationMessage conversationMessage) { - this.messageList.add(conversationMessage); - } - - public boolean contains(SimulationMember member) { - for (ConversationMember conversationMember : this.memberList) { - if (Objects.equals(member, conversationMember.getMember())) { - return true; - } - } - return false; - } - - /** - * 该成员退出会话 - */ - public void exit(SimulationMember member) { - if (CollectionUtils.isEmpty(memberList)) { - return; - } - this.memberList.removeIf(conversationMember -> Objects.equals(conversationMember.getMember().getId(), member.getId())); - } - /** * 会话中是否已经没有成员了 */ public boolean isEmpty() { - return CollectionUtils.isEmpty(memberList); + return CollectionUtils.isEmpty(getMemberList()); } /** diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroup.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroup.java new file mode 100644 index 000000000..8c4e35265 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroup.java @@ -0,0 +1,107 @@ +package club.joylink.rtss.simulation.cbtc.conversation; + +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO; +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; +import club.joylink.rtss.vo.conversation.ConversationGroupVO; +import lombok.Data; +import lombok.Getter; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +/** + * 群组对象 + */ +@Getter +public class ConversationGroup extends Chat { + + /** + * 聊天室ID + */ + private Long id; + + /** + * 聊天室名称 + */ + private String name; + + private List messageList = new ArrayList<>(); + + private AtomicInteger messageId = new AtomicInteger(0); + + /** + * 用户组信息 + * + * @param simulation 仿真信息 + * @param info 群组配置信息 + */ + public ConversationGroup(Simulation simulation, ConversationGroupVO info) { + this.id = info.getId(); + this.name = info.getName(); + SimulationMember leader = null; + if (info.getLeaderId() != null) { + leader = simulation.getSimulationMemberById(info.getLeaderId()); + setCreator(leader); + } + List memberList = null; + if (CollectionUtils.isEmpty(info.getMemberIds())) { + memberList = info.getMemberIds().stream().map(simulation::getSimulationMemberById).map(ConversationMember::new).collect(Collectors.toList()); + setMemberList(memberList); + } + } + + /** + * 生成消息ID + * + * @return 消息ID + */ + public String generateMessageId() { + return String.format("%s_%s", id, messageId.incrementAndGet()); + } + + public void addMessage(ConversationGroupMessage message) { + this.messageList.add(message); + } + + /** + * 获取该角色未读信息列表 + * + * @param member 角色信息 + * @return 消息列表 + */ + public List getUnreadMessages(SimulationMember member) { + // 没有消息,不是本群人员 + if (CollectionUtils.isEmpty(getMessageList()) && !isCreator(member) && !isConversationMember(member)) { + return List.of(); + } + return messageList.stream().filter(message -> { + if (message.isAllRead()) { // 全部已读 + return false; + } + return !message.getReaderSet().contains(member.getId()); // 在已读名单中 + }).collect(Collectors.toList()); + } + + /** + * 用户读消息 + * + * @param member 角色信息 + */ + public void readMessage(SimulationMember member){ + // 没有消息,不是本群人员 + List messageList = getUnreadMessages(member); + if (CollectionUtils.isEmpty(messageList)) { + return; + } + messageList.forEach(message -> { + message.read(member); + if (message.getReaderSet().size() >= getMemberList().size()) { // 全部用户已读 + message.finishRead(); + } + }); + } +} 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 new file mode 100644 index 000000000..98f4a7c0a --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupMessage.java @@ -0,0 +1,44 @@ +package club.joylink.rtss.simulation.cbtc.conversation; + +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; +import lombok.Getter; +import org.springframework.util.StringUtils; + +import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * 用户组消息实体 + */ +@Getter +public class ConversationGroupMessage extends ConversationMessage { + /** + * 已读角色的ID列表 + */ + private final Set readerSet = new HashSet<>(); + + /** + * 是否全部已读 + */ + private boolean allRead; + + public ConversationGroupMessage(String id, SimulationMember member, LocalDateTime systemTime, String content, String filePath) { + super(id, member, systemTime, content, filePath); + } + + /** + * 用户读群消息 + */ + public void read(SimulationMember member) { + readerSet.add(member.getId()); + } + + /** + * 所有人都已读完 + */ + public void finishRead() { + this.allRead = true; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationManagerService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationManagerService.java index 7ee3def51..839b2be3b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationManagerService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationManagerService.java @@ -4,6 +4,7 @@ import club.joylink.rtss.services.voice.VoiceService; import club.joylink.rtss.simulation.cbtc.GroupSimulationCache; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.competition.ScriptExecuteService; +import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO; import club.joylink.rtss.simulation.cbtc.data.vo.ConversationMessageVO; import club.joylink.rtss.simulation.cbtc.data.vo.ConversationVO; import club.joylink.rtss.simulation.cbtc.event.*; @@ -447,4 +448,16 @@ public class ConversationManagerService { simulation.addConversation(conversation); return conversation; } + + /** + * 获取所有群组信息 + * @param group + * @return + */ + public List getAllConversationsGroup(String group) { + Simulation simulation = groupSimulationCache.getSimulationByGroup(group); + List allGroup = simulation.queryAllConversationGroup(); + return ConversationGroupVO.convert2VOList(allGroup); + } + } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ConversationGroupMessageVO.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ConversationGroupMessageVO.java new file mode 100644 index 000000000..041f65130 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ConversationGroupMessageVO.java @@ -0,0 +1,40 @@ +package club.joylink.rtss.simulation.cbtc.data.vo; + +import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroupMessage; +import club.joylink.rtss.simulation.cbtc.conversation.ConversationMessage; +import lombok.Getter; +import lombok.Setter; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@Getter +@Setter +public class ConversationGroupMessageVO extends ConversationMessageVO { + /** + * 已读角色的ID列表 + */ + private Set readerSet; + + /** + * 是否全部已读 + */ + private boolean allRead; + + public ConversationGroupMessageVO(ConversationGroupMessage message) { + super(message); + this.readerSet = message.getReaderSet(); + this.allRead = message.isAllRead(); + } + + public static List convert2VO(List list) { + if (CollectionUtils.isEmpty(list)) { + return List.of(); + } + return list.stream().map(ConversationGroupMessageVO::new).collect(Collectors.toList()); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ConversationGroupVO.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ConversationGroupVO.java new file mode 100644 index 000000000..4503cf041 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ConversationGroupVO.java @@ -0,0 +1,41 @@ +package club.joylink.rtss.simulation.cbtc.data.vo; + +import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup; +import lombok.Getter; +import lombok.Setter; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +public class ConversationGroupVO { + + private Long id; + + private String creatorId; + + private List memberList; + + private List messageList; + + public ConversationGroupVO(ConversationGroup conversation) { + this.id = conversation.getId(); + if (conversation.getCreator() != null) { + this.creatorId = conversation.getCreator().getId(); + } + this.memberList = ConversationMemberVO.convert2VOList(conversation.getMemberList()); + this.messageList = ConversationGroupMessageVO.convert2VO(conversation.getMessageList()); + } + + public static List convert2VOList(List list) { + List voList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + for (ConversationGroup conversation : list) { + voList.add(new ConversationGroupVO(conversation)); + } + } + return voList; + } +} diff --git a/src/main/java/club/joylink/rtss/vo/conversation/ConversationGroupVO.java b/src/main/java/club/joylink/rtss/vo/conversation/ConversationGroupVO.java index 4636f3549..4707e108e 100644 --- a/src/main/java/club/joylink/rtss/vo/conversation/ConversationGroupVO.java +++ b/src/main/java/club/joylink/rtss/vo/conversation/ConversationGroupVO.java @@ -39,12 +39,12 @@ public class ConversationGroupVO { /** * 群主角色ID */ - private Long leaderId; + private String leaderId; /** * 群成员ID */ - private List memberIds; + private List memberIds; public ConversationGroupVO(RtsConversationGroupInfo info) { this.id = info.getId(); @@ -53,7 +53,7 @@ public class ConversationGroupVO { this.leaderId = info.getLeaderId(); this.projectCode = info.getProjectCode(); if (StringUtils.hasText(info.getMemberIds())) { - this.memberIds = Arrays.stream(info.getMemberIds().split(",")).map(Long::valueOf).collect(Collectors.toList()); + this.memberIds = Arrays.stream(info.getMemberIds().split(",")).collect(Collectors.toList()); } } @@ -70,7 +70,7 @@ public class ConversationGroupVO { info.setProjectCode(this.projectCode); info.setLeaderId(this.leaderId); if (this.memberIds != null) { - info.setMemberIds(this.memberIds.stream().map(String::valueOf).collect(Collectors.joining(","))); + info.setMemberIds(String.join(",", this.memberIds)); } return info; } diff --git a/src/main/resources/mybatis/mapper/RtsConversationGroupInfoMapper.xml b/src/main/resources/mybatis/mapper/RtsConversationGroupInfoMapper.xml index 0a774b603..418531ec8 100644 --- a/src/main/resources/mybatis/mapper/RtsConversationGroupInfoMapper.xml +++ b/src/main/resources/mybatis/mapper/RtsConversationGroupInfoMapper.xml @@ -7,7 +7,7 @@ - + @@ -135,7 +135,7 @@ #{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{mapId,jdbcType=BIGINT}, #{projectCode,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{creatorId,jdbcType=BIGINT}, #{status,jdbcType=INTEGER}, #{memberIds,jdbcType=LONGVARCHAR}, - #{leaderId,jdbcType=BIGINT} + #{leaderId,jdbcType=VARCHAR} ) @@ -202,7 +202,7 @@ #{memberIds,jdbcType=LONGVARCHAR}, - #{leaderId,jdbcType=BIGINT}, + #{leaderId,jdbcType=VARCHAR}, @@ -238,7 +238,7 @@ member_ids = #{record.memberIds,jdbcType=LONGVARCHAR}, - leader_id = #{record.leaderId,jdbcType=BIGINT}, + leader_id = #{record.leaderId,jdbcType=VARCHAR}, @@ -257,7 +257,7 @@ creator_id = #{record.creatorId,jdbcType=BIGINT}, status = #{record.status,jdbcType=INTEGER}, member_ids = #{record.memberIds,jdbcType=LONGVARCHAR}, - leader_id = #{record.leaderId,jdbcType=BIGINT} + leader_id = #{record.leaderId,jdbcType=VARCHAR} @@ -273,7 +273,7 @@ update_time = #{record.updateTime,jdbcType=TIMESTAMP}, creator_id = #{record.creatorId,jdbcType=BIGINT}, status = #{record.status,jdbcType=INTEGER}, - leader_id = #{record.leaderId,jdbcType=BIGINT} + leader_id = #{record.leaderId,jdbcType=VARCHAR} @@ -307,7 +307,7 @@ member_ids = #{memberIds,jdbcType=LONGVARCHAR}, - leader_id = #{leaderId,jdbcType=BIGINT}, + leader_id = #{leaderId,jdbcType=VARCHAR}, where id = #{id,jdbcType=BIGINT} @@ -319,7 +319,7 @@ project_code = #{projectCode,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP}, creator_id = #{creatorId,jdbcType=BIGINT}, status = #{status,jdbcType=INTEGER}, member_ids = #{memberIds,jdbcType=LONGVARCHAR}, - leader_id = #{leaderId,jdbcType=BIGINT} + leader_id = #{leaderId,jdbcType=VARCHAR} where id = #{id,jdbcType=BIGINT} @@ -327,7 +327,7 @@ update rts_conversation_group_info set name = #{name,jdbcType=VARCHAR}, map_id = #{mapId,jdbcType=BIGINT}, project_code = #{projectCode,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP}, - creator_id = #{creatorId,jdbcType=BIGINT}, status = #{status,jdbcType=INTEGER},leader_id = #{leaderId,jdbcType=BIGINT} + creator_id = #{creatorId,jdbcType=BIGINT}, status = #{status,jdbcType=INTEGER},leader_id = #{leaderId,jdbcType=VARCHAR} where id = #{id,jdbcType=BIGINT} \ No newline at end of file