From 424f828f47ef3cb18e84f66af2ec89b421f6f46d Mon Sep 17 00:00:00 2001 From: tyty Date: Tue, 5 Dec 2023 18:53:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B5=B7=E5=BA=B7=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E8=BD=AC=E6=8D=A2=E4=B8=BAflv=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StationVideoTypeController.java | 28 +++++++++++++----- .../service/impl/StationVideoTypeServiceImpl.java | 21 +++----------- .../station/utils/ArtemisPostUtils.java | 33 ++++++++++++++++++++-- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java index 2cc57ac..13e8950 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java @@ -2,10 +2,8 @@ package com.hnac.hzims.operational.station.controller; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.logs.annotation.OperationAnnotation; import com.hnac.hzims.common.logs.enums.BusinessType; @@ -16,16 +14,15 @@ import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; import com.hnac.hzims.operational.station.response.HikDeviceResp; import com.hnac.hzims.operational.station.response.HikMonitorResp; import com.hnac.hzims.operational.station.service.IStationService; +import com.hnac.hzims.operational.station.service.IStationVideoTypeService; +import com.hnac.hzims.operational.station.utils.ArtemisPostUtils; import com.hnac.hzims.operational.station.vo.StationVO; +import com.hnac.hzims.operational.station.vo.StationVideoTypeVO; import com.hnac.hzims.operational.station.vo.VideoMonitorVO; import com.hnac.hzims.operational.station.wrapper.StationVideoTypeWrapper; -import com.hnac.hzims.operational.station.service.IStationVideoTypeService; -import com.hnac.hzims.operational.station.vo.StationVideoTypeVO; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.log.annotation.ApiLog; @@ -43,6 +40,7 @@ import javax.validation.Valid; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Consumer; /** * @author hx @@ -217,7 +215,23 @@ public class StationVideoTypeController extends BladeController { public R> getHikVisionStations() { return R.data(stationVideoTypeService.getHikVisionStations()); } - + @ApiLog + @GetMapping("/getHikVideo") + @ApiOperationSupport(order = 120) + @ApiOperation(value = "获取海康视频区域列表", notes = "获取海康视频区域列表") + public R getVideoMonitor(StationVideoTypeEntity req,Query query) { + LambdaQueryWrapper queryWrapper = com.hnac.hzims.common.utils.Condition.getQueryWrapper(StationVideoTypeEntity.class, req); + IPage page = stationVideoTypeService.page(com.hnac.hzims.common.utils.Condition.getPage(query), queryWrapper); + Consumer getFlvVideo = video -> { + try { + video.setLiveSourceAddress(ArtemisPostUtils.getCameraPreviewFlvURL(video.getVideoHost(), video.getAppKey(), video.getAppSecret(), video.getPointCode(), 1)); + } catch (Exception e) { + video.setLiveSourceAddress(null); + } + }; + page.getRecords().forEach(getFlvVideo); + return R.data(page); + } @ApiLog @GetMapping("/getMonitorsByStation") @ApiOperationSupport(order = 130) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java index 6841db2..fd50c95 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java @@ -1,6 +1,5 @@ package com.hnac.hzims.operational.station.service.impl; -import cn.hutool.core.util.RandomUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; @@ -10,7 +9,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hikvision.artemis.sdk.ArtemisHttpUtil; import com.hnac.hzims.operational.config.HikPathConfiguration; import com.hnac.hzims.operational.station.StationConstants; import com.hnac.hzims.operational.station.dto.StationVideoTypeDTO; @@ -19,39 +17,28 @@ import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; import com.hnac.hzims.operational.station.mapper.StationVideoTypeMapper; import com.hnac.hzims.operational.station.response.HikDeviceResp; import com.hnac.hzims.operational.station.response.HikMonitorResp; -import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.operational.station.service.IStationVideoTypeService; import com.hnac.hzims.operational.station.utils.ArtemisPostUtils; -import com.hnac.hzims.operational.station.vo.StationVO; import com.hnac.hzims.operational.station.vo.StationVideoTypeVO; import com.hnac.hzims.operational.station.vo.VideoMonitorVO; -import com.hnac.hzims.operational.station.wrapper.StationVideoTypeWrapper; -import com.hnac.hzims.operational.station.wrapper.StationWrapper; -import com.hnac.hzims.operational.util.HttpClientUtils; -import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.core.jwt.JwtUtil; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; import org.springblade.system.cache.DictCache; -import org.springblade.system.entity.Dept; -import org.springblade.system.feign.ISysClient; -import org.springblade.system.user.entity.User; -import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import javax.servlet.http.HttpServletResponse; -import java.sql.Wrapper; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/utils/ArtemisPostUtils.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/utils/ArtemisPostUtils.java index ec1d13b..41ef519 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/utils/ArtemisPostUtils.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/utils/ArtemisPostUtils.java @@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.hikvision.artemis.sdk.ArtemisHttpUtil; import com.hikvision.artemis.sdk.config.ArtemisConfig; -import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; public class ArtemisPostUtils { @@ -187,4 +184,34 @@ public class ArtemisPostUtils { list = json.getJSONArray("data"); return list; }*/ + + public static String getCameraPreviewFlvURL(String host, String appKey, String appSecret, String cameraIndexCode, int streamType) { + ArtemisConfig.host = host; + ArtemisConfig.appKey = appKey; + ArtemisConfig.appSecret = appSecret; + String ARTEMIS_PATH = "/artemis"; + String getCamsApi = ARTEMIS_PATH+"/api/video/v2/cameras/previewURLs"; + Map path = new HashMap(2) { + { + this.put("https://", getCamsApi); + } + }; + String contentType = "application/json"; + JSONObject jsonBody = new JSONObject(); + jsonBody.put("cameraIndexCode", cameraIndexCode); + jsonBody.put("streamType", 0); + jsonBody.put("protocol", "httpflv"); + jsonBody.put("transmode", 1); + + String body = jsonBody.toJSONString(); + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, (Map)null, (String)null, contentType, (Map)null); + if (null == result && "".equals(result)) { + return null; + } else { + JSONObject json = JSONObject.parseObject(result); + json = JSONObject.parseObject(json.getString("data")); + String url = json.getString("url"); + return url; + } + } }