Browse Source

# 视频点位选择优化

zhongwei
haungxing 10 months ago
parent
commit
6d9d984da2
  1. 15
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/constants/HikApiConstants.java
  2. 48
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/HikVideoController.java
  3. 15
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java
  4. 23
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IHikVideoService.java
  5. 5
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java
  6. 102
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/HikVideoServiceImpl.java
  7. 39
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java
  8. 20
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HikVideoAreaTreeVO.java
  9. 28
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HikVideoAreaVO.java

15
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/constants/HikApiConstants.java

@ -0,0 +1,15 @@
package com.hnac.hzims.operational.station.constants;
public interface HikApiConstants {
String ARTEMIS_PATH = "/artemis";
/**查询区域列表**/
String NODE_BY_PARAMS = "/api/irds/v1/region/nodesByParams";
/**根据区域获取下级编码设备列表**/
String SUB_RESOURCES = "/api/resource/v1/encodeDevice/subResources";
/**根据区域编号获取下级监控点列表**/
String CAMERAS = "/api/resource/v1/regions/regionIndexCode/cameras";
}

48
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/HikVideoController.java

@ -0,0 +1,48 @@
package com.hnac.hzims.operational.station.controller;
import com.hnac.hzims.operational.station.service.IHikVideoService;
import com.hnac.hzims.operational.station.vo.HikVideoAreaVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/hik/video")
@Api(value = "海康API管理",tags = "海康API管理")
@AllArgsConstructor
public class HikVideoController extends BladeController {
private final IHikVideoService hikVideoService;
@ApiOperation("查询区域列表")
@ApiOperationSupport(order = 1)
@GetMapping("/nodesByParams")
public R<List<HikVideoAreaVO>> nodesByParams(@ApiParam("区域父级编号")@RequestParam(required = false) String parentIndexCode) {
return R.data(hikVideoService.nodesByParams(parentIndexCode));
}
@ApiOperation("根据区域获取下级编码设备列表")
@ApiOperationSupport(order = 2)
@GetMapping("/subResources")
public R<List> subResources(@ApiParam("区域父级编号")@RequestParam String regionIndexCode) {
return R.data(hikVideoService.subResources(regionIndexCode));
}
@ApiOperation("查询监控点列表")
@ApiOperationSupport(order = 3)
@GetMapping("/cameras")
public R<List> cameras(@ApiParam("区域父级编号")@RequestParam String regionIndexCode) {
return R.data(hikVideoService.cameras(regionIndexCode));
}
}

15
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java

@ -19,6 +19,7 @@ import com.hnac.hzims.operational.station.service.IStationService;
import com.hnac.hzims.operational.station.service.IStationVideoTypeService;
import com.hnac.hzims.operational.station.service.VideoConfigService;
import com.hnac.hzims.operational.station.utils.ArtemisPostUtils;
import com.hnac.hzims.operational.station.vo.HikVideoAreaTreeVO;
import com.hnac.hzims.operational.station.vo.StationVO;
import com.hnac.hzims.operational.station.vo.StationVideoTypeVO;
import com.hnac.hzims.operational.station.vo.VideoMonitorVO;
@ -312,4 +313,18 @@ public class StationVideoTypeController extends BladeController {
return R.data(stationVideoTypeService.getWsUrlByPointCode(pointCodes,host,appKey,appSecret,streamType));
}
@GetMapping("/getHikVideoAreaTree")
@ApiOperationSupport(order = 150)
@ApiOperation(value = "获取海康区域树", notes = "获取海康区域树")
public R<List<HikVideoAreaTreeVO>> getHikVideoAreaTree() {
return R.data(stationVideoTypeService.getHikVideoAreaTree());
}
@GetMapping("/getVideoPointByRegion")
@ApiOperationSupport(order = 160)
@ApiOperation(value = "获取海康监控点树", notes = "获取海康监控点树")
public R<Map> getVideoPointByRegion(@RequestParam @ApiParam("所属机构") Long refDept, @RequestParam @ApiParam("区域唯一标识") String regionCode) {
return R.data(stationVideoTypeService.getVideoPointByRegion(refDept,regionCode));
}
}

23
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IHikVideoService.java

@ -0,0 +1,23 @@
package com.hnac.hzims.operational.station.service;
import com.hnac.hzims.operational.station.vo.HikVideoAreaVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
public interface IHikVideoService {
/**
* 查询区域列表
* @return 区域列表
*/
List<HikVideoAreaVO> nodesByParams(String parentIndexCode);
List subResources(String regionIndexCode);
List cameras(String regionIndexCode);
}

5
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java

@ -7,6 +7,7 @@ import com.hnac.hzims.operational.station.entity.StationEntity;
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.vo.HikVideoAreaTreeVO;
import com.hnac.hzims.operational.station.vo.StationVideoTypeVO;
import com.hnac.hzims.operational.station.vo.VideoMonitorVO;
import org.apache.ibatis.annotations.Param;
@ -76,4 +77,8 @@ public interface IStationVideoTypeService extends BaseService<StationVideoTypeEn
*/
Map<String,Object> getWsUrlByPointCode(String pointCodes,String host,String appKey,String appSecret,Integer streamType);
List<HikVideoAreaTreeVO> getHikVideoAreaTree();
Map getVideoPointByRegion(Long refDept,String regionCode);
}

102
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/HikVideoServiceImpl.java

@ -0,0 +1,102 @@
package com.hnac.hzims.operational.station.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.hnac.hzims.operational.station.service.IHikVideoService;
import com.hnac.hzims.operational.station.vo.HikVideoAreaVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.hnac.hzims.operational.station.constants.HikApiConstants.*;
@RequiredArgsConstructor
@Slf4j
@Service
public class HikVideoServiceImpl implements IHikVideoService {
@Value("${hzims.videoProperties.appKey}")
private String videoAppKey;
@Value("${hzims.videoProperties.videoHost}")
private String videoHost;
@Value("${hzims.videoProperties.appSecret}")
private String videoAppSecret;
private void init() {
ArtemisConfig.host = videoHost;
ArtemisConfig.appKey = videoAppKey;
ArtemisConfig.appSecret = videoAppSecret;
}
private String doPostStringArtemis(Map<String, String> path,String body) {
String contentType = "application/json";
String resultStr = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);
JSONObject resultObj = JSONObject.parseObject(resultStr);
Assert.isTrue("0".equals(resultObj.getString("code")),()-> {
throw new ServiceException(resultObj.getString("msg"));
});
return resultObj.getString("data");
}
@Override
public List<HikVideoAreaVO> nodesByParams(String parentIndexCode) {
init();
Map<String, String> path = new HashMap<>();
path.put("https://", ARTEMIS_PATH + NODE_BY_PARAMS);
HashMap<String, Object> body = new HashMap<String, Object>() {{
put("pageNo",1);
put("pageSize",999);
put("resourceType","camera");
if(StringUtil.isNotBlank(parentIndexCode)) {
put("parentIndexCodes", Func.toStrList(",",parentIndexCode));
}
}};
String result = doPostStringArtemis(path, JSON.toJSONString(body));
String list = JSONObject.parseObject(result).getString("list");
return JSONArray.parseArray(list,HikVideoAreaVO.class);
}
@Override
public List subResources(String regionIndexCode) {
init();
Map<String, String> path = new HashMap<>();
path.put("https://", ARTEMIS_PATH + SUB_RESOURCES);
HashMap<String, Object> body = new HashMap<String, Object>() {{
put("pageNo",1);
put("pageSize",999);
put("regionIndexCode", regionIndexCode);
}};
String result = doPostStringArtemis(path, JSON.toJSONString(body));
String list = JSONObject.parseObject(result).getString("list");
return JSONArray.parseArray(list);
}
@Override
public List cameras(String regionIndexCode) {
init();
Map<String, String> path = new HashMap<>();
path.put("https://", ARTEMIS_PATH + CAMERAS);
HashMap<String, Object> body = new HashMap<String, Object>() {{
put("pageNo",1);
put("pageSize",999);
put("regionIndexCode", regionIndexCode);
}};
String result = doPostStringArtemis(path, JSON.toJSONString(body));
String list = JSONObject.parseObject(result).getString("list");
return JSONArray.parseArray(list);
}
}

39
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java

@ -18,8 +18,11 @@ 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.IHikVideoService;
import com.hnac.hzims.operational.station.service.IStationVideoTypeService;
import com.hnac.hzims.operational.station.utils.ArtemisPostUtils;
import com.hnac.hzims.operational.station.vo.HikVideoAreaTreeVO;
import com.hnac.hzims.operational.station.vo.HikVideoAreaVO;
import com.hnac.hzims.operational.station.vo.StationVideoTypeVO;
import com.hnac.hzims.operational.station.vo.VideoMonitorVO;
import lombok.RequiredArgsConstructor;
@ -49,6 +52,7 @@ public class StationVideoTypeServiceImpl extends BaseServiceImpl<StationVideoTyp
private final HikPathConfiguration pathConfiguration;
private final BladeLogger logger;
private final IHikVideoService hikVideoService;
@Value("${url.video.login}")
private String videoLoginUrl;
@ -230,6 +234,41 @@ public class StationVideoTypeServiceImpl extends BaseServiceImpl<StationVideoTyp
}
@Override
public List<HikVideoAreaTreeVO> getHikVideoAreaTree() {
List<HikVideoAreaVO> hikVideoAreaList = hikVideoService.nodesByParams(null);
Map<String, List<HikVideoAreaVO>> videoAreaMapByParent = hikVideoAreaList.stream().collect(Collectors.groupingBy(HikVideoAreaVO::getParentIndexCode));
List<HikVideoAreaVO> firstLevelArea = videoAreaMapByParent.get("-1");
List<HikVideoAreaTreeVO> result = firstLevelArea.stream().map(area -> this.generateAreaTree(videoAreaMapByParent, area)).collect(Collectors.toList());
return result;
}
@Override
public Map getVideoPointByRegion(Long refDept, String regionCode) {
LambdaQueryWrapper<StationVideoTypeEntity> queryWrapper = Wrappers.<StationVideoTypeEntity>lambdaQuery().select(StationVideoTypeEntity::getPointCode).eq(StationVideoTypeEntity::getDeptId, refDept);
List<String> pointCodes = this.listObjs(queryWrapper, String::valueOf);
List<JSONObject> cameras = hikVideoService.cameras(regionCode);
cameras.stream().forEach(camera -> {
if(pointCodes.contains(camera.getString("cameraIndexCode"))) {
camera.put("disabled",true);
}
else {
camera.put("disabled",false);
}
});
return cameras.stream().collect(Collectors.groupingBy(c -> c.getString("cameraName")));
}
private HikVideoAreaTreeVO generateAreaTree(Map<String, List<HikVideoAreaVO>> videoAreaMapByParent,HikVideoAreaVO area) {
HikVideoAreaTreeVO parentTree = BeanUtil.copy(area,HikVideoAreaTreeVO.class);
if(CollectionUtil.isNotEmpty(videoAreaMapByParent.get(area.getIndexCode()))) {
List<HikVideoAreaVO> children = videoAreaMapByParent.get(area.getIndexCode());
List<HikVideoAreaTreeVO> childrenTree = children.stream().map(childrenArea -> this.generateAreaTree(videoAreaMapByParent,childrenArea)).collect(Collectors.toList());
parentTree.setChildren(childrenTree);
}
return parentTree;
}
@Override
public StationVideoTypeEntity getById(Long id,int streamType){
StationVideoTypeEntity stationVideoTypeEntity = this.getById(id);
if(ObjectUtil.isNotEmpty(stationVideoTypeEntity.getIsHikvideo()) && stationVideoTypeEntity.getIsHikvideo() == 1){

20
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HikVideoAreaTreeVO.java

@ -0,0 +1,20 @@
package com.hnac.hzims.operational.station.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.List;
@Data
@EqualsAndHashCode
@ApiModel(value = "海康平台区域树结构",description = "海康平台区域树结构")
public class HikVideoAreaTreeVO extends HikVideoAreaVO implements Serializable {
@ApiModelProperty("子区域")
private List<HikVideoAreaTreeVO> children;
}

28
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HikVideoAreaVO.java

@ -0,0 +1,28 @@
package com.hnac.hzims.operational.station.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
@Data
@EqualsAndHashCode
@ApiModel("海康区域对象")
public class HikVideoAreaVO implements Serializable {
@ApiModelProperty("区域名称")
private String name;
@ApiModelProperty("区域唯一标识码")
private String indexCode;
@ApiModelProperty("树编号")
private String treeCode;
@ApiModelProperty("父区域唯一标识码")
private String parentIndexCode;
}
Loading…
Cancel
Save