From 5359bf1c2715f6383dae43c3ed56308c5ee1d751 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 18 Apr 2023 16:33:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E7=BE=A4=E7=BB=84BU?= =?UTF-8?q?G=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConversationGroupController.java | 12 ++++- .../SimulationConversationController.java | 4 +- .../ConversationGroupService.java | 11 ++++- .../ConversationGroupServiceImpl.java | 44 ++++++++++++++++--- .../cbtc/SimulationServiceImpl.java | 7 +-- .../ConversationGroupHandlerService.java | 12 +++-- .../mapper/RtsConversationGroupInfoMapper.xml | 2 +- 7 files changed, 73 insertions(+), 19 deletions(-) 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 d30d2a293..14aec2d73 100644 --- a/src/main/java/club/joylink/rtss/controller/conversation/ConversationGroupController.java +++ b/src/main/java/club/joylink/rtss/controller/conversation/ConversationGroupController.java @@ -41,13 +41,21 @@ public class ConversationGroupController { } @PutMapping("/{id}/data") - public void update(@PathVariable Long id, @RequestBody ConversationGroupVO vo) { + public String update(@PathVariable Long id, @RequestBody ConversationGroupVO vo) { vo.setId(id); - conversationGroupService.update(vo); + return conversationGroupService.update(vo); } @DeleteMapping("/{id}") public void delete(@PathVariable Long id) { conversationGroupService.delete(id); } + + /** + * 检查群组名是否存在 + */ + @GetMapping("/checkName") + public boolean checkName(Long id, String name, Long mapId){ + return conversationGroupService.checkNameNotExist(id, name, mapId); + } } 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 04d590ae5..98a97f3bd 100644 --- a/src/main/java/club/joylink/rtss/controller/simulation/SimulationConversationController.java +++ b/src/main/java/club/joylink/rtss/controller/simulation/SimulationConversationController.java @@ -112,7 +112,7 @@ public class SimulationConversationController { * @return 用户群组 */ @GetMapping("/group/list") - public List groupList(@PathVariable String group) { - return conversationGroupHandlerService.getAllConversationsGroup(group); + public List groupList(@PathVariable String group, @RequestAttribute AccountVO user) { + return conversationGroupHandlerService.getAllConversationsGroup(group, user); } } 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 677de85b2..cd9c58f00 100644 --- a/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupService.java +++ b/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupService.java @@ -51,7 +51,7 @@ public interface ConversationGroupService { * 更新群组信息 * @param vo 群组信息 */ - void update(ConversationGroupVO vo); + String update(ConversationGroupVO vo); /** * 删除群组信息 @@ -67,4 +67,13 @@ public interface ConversationGroupService { * @return 群组列表 */ List getConversationGroupByMapId(Long mapId); + + /** + * 检查本地图下群组名是否不存在 + * @param id 群组ID(编辑时存在) + * @param name 群组名称 + * @param mapId 地图ID + * @return 是否存在 + */ + boolean checkNameNotExist(Long id, String name, 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 8d98137a8..bea88ff1c 100644 --- a/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/conversation/ConversationGroupServiceImpl.java @@ -50,17 +50,24 @@ public class ConversationGroupServiceImpl implements ConversationGroupService { @Override public ConversationGroupVO getById(Long id) { RtsConversationGroupInfo rtsConversationGroupInfo = conversationGroupInfoMapper.selectByPrimaryKey(id); - return new ConversationGroupVO(rtsConversationGroupInfo); + if (rtsConversationGroupInfo != null) { + return new ConversationGroupVO(rtsConversationGroupInfo); + } + return null; } @Override public String create(ConversationGroupVO vo, AccountVO user) { if (vo.getId() != null) { - update(vo); + return update(vo); } else { + if (checkNameNotExist(null, vo.getName(), vo.getMapId())) { + throw new IllegalArgumentException("名称已存在"); + } RtsConversationGroupInfo rtsConversationGroupInfo = vo.toEntity(); rtsConversationGroupInfo.setCreateTime(LocalDateTime.now()); rtsConversationGroupInfo.setUpdateTime(LocalDateTime.now()); + rtsConversationGroupInfo.setCreatorId(user.getId().toString()); rtsConversationGroupInfo.setStatus(VALID); conversationGroupInfoMapper.insert(rtsConversationGroupInfo); } @@ -68,11 +75,14 @@ public class ConversationGroupServiceImpl implements ConversationGroupService { } @Override - public void update(ConversationGroupVO vo) { - if (vo.getId() != null) { + public String update(ConversationGroupVO vo) { + if (vo.getId() != null && !checkNameNotExist(vo.getId(), vo.getName(), vo.getMapId())) { RtsConversationGroupInfo rtsConversationGroupInfo = vo.toEntity(); rtsConversationGroupInfo.setUpdateTime(LocalDateTime.now()); conversationGroupInfoMapper.updateByPrimaryKeySelective(rtsConversationGroupInfo); + return "保存成功"; + } else { + return "保存失败"; } } @@ -88,6 +98,30 @@ public class ConversationGroupServiceImpl implements ConversationGroupService { return queryList(queryVO); } + /** + * 检查群组名称是否存在 + * @param id 群组ID(编辑时存在) + * @param name 群组名称 + * @param mapId 地图ID + * @return 存在结果 + */ + @Override + public boolean checkNameNotExist(Long id, String name, Long mapId) { + RtsConversationGroupInfoExample example = new RtsConversationGroupInfoExample(); + RtsConversationGroupInfoExample.Criteria criteria = example.createCriteria(); + if (StringUtils.hasText(name)) { + criteria.andNameEqualTo(name); + } + if (mapId != null) { + criteria.andMapIdEqualTo(mapId); + } + if (id != null) { + criteria.andMapIdNotEqualTo(id); + } + criteria.andStatusEqualTo(VALID); + return CollectionUtils.isEmpty(conversationGroupInfoMapper.selectByExampleWithBLOBs(example)); + } + /** * 获取查询条件 @@ -101,7 +135,7 @@ public class ConversationGroupServiceImpl implements ConversationGroupService { if (StringUtils.hasText(queryVO.getName())) { criteria.andNameLike(String.format("%%%s%%", queryVO.getName())); } - if (CollectionUtils.isEmpty(queryVO.getMapIds())) { + if (!CollectionUtils.isEmpty(queryVO.getMapIds())) { criteria.andMapIdIn(queryVO.getMapIds()); } if (StringUtils.hasText(queryVO.getProjectCode())) { 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 ab41a0c86..5561734d4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java @@ -302,19 +302,14 @@ public class SimulationServiceImpl implements SimulationService { //获取仿真工作服务 SimulationWorkService initService = simulationWorkServiceManager.getWorkService(workParamVO.getType()); - //创建仿真 String simulationId = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), mapId); Simulation simulation = initService.create(mapId, workParamVO, loginUserInfoVO, simulationId); - //语音配置数据 List ruleList = this.discriminateRule.findRuleByMapId(mapId); simulation.setVoiceRuleList(ruleList); - // 群组配置信息 - initConversationGroup(simulation); - simulation.setMapFunctionId(mapFunctionId); simulation.setCreateUserType(createUserType); LoginUserInfoVO loginUserInfo = simulation.getBuildParams().getLoginUserInfo(); @@ -336,6 +331,8 @@ public class SimulationServiceImpl implements SimulationService { initService.addItems(simulation, workParamVO.getItemMap()); } applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation)); + // 群组配置信息 + initConversationGroup(simulation); // 仿真开始运行 simulationManager.start(simulation.getId()); return simulation; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java index 4f78ca59c..686c480d2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java @@ -11,6 +11,7 @@ import club.joylink.rtss.simulation.cbtc.event.conversation.*; 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.SocketMessageVO; import club.joylink.rtss.vo.client.WebSocketMessageType; import club.joylink.rtss.vo.client.factory.SocketMessageFactory; @@ -53,10 +54,15 @@ public class ConversationGroupHandlerService { * @param group 仿真ID * @return 群组信息 */ - public List getAllConversationsGroup(String group) { + public List getAllConversationsGroup(String group, AccountVO user) { Simulation simulation = groupSimulationCache.getSimulationByGroup(group); List allGroup = simulation.queryAllConversationGroup(); - return ConversationGroupVO.convert2VOList(allGroup); + SimulationMember member = simulation.querySimulationMemberByUserId(user.getId()); + if (member == null) { + return List.of(); + } else { + return allGroup.stream().filter(g -> g.isConversationMember(member)).map(ConversationGroupVO::new).collect(Collectors.toList()); + } } /** @@ -180,7 +186,7 @@ public class ConversationGroupHandlerService { if (!conversationGroup.isConversationMember(member)) { throw new SimulationException(SimulationExceptionType.Illegal_Argument, "非本组成员,不能邀请用户"); } - if (conversationGroup.isCreator(member)) { + if (conversationGroup.isLeader(member)) { throw new SimulationException(SimulationExceptionType.Illegal_Argument, "请先变更群主"); } conversationGroup.exit(member); diff --git a/src/main/resources/mybatis/mapper/RtsConversationGroupInfoMapper.xml b/src/main/resources/mybatis/mapper/RtsConversationGroupInfoMapper.xml index 86850f8d8..3704c6884 100644 --- a/src/main/resources/mybatis/mapper/RtsConversationGroupInfoMapper.xml +++ b/src/main/resources/mybatis/mapper/RtsConversationGroupInfoMapper.xml @@ -5,7 +5,7 @@ - +