优化分组管理

结构优化
648540858 2023-11-03 17:20:00 +08:00
parent e5ac02ff17
commit 887f20524f
11 changed files with 68 additions and 45 deletions

View File

@ -2,7 +2,7 @@ package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.common.CommonGbChannel;
import com.genersoft.iot.vmp.service.bean.Group;
import com.genersoft.iot.vmp.vmanager.bean.PageInfo;
import com.github.pagehelper.PageInfo;
import java.util.List;

View File

@ -1,9 +1,8 @@
package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.service.bean.Region;
import com.genersoft.iot.vmp.vmanager.bean.PageInfo;
import com.github.pagehelper.PageInfo;
import java.util.List;
public interface IRegionService {

View File

@ -164,17 +164,18 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
commonGbChannelList.add(commonGbChannel);
}
});
// 检查是否存在已存在通道与将写入通道相同的情况
List<CommonGbChannel> commonGbChannelInDbList = commonGbChannelMapper.queryInList(commonGbChannelList);
if (!commonGbChannelInDbList.isEmpty()) {
// 这里可以控制新数据覆盖旧数据还是丢弃重复的新数据
// 目前使用新数据覆盖旧数据,后续分局实际业务需求再做修改
commonGbChannelInDbList.stream().forEach(commonGbChannel->{
clearChannels.add(commonGbChannel.getCommonGbDeviceID());
});
if (!commonGbChannelList.isEmpty()) {
// 检查是否存在已存在通道与将写入通道相同的情况
List<CommonGbChannel> commonGbChannelInDbList = commonGbChannelMapper.queryInList(commonGbChannelList);
if (!commonGbChannelInDbList.isEmpty()) {
// 这里可以控制新数据覆盖旧数据还是丢弃重复的新数据
// 目前使用新数据覆盖旧数据,后续分局实际业务需求再做修改
commonGbChannelInDbList.stream().forEach(commonGbChannel->{
clearChannels.add(commonGbChannel.getCommonGbDeviceID());
});
}
}
// 检测分组境况
if (businessGroupMap.isEmpty()) {
virtuallyGroupMap.clear();
@ -251,22 +252,26 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
}
// 写入通道数据
boolean result;
if (commonGbChannelList.size() <= limit) {
result = commonGbChannelMapper.addAll(commonGbChannelList) > 0;
} else {
for (int i = 0; i < commonGbChannelList.size(); i += limit) {
int toIndex = i + limit;
if (i + limit > commonGbChannelList.size()) {
toIndex = commonGbChannelList.size();
}
List<CommonGbChannel> commonGbChannelListSub = commonGbChannelList.subList(i, toIndex);
int currentResult = commonGbChannelMapper.addAll(commonGbChannelListSub);
if (currentResult <= 0) {
dataSourceTransactionManager.rollback(transactionStatus);
logger.info("[同步通用通道]来自国标设备,失败, 写入数据库失败, 国标编号: {}", gbDeviceId);
return false;
if (!commonGbChannelList.isEmpty()) {
if (commonGbChannelList.size() <= limit) {
result = commonGbChannelMapper.addAll(commonGbChannelList) > 0;
} else {
for (int i = 0; i < commonGbChannelList.size(); i += limit) {
int toIndex = i + limit;
if (i + limit > commonGbChannelList.size()) {
toIndex = commonGbChannelList.size();
}
List<CommonGbChannel> commonGbChannelListSub = commonGbChannelList.subList(i, toIndex);
int currentResult = commonGbChannelMapper.addAll(commonGbChannelListSub);
if (currentResult <= 0) {
dataSourceTransactionManager.rollback(transactionStatus);
logger.info("[同步通用通道]来自国标设备,失败, 写入数据库失败, 国标编号: {}", gbDeviceId);
return false;
}
}
result = true;
}
}else {
result = true;
}
deviceChannelMapper.updateCommonChannelId(gbDeviceId);

View File

@ -2,12 +2,14 @@ package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.common.CommonGbChannel;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.Gb28181CodeType;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.service.IGroupService;
import com.genersoft.iot.vmp.service.bean.Group;
import com.genersoft.iot.vmp.storager.dao.GroupMapper;
import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.PageInfo;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -192,7 +194,14 @@ public class GroupServiceImpl implements IGroupService {
@Override
public PageInfo<Group> queryChildGroupList(String groupParentId, int page, int count) {
PageHelper.startPage(page, count);
List<Group> groupList = groupMapper.queryChildGroupList(groupParentId);
Gb28181CodeType channelIdType = SipUtils.getChannelIdType(groupParentId);
List<Group> groupList;
if (groupParentId == null || channelIdType == Gb28181CodeType.BUSINESS_GROUP) {
groupList = groupMapper.queryVirtualGroupList(groupParentId);
}else {
groupList = groupMapper.queryChildGroupList(groupParentId);
}
return new PageInfo<>(groupList);
}
}

View File

@ -1,14 +1,13 @@
package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.IRegionService;
import com.genersoft.iot.vmp.service.bean.Region;
import com.genersoft.iot.vmp.storager.dao.CommonGbChannelMapper;
import com.genersoft.iot.vmp.storager.dao.RegionMapper;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.PageInfo;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

View File

@ -109,8 +109,16 @@ public interface GroupMapper {
void updateParentDeviceId(@Param("oldParentDeviceId") String oldParentDeviceId, @Param("newParentDeviceId") String newParentDeviceId);
@Select("<script> "+
"select * from wvp_common_group where common_group_parent_id = #{groupParentId} " +
"select * from wvp_common_group where common_group_parent_id = #{groupParentId}" +
"</script>")
List<Group> queryChildGroupList(String groupParentId);
List<Group> queryChildGroupList(@Param("groupParentId") String groupParentId);
@Select("<script> "+
"select * from wvp_common_group where " +
"<if test='groupParentId != null'> " +
"common_group_top_id = #{groupParentId} and common_group_parent_id is null and common_group_device_id != common_group_top_id " +
"</if>" +
"<if test='groupParentId == null'> common_group_device_id = common_group_top_id</if>" +
"</script>")
List<Group> queryVirtualGroupList(@Param("groupParentId") String groupParentId);
}

View File

@ -3,7 +3,7 @@ package com.genersoft.iot.vmp.vmanager.bean;
import java.util.ArrayList;
import java.util.List;
public class PageInfo<T> {
public class WVPPageInfo<T> {
//当前页
private int pageNum;
//每页的数量
@ -19,11 +19,11 @@ public class PageInfo<T> {
private List<T> list;
public PageInfo(List<T> resultData) {
public WVPPageInfo(List<T> resultData) {
this.resultData = resultData;
}
public PageInfo() {
public WVPPageInfo() {
}
public void startPage(int page, int count) {

View File

@ -91,7 +91,7 @@ public class CommonChannelController {
@Operation(summary = "更新通道")
@Parameter(name = "CommonGbChannel", description = "commonGbChannel", required = true)
@ResponseBody
@GetMapping("/list")
@GetMapping("/update")
public void update(
@RequestParam(required = false) CommonGbChannel commonGbChannel
){

View File

@ -9,7 +9,7 @@ import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.PageInfo;
import com.genersoft.iot.vmp.vmanager.bean.WVPPageInfo;
import com.genersoft.iot.vmp.vmanager.bean.RecordFile;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@ -108,7 +108,7 @@ public class CloudRecordController {
@Parameter(name = "startTime", description = "开始时间(yyyy-MM-dd HH:mm:ss)", required = true)
@Parameter(name = "endTime", description = "结束时间(yyyy-MM-dd HH:mm:ss)", required = true)
@Parameter(name = "mediaServerId", description = "流媒体ID置空则查询全部流媒体", required = false)
public PageInfo<RecordFile> openRtpServer(
public WVPPageInfo<RecordFile> openRtpServer(
@RequestParam String app,
@RequestParam String stream,
@RequestParam int page,
@ -133,10 +133,10 @@ public class CloudRecordController {
mediaServerItems = mediaServerService.getAll();
}
if (mediaServerItems.isEmpty()) {
return new PageInfo<>();
return new WVPPageInfo<>();
}
List<RecordFile> records = mediaServerService.getRecords(app, stream, startTime, endTime, mediaServerItems);
PageInfo<RecordFile> pageInfo = new PageInfo<>(records);
WVPPageInfo<RecordFile> pageInfo = new WVPPageInfo<>(records);
pageInfo.startPage(page, count);
return pageInfo;
}

View File

@ -4,10 +4,11 @@ import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.service.IGroupService;
import com.genersoft.iot.vmp.service.bean.Group;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.PageInfo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -73,10 +74,13 @@ public class GroupController {
@ResponseBody
@GetMapping("/child/list")
public PageInfo<Group> queryChildGroupList(
@RequestParam(required = true) String groupParentId,
@RequestParam(required = false) String groupParentId,
@RequestParam(required = true) int page,
@RequestParam(required = true) int count
){
return groupService.queryChildGroupList(groupParentId, page, count);
if (ObjectUtils.isEmpty(groupParentId)) {
groupParentId = null;
}
return groupService.queryChildGroupList(groupParentId, page, count);
}
}

View File

@ -1,9 +1,8 @@
package com.genersoft.iot.vmp.vmanager.region;
import com.genersoft.iot.vmp.service.IRegionService;
import com.genersoft.iot.vmp.service.bean.Group;
import com.genersoft.iot.vmp.service.bean.Region;
import com.genersoft.iot.vmp.vmanager.bean.PageInfo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;