From bcd5ce25cadcffab23060ec919876baee97da578 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 14 Nov 2023 18:36:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E7=BB=84=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmp/service/ICommonGbChannelService.java | 8 +- .../impl/CommonGbChannelServiceImpl.java | 29 ++++++- .../vmp/service/impl/GroupServiceImpl.java | 78 ++++++++++++++++--- .../storager/dao/CommonGbChannelMapper.java | 47 ++++++++++- .../iot/vmp/storager/dao/GroupMapper.java | 18 +++++ .../bean/UpdateCommonChannelToGroup.java | 26 +++++++ .../channel/CommonChannelController.java | 45 ++++++++++- .../vmp/vmanager/group/GroupController.java | 3 +- 8 files changed, 233 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/vmanager/bean/UpdateCommonChannelToGroup.java diff --git a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java index 5736bd39..e8aaf7a1 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType; import com.genersoft.iot.vmp.service.bean.*; +import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup; import com.github.pagehelper.PageInfo; import java.util.ArrayList; @@ -48,7 +49,9 @@ public interface ICommonGbChannelService { void channelsOfflineFromList(List deleteChannelList); - PageInfo queryChannelListInGroup(String groupDeviceId, String query, int page, int count); + PageInfo queryChannelListInGroup(int page, int count, String query, String groupDeviceId, + String regionDeviceId, Boolean inGroup, Boolean inRegion, + String type); PageInfo queryChannelList(String query, int page, int count); @@ -60,4 +63,7 @@ public interface ICommonGbChannelService { List getNetworkIdentificationTypeList(); + void updateChannelToGroup(UpdateCommonChannelToGroup commonGbChannel); + + void removeFromGroup(UpdateCommonChannelToGroup params); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java index 432145b2..7a98e62d 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java @@ -14,8 +14,10 @@ import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; import com.genersoft.iot.vmp.storager.dao.GroupMapper; import com.genersoft.iot.vmp.storager.dao.RegionMapper; import com.genersoft.iot.vmp.utils.DateUtil; +import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.assertj.core.util.Lists; @@ -607,10 +609,21 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { } @Override - public PageInfo queryChannelListInGroup(String groupDeviceId, String query, int page, int count) { - assert groupDeviceId != null; + public PageInfo queryChannelListInGroup(int page, int count, String query, String groupDeviceId, + String regionDeviceId, Boolean inGroup, Boolean inRegion, + String type) { PageHelper.startPage(page, count); - List all = commonGbChannelMapper.queryChannelListInGroup(groupDeviceId, query); + if (groupDeviceId != null && ObjectUtils.isEmpty(groupDeviceId.trim())) { + inGroup = null; + } + if (regionDeviceId != null && ObjectUtils.isEmpty(regionDeviceId.trim())) { + inRegion = null; + } + if (type != null && ObjectUtils.isEmpty(type.trim())) { + type = null; + } + List all = commonGbChannelMapper.queryChannelListInGroup(query, groupDeviceId, + regionDeviceId, inGroup, inRegion, type); return new PageInfo<>(all); } @@ -659,4 +672,14 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { Collections.sort(result); return result; } + + @Override + public void updateChannelToGroup(UpdateCommonChannelToGroup updateCommonChannelToGroup) { + commonGbChannelMapper.updateChannelToGroup(updateCommonChannelToGroup); + } + + @Override + public void removeFromGroup(UpdateCommonChannelToGroup params) { + commonGbChannelMapper.removeFromGroup(params); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/GroupServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/GroupServiceImpl.java index 31f04626..355f950e 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/GroupServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/GroupServiceImpl.java @@ -22,6 +22,7 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; +import java.util.ArrayList; import java.util.List; @Service @@ -30,7 +31,7 @@ public class GroupServiceImpl implements IGroupService { private final static Logger logger = LoggerFactory.getLogger(GroupServiceImpl.class); @Autowired - private CommonGbChannelMapper commonGbChannelDao; + private CommonGbChannelMapper commonGbChannelMapper; @Autowired private GroupMapper groupMapper; @@ -53,7 +54,7 @@ public class GroupServiceImpl implements IGroupService { if (group == null) { return null; } - return commonGbChannelDao.getChannels(group.getCommonGroupDeviceId()); + return commonGbChannelMapper.getChannels(group.getCommonGroupDeviceId()); } @Override @@ -62,7 +63,7 @@ public class GroupServiceImpl implements IGroupService { if (group == null) { return null; } - return commonGbChannelDao.getChannels(group.getCommonGroupDeviceId()); + return commonGbChannelMapper.getChannels(group.getCommonGroupDeviceId()); } @Override @@ -90,8 +91,67 @@ public class GroupServiceImpl implements IGroupService { } @Override + @Transactional public boolean remove(String deviceId) { - return groupMapper.removeByDeviceId(deviceId) > 0; + assert deviceId != null; + Gb28181CodeType channelIdType = SipUtils.getChannelIdType(deviceId); + // 查询所有从属的分组 + List groupList; + if (channelIdType == Gb28181CodeType.BUSINESS_GROUP) { + // 如果要删除的是一个业务分组,那么直接查询commonGroupTopId是这个节点的即可,这里也包括要删除的节点本身 + groupList = groupMapper.queryGroupListByTopId(deviceId); + }else { + // 如果要删除的是一个虚拟组织,那么就不只能不断的递归拿到所有的子节点了 + Group group = groupMapper.queryByDeviceId(deviceId); + assert group != null; + List groupParentList = new ArrayList<>(); + groupParentList.add(group); + groupList = queryAllChildGroup(groupParentList, group.getCommonGroupTopId(), groupParentList); + } + // 移除所有管理当前节点和字节点的通道 + int limitCount = 50; + if (!groupList.isEmpty()) { + if (groupList.size() > limitCount) { + for (int i = 0; i < groupList.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > groupList.size()) { + toIndex = groupList.size(); + } + commonGbChannelMapper.removeGroupInfo(groupList.subList(i, toIndex)); + } + }else { + commonGbChannelMapper.removeGroupInfo(groupList); + } + } + + // 移除所有子节点 + if (!groupList.isEmpty()) { + if (groupList.size() > limitCount) { + for (int i = 0; i < groupList.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > groupList.size()) { + toIndex = groupList.size(); + } + groupMapper.removeGroupByList(groupList.subList(i, toIndex)); + } + }else { + groupMapper.removeGroupByList(groupList); + } + } + return true; + } + + private List queryAllChildGroup(List parentGroups, String commonGroupTopId, List resultList) { + if (parentGroups.isEmpty()) { + return resultList; + } + List childGroupList = groupMapper.queryChildGroupListInParentGroup(parentGroups, commonGroupTopId); + if (childGroupList.isEmpty()) { + return resultList; + }else { + resultList.addAll(childGroupList); + return queryAllChildGroup(childGroupList, commonGroupTopId, resultList); + } } @Override @@ -107,7 +167,7 @@ public class GroupServiceImpl implements IGroupService { // 修改所有子分组的父节点编号 groupMapper.updateParentDeviceId(groupInDb.getCommonGroupDeviceId(), group.getCommonGroupDeviceId()); // 修改所有通用通道中分组编号 - commonGbChannelDao.updateChanelGroup(groupInDb.getCommonGroupDeviceId(), group.getCommonGroupDeviceId()); + commonGbChannelMapper.updateChanelGroup(groupInDb.getCommonGroupDeviceId(), group.getCommonGroupDeviceId()); }else if ( ((groupInDb.getCommonGroupParentId() == null && group.getCommonGroupParentId() == null) || groupInDb.getCommonGroupParentId().equals(group.getCommonGroupParentId())) @@ -150,7 +210,7 @@ public class GroupServiceImpl implements IGroupService { } int limit = 50; if (channels.size() <= limit) { - if (commonGbChannelDao.updateChanelForGroup(channels) <= 0) { + if (commonGbChannelMapper.updateChanelForGroup(channels) <= 0) { logger.info("[添加通道到分组] 失败"); return false; } @@ -162,7 +222,7 @@ public class GroupServiceImpl implements IGroupService { toIndex = channels.size(); } List channelsSub = channels.subList(i, toIndex); - if (commonGbChannelDao.updateChanelForGroup(channelsSub) <= 0) { + if (commonGbChannelMapper.updateChanelForGroup(channelsSub) <= 0) { dataSourceTransactionManager.rollback(transactionStatus); logger.info("[添加通道到分组] 失败"); return false; @@ -177,7 +237,7 @@ public class GroupServiceImpl implements IGroupService { public boolean removeChannelsFromGroup(List channels) { int limit = 50; if (channels.size() <= limit) { - if (commonGbChannelDao.removeChannelsForGroup(channels) <= 0) { + if (commonGbChannelMapper.removeChannelsForGroup(channels) <= 0) { logger.info("[从分组移除通道] 失败"); return false; } @@ -189,7 +249,7 @@ public class GroupServiceImpl implements IGroupService { toIndex = channels.size(); } List channelsSub = channels.subList(i, toIndex); - if (commonGbChannelDao.removeChannelsForGroup(channelsSub) <= 0) { + if (commonGbChannelMapper.removeChannelsForGroup(channelsSub) <= 0) { dataSourceTransactionManager.rollback(transactionStatus); logger.info("[从分组移除通道] 失败"); return false; diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java index fa658162..4db3d1af 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java @@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.storager.dao; import com.genersoft.iot.vmp.common.CommonGbChannel; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.service.bean.Group; +import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup; import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; @@ -339,15 +341,54 @@ public interface CommonGbChannelMapper { @Param("query") String query); @Select("") - List queryChannelListInGroup(@Param("groupDeviceId") String groupDeviceId, - @Param("query") String query); + List queryChannelListInGroup(@Param("query") String query, + @Param("groupDeviceId") String groupDeviceId, + @Param("regionDeviceId") String regionDeviceId, + @Param("inGroup") Boolean inGroup, + @Param("inRegion") Boolean inRegion, + @Param("type") String type + ); + + @Select("") List query(@Param("query") String query); + + @Select("") + void removeGroupInfo(@Param("groupList") List groupList); + + @Update({""}) + void updateChannelToGroup(@Param("commonGbChannel") UpdateCommonChannelToGroup commonGbChannel); + + @Update({""}) + void removeFromGroup(@Param("commonGbChannel") UpdateCommonChannelToGroup commonGbChannel); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java index 75223c8b..6afb7407 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/GroupMapper.java @@ -123,4 +123,22 @@ public interface GroupMapper { " common_group_device_id = common_group_top_id" + "") List queryVirtualGroupList(@Param("groupParentId") String groupParentId); + + @Select("") + List queryGroupListByTopId(@Param("commonGroupTopId") String commonGroupTopId); + + @Select("") + List queryChildGroupListInParentGroup(@Param("parentGroups") List parentGroups, + @Param("commonGroupTopId") String commonGroupTopId); + + @Select("") + void removeGroupByList(@Param("groups") List groups); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/UpdateCommonChannelToGroup.java b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/UpdateCommonChannelToGroup.java new file mode 100644 index 00000000..848849b9 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/UpdateCommonChannelToGroup.java @@ -0,0 +1,26 @@ +package com.genersoft.iot.vmp.vmanager.bean; + +import java.util.List; + +public class UpdateCommonChannelToGroup { + + private String commonGbBusinessGroupID; + + private List commonGbIds; + + public String getCommonGbBusinessGroupID() { + return commonGbBusinessGroupID; + } + + public void setCommonGbBusinessGroupID(String commonGbBusinessGroupID) { + this.commonGbBusinessGroupID = commonGbBusinessGroupID; + } + + public List getCommonGbIds() { + return commonGbIds; + } + + public void setCommonGbIds(List commonGbIds) { + this.commonGbIds = commonGbIds; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java index 8f5e0c27..5b280747 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.common.CommonGbChannel; import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType; import com.genersoft.iot.vmp.service.ICommonGbChannelService; import com.genersoft.iot.vmp.service.bean.*; +import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup; import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; import io.swagger.v3.oas.annotations.Operation; @@ -46,23 +47,42 @@ public class CommonChannelController { } @Operation(summary = "查询分组下的通道") - @Parameter(name = "groupDeviceId", description = "分组的编号", required = true) + @Parameter(name = "groupDeviceId", description = "分组的编号", required = false) + @Parameter(name = "regionDeviceId", description = "区域的编号", required = false) + @Parameter(name = "query", description = "要搜索的内容", required = false) + @Parameter(name = "inGroup", description = "是否已经在分组下了", required = false) + @Parameter(name = "inRegion", description = "是否已经在地区下了", required = false) + @Parameter(name = "type", description = "通道类型", required = false) @Parameter(name = "query", description = "要搜索的内容", required = false) @Parameter(name = "page", description = "当前页", required = true) @Parameter(name = "count", description = "每页查询数量", required = true) @ResponseBody @GetMapping("/group/list") public PageInfo queryChannelListInGroup( - @RequestParam(required = true) String groupDeviceId, + @RequestParam(required = false) String groupDeviceId, + @RequestParam(required = false) String regionDeviceId, @RequestParam(required = false) String query, + @RequestParam(required = false) String type, + @RequestParam(required = false) Boolean inGroup, + @RequestParam(required = false) Boolean inRegion, @RequestParam(required = true) int page, @RequestParam(required = true) int count ){ - if (ObjectUtils.isEmpty(query)) { + if (query != null && ObjectUtils.isEmpty(query.trim())) { query = null; } + if (groupDeviceId != null && ObjectUtils.isEmpty(groupDeviceId.trim())) { + groupDeviceId = null; + } + if (regionDeviceId != null && ObjectUtils.isEmpty(regionDeviceId.trim())) { + regionDeviceId = null; + } + if (type != null && ObjectUtils.isEmpty(type.trim())) { + type = null; + } assert !ObjectUtils.isEmpty(groupDeviceId); - return commonGbChannelService.queryChannelListInGroup(groupDeviceId, query, page, count); + return commonGbChannelService.queryChannelListInGroup(page, count, query, groupDeviceId, regionDeviceId, + inGroup, inRegion, type); } /** @@ -142,6 +162,23 @@ public class CommonChannelController { return commonGbChannelService.getNetworkIdentificationTypeList(); } + @Operation(summary = "为通道添加分组") + @ResponseBody + @PostMapping("/group/update") + public void updateChannelToGroup(@RequestBody UpdateCommonChannelToGroup params){ + assert params.getCommonGbBusinessGroupID() != null; + assert !params.getCommonGbIds().isEmpty(); + commonGbChannelService.updateChannelToGroup(params); + } + + @Operation(summary = "为通道添加分组") + @ResponseBody + @PostMapping("/group/remove") + public void removeFromGroup(@RequestBody UpdateCommonChannelToGroup params){ + assert params.getCommonGbBusinessGroupID() != null; + commonGbChannelService.removeFromGroup(params); + } + diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/group/GroupController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/group/GroupController.java index 76ec03c6..da171fbb 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/group/GroupController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/group/GroupController.java @@ -59,8 +59,9 @@ public class GroupController { @Operation(summary = "删除区域") @Parameter(name = "groupDeviceId", description = "待删除的节点编号", required = true) @ResponseBody - @DeleteMapping("/delete") + @GetMapping("/delete") public void deleteGroup(String groupDeviceId){ + assert groupDeviceId != null; boolean result = groupService.remove(groupDeviceId); if (!result) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "移除失败");