From 8d9a2d656e4ae007590c622e5f7c228adacdca49 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Fri, 14 Jun 2024 10:11:36 +0800
Subject: [PATCH] 统一风格

---
 src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java b/src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java
index 5097109..1ddd9db 100644
--- a/src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/dji/sample/manage/service/impl/DeviceServiceImpl.java
@@ -26,6 +26,9 @@
 import com.dji.sample.manage.model.param.DeviceQueryParam;
 import com.dji.sample.manage.model.receiver.*;
 import com.dji.sample.manage.service.*;
+import com.dji.sample.wayline.model.entity.WaylineJobEntity;
+import com.dji.sample.wayline.model.param.WaylineJobQueryParam;
+import com.dji.sample.wayline.service.IWaylineJobService;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -97,6 +100,9 @@
 
     @Autowired
     private IDeviceRedisService deviceRedisService;
+
+    @Autowired
+    private IWaylineJobService waylineJobService;
 
     @Autowired
     @Qualifier("gatewayOSDServiceImpl")
@@ -298,6 +304,7 @@
                         .eq(StringUtils.hasText(param.getWorkspaceId()),
                                 DeviceEntity::getWorkspaceId, param.getWorkspaceId())
                         .eq(param.getBoundStatus() != null, DeviceEntity::getBoundStatus, param.getBoundStatus())
+                        .eq(param.getReserveId() != null, DeviceEntity::getReserveId, param.getReserveId())
                         .orderBy(param.isOrderBy(),
                                 param.isAsc(), DeviceEntity::getId))
                 .stream()
@@ -306,10 +313,11 @@
     }
 
     @Override
-    public List<DeviceDTO> getDevicesTopoForWeb(String workspaceId) {
+    public List<DeviceDTO> getDevicesTopoForWeb(String workspaceId, String reserveId) {
         List<DeviceDTO> devicesList = this.getDevicesByParams(
                 DeviceQueryParam.builder()
                         .workspaceId(workspaceId)
+                        .reserveId(reserveId)
                         .domains(List.of(DeviceDomainEnum.GATEWAY.getVal(), DeviceDomainEnum.DOCK.getVal()))
                         .build());
 
@@ -317,6 +325,17 @@
                 .filter(gateway -> DeviceDomainEnum.DOCK.getVal() == gateway.getDomain() ||
                         deviceRedisService.checkDeviceOnline(gateway.getDeviceSn()))
                 .forEach(this::spliceDeviceTopo);
+
+        devicesList.forEach(deviceDTO -> {
+            WaylineJobQueryParam waylineJobQueryParam = new WaylineJobQueryParam();
+            waylineJobQueryParam.setDockSn(deviceDTO.getDeviceSn());
+            WaylineJobEntity latestJob = waylineJobService.getLatestJob(workspaceId, waylineJobQueryParam);
+            deviceDTO.setLatestWaylineJob(latestJob);
+            deviceDTO.setOnlineStatus(true);
+            OsdDockReceiver osdDockReceiver = (OsdDockReceiver) RedisOpsUtils.get("osd:" + deviceDTO.getDeviceSn());
+            deviceDTO.setLatitude(osdDockReceiver!=null? osdDockReceiver.getLatitude():null);
+            deviceDTO.setLongitude(osdDockReceiver!=null? osdDockReceiver.getLongitude():null);
+        });
 
         return devicesList;
     }
@@ -438,7 +457,7 @@
             if (deviceOpt.isEmpty()) {
                 deviceOpt = this.getDeviceBySn(from);
                 if (deviceOpt.isEmpty()) {
-                    log.error("Please restart the drone.");
+                    log.error("请重新启动无人机.");
                     return;
                 }
 
@@ -911,7 +930,7 @@
 
         Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(deviceOtaFirmwares.get(0).getSn());
         if (deviceOpt.isEmpty()) {
-            throw new RuntimeException("Device is offline.");
+            throw new RuntimeException("设备离线");
         }
         DeviceDTO device = deviceOpt.get();
         String gatewaySn = DeviceDomainEnum.DOCK.getVal() == device.getDomain() ? device.getDeviceSn() : device.getParentSn();
@@ -922,7 +941,7 @@
         ServiceReply serviceReply = messageSender.publishServicesTopic(
                 gatewaySn, FirmwareMethodEnum.OTA_CREATE.getMethod(), Map.of(MapKeyConst.DEVICES, deviceOtaFirmwares), bid);
         if (serviceReply.getResult() != ResponseResult.CODE_SUCCESS) {
-            return ResponseResult.error(serviceReply.getResult(), "Firmware Error Code: " + serviceReply.getResult());
+            return ResponseResult.error(serviceReply.getResult(), "硬件错误码 " + serviceReply.getResult());
         }
 
         // Record the device state that needs to be updated.
@@ -939,16 +958,17 @@
     private void checkOtaConditions(String dockSn) {
         Optional<OsdDockReceiver> deviceOpt = deviceRedisService.getDeviceOsd(dockSn, OsdDockReceiver.class);
         if (deviceOpt.isEmpty()) {
-            throw new RuntimeException("Dock is offline.");
+            throw new RuntimeException("机场离线");
         }
         boolean emergencyStopState = deviceOpt.get().getEmergencyStopState();
         if (emergencyStopState) {
-            throw new RuntimeException("The emergency stop button of the dock is pressed and can't be upgraded.");
+//            throw new RuntimeException("The emergency stop button of the dock is pressed and can't be upgraded.");
+            throw new RuntimeException("机场急停按钮被按下,无法升级");
         }
 
         DockModeCodeEnum dockMode = this.getDockMode(dockSn);
         if (DockModeCodeEnum.IDLE != dockMode) {
-            throw new RuntimeException("The current status of the dock can't be upgraded.");
+            throw new RuntimeException("当前机场状态无法升级");
         }
     }
 
@@ -956,13 +976,13 @@
     public void devicePropertySet(String workspaceId, String dockSn, DeviceSetPropertyEnum propertyEnum, JsonNode param) {
         Optional<DeviceDTO> dockOpt = deviceRedisService.getDeviceOnline(dockSn);
         if (dockOpt.isEmpty()) {
-            throw new RuntimeException("Dock is offline.");
+            throw new RuntimeException("机场离线");
         }
         String childSn = dockOpt.get().getChildDeviceSn();
         boolean deviceOnline = deviceRedisService.checkDeviceOnline(childSn);
         Optional<OsdSubDeviceReceiver> osdOpt = deviceRedisService.getDeviceOsd(childSn, OsdSubDeviceReceiver.class);
         if (!deviceOnline || osdOpt.isEmpty()) {
-            throw new RuntimeException("Device is offline.");
+            throw new RuntimeException("设备离线");
         }
 
         // Make sure the data is valid.
@@ -1014,7 +1034,7 @@
 
         SetReply setReply = objectMapper.convertValue(reply, SetReply.class);
         if (SetReplyStatusResultEnum.SUCCESS.getVal() != setReply.getResult()) {
-            throw new RuntimeException("Failed to set " + value.getKey() + "; Error Code: " + setReply.getResult());
+            throw new RuntimeException("设置失败" + value.getKey() + "; 错误码: " + setReply.getResult());
         }
 
     }

--
Gitblit v1.9.3