优化分组树

结构优化
648540858 2023-11-14 18:36:40 +08:00
parent 4ab0200c90
commit bcd5ce25ca
8 changed files with 233 additions and 21 deletions

View File

@ -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<DeviceChannel> deleteChannelList);
PageInfo<CommonGbChannel> queryChannelListInGroup(String groupDeviceId, String query, int page, int count);
PageInfo<CommonGbChannel> queryChannelListInGroup(int page, int count, String query, String groupDeviceId,
String regionDeviceId, Boolean inGroup, Boolean inRegion,
String type);
PageInfo<CommonGbChannel> queryChannelList(String query, int page, int count);
@ -60,4 +63,7 @@ public interface ICommonGbChannelService {
List<NetworkIdentificationType> getNetworkIdentificationTypeList();
void updateChannelToGroup(UpdateCommonChannelToGroup commonGbChannel);
void removeFromGroup(UpdateCommonChannelToGroup params);
}

View File

@ -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<CommonGbChannel> queryChannelListInGroup(String groupDeviceId, String query, int page, int count) {
assert groupDeviceId != null;
public PageInfo<CommonGbChannel> queryChannelListInGroup(int page, int count, String query, String groupDeviceId,
String regionDeviceId, Boolean inGroup, Boolean inRegion,
String type) {
PageHelper.startPage(page, count);
List<CommonGbChannel> 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<CommonGbChannel> 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);
}
}

View File

@ -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<Group> groupList;
if (channelIdType == Gb28181CodeType.BUSINESS_GROUP) {
// 如果要删除的是一个业务分组那么直接查询commonGroupTopId是这个节点的即可这里也包括要删除的节点本身
groupList = groupMapper.queryGroupListByTopId(deviceId);
}else {
// 如果要删除的是一个虚拟组织,那么就不只能不断的递归拿到所有的子节点了
Group group = groupMapper.queryByDeviceId(deviceId);
assert group != null;
List<Group> 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<Group> queryAllChildGroup(List<Group> parentGroups, String commonGroupTopId, List<Group> resultList) {
if (parentGroups.isEmpty()) {
return resultList;
}
List<Group> 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<CommonGbChannel> 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<CommonGbChannel> 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<CommonGbChannel> channelsSub = channels.subList(i, toIndex);
if (commonGbChannelDao.removeChannelsForGroup(channelsSub) <= 0) {
if (commonGbChannelMapper.removeChannelsForGroup(channelsSub) <= 0) {
dataSourceTransactionManager.rollback(transactionStatus);
logger.info("[从分组移除通道] 失败");
return false;

View File

@ -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("<script> "+
"select * from wvp_common_gb_channel where common_gb_business_group_id = #{groupDeviceId}" +
"select * from wvp_common_gb_channel where 1=1 " +
"<if test='groupDeviceId != null'> and common_gb_business_group_id = #{groupDeviceId} </if>" +
"<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='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>")
List<CommonGbChannel> queryChannelListInGroup(@Param("groupDeviceId") String groupDeviceId,
@Param("query") String query);
List<CommonGbChannel> 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("<script> "+
"select * from wvp_common_gb_channel where 1=1 " +
"<if test='query != null'> and ( common_gb_device_id LIKE concat('%',#{query},'%') or common_gb_name LIKE concat('%',#{query},'%') ) </if>" +
"</script>")
List<CommonGbChannel> query(@Param("query") String query);
@Select("<script> "+
"UPDATE wvp_common_gb_channel SET common_gb_business_group_id = null WHERE common_gb_business_group_id in" +
"<foreach collection='groupList' item='item' open='(' separator=',' close=')' > #{item.commonGroupDeviceId}</foreach>" +
"</script>")
void removeGroupInfo(@Param("groupList") List<Group> groupList);
@Update({"<script>" +
"<foreach collection='commonGbChannel.commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" SET common_gb_business_group_id = #{commonGbChannel.commonGbBusinessGroupID}" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
"</script>"})
void updateChannelToGroup(@Param("commonGbChannel") UpdateCommonChannelToGroup commonGbChannel);
@Update({"<script>" +
"<foreach collection='commonGbChannel.commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" SET common_gb_business_group_id = null" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
"</script>"})
void removeFromGroup(@Param("commonGbChannel") UpdateCommonChannelToGroup commonGbChannel);
}

View File

@ -123,4 +123,22 @@ public interface GroupMapper {
"<if test='groupParentId == null'> common_group_device_id = common_group_top_id</if>" +
"</script>")
List<Group> queryVirtualGroupList(@Param("groupParentId") String groupParentId);
@Select("<script> "+
"select * from wvp_common_group where common_group_top_id = #{commonGroupTopId}" +
"</script>")
List<Group> queryGroupListByTopId(@Param("commonGroupTopId") String commonGroupTopId);
@Select("<script> "+
"SELECT * FROM wvp_common_group WHERE common_group_top_id = #{commonGroupTopId} and common_group_parent_id in" +
"<foreach collection='parentGroups' item='item' open='(' separator=',' close=')' > #{item.commonGroupDeviceId}</foreach>" +
"</script>")
List<Group> queryChildGroupListInParentGroup(@Param("parentGroups") List<Group> parentGroups,
@Param("commonGroupTopId") String commonGroupTopId);
@Select("<script> "+
"delete from wvp_common_group where common_group_id in" +
"<foreach collection='groups' item='item' open='(' separator=',' close=')' > #{item.commonGroupId}</foreach>" +
"</script>")
void removeGroupByList(@Param("groups") List<Group> groups);
}

View File

@ -0,0 +1,26 @@
package com.genersoft.iot.vmp.vmanager.bean;
import java.util.List;
public class UpdateCommonChannelToGroup {
private String commonGbBusinessGroupID;
private List<Integer> commonGbIds;
public String getCommonGbBusinessGroupID() {
return commonGbBusinessGroupID;
}
public void setCommonGbBusinessGroupID(String commonGbBusinessGroupID) {
this.commonGbBusinessGroupID = commonGbBusinessGroupID;
}
public List<Integer> getCommonGbIds() {
return commonGbIds;
}
public void setCommonGbIds(List<Integer> commonGbIds) {
this.commonGbIds = commonGbIds;
}
}

View File

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

View File

@ -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(), "移除失败");