From b0dd7ca693fcd13e539316cfc8c63150182a0315 Mon Sep 17 00:00:00 2001
From: aix <vip_xiaobin810@163.com>
Date: Tue, 20 Aug 2024 15:18:12 +0800
Subject: [PATCH] 红外设置

---
 src/main/java/com/dji/sample/manage/controller/DeviceController.java |   78 ++++++++++++++++++++++++++++++++------
 1 files changed, 65 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/dji/sample/manage/controller/DeviceController.java b/src/main/java/com/dji/sample/manage/controller/DeviceController.java
index 9e8870e..135be37 100644
--- a/src/main/java/com/dji/sample/manage/controller/DeviceController.java
+++ b/src/main/java/com/dji/sample/manage/controller/DeviceController.java
@@ -6,6 +6,7 @@
 import com.dji.sample.component.mqtt.model.ChannelName;
 import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
 import com.dji.sample.component.mqtt.model.CommonTopicResponse;
+import com.dji.sample.droneairport.service.RegistService;
 import com.dji.sample.manage.model.dto.DeviceDTO;
 import com.dji.sample.manage.model.dto.DeviceFirmwareUpgradeDTO;
 import com.dji.sample.manage.model.enums.DeviceSetPropertyEnum;
@@ -32,6 +33,8 @@
 
     @Autowired
     private IDeviceService deviceService;
+    @Autowired
+    private RegistService registService;
 
     /**
      * Handles the message that the drone goes online.
@@ -49,6 +52,9 @@
                             .timestamp(System.currentTimeMillis())
                             .method(receiver.getMethod())
                             .build());
+        }
+        if (receiver.getData().getSn().length()==14){
+            registService.Authorization(receiver.getData().getSn());
         }
     }
 
@@ -71,6 +77,33 @@
                             .build());
 
         }
+        if (receiver.getData().getSn().length()==14){
+            registService.noAuthorization(receiver.getData().getSn());
+        }
+    }
+
+    /**
+     * 手动在线
+     * @param workspaceId
+     * @param receiver
+     * @return
+     */
+    @PostMapping("/{workspace_id}/deviceOnline")
+    public ResponseResult<List<DeviceDTO>> deviceOnline(@PathVariable("workspace_id") String workspaceId,
+                                                        @RequestBody CommonTopicReceiver<StatusGatewayReceiver> receiver) {
+        boolean offline = deviceService.deviceOnline(receiver.getData());
+        if (offline) {
+            // Notify pilot that the device is offline successfully.
+            deviceService.publishStatusReply(receiver.getData().getSn(),
+                    CommonTopicResponse.builder()
+                            .tid(receiver.getTid())
+                            .bid(receiver.getBid())
+                            .timestamp(System.currentTimeMillis())
+                            .method(receiver.getMethod())
+                            .build());
+
+        }
+        return ResponseResult.success();
     }
 
     /**
@@ -85,19 +118,19 @@
         return ResponseResult.success(devicesList);
     }
 
-    @GetMapping("/{device_sn}/subscribeTopic")
-    public ResponseResult<List<DeviceDTO>> testBinding(@PathVariable("device_sn") String deviceSn) {
-        deviceService.subscribeTopicOnline(deviceSn);
-
-        return ResponseResult.success();
-    }
-
-    @GetMapping("/{device_sn}/unsubscribeTopic")
-    public ResponseResult<List<DeviceDTO>> testUnBinding(@PathVariable("device_sn") String deviceSn) {
-        deviceService.unsubscribeTopicOffline(deviceSn);
-
-        return ResponseResult.success();
-    }
+//    @GetMapping("/{device_sn}/subscribeTopic2")
+//    public ResponseResult<List<DeviceDTO>> testBinding(@PathVariable("device_sn") String deviceSn) {
+//        deviceService.subscribeTopicOnline(deviceSn);
+//
+//        return ResponseResult.success();
+//    }
+//
+//    @GetMapping("/{device_sn}/unsubscribeTopic2")
+//    public ResponseResult<List<DeviceDTO>> testUnBinding(@PathVariable("device_sn") String deviceSn) {
+//        deviceService.unsubscribeTopicOffline(deviceSn);
+//
+//        return ResponseResult.success();
+//    }
 
     /**
      * After binding the device to the workspace, the device data can only be seen on the web.
@@ -203,4 +236,23 @@
         deviceService.devicePropertySet(workspaceId, dockSn, propertyEnumOpt.get(), param.get(property));
         return ResponseResult.success();
     }
+
+    /**
+     * 红外设置方法
+     * @param workspaceId
+     * @param dockSn
+     * @param param
+     * @return
+     */
+    @PutMapping("/{workspace_id}/devices/{device_sn}/property2")
+    public ResponseResult devicePropertySet2(@PathVariable("workspace_id") String workspaceId,
+                                             @PathVariable("device_sn") String dockSn,
+                                             @RequestBody JsonNode param) {
+        if (param.size() != 1) {
+            return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
+        }
+        int result = deviceService.devicePropertySet(workspaceId, dockSn, param);
+        return ResponseResult.success().getCode() == result ?ResponseResult.success():ResponseResult.error();
+    }
+
 }

--
Gitblit v1.9.3