From 8c68d9dfa19506b359207dbb4b3568ceb9426f71 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Thu, 11 Jan 2024 14:15:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20/recordInfo=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wvp/api/gb28181/Gb28181Controller.java | 9 +++- .../wvp/service/record/RecordInfoService.java | 51 ++++++++++++++++++- .../wvp/service/record/dto/RecordInfoDTO.java | 25 ++------- .../record/dto/RecordInfoDTOConvertor.java | 14 ----- 4 files changed, 61 insertions(+), 38 deletions(-) delete mode 100644 gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/dto/RecordInfoDTOConvertor.java diff --git a/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/gb28181/Gb28181Controller.java b/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/gb28181/Gb28181Controller.java index d557678..aad15fc 100644 --- a/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/gb28181/Gb28181Controller.java +++ b/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/gb28181/Gb28181Controller.java @@ -4,10 +4,12 @@ import cn.skcks.docking.gb28181.annotation.web.JsonMapping; import cn.skcks.docking.gb28181.annotation.web.methods.GetJson; import cn.skcks.docking.gb28181.annotation.web.methods.PostJson; import cn.skcks.docking.gb28181.common.json.JsonResponse; -import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.query.dto.RecordInfoRequestDTO; +import cn.skcks.docking.gb28181.sip.manscdp.recordinfo.request.RecordInfoRequestDTO; import cn.skcks.docking.gb28181.wvp.config.SwaggerConfig; import cn.skcks.docking.gb28181.wvp.service.catalog.CatalogService; import cn.skcks.docking.gb28181.wvp.service.device.control.DeviceControlService; +import cn.skcks.docking.gb28181.wvp.service.record.RecordInfoService; +import cn.skcks.docking.gb28181.wvp.service.record.dto.RecordInfoDTO; import cn.skcks.docking.gb28181.wvp.sip.message.message.catalog.dto.CatalogItemDTO; import cn.skcks.docking.gb28181.wvp.sip.message.message.catalog.dto.CatalogResponseDTO; import lombok.RequiredArgsConstructor; @@ -27,6 +29,8 @@ import java.util.concurrent.CompletableFuture; public class Gb28181Controller { private final CatalogService catalogService; private final DeviceControlService deviceControlService; + private final RecordInfoService recordInfoService; + @Bean public GroupedOpenApi gb28181Api() { return SwaggerConfig.api("Gb28181Api", "/gb28181"); @@ -53,7 +57,8 @@ public class Gb28181Controller { } @PostJson("/recordInfo") - public JsonResponse recordInfo(RecordInfoRequestDTO dto){ + public JsonResponse recordInfo(RecordInfoDTO dto){ + recordInfoService.requestRecordInfo(dto); return JsonResponse.success(null); } } diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/RecordInfoService.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/RecordInfoService.java index 02b5837..88d0297 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/RecordInfoService.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/RecordInfoService.java @@ -1,14 +1,24 @@ package cn.skcks.docking.gb28181.wvp.service.record; -import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.query.dto.RecordInfoRequestDTO; +import cn.skcks.docking.gb28181.common.json.JsonException; +import cn.skcks.docking.gb28181.common.xml.XmlUtils; +import cn.skcks.docking.gb28181.core.sip.utils.SipUtil; +import cn.skcks.docking.gb28181.sip.manscdp.recordinfo.request.RecordInfoRequestDTO; +import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDevice; +import cn.skcks.docking.gb28181.wvp.orm.mybatis.dynamic.model.WvpProxyDocking; import cn.skcks.docking.gb28181.wvp.service.device.DeviceService; import cn.skcks.docking.gb28181.wvp.service.docking.DockingService; +import cn.skcks.docking.gb28181.wvp.service.record.dto.RecordInfoDTO; +import cn.skcks.docking.gb28181.wvp.sip.request.SipRequestBuilder; import cn.skcks.docking.gb28181.wvp.sip.sender.SipSender; import cn.skcks.docking.gb28181.wvp.sip.subscribe.SipSubscribe; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.text.MessageFormat; +import java.util.Optional; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -22,7 +32,44 @@ public class RecordInfoService { private final DockingService dockingService; private final DeviceService deviceService; - public void requestRecordInfo(String deviceCode, RecordInfoRequestDTO dto){ + @SneakyThrows + public void requestRecordInfo(RecordInfoDTO dto){ + String deviceCode = dto.getDeviceCode(); + Optional deviceByDeviceCode = deviceService.getDeviceByDeviceCode(deviceCode); + if (deviceByDeviceCode.isEmpty()) { + String reason = MessageFormat.format("未能找到 设备编码 为 {0} 的设备", deviceCode); + log.error("{}",reason); + throw new JsonException(reason); + } else { + WvpProxyDevice device = deviceByDeviceCode.get(); + requestRecordInfo(device.getGbDeviceId(), device.getGbDeviceChannelId(), dto); + } + } + public void requestRecordInfo(String gbDeviceId, String channel, RecordInfoDTO dto){ + Optional deviceByGbDeviceId = dockingService.getDeviceByGbDeviceId(gbDeviceId); + if(deviceByGbDeviceId.isEmpty()){ + log.info("未能找到 国标编码 {} 的注册信息", gbDeviceId); + return; + } + Optional deviceByGbDeviceIdAndChannel = deviceService.getDeviceByGbDeviceIdAndChannel(gbDeviceId, channel); + if (deviceByGbDeviceIdAndChannel.isEmpty()) { + log.info("未能找到 编码 {}, 通道 {} 的设备", gbDeviceId, channel); + return; + } + WvpProxyDocking device = deviceByGbDeviceId.get(); + String sn = String.valueOf((int) (Math.random() * 9 + 1) * 100000); + RecordInfoRequestDTO recordInfoRequestDTO = RecordInfoRequestDTO.builder() + .deviceId(channel) + .sn(sn) + .startTime(dto.getStartTime()) + .endTime(dto.getEndTime()) + .type(dto.getType()) + .Secrecy(dto.getSecrecy()) + .filePath(dto.getFilePath()) + .IndistinctQuery(0) + .build(); + sipSender.sendRequest((provider, ip, port)-> SipRequestBuilder.createMessageRequest(device,ip,port,SipRequestBuilder.getCSeq(), XmlUtils.toXml(recordInfoRequestDTO), SipUtil.generateViaTag(), + SipUtil.generateFromTag(), provider.getNewCallId())); } } diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/dto/RecordInfoDTO.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/dto/RecordInfoDTO.java index a996bdf..b026970 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/dto/RecordInfoDTO.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/dto/RecordInfoDTO.java @@ -2,45 +2,30 @@ package cn.skcks.docking.gb28181.wvp.service.record.dto; import cn.hutool.core.date.DatePattern; import cn.skcks.docking.gb28181.constant.GB28181Constant; -import cn.skcks.docking.gb28181.core.sip.gb28181.constant.CmdType; import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; +@Data public class RecordInfoDTO { - private String cmdType = CmdType.RECORD_INFO; - - /** - * 命令序列号(必选) - */ - private String sn; - /** * 目标设备的设备编码(必选) */ - private String deviceId; + private String deviceCode; @DateTimeFormat(pattern= DatePattern.NORM_DATETIME_PATTERN) - @JsonFormat(pattern = GB28181Constant.DATETIME_FORMAT, timezone = GB28181Constant.TIME_ZONE) + @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = GB28181Constant.TIME_ZONE) private Date startTime; @DateTimeFormat(pattern= DatePattern.NORM_DATETIME_PATTERN) - @JsonFormat(pattern = GB28181Constant.DATETIME_FORMAT, timezone = GB28181Constant.TIME_ZONE) + @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = GB28181Constant.TIME_ZONE) private Date endTime; private String filePath; - private String address; - - private Integer Secrecy = 0; - private String type = "all"; - - - private String recorderId; - - private Integer IndistinctQuery; } diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/dto/RecordInfoDTOConvertor.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/dto/RecordInfoDTOConvertor.java deleted file mode 100644 index 16a2d26..0000000 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/record/dto/RecordInfoDTOConvertor.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.skcks.docking.gb28181.wvp.service.record.dto; - -import cn.skcks.docking.gb28181.core.sip.message.processor.message.types.recordinfo.query.dto.RecordInfoRequestDTO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface RecordInfoDTOConvertor { - RecordInfoDTOConvertor INSTANCE = Mappers.getMapper(RecordInfoDTOConvertor.class); - - RecordInfoDTO convert(RecordInfoRequestDTO dto); - - RecordInfoRequestDTO convert(RecordInfoDTO dto); -}