hanzhiwei преди 3 години
родител
ревизия
5299fb3aac

+ 30 - 0
zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/camera/feign/RemoteCameraService.java

@@ -0,0 +1,30 @@
+package com.zd.algorithm.api.camera.feign;
+
+import com.zd.algorithm.api.camera.feign.fallback.RemoteCameraFallBackFactory;
+import com.zd.model.constant.ApplicationConstants;
+import com.zd.model.domain.R;
+import com.zd.model.enums.HardwareOperate;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@FeignClient(contextId = "remoteCameraService",value = ApplicationConstants.ALGORITHM_SERVICE,fallbackFactory= RemoteCameraFallBackFactory.class)
+public interface RemoteCameraService {
+    @RequestMapping("/service/mqtt/send/{num}/{hardwareOperate}")
+    public R sends(@PathVariable("num") String num, @PathVariable("hardwareOperate") HardwareOperate hardwareOperate);
+
+    /**
+     * 视频头开始录制
+     * @param hostname IP地址
+     */
+    @RequestMapping("/api/onvif/startRecord")
+    public R startRecord(@RequestParam("hostname") String hostname);
+
+    /**
+     * 视频头结束录制获取录制mp4
+     * @param hostname IP地址
+     */
+    @RequestMapping("/api/onvif/stopRecord")
+    public R stopRecord(@RequestParam("hostname") String hostname);
+}

+ 35 - 0
zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/camera/feign/fallback/RemoteCameraFallBackFactory.java

@@ -0,0 +1,35 @@
+package com.zd.algorithm.api.camera.feign.fallback;
+
+import com.zd.algorithm.api.camera.feign.RemoteCameraService;
+import com.zd.model.domain.R;
+import com.zd.model.enums.HardwareOperate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cloud.openfeign.FallbackFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class RemoteCameraFallBackFactory implements FallbackFactory<RemoteCameraService> {
+    private static final Logger log = LoggerFactory.getLogger(RemoteCameraFallBackFactory.class);
+
+    @Override
+    public RemoteCameraService create(Throwable throwable) {
+        log.error("摄像头在线离线调用失败:{}", throwable.getMessage());
+        return new RemoteCameraService() {
+            @Override
+            public R sends(String num, HardwareOperate hardwareOperate) {
+                return R.fail("摄像头在线离线调用失败:" + throwable.getMessage());
+            }
+
+            @Override
+            public R startRecord(String hostname) {
+                return R.fail("摄像头开始录像调用失败:" + throwable.getMessage());
+            }
+
+            @Override
+            public R stopRecord(String hostname) {
+                return R.fail("摄像头结束录像调用失败:" + throwable.getMessage());
+            }
+        };
+    }
+}