Преглед изворни кода

Merge branch 'master' of http://39.105.126.192:3000/DR3_server/sky_ioc_server

ZhangManMan пре 2 година
родитељ
комит
4614950c9b

+ 8 - 0
src/main/java/com/sky/ioc/controller/security/CameraController.java

@@ -3,6 +3,7 @@ package com.sky.ioc.controller.security;
 import com.sky.ioc.service.security.SecurityDeviceService;
 import com.sky.ioc.tool.ReturnMsg;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -18,6 +19,13 @@ public class CameraController {
     @Autowired
     SecurityDeviceService service;
 
+    @ApiOperation("海康平台--配置信息")
+    @PostMapping("/apiInfo")
+    private ReturnMsg getApiInfo() {
+        return service.getCameraApiInfo();
+    }
+
+    @ApiOperation("海康平台--摄像头列表")
     @PostMapping("/getCameras")
     private ReturnMsg getCameras() {
         return service.getAllCameras();

+ 5 - 0
src/main/java/com/sky/ioc/service/security/SecurityDeviceService.java

@@ -15,4 +15,9 @@ public interface SecurityDeviceService {
      */
     ReturnMsg getAllCameras();
 
+    /**
+     * 获取api信息
+     * @return
+     */
+    ReturnMsg getCameraApiInfo();
 }

+ 36 - 1
src/main/java/com/sky/ioc/service/security/impl/SecurityDeviceServiceImpl.java

@@ -1,5 +1,6 @@
 package com.sky.ioc.service.security.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.sky.ioc.entity.domain.security.SecurityDevice;
 import com.sky.ioc.mapper.job.TokenMapper;
 import com.sky.ioc.mapper.security.SecurityDeviceMapper;
@@ -30,6 +31,7 @@ public class SecurityDeviceServiceImpl implements SecurityDeviceService {
     private SecurityDeviceMapper securityDeviceMapper;
 
     final static String SECURITY_CAMERA_URL = "http://192.168.1.45:9001/api/safety/Hikvision/camera/list?pageNum=1&pageSize=1000";
+    final static String SECURITY_CAMERA_API_INFO_URL = "http://192.168.1.45:9001/api/safety/Hikvision/api/apiInfo";
 
     @Override
     public ReturnMsg syncAllCameras() {
@@ -84,8 +86,41 @@ public class SecurityDeviceServiceImpl implements SecurityDeviceService {
 
     @Override
     public ReturnMsg getAllCameras() {
-        List<SecurityDevice> securityDevices = securityDeviceMapper.selectList(null);
+        LambdaQueryWrapper<SecurityDevice> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(SecurityDevice::getDeviceType, "1");
+        List<SecurityDevice> securityDevices = securityDeviceMapper.selectList(queryWrapper);
         return ReturnMsg.ok(securityDevices);
     }
 
+    @Override
+    public ReturnMsg getCameraApiInfo() {
+        Map<String,String> tokenMap = tokenMapper.getNewToken();
+        String token ="Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6IjUwZTU1NTRkLWJjYzYtNGRhMS1iZDUxLWFhNTc3YzU4YTFiNCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.X10VPYJfeeRTka7OtqNPOGMpL4QkW3fR_TfCKXCmO-yXbIIrr_40fcwiVnpXfYVENo_BvXWEACRd-Y6nXsbkog";
+        if(tokenMap!=null){
+            token = "Bearer "+tokenMap.get("token");
+        }
+        // 创建一个请求头对象
+        HttpHeaders httpHeaders = new HttpHeaders();
+        // 设置参数
+        httpHeaders.set("authorization", token);
+        // 创建一个响应体对象
+        HttpEntity<String> httpEntity = new HttpEntity(httpHeaders);
+        // 3.创建RestTemplate
+        RestTemplate restTemplate = new RestTemplate();
+        // 发送GET请求
+        ResponseEntity<Map> responseEntity = restTemplate.exchange(SECURITY_CAMERA_API_INFO_URL, HttpMethod.GET, httpEntity, Map.class);
+        // 获取响应对象里的 body 对象
+        Map<String, Object> body = responseEntity.getBody();
+        // 获取状态码
+        Integer code = (Integer)body.get("code");
+        // 获取响应信息
+        String message = (String)body.get("msg");
+        if(code==200){
+            return ReturnMsg.ok(body.get("data"));
+        }else{
+            log.info("获取摄像头api信息:"+message);
+            return ReturnMsg.fail(message);
+        }
+    }
+
 }