diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/constants/HikApiConstants.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/constants/HikApiConstants.java new file mode 100644 index 0000000..eeef631 --- /dev/null +++ b/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"; + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/HikVideoController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/HikVideoController.java new file mode 100644 index 0000000..4dc814a --- /dev/null +++ b/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> nodesByParams(@ApiParam("区域父级编号")@RequestParam(required = false) String parentIndexCode) { + return R.data(hikVideoService.nodesByParams(parentIndexCode)); + } + + @ApiOperation("根据区域获取下级编码设备列表") + @ApiOperationSupport(order = 2) + @GetMapping("/subResources") + public R subResources(@ApiParam("区域父级编号")@RequestParam String regionIndexCode) { + return R.data(hikVideoService.subResources(regionIndexCode)); + } + + @ApiOperation("查询监控点列表") + @ApiOperationSupport(order = 3) + @GetMapping("/cameras") + public R cameras(@ApiParam("区域父级编号")@RequestParam String regionIndexCode) { + return R.data(hikVideoService.cameras(regionIndexCode)); + } +} 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 981ab67..ffea1c9 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 @@ -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> getHikVideoAreaTree() { + return R.data(stationVideoTypeService.getHikVideoAreaTree()); + } + + @GetMapping("/getVideoPointByRegion") + @ApiOperationSupport(order = 160) + @ApiOperation(value = "获取海康监控点树", notes = "获取海康监控点树") + public R getVideoPointByRegion(@RequestParam @ApiParam("所属机构") Long refDept, @RequestParam @ApiParam("区域唯一标识") String regionCode) { + return R.data(stationVideoTypeService.getVideoPointByRegion(refDept,regionCode)); + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IHikVideoService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IHikVideoService.java new file mode 100644 index 0000000..8956ae3 --- /dev/null +++ b/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 nodesByParams(String parentIndexCode); + + List subResources(String regionIndexCode); + + List cameras(String regionIndexCode); + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java index 834a7e3..3862dff 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java +++ b/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 getWsUrlByPointCode(String pointCodes,String host,String appKey,String appSecret,Integer streamType); + List getHikVideoAreaTree(); + + Map getVideoPointByRegion(Long refDept,String regionCode); + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/HikVideoServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/HikVideoServiceImpl.java new file mode 100644 index 0000000..e61092a --- /dev/null +++ b/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 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 nodesByParams(String parentIndexCode) { + init(); + Map path = new HashMap<>(); + path.put("https://", ARTEMIS_PATH + NODE_BY_PARAMS); + HashMap body = new HashMap() {{ + 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 path = new HashMap<>(); + path.put("https://", ARTEMIS_PATH + SUB_RESOURCES); + HashMap body = new HashMap() {{ + 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 path = new HashMap<>(); + path.put("https://", ARTEMIS_PATH + CAMERAS); + HashMap body = new HashMap() {{ + 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); + } +} 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 f3500bb..b50cb95 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 @@ -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 getHikVideoAreaTree() { + List hikVideoAreaList = hikVideoService.nodesByParams(null); + Map> videoAreaMapByParent = hikVideoAreaList.stream().collect(Collectors.groupingBy(HikVideoAreaVO::getParentIndexCode)); + List firstLevelArea = videoAreaMapByParent.get("-1"); + List result = firstLevelArea.stream().map(area -> this.generateAreaTree(videoAreaMapByParent, area)).collect(Collectors.toList()); + return result; + } + + @Override + public Map getVideoPointByRegion(Long refDept, String regionCode) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().select(StationVideoTypeEntity::getPointCode).eq(StationVideoTypeEntity::getDeptId, refDept); + List pointCodes = this.listObjs(queryWrapper, String::valueOf); + List 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> videoAreaMapByParent,HikVideoAreaVO area) { + HikVideoAreaTreeVO parentTree = BeanUtil.copy(area,HikVideoAreaTreeVO.class); + if(CollectionUtil.isNotEmpty(videoAreaMapByParent.get(area.getIndexCode()))) { + List children = videoAreaMapByParent.get(area.getIndexCode()); + List 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){ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HikVideoAreaTreeVO.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HikVideoAreaTreeVO.java new file mode 100644 index 0000000..4cd7ccb --- /dev/null +++ b/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 children; + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HikVideoAreaVO.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/vo/HikVideoAreaVO.java new file mode 100644 index 0000000..315b2c6 --- /dev/null +++ b/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; + +}