diff --git a/src/main/java/com/genersoft/iot/vmp/service/IRegionService.java b/src/main/java/com/genersoft/iot/vmp/service/IRegionService.java index 7c9192bc..b61c31b7 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IRegionService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IRegionService.java @@ -10,7 +10,7 @@ public interface IRegionService { void add(Region region); - void deleteByDeviceId(String regionDeviceId); + boolean deleteByDeviceId(String regionDeviceId); /** * 查询区划列表 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 355f950e..03848c75 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 @@ -108,7 +108,7 @@ public class GroupServiceImpl implements IGroupService { groupParentList.add(group); groupList = queryAllChildGroup(groupParentList, group.getCommonGroupTopId(), groupParentList); } - // 移除所有管理当前节点和字节点的通道 + int limitCount = 50; if (!groupList.isEmpty()) { if (groupList.size() > limitCount) { @@ -117,24 +117,16 @@ public class GroupServiceImpl implements IGroupService { if (i + limitCount > groupList.size()) { toIndex = groupList.size(); } - commonGbChannelMapper.removeGroupInfo(groupList.subList(i, toIndex)); + List subList = groupList.subList(i, toIndex); + // 移除所有管理当前节点和字节点的通道 + commonGbChannelMapper.removeGroupInfo(subList); + // 移除所有子节点 + groupMapper.removeGroupByList(subList); } }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); } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RegionServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RegionServiceImpl.java index d760d95b..f7aa25fa 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/RegionServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RegionServiceImpl.java @@ -49,8 +49,31 @@ public class RegionServiceImpl implements IRegionService { } @Override - public void deleteByDeviceId(String regionDeviceId) { - regionMapper.deleteByDeviceId(regionDeviceId); + @Transactional + public boolean deleteByDeviceId(String regionDeviceId) { + // 查询所有从属的地区,从属地区的编号一定是父节点编号开头的,基于这个获取所有的子节点 + List regionList = regionMapper.queryAllChildByDeviceId(regionDeviceId); + + int limitCount = 50; + if (regionList.size() > limitCount) { + for (int i = 0; i < regionList.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > regionList.size()) { + toIndex = regionList.size(); + } + List subList = regionList.subList(i, toIndex); + // 移除所有关联当前节点和子节点的通道 + commonGbChannelMapper.removeRegionInfo(subList); + // 移除所有节点 + regionMapper.removeRegionByList(subList); + } + }else { + // 移除所有关联当前节点和子节点的通道 + commonGbChannelMapper.removeRegionInfo(regionList); + // 移除所有节点 + regionMapper.removeRegionByList(regionList); + } + return true; } @Override @@ -87,8 +110,10 @@ public class RegionServiceImpl implements IRegionService { // 修改所有所属的通道的编号 commonGbChannelMapper.updateChanelRegion(regionInDb.getCommonRegionDeviceId(), region.getCommonRegionDeviceId()); - }else if (region.getCommonRegionName().equals(regionInDb.getCommonRegionName()) && - region.getCommonRegionParentId().equals(regionInDb.getCommonRegionParentId())) { + }else if ( + ((regionInDb.getCommonRegionParentId() == null && region.getCommonRegionParentId() == null) + || regionInDb.getCommonRegionParentId().equals(region.getCommonRegionParentId())) + && regionInDb.getCommonRegionName().equals(region.getCommonRegionName())) { // 数据没有变化 return; } 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 2179d185..2163a67b 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 @@ -3,6 +3,7 @@ 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.service.bean.Region; import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup; import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; @@ -346,7 +347,8 @@ public interface CommonGbChannelMapper { " and common_gb_civilCode = #{regionDeviceId} " + " and common_gb_business_group_id is not null " + " and common_gb_business_group_id is null " + - " and common_gb_civilCode is not null " + + " and common_gb_civilCode is not null " + + " and common_gb_civilCode is null " + " and type = #{type} " + " and ( common_gb_device_id LIKE concat('%',#{query},'%') or common_gb_name LIKE concat('%',#{query},'%') ) " + "") @@ -399,4 +401,10 @@ public interface CommonGbChannelMapper { " WHERE common_gb_business_group_id = #{commonGbBusinessGroupID}" + ""}) void removeFromGroupByGroupId(@Param("commonGbBusinessGroupID") String commonGbBusinessGroupID); + + @Select("") + void removeRegionInfo(@Param("regionList") List regionList); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/RegionMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/RegionMapper.java index 3846a265..55379299 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/RegionMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/RegionMapper.java @@ -7,7 +7,11 @@ import java.util.List; @Mapper public interface RegionMapper { - @Select("select * from wvp_common_region where common_region_parent_id = #{parentDeviceId}") + @Select(" ") List getChildren(@Param("parentDeviceId") String parentDeviceId); @Insert("INSERT INTO wvp_common_region (" + @@ -101,4 +105,15 @@ public interface RegionMapper { " and (common_region_device_id LIKE concat('%',#{query},'%') or common_region_name LIKE concat('%',#{query},'%') ) " + "") List query(String query); + + @Select("") + List queryAllChildByDeviceId(@Param("regionDeviceId") String regionDeviceId); + + @Select("") + void removeRegionByList(@Param("regionList") List regionList); } 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 4a085efc..b1a7f761 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 @@ -57,7 +57,7 @@ public class CommonChannelController { @Parameter(name = "page", description = "当前页", required = true) @Parameter(name = "count", description = "每页查询数量", required = true) @ResponseBody - @GetMapping("/group/list") + @GetMapping("/list") public PageInfo queryChannelListInGroup( @RequestParam(required = false) String groupDeviceId, @RequestParam(required = false) String regionDeviceId, @@ -101,19 +101,19 @@ public class CommonChannelController { } - @Operation(summary = "分页查询通道") - @Parameter(name = "query", description = "要搜索的内容", required = false) - @Parameter(name = "page", description = "当前页", required = true) - @Parameter(name = "count", description = "每页查询数量", required = true) - @ResponseBody - @GetMapping("/list") - public PageInfo queryChannelList( - @RequestParam(required = false) String query, - @RequestParam(required = true) int page, - @RequestParam(required = true) int count ){ - - return commonGbChannelService.queryChannelList(query, page, count); - } +// @Operation(summary = "分页查询通道") +// @Parameter(name = "query", description = "要搜索的内容", required = false) +// @Parameter(name = "page", description = "当前页", required = true) +// @Parameter(name = "count", description = "每页查询数量", required = true) +// @ResponseBody +// @GetMapping("/list") +// public PageInfo queryChannelList( +// @RequestParam(required = false) String query, +// @RequestParam(required = true) int page, +// @RequestParam(required = true) int count ){ +// +// return commonGbChannelService.queryChannelList(query, page, count); +// } @Operation(summary = "更新通道") @Parameter(name = "CommonGbChannel", description = "commonGbChannel", required = true) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/region/RegionController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/region/RegionController.java index 3dabdbc9..96b8b0bc 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/region/RegionController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/region/RegionController.java @@ -1,8 +1,10 @@ package com.genersoft.iot.vmp.vmanager.region; +import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType; import com.genersoft.iot.vmp.service.IRegionService; import com.genersoft.iot.vmp.service.bean.Region; +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.github.pagehelper.PageInfo; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -60,7 +62,11 @@ public class RegionController { @ResponseBody @DeleteMapping("/delete") public void delete(@RequestBody String regionDeviceId){ - regionService.deleteByDeviceId(regionDeviceId); + assert regionDeviceId != null; + boolean result = regionService.deleteByDeviceId(regionDeviceId); + if (!result) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "移除失败"); + } } @Operation(summary = "分页区域子节点") @@ -74,6 +80,9 @@ public class RegionController { @RequestParam(required = true) int page, @RequestParam(required = true) int count ){ + if (ObjectUtils.isEmpty(regionParentId.trim())) { + regionParentId = null; + } return regionService.queryChildGroupList(regionParentId, page, count); }