From f38d561e601f6f783db49eb6f3ee379c77d03ab4 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Wed, 17 Jan 2024 18:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E7=94=A8=E9=80=9A?= =?UTF-8?q?=E9=81=93=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/GB28181ResourceServiceImpl.java | 12 ++--- .../query/cmd/CatalogQueryMessageHandler.java | 2 +- .../vmp/service/ICommonGbChannelService.java | 1 + .../impl/CommonGbChannelServiceImpl.java | 37 +++++++++++++++- .../impl/DeviceChannelServiceImpl.java | 10 +++-- .../impl/PlatformChannelServiceImpl.java | 2 +- .../vmp/storager/dao/CommonChannelMapper.java | 44 +++++++++++++++++++ .../iot/vmp/storager/dao/LogMapper.java | 2 +- .../channel/CommonChannelController.java | 5 ++- 9 files changed, 99 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/GB28181ResourceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/GB28181ResourceServiceImpl.java index 24c89b39..22cef671 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/GB28181ResourceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/GB28181ResourceServiceImpl.java @@ -57,20 +57,20 @@ public class GB28181ResourceServiceImpl implements IResourceService { assert callback != null; if (!CommonGbChannelType.GB28181.equals(commonGbChannel.getType())) { logger.warn("[资源类-国标28181] 收到播放通道: {} 时发现类型不为28181", commonGbChannel.getCommonGbId()); - callback.call(commonGbChannel, null, ErrorCode.ERROR500.getCode(), ErrorCode.ERROR500.getMsg(), null); + callback.call(commonGbChannel, null, ErrorCode.ERROR100.getCode(), "数据关系错误", null); return; } DeviceChannel channel = deviceChannelMapper.getChannelByCommonChannelId(commonGbChannel.getCommonGbId()); if (channel == null) { logger.warn("[资源类-国标28181] 收到播放通道: {} 时未找到国标通道", commonGbChannel.getCommonGbId()); - callback.call(commonGbChannel, null, ErrorCode.ERROR500.getCode(), ErrorCode.ERROR500.getMsg(), null); + callback.call(commonGbChannel, null, ErrorCode.ERROR100.getCode(), "未找到通道", null); return; } Device device = deviceMapper.getDeviceByDeviceId(channel.getDeviceId()); if (device == null) { logger.warn("[资源类-国标28181] 收到播放通道: {} 时未找到通道 {} 所属的国标设备", commonGbChannel.getCommonGbId(), channel.getDeviceId()); - callback.call(commonGbChannel, null, ErrorCode.ERROR500.getCode(), ErrorCode.ERROR500.getMsg(), null); + callback.call(commonGbChannel, null, ErrorCode.ERROR100.getCode(), "未找到设备", null); return; } MediaServerItem mediaServerItem = playService.getNewMediaServerItem(device); @@ -78,7 +78,7 @@ public class GB28181ResourceServiceImpl implements IResourceService { if (code == InviteErrorCode.SUCCESS.getCode()) { if (data != null) { StreamInfo streamInfo = (StreamInfo)data; - callback.call(commonGbChannel, mediaServerItem, ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); + callback.call(commonGbChannel, mediaServerItem, ErrorCode.ERROR100.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); } }else { callback.call(commonGbChannel, null, code, msg, null); @@ -91,7 +91,7 @@ public class GB28181ResourceServiceImpl implements IResourceService { if (!CommonGbChannelType.GB28181.equals(commonGbChannel.getType())) { logger.warn("[资源类-国标28181] 收到停止播放通道: {} 时发现类型不为28181", commonGbChannel.getCommonGbId()); if (callback != null) { - callback.call(commonGbChannel,null, ErrorCode.ERROR500.getCode(), ErrorCode.ERROR500.getMsg(), null); + callback.call(commonGbChannel,null, ErrorCode.ERROR100.getCode(), "数据关系错误", null); } return; } @@ -99,7 +99,7 @@ public class GB28181ResourceServiceImpl implements IResourceService { if (channel == null) { logger.warn("[资源类-国标28181] 收到停止播放通道: {} 时未找到国标通道", commonGbChannel.getCommonGbId()); if (callback != null) { - callback.call(commonGbChannel, null, ErrorCode.ERROR500.getCode(), ErrorCode.ERROR500.getMsg(), null); + callback.call(commonGbChannel, null, ErrorCode.ERROR100.getCode(), "未找到通道", null); } return; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java index 3e9e9fe7..d8987a5c 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java @@ -80,7 +80,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem List commonGbChannelList = platformChannelService.queryChannelList(parentPlatform); try { - if (commonGbChannelList.size() > 0) { + if (!commonGbChannelList.isEmpty()) { cmderFroPlatform.catalogQuery(commonGbChannelList, parentPlatform, sn, fromHeader.getTag()); }else { // 回复无通道 diff --git a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java index cc507f04..08bbe7d3 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java @@ -23,6 +23,7 @@ public interface ICommonGbChannelService { int add(CommonGbChannel channel); int update(CommonGbChannel channel); + int updateForForm(CommonGbChannel channel); PageInfo getChannelsInRegion(String regionDeviceId, String query, int page, int count); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java index 81a26eb1..ff264026 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.common.BatchLimit; import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEventType; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; @@ -10,6 +11,7 @@ import com.genersoft.iot.vmp.service.*; import com.genersoft.iot.vmp.service.bean.*; import com.genersoft.iot.vmp.storager.dao.CommonChannelMapper; import com.genersoft.iot.vmp.utils.DateUtil; +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToGroup; import com.genersoft.iot.vmp.vmanager.bean.UpdateCommonChannelToRegion; import com.github.pagehelper.PageHelper; @@ -115,6 +117,25 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { return result; } + @Override + public int updateForForm(CommonGbChannel channel) { + assert channel.getCommonGbId() >= 0; + assert channel.getCommonGbDeviceID() != null; + assert channel.getCommonGbName() != null; + channel.setUpdateTime(DateUtil.getNow()); + CommonGbChannel commonGbChannel = commonGbChannelMapper.queryByDeviceID(channel.getCommonGbDeviceID()); + if (commonGbChannel != null && commonGbChannel.getCommonGbId() != channel.getCommonGbId()) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "失败: 编号 " + channel.getCommonGbDeviceID() + " 已存在"); + } + + int result = commonGbChannelMapper.updateForForm(channel); + if (result == 0) { + return 0; + } + sendCatalogEvent(channel, CatalogEventType.UPDATE); + return result; + } + @Override public void deleteGbChannelsFromList(List channelList) { if (channelList.isEmpty()) { @@ -235,14 +256,24 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { public void startPlay(CommonGbChannel channel, IResourcePlayCallback callback) { IResourceService resourceService = resourceServiceMap.get(channel.getType()); assert resourceService != null; - resourceService.startPlay(channel, callback); + resourceService.startPlay(channel, ((commonGbChannel, mediaServerItem, code, message, streamInfo) -> { + if (code == InviteErrorCode.SUCCESS.getCode()) { + // 记录到数据库 + } + callback.call(commonGbChannel, mediaServerItem, code, message, streamInfo); + })); } @Override public void stopPlay(CommonGbChannel channel, IResourcePlayCallback callback) { IResourceService resourceService = resourceServiceMap.get(channel.getType()); assert resourceService != null; - resourceService.stopPlay(channel,callback); + resourceService.stopPlay(channel,((commonGbChannel, mediaServerItem, code, message, streamInfo) -> { + if (code == InviteErrorCode.SUCCESS.getCode()) { + // 记录到数据库 + } + callback.call(commonGbChannel, mediaServerItem, code, message, streamInfo); + })); } @Override @@ -257,9 +288,11 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { toIndex = commonGbChannels.size(); } commonGbChannelMapper.batchAdd(commonGbChannels.subList(i, toIndex)); + System.out.println(11); } }else { commonGbChannelMapper.batchAdd(commonGbChannels); + System.out.println(11); } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java index 35e52f97..f48a2936 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java @@ -292,11 +292,15 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @Override public void batchAddChannel(List channels) { - List commonGbChannelList = new ArrayList<>(); + + Map channelMap = new HashMap<>(); channels.stream().forEach(channel->{ - commonGbChannelList.add(CommonGbChannel.getInstance(null, channel)); + channelMap.put(channel.getChannelId(),CommonGbChannel.getInstance(null, channel)); }); - commonGbChannelService.batchAdd(commonGbChannelList); + commonGbChannelService.batchAdd(new ArrayList<>(channelMap.values())); + for (DeviceChannel channel : channels) { + channel.setCommonGbChannelId(channelMap.get(channel.getChannelId()).getCommonGbId()); + } channelMapper.batchAdd(channels); for (DeviceChannel channel : channels) { if (channel.getParentId() != null) { diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java index 1c938523..5e914643 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java @@ -146,7 +146,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { } } - return null; + return result; } @Override diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonChannelMapper.java index da30e673..22c406d8 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonChannelMapper.java @@ -194,11 +194,54 @@ public interface CommonChannelMapper { " ,common_gb_business_group_id= #{ commonGbBusinessGroupID} " + " ,common_gb_download_speed= #{ commonGbDownloadSpeed} " + " ,common_gb_svc_time_support_mode= #{ commonGbSVCTimeSupportMode} " + + " ,common_gb_svc_space_support_mode= #{commonGbSVCSpaceSupportMode} " + " ,type= #{ type} " + " WHERE common_gb_id=#{commonGbId}" + "") int update(CommonGbChannel channel); + @Update(value = "") + int updateForForm(CommonGbChannel channel); + @Select("select count(1)\n" + "from wvp_common_channel gc " + "right join wvp_common_platform_channel pc " + @@ -565,6 +608,7 @@ public interface CommonChannelMapper { " WHERE common_gb_id=#{item.commonGbId}" + "" + ""}) + @Options(useGeneratedKeys=true, keyProperty="commonGbId", keyColumn="common_gb_id") int batchUpdate(@Param("commonGbChannels") List commonGbChannels); diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/LogMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/LogMapper.java index 0d2fa015..1d6c3cdf 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/LogMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/LogMapper.java @@ -24,7 +24,7 @@ public interface LogMapper { @Select(value = {"