haungxing
10 months ago
9 changed files with 295 additions and 0 deletions
@ -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"; |
||||||
|
|
||||||
|
} |
@ -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)); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
|
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
|
||||||
|
} |
@ -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…
Reference in new issue