优化区域树

结构优化
648540858 2023-11-15 18:04:59 +08:00
parent fd71a96580
commit 7d064b0830
7 changed files with 87 additions and 38 deletions

View File

@ -10,7 +10,7 @@ public interface IRegionService {
void add(Region region);
void deleteByDeviceId(String regionDeviceId);
boolean deleteByDeviceId(String regionDeviceId);
/**
*

View File

@ -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<Group> 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);
}
}

View File

@ -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<Region> 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<Region> 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;
}

View File

@ -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 {
"<if test='regionDeviceId != null'> and common_gb_civilCode = #{regionDeviceId} </if>" +
"<if test='inGroup != null &amp; inGroup'> and common_gb_business_group_id is not null </if>" +
"<if test='inGroup != null &amp; !inGroup'> and common_gb_business_group_id is null </if>" +
"<if test='inRegion != null'> and common_gb_civilCode is not null </if>" +
"<if test='inRegion != null &amp; inRegion'> and common_gb_civilCode is not null </if>" +
"<if test='inRegion != null &amp; !inRegion'> and common_gb_civilCode is null </if>" +
"<if test='type != null'> and type = #{type} </if>" +
"<if test='query != null'> and ( common_gb_device_id LIKE concat('%',#{query},'%') or common_gb_name LIKE concat('%',#{query},'%') ) </if>" +
"</script>")
@ -399,4 +401,10 @@ public interface CommonGbChannelMapper {
" WHERE common_gb_business_group_id = #{commonGbBusinessGroupID}" +
"</script>"})
void removeFromGroupByGroupId(@Param("commonGbBusinessGroupID") String commonGbBusinessGroupID);
@Select("<script> "+
"UPDATE wvp_common_gb_channel SET common_gb_civilCode = null WHERE common_gb_civilCode in" +
"<foreach collection='regionList' item='item' open='(' separator=',' close=')' > #{item.commonRegionDeviceId}</foreach>" +
"</script>")
void removeRegionInfo(@Param("regionList") List<Region> regionList);
}

View File

@ -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(" <script>" +
"select * from wvp_common_region where" +
"<if test='parentDeviceId != null'> common_region_parent_id = #{parentDeviceId}</if>" +
"<if test='parentDeviceId == null'> common_region_parent_id is null</if>" +
" </script>")
List<Region> getChildren(@Param("parentDeviceId") String parentDeviceId);
@Insert("INSERT INTO wvp_common_region (" +
@ -101,4 +105,15 @@ public interface RegionMapper {
"<if test='query != null'> and (common_region_device_id LIKE concat('%',#{query},'%') or common_region_name LIKE concat('%',#{query},'%') ) </if>" +
"</script>")
List<Region> query(String query);
@Select("<script> "+
"select * from wvp_common_region where common_region_device_id LIKE concat(#{regionDeviceId},'%') " +
"</script>")
List<Region> queryAllChildByDeviceId(@Param("regionDeviceId") String regionDeviceId);
@Select("<script> "+
"delete from wvp_common_region where common_region_id in" +
"<foreach collection='regionList' item='item' open='(' separator=',' close=')' > #{item.commonRegionId}</foreach>" +
"</script>")
void removeRegionByList(@Param("regionList") List<Region> regionList);
}

View File

@ -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<CommonGbChannel> 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<CommonGbChannel> 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<CommonGbChannel> 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)

View File

@ -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);
}