From 3430a3dd889ba51d06cbdb77014aa63d0a070e48 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Fri, 16 Aug 2024 16:38:08 +0800
Subject: [PATCH] 优化国土对接接口

---
 src/main/java/com/dji/sample/manage/controller/DeviceController.java |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 52 insertions(+), 5 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 602e8c9..2fa7308 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();
     }
 
     /**
@@ -79,11 +112,25 @@
      * @return
      */
     @GetMapping("/{workspace_id}/devices")
-    public ResponseResult<List<DeviceDTO>> getDevices(@PathVariable("workspace_id") String workspaceId) {
-        List<DeviceDTO> devicesList = deviceService.getDevicesTopoForWeb(workspaceId);
+    public ResponseResult<List<DeviceDTO>> getDevices(@PathVariable("workspace_id") String workspaceId,String reserveId) {
+        List<DeviceDTO> devicesList = deviceService.getDevicesTopoForWeb(workspaceId,reserveId);
 
         return ResponseResult.success(devicesList);
     }
+
+//    @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.
@@ -108,7 +155,7 @@
     public ResponseResult getDevice(@PathVariable("workspace_id") String workspaceId,
                                                @PathVariable("device_sn") String deviceSn) {
         Optional<DeviceDTO> deviceOpt = deviceService.getDeviceBySn(deviceSn);
-        return deviceOpt.isEmpty() ? ResponseResult.error("device not found.") : ResponseResult.success(deviceOpt.get());
+        return deviceOpt.isEmpty() ? ResponseResult.error("设备未找到") : ResponseResult.success(deviceOpt.get());
     }
 
     /**
@@ -120,7 +167,7 @@
      */
     @GetMapping("/{workspace_id}/devices/bound")
     public ResponseResult<PaginationData<DeviceDTO>> getBoundDevicesWithDomain(
-            @PathVariable("workspace_id") String workspaceId, String domain,
+            @PathVariable("workspace_id") String workspaceId, Integer domain,
             @RequestParam(defaultValue = "1") Long page,
             @RequestParam(value = "page_size", defaultValue = "50") Long pageSize) {
         PaginationData<DeviceDTO> devices = deviceService.getBoundDevicesWithDomain(workspaceId, page, pageSize, domain);
@@ -189,4 +236,4 @@
         deviceService.devicePropertySet(workspaceId, dockSn, propertyEnumOpt.get(), param.get(property));
         return ResponseResult.success();
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.9.3