From 8b696e1ce2c1b02f422621e05e6a6ca14d259302 Mon Sep 17 00:00:00 2001 From: punchhhh <87906027+punchhhh@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:06:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B5=B7=E5=BA=B7=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=A8=A1=E5=9D=97=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/hiking/GetCameraInfoUtil.java | 243 ++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/GetCameraInfoUtil.java diff --git a/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/GetCameraInfoUtil.java b/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/GetCameraInfoUtil.java new file mode 100644 index 000000000..afb621b10 --- /dev/null +++ b/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/GetCameraInfoUtil.java @@ -0,0 +1,243 @@ +package cn.iocoder.yudao.module.hiking; + +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.hiking.controller.admin.camera.vo.CameraSaveReqVO; +import cn.iocoder.yudao.module.hiking.controller.admin.region.vo.RegionSaveReqVO; +import cn.iocoder.yudao.module.hiking.dal.dataobject.camera.CameraDO; +import cn.iocoder.yudao.module.hiking.service.camera.CameraService; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Iterator; +import java.util.concurrent.TimeUnit; + + +@RestController +public class GetCameraInfoUtil { + @Autowired + private RedisTemplate redisTemplate; + @Resource + private CameraService cameraService; + private static final String ACCESS_TOKEN_KEY = "hikingAPI:access_token"; + + + public String getAccessToken() { + // 检查 Redis 中是否有 access_token + String accessToken = redisTemplate.opsForValue().get(ACCESS_TOKEN_KEY); + if (!StringUtils.isEmpty(accessToken)) { + System.out.println("使用缓存的token:" + accessToken); + return accessToken; // 如果存在则直接返回 + } + + // 如果没有,调用 API 获取并存入 Redis + System.out.println("获取新的token"); + String accessTokenUrlResp = IntegrationURL.getAccessTokenURL(); + try { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(accessTokenUrlResp); + accessToken = jsonNode.get("access_token").asText(); + + // 将 access_token 存入 Redis,设置过期时间为 11 小时(有效期12小时) + redisTemplate.opsForValue().set(ACCESS_TOKEN_KEY, accessToken, 11, TimeUnit.HOURS); + } catch (Exception e) { + + e.printStackTrace(); + } + return accessToken; + } + + public void deleteAccessToken() { + redisTemplate.delete(ACCESS_TOKEN_KEY); + } + + + public Boolean checkToken(String result) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(result); + String code = jsonNode.path("code").asText(); + if ("0x02401007".equals(code)) { + System.out.println("token失效,重新获取"); + deleteAccessToken(); + return false; + } + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return true; + } + + @GetMapping("/getCameraListToDB") + public void getCameraListToDB() { + try { + // 总记录数 + int total = 0; + JsonNode jsonNode; + JsonNode cameraDataList; + // 查询有几条记录 +// String cameraListPageURL = IntegrationURL.getCameraResourceURL(1, 1, getAccessToken()); +// if (!checkToken(cameraListPageURL)) { +// cameraListPageURL = IntegrationURL.getCameraResourceURL(1, 1, getAccessToken()); +// } + String cameraListPageURL = " {\n" + + " \"code\": \"0\", \n" + + " \"msg\": \"success\", \n" + + " \"data\": {\n" + + " \"total\": 13, \n" + + " \"pageNo\": 1, \n" + + " \"pageSize\": 1, \n" + + " \"list\": [\n" + + " {\n" + + " \"altitude\": null, \n" + + " \"cameraIndexCode\": \"eddf8458f74d42e9bf4ecfc752dba146\", \n" + + " \"cameraName\": \"3层吉米后厨入口\", \n" + + " \"cameraType\": 0, \n" + + " \"cameraTypeName\": \"枪机\", \n" + + " \"capabilitySet\": \"io,event_io,event_ias,event_rule,event_heat,record,net,event_face,vss,ptz,status,maintenance,event_device\", \n" + + " \"capabilitySetName\": null, \n" + + " \"intelligentSet\": null, \n" + + " \"intelligentSetName\": null, \n" + + " \"channelNo\": \"33\", \n" + + " \"channelType\": \"digital\", \n" + + " \"channelTypeName\": \"数字通道\", \n" + + " \"createTime\": \"2018-09-15T11:14:27.812+08:00\", \n" + + " \"encodeDevIndexCode\": \"1d3d5c26e6174cf1aa452f57cac91879\", \n" + + " \"encodeDevResourceType\": null, \n" + + " \"encodeDevResourceTypeName\": null, \n" + + " \"gbIndexCode\": null, \n" + + " \"installLocation\": null, \n" + + " \"keyBoardCode\": null, \n" + + " \"latitude\": null, \n" + + " \"longitude\": null, \n" + + " \"pixel\": null, \n" + + " \"ptz\": null, \n" + + " \"ptzName\": null, \n" + + " \"ptzController\": null, \n" + + " \"ptzControllerName\": null, \n" + + " \"recordLocation\": null, \n" + + " \"recordLocationName\": null, \n" + + " \"regionIndexCode\": \"2feadc43-ffef-464b-a2e2-b146a02de5ba\", \n" + + " \"status\": null, \n" + + " \"statusName\": null, \n" + + " \"transType\": 1, \n" + + " \"transTypeName\": \"TCP\", \n" + + " \"treatyType\": null, \n" + + " \"treatyTypeName\": null, \n" + + " \"viewshed\": null, \n" + + " \"updateTime\": \"2018-09-15T11:19:48.973+08:00\"\n" + + " }\n" + + " ]\n" + + " }\n" + + "}\n"; + ObjectMapper objectMapper = new ObjectMapper(); + jsonNode = objectMapper.readTree(cameraListPageURL); +// total = jsonNode.path("data").path("total").asInt(); + total = 1; + + JsonNode cameraNode; + // 查询所有记录的cameraIndexCode并保存 + for (int i = 1; i <= (total / 100) + 1; i++) { + System.out.println("开始第" + i + "次查询"); +// cameraListPageURL = IntegrationURL.getCameraResourceURL(i, 100, getAccessToken()); + jsonNode = objectMapper.readTree(cameraListPageURL); + cameraDataList = jsonNode.path("data").path("list"); + System.out.println(cameraDataList); + Iterator elements2 = cameraDataList.elements(); + while (elements2.hasNext()) { + CameraDO cameraDO = new CameraDO(); + cameraNode = elements2.next(); + System.out.println("cameraNode:"+cameraNode); + cameraDO.setAltitude(cameraNode.path("altitude").asText()); + cameraDO.setCameraIndexCode(cameraNode.path("cameraIndexCode").asText()); + cameraDO.setCameraName(cameraNode.path("cameraName").asText()); + cameraDO.setCameraType(cameraNode.path("cameraType").asInt()); + cameraDO.setCameraTypeName(cameraNode.path("cameraTypeName").asText()); + cameraDO.setCapabilitySet(cameraNode.path("capabilitySet").asText()); + cameraDO.setCapabilitySetName(cameraNode.path("capabilitySetName").asText()); + cameraDO.setIntelligentSet(cameraNode.path("intelligentSet").asText()); + cameraDO.setIntelligentSetName(cameraNode.path("intelligentSetName").asText()); + cameraDO.setChannelNo(cameraNode.path("channelNo").asText()); + cameraDO.setChannelType(cameraNode.path("channelType").asText()); + cameraDO.setChannelTypeName(cameraNode.path("channelTypeName").asText()); + cameraDO.setCreateTime(dateParse(cameraNode.path("createTime").asText())); + cameraDO.setEncodeDevIndexCode(cameraNode.path("encodeDevIndexCode").asText()); + cameraDO.setEncodeDevResourceType(cameraNode.path("encodeDevResourceType").asText()); + cameraDO.setEncodeDevResourceTypeName(cameraNode.path("encodeDevResourceTypeName").asText()); + cameraDO.setGbIndexCode(cameraNode.path("gbIndexCode").asText()); + cameraDO.setInstallLocation(cameraNode.path("installLocation").asText()); + cameraDO.setKeyBoardCode(cameraNode.path("keyBoardCode").asText()); + cameraDO.setLatitude(cameraNode.path("latitude").asText()); + cameraDO.setLongitude(cameraNode.path("longitude").asText()); + cameraDO.setPixel(cameraNode.path("pixel").asText()); + cameraDO.setPtz(cameraNode.path("ptz").asText()); + cameraDO.setPtzName(cameraNode.path("ptzName").asText()); + cameraDO.setPtzController(cameraNode.path("ptzController").asText()); + cameraDO.setPtzControllerName(cameraNode.path("ptzControllerName").asText()); + cameraDO.setRecordLocation(cameraNode.path("recordLocation").asText()); + cameraDO.setRecordLocationName(cameraNode.path("recordLocationName").asText()); + cameraDO.setRegionIndexCode(cameraNode.path("regionIndexCode").asText()); + cameraDO.setStatus(cameraNode.path("status").asText()); + cameraDO.setStatusName(cameraNode.path("statusName").asText()); + cameraDO.setTransType(cameraNode.path("transType").asInt()); + cameraDO.setTransTypeName(cameraNode.path("transTypeName").asText()); + cameraDO.setTreatyType(cameraNode.path("treatyType").asText()); + cameraDO.setTreatyTypeName(cameraNode.path("treatyTypeName").asText()); + cameraDO.setViewshed(cameraNode.path("viewshed").asText()); + cameraDO.setUpdateTime(dateParse(cameraNode.path("updateTime").asText())); + + // 查询数据库中是否已有数据 + CameraDO dbCameraData = cameraService.selectByCameraIndexCode(cameraDO.getCameraIndexCode()); + System.out.println("dbCameraData: " + dbCameraData); + System.out.println(cameraDO); + CameraSaveReqVO cameraSaveReqVO = BeanUtils.toBean(cameraDO, CameraSaveReqVO.class); + // 如果数据库中有记录且数据不一致,执行更新操作 + if (dbCameraData != null && !cameraDO.getUpdateTime().equals(dbCameraData.getUpdateTime())) { + // 进行更新操作 + cameraService.updateCameraCheckByCameraIndexCode(cameraSaveReqVO); + System.out.println("更新了" + cameraDO.getCameraIndexCode() + "的数据"); + } else if (dbCameraData == null) { + // 如果数据库中没有记录,则插入新数据 + cameraService.createCamera(cameraSaveReqVO); + System.out.println("插入了" + cameraDO.getCameraIndexCode() + "的数据"); + } else { + System.out.println("无需更新" + cameraDO.getCameraIndexCode() + "的数据"); + } + } + } + } catch ( + Exception e) { + e.printStackTrace(); + } + + } + + private LocalDateTime dateParse(String dateStr) { + String dateString = dateStr; + // 通过正则调整时区格式 + // 这次确保只有一位数字时区后缀 +0800 被替换为 +08:00 + if (dateString.matches(".*\\+\\d{4}$")) { + dateString = dateString.replaceAll("(\\+\\d{2})(\\d{2})$", "$1:$2"); + } + + // 定义一个日期格式化器,包括时区信息 + DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + + // 解析带有时区的字符串 + OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateString, formatter); + + // 转换为 LocalDateTime + LocalDateTime localDateTime = offsetDateTime.toLocalDateTime(); + + return localDateTime; + } +} -- 2.45.2 From aebdb97ceea3b910073d55f5dc37bf4a1b767555 Mon Sep 17 00:00:00 2001 From: punchhhh <87906027+punchhhh@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:38:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B5=B7=E5=BA=B7=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/hiking/IntegrationURL.java | 511 ++++++++++++++++++ .../hiking/api/HikingCameraApiImpl.java | 8 +- .../service/camera/CameraServiceImpl.java | 8 +- 3 files changed, 519 insertions(+), 8 deletions(-) create mode 100644 ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/IntegrationURL.java diff --git a/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/IntegrationURL.java b/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/IntegrationURL.java new file mode 100644 index 000000000..790bb0291 --- /dev/null +++ b/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/IntegrationURL.java @@ -0,0 +1,511 @@ +package cn.iocoder.yudao.module.hiking; + +import com.alibaba.fastjson.JSONObject; +import com.hikvision.artemis.sdk.ArtemisHttpUtil; +import com.hikvision.artemis.sdk.config.ArtemisConfig; + +import java.util.HashMap; +import java.util.Map; + +public class IntegrationURL { + + + //设置平台参数,根据实际情况,设置host appKey appSecret 三个参数. + static { + ArtemisConfig.host = "127.0.0.1:443"; // 平台的ip端口 + ArtemisConfig.appKey = "29180881"; // 密钥appkey + ArtemisConfig.appSecret = "XO0wCAYGi4KV70ybjznx";// 密钥appSecret + } + + //设置OpenAPI接口的上下文 + public static final String ARTEMIS_PATH = "/artemis"; + + + // 获取根区域信息 + public static String getRegionsRootURL(String accessToken) { + + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/regions/root"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, null, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + //查询区域列表v2 + public static String getRegionListURL(String resourceType,int pageNo,int pageSize,String accessToken) { + + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/irds/v2/region/nodesByParams"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("resourceType",resourceType); + jsonBody.put("pageNo", pageNo); + jsonBody.put("pageSize", pageSize); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + // 根据区域编号获取下一级区域列表v2 + public static String getRegionListByParentIndexCodeURL(String parentIndexCode, String resourceType,int pageNo,int pageSize,String accessToken) { + + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v2/regions/subRegions"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("parentIndexCode", parentIndexCode); + jsonBody.put("resourceType",resourceType); + jsonBody.put("pageNo", pageNo); + jsonBody.put("pageSize", pageSize); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + // 分页获取区域列表 + public static String getRegionListPageURL(int pageNo,int pageSize,String accessToken) { + + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/regions"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("pageNo", pageNo); + jsonBody.put("pageSize", pageSize); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + // 根据编号获取区域详细信息 + public static String getRegionByIndexCodesURL(String[] indexCodes,String accessToken) { + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/region/regionCatalog/regionInfo"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("indexCodes", indexCodes); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + // 增量获取区域数据 + public static String getRegionTimeRangeURL(String startTime, String pageNo, String pageSize,String accessToken) { + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/region/timeRange"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("startTime", startTime); + jsonBody.put("pageNo", pageNo); + jsonBody.put("pageSize", pageSize); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + //查询监控点列表v2 + public static String getCameraListURL(int pageNo,int pageSize,String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v2/camera/search"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("pageNo", pageNo); //当前页码 + jsonBody.put("pageSize", pageSize); //分页大小 + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + + //分页获取监控点资源 + public static String getCameraResourceURL(int pageNo,int pageSize,String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/cameras"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("pageNo", pageNo); //当前页码 + jsonBody.put("pageSize", pageSize); //分页大小 + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + // 根据区域编号获取下级监控点列表 + public static String getCameraListByRegionIndexCodeURL(String regionIndexCode, int pageNo,int pageSize,String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/regions/regionIndexCode/cameras"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("regionIndexCode", regionIndexCode); //区域编号 + jsonBody.put("pageNo", pageNo); //当前页码 + jsonBody.put("pageSize", pageSize); //分页大小 + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + // 根据编号获取监控点详细信息 + public static String getCameraByCameraIndexCodeURL(String cameraIndexCode,String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/cameras/indexCode"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("cameraIndexCode", cameraIndexCode); //监控点唯一标识 + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + // 增量获取监控点数据 + public static String getCameraTimeRangeURL(String startTime, int pageNo, int pageSize, String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/camera/timeRange"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("startTime", startTime); + jsonBody.put("pageNo", pageNo); //当前页码 + jsonBody.put("pageSize", pageSize); //分页大小 + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + + //获取监控点预览取流URLv2 + public static String getPreviewURL(String cameraIndexCode, Integer streamType, String protocol, Integer transmode, String expand, String streamform, String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/video/v2/cameras/previewURLs"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("cameraIndexCode", cameraIndexCode); //监控点唯一标识,分页获取监控点资源接口获取返回参数cameraIndexCode + jsonBody.put("streamType", streamType); + jsonBody.put("protocol", protocol); + jsonBody.put("transmode", transmode); + jsonBody.put("expand", expand); + jsonBody.put("streamform", streamform); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + + //获取监控点回放取流URLv2 + public static String getPlaybackURL(String cameraIndexCode, Integer recordLocation, String protocol, Integer transmode, String beginTime, String endTime, String uuid, String expand, String streamform, Integer lockType,String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/video/v2/cameras/playbackURLs"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("cameraIndexCode", cameraIndexCode);//监控点唯一标识,分页获取监控点资源接口获取返回参数cameraIndexCode + jsonBody.put("recordLocation", recordLocation); + jsonBody.put("protocol", protocol); + jsonBody.put("transmode", transmode); + jsonBody.put("beginTime",beginTime );//开始查询时间(IOS8601格式:yyyy-MM-dd’T’HH:mm:ss.SSSXXX)例如北京时间:2017-06-14T00:00:00.000+08:00, + jsonBody.put("endTime",endTime);//结束时间 + jsonBody.put("uuid",uuid ); + jsonBody.put("expand",expand ); + jsonBody.put("streamform",streamform ); + jsonBody.put("lockType",lockType ); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + + //监控点3D放大 + public static String getControlURL(String cameraIndexCode,int startX,int startY,int endX,int endY,String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/ptzs/selZoom"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("cameraIndexCode",cameraIndexCode ); + jsonBody.put("startX",startX ); + jsonBody.put("startY",startY ); + jsonBody.put("endX",endX ); + jsonBody.put("endY",endY ); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + + //根据监控点编号进行云台操作 + public static String getYunTaiOperationURL(String cameraIndexCode, Integer action, String command, Integer speed, Integer presetIndex,String accessToken) { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/ptzs/controlling"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + jsonBody.put("cameraIndexCode", cameraIndexCode); + jsonBody.put("action",action ); + jsonBody.put("command",command ); + jsonBody.put("speed",speed ); + jsonBody.put("presetIndex",presetIndex ); + String body = jsonBody.toJSONString(); + + //请求头添加 access_token认证 + Map attributesMap = new HashMap<>(); + attributesMap.put("access_token", accessToken); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , attributesMap);// post请求application/json类型参数 + return result; + } + + + //access_token认证 + public static String getAccessTokenURL() { + + //设置接口的URI地址 + final String previewURLsApi = ARTEMIS_PATH + "/api/v1/oauth/token"; + Map path = new HashMap(2) { + { + put("https://", previewURLsApi);//根据现场环境部署确认是http还是https + } + }; + + //设置参数提交方式 + String contentType = "application/json"; + + //组装请求参数 + JSONObject jsonBody = new JSONObject(); + String body = jsonBody.toJSONString(); + + //调用接口 + String result = ArtemisHttpUtil.doPostStringArtemis(path, null, null, null, contentType , null);// post请求application/json类型参数 + + return result; + } + + + + + +} diff --git a/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/api/HikingCameraApiImpl.java b/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/api/HikingCameraApiImpl.java index 8acac3681..ffd18ea79 100644 --- a/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/api/HikingCameraApiImpl.java +++ b/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/api/HikingCameraApiImpl.java @@ -43,12 +43,12 @@ public class HikingCameraApiImpl implements CameraApi { } @Override - public CommonResult selectPreviewUrlByCameraIndexCode(String cameraIndexCode) { - return success(cameraService.getPreviewUrl(cameraIndexCode)); + public CommonResult selectPreviewUrlByCameraIndexCode(String cameraIndexCode, Integer streamType, String protocol, Integer transmode, String expand, String streamform) { + return success(cameraService.getPreviewUrl(cameraIndexCode, streamType, protocol, transmode, expand, streamform)); } @Override - public CommonResult selectPlayBackUrlByCameraIndexCode(String cameraIndexCode, String beginTime, String endTime) { - return success(cameraService.getPlayBackUrl(cameraIndexCode, beginTime, endTime)); + public CommonResult selectPlayBackUrlByCameraIndexCode(String cameraIndexCode, Integer recordLocation, String protocol, Integer transmode, String beginTime, String endTime, String uuid, String expand, String streamform, Integer lockType) { + return success(cameraService.getPlayBackUrl(cameraIndexCode, recordLocation,protocol,transmode,beginTime,endTime, uuid, expand, streamform, lockType)); } } diff --git a/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/service/camera/CameraServiceImpl.java b/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/service/camera/CameraServiceImpl.java index 84f800a58..3f61e488c 100644 --- a/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/service/camera/CameraServiceImpl.java +++ b/ludu-module-hiking/ludu-module-hiking-biz/src/main/java/cn/iocoder/yudao/module/hiking/service/camera/CameraServiceImpl.java @@ -147,13 +147,13 @@ public class CameraServiceImpl implements CameraService { } @Override - public String getPreviewUrl(String cameraIndexCode) { - return IntegrationURL.getPreviewURL(cameraIndexCode, getAccessToken()); + public String getPreviewUrl(String cameraIndexCode, Integer streamType, String protocol, Integer transmode, String expand, String streamform) { + return IntegrationURL.getPreviewURL(cameraIndexCode, streamType, protocol, transmode, expand, streamform, getAccessToken()); } @Override - public String getPlayBackUrl(String cameraIndexCode, String startTime, String endTime) { - return IntegrationURL.getPlaybackURL(cameraIndexCode, startTime, endTime, getAccessToken()); + public String getPlayBackUrl(String cameraIndexCode, Integer recordLocation, String protocol, Integer transmode, String beginTime, String endTime, String uuid, String expand, String streamform, Integer lockType) { + return IntegrationURL.getPlaybackURL(cameraIndexCode, recordLocation,protocol,transmode,beginTime,endTime, uuid, expand, streamform, lockType, getAccessToken()); } @Override -- 2.45.2