优化区域树
parent
fd71a96580
commit
7d064b0830
|
@ -10,7 +10,7 @@ public interface IRegionService {
|
||||||
|
|
||||||
void add(Region region);
|
void add(Region region);
|
||||||
|
|
||||||
void deleteByDeviceId(String regionDeviceId);
|
boolean deleteByDeviceId(String regionDeviceId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询区划列表
|
* 查询区划列表
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class GroupServiceImpl implements IGroupService {
|
||||||
groupParentList.add(group);
|
groupParentList.add(group);
|
||||||
groupList = queryAllChildGroup(groupParentList, group.getCommonGroupTopId(), groupParentList);
|
groupList = queryAllChildGroup(groupParentList, group.getCommonGroupTopId(), groupParentList);
|
||||||
}
|
}
|
||||||
// 移除所有管理当前节点和字节点的通道
|
|
||||||
int limitCount = 50;
|
int limitCount = 50;
|
||||||
if (!groupList.isEmpty()) {
|
if (!groupList.isEmpty()) {
|
||||||
if (groupList.size() > limitCount) {
|
if (groupList.size() > limitCount) {
|
||||||
|
@ -117,24 +117,16 @@ public class GroupServiceImpl implements IGroupService {
|
||||||
if (i + limitCount > groupList.size()) {
|
if (i + limitCount > groupList.size()) {
|
||||||
toIndex = 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 {
|
}else {
|
||||||
|
// 移除所有管理当前节点和字节点的通道
|
||||||
commonGbChannelMapper.removeGroupInfo(groupList);
|
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);
|
groupMapper.removeGroupByList(groupList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,31 @@ public class RegionServiceImpl implements IRegionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteByDeviceId(String regionDeviceId) {
|
@Transactional
|
||||||
regionMapper.deleteByDeviceId(regionDeviceId);
|
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
|
@Override
|
||||||
|
@ -87,8 +110,10 @@ public class RegionServiceImpl implements IRegionService {
|
||||||
// 修改所有所属的通道的编号
|
// 修改所有所属的通道的编号
|
||||||
commonGbChannelMapper.updateChanelRegion(regionInDb.getCommonRegionDeviceId(),
|
commonGbChannelMapper.updateChanelRegion(regionInDb.getCommonRegionDeviceId(),
|
||||||
region.getCommonRegionDeviceId());
|
region.getCommonRegionDeviceId());
|
||||||
}else if (region.getCommonRegionName().equals(regionInDb.getCommonRegionName()) &&
|
}else if (
|
||||||
region.getCommonRegionParentId().equals(regionInDb.getCommonRegionParentId())) {
|
((regionInDb.getCommonRegionParentId() == null && region.getCommonRegionParentId() == null)
|
||||||
|
|| regionInDb.getCommonRegionParentId().equals(region.getCommonRegionParentId()))
|
||||||
|
&& regionInDb.getCommonRegionName().equals(region.getCommonRegionName())) {
|
||||||
// 数据没有变化
|
// 数据没有变化
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.storager.dao;
|
||||||
import com.genersoft.iot.vmp.common.CommonGbChannel;
|
import com.genersoft.iot.vmp.common.CommonGbChannel;
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||||
import com.genersoft.iot.vmp.service.bean.Group;
|
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 com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup;
|
||||||
import org.apache.ibatis.annotations.*;
|
import org.apache.ibatis.annotations.*;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
@ -346,7 +347,8 @@ public interface CommonGbChannelMapper {
|
||||||
"<if test='regionDeviceId != null'> and common_gb_civilCode = #{regionDeviceId} </if>" +
|
"<if test='regionDeviceId != null'> and common_gb_civilCode = #{regionDeviceId} </if>" +
|
||||||
"<if test='inGroup != null & inGroup'> and common_gb_business_group_id is not null </if>" +
|
"<if test='inGroup != null & inGroup'> and common_gb_business_group_id is not null </if>" +
|
||||||
"<if test='inGroup != null & !inGroup'> and common_gb_business_group_id is null </if>" +
|
"<if test='inGroup != null & !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 & inRegion'> and common_gb_civilCode is not null </if>" +
|
||||||
|
"<if test='inRegion != null & !inRegion'> and common_gb_civilCode is null </if>" +
|
||||||
"<if test='type != null'> and type = #{type} </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>" +
|
"<if test='query != null'> and ( common_gb_device_id LIKE concat('%',#{query},'%') or common_gb_name LIKE concat('%',#{query},'%') ) </if>" +
|
||||||
"</script>")
|
"</script>")
|
||||||
|
@ -399,4 +401,10 @@ public interface CommonGbChannelMapper {
|
||||||
" WHERE common_gb_business_group_id = #{commonGbBusinessGroupID}" +
|
" WHERE common_gb_business_group_id = #{commonGbBusinessGroupID}" +
|
||||||
"</script>"})
|
"</script>"})
|
||||||
void removeFromGroupByGroupId(@Param("commonGbBusinessGroupID") String commonGbBusinessGroupID);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,11 @@ import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface RegionMapper {
|
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);
|
List<Region> getChildren(@Param("parentDeviceId") String parentDeviceId);
|
||||||
|
|
||||||
@Insert("INSERT INTO wvp_common_region (" +
|
@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>" +
|
"<if test='query != null'> and (common_region_device_id LIKE concat('%',#{query},'%') or common_region_name LIKE concat('%',#{query},'%') ) </if>" +
|
||||||
"</script>")
|
"</script>")
|
||||||
List<Region> query(String query);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class CommonChannelController {
|
||||||
@Parameter(name = "page", description = "当前页", required = true)
|
@Parameter(name = "page", description = "当前页", required = true)
|
||||||
@Parameter(name = "count", description = "每页查询数量", required = true)
|
@Parameter(name = "count", description = "每页查询数量", required = true)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@GetMapping("/group/list")
|
@GetMapping("/list")
|
||||||
public PageInfo<CommonGbChannel> queryChannelListInGroup(
|
public PageInfo<CommonGbChannel> queryChannelListInGroup(
|
||||||
@RequestParam(required = false) String groupDeviceId,
|
@RequestParam(required = false) String groupDeviceId,
|
||||||
@RequestParam(required = false) String regionDeviceId,
|
@RequestParam(required = false) String regionDeviceId,
|
||||||
|
@ -101,19 +101,19 @@ public class CommonChannelController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "分页查询通道")
|
// @Operation(summary = "分页查询通道")
|
||||||
@Parameter(name = "query", description = "要搜索的内容", required = false)
|
// @Parameter(name = "query", description = "要搜索的内容", required = false)
|
||||||
@Parameter(name = "page", description = "当前页", required = true)
|
// @Parameter(name = "page", description = "当前页", required = true)
|
||||||
@Parameter(name = "count", description = "每页查询数量", required = true)
|
// @Parameter(name = "count", description = "每页查询数量", required = true)
|
||||||
@ResponseBody
|
// @ResponseBody
|
||||||
@GetMapping("/list")
|
// @GetMapping("/list")
|
||||||
public PageInfo<CommonGbChannel> queryChannelList(
|
// public PageInfo<CommonGbChannel> queryChannelList(
|
||||||
@RequestParam(required = false) String query,
|
// @RequestParam(required = false) String query,
|
||||||
@RequestParam(required = true) int page,
|
// @RequestParam(required = true) int page,
|
||||||
@RequestParam(required = true) int count ){
|
// @RequestParam(required = true) int count ){
|
||||||
|
//
|
||||||
return commonGbChannelService.queryChannelList(query, page, count);
|
// return commonGbChannelService.queryChannelList(query, page, count);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Operation(summary = "更新通道")
|
@Operation(summary = "更新通道")
|
||||||
@Parameter(name = "CommonGbChannel", description = "commonGbChannel", required = true)
|
@Parameter(name = "CommonGbChannel", description = "commonGbChannel", required = true)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.genersoft.iot.vmp.vmanager.region;
|
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.gb28181.bean.Gb28181CodeType;
|
||||||
import com.genersoft.iot.vmp.service.IRegionService;
|
import com.genersoft.iot.vmp.service.IRegionService;
|
||||||
import com.genersoft.iot.vmp.service.bean.Region;
|
import com.genersoft.iot.vmp.service.bean.Region;
|
||||||
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
@ -60,7 +62,11 @@ public class RegionController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
public void delete(@RequestBody String regionDeviceId){
|
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 = "分页区域子节点")
|
@Operation(summary = "分页区域子节点")
|
||||||
|
@ -74,6 +80,9 @@ public class RegionController {
|
||||||
@RequestParam(required = true) int page,
|
@RequestParam(required = true) int page,
|
||||||
@RequestParam(required = true) int count
|
@RequestParam(required = true) int count
|
||||||
){
|
){
|
||||||
|
if (ObjectUtils.isEmpty(regionParentId.trim())) {
|
||||||
|
regionParentId = null;
|
||||||
|
}
|
||||||
return regionService.queryChildGroupList(regionParentId, page, count);
|
return regionService.queryChildGroupList(regionParentId, page, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue