From abc35b38ff9e0e1a4f2979df648d50af24359650 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Mon, 02 Feb 2026 11:42:31 +0800
Subject: [PATCH] 设备同步优化

---
 drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdManageDeviceServiceImpl.java |   76 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdManageDeviceServiceImpl.java b/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdManageDeviceServiceImpl.java
index 1c4b2d1..00e08ce 100644
--- a/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdManageDeviceServiceImpl.java
+++ b/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdManageDeviceServiceImpl.java
@@ -19,6 +19,7 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -104,16 +105,23 @@
 	 * @return 同步数量
 	 */
 	@Override
-	@Async
 	@Scheduled(cron = "0 0 0 * * ?")
+	// @Scheduled(cron = "*/10 * * * * ?")
 	public int syncXingtuDevice() throws Exception {
 		int total = 0;
-		total += syncPilotDevices();
+		// 2.同步机巢设备
 		total += syncAirportDevices();
+		// 1.同步无人机设备
+		total += syncPilotDevices();
 		log.info("更新或新增设备"+total);
 		return total;
 	}
 
+	/**
+	 * 同步星图无人机设备并入库
+	 *
+	 * @return 新增或更新数量
+	 */
 	private int syncPilotDevices() throws Exception {
 		R response = jianXingtuApiService.getDevicePilotList(null);
 		List<GdXingtuPilotListDTO> items = parseList(response, GdXingtuPilotListDTO.class);
@@ -133,6 +141,11 @@
 		return count;
 	}
 
+	/**
+	 * 同步星图机巢设备并入库
+	 *
+	 * @return 新增或更新数量
+	 */
 	private int syncAirportDevices() throws Exception {
 		R response = jianXingtuApiService.getDeviceAirportList(null);
 		List<GdXingtuAirportListDTO> items = parseList(response, GdXingtuAirportListDTO.class);
@@ -152,13 +165,22 @@
 		return count;
 	}
 
+	/**
+	 * 按机场ID保存或更新设备信息
+	 *
+	 * @param entity 设备信息
+	 * @return 是否保存成功
+	 */
 	private boolean saveOrUpdateByAirportId(GdManageDeviceEntity entity) throws Exception {
 		if (StringUtil.isBlank(entity.getAirportId())) {
 			return false;
 		}
+		// 获取设备信息
 		GdManageDeviceEntity exist = lambdaQuery()
 			.eq(GdManageDeviceEntity::getAirportId, entity.getAirportId())
 			.one();
+		// 获取父级设备信息
+		GdManageDeviceEntity parent = getOne(Wrappers.<GdManageDeviceEntity>lambdaQuery().eq(GdManageDeviceEntity::getChildSn, entity.getDeviceSn()));
 		if (exist != null) {
 			entity.setId(exist.getId());
 			if (entity.getLongitude() == null) {
@@ -170,10 +192,21 @@
 			if (entity.getInsureExpiredTime() == null) {
 				entity.setInsureExpiredTime(exist.getInsureExpiredTime());
 			}
+			// 获取父级设备位置信息
+			if (parent != null) {
+				entity.setLongitude(parent.getLongitude());
+				entity.setLatitude(parent.getLatitude());
+			}
 		}
 		return saveOrUpdateDevice(entity);
 	}
 
+	/**
+	 * 从星图无人机数据构建设备实体
+	 *
+	 * @param item 星图无人机数据
+	 * @return 设备实体
+	 */
 	private GdManageDeviceEntity buildFromPilot(GdXingtuPilotListDTO item) {
 		if (item == null) {
 			return null;
@@ -190,9 +223,16 @@
 		entity.setModeCode(parseModeCode(item.getStatus()));
 		entity.setInsureExpiredTime(parseInsuranceDate(item.getInsuranceInfo()));
 		entity.setAreaCode(extractAreaCode(item.getRegionCode()));
+		entity.setIsWithDock(item.getIsWithDock());
 		return entity;
 	}
 
+	/**
+	 * 从星图机巢数据构建设备实体
+	 *
+	 * @param item 星图机巢数据
+	 * @return 设备实体
+	 */
 	private GdManageDeviceEntity buildFromAirport(GdXingtuAirportListDTO item) {
 		if (item == null) {
 			return null;
@@ -210,9 +250,16 @@
 		entity.setModeCode(parseModeCode(item.getStatus()));
 		entity.setInsureExpiredTime(parseInsuranceDate(item.getInsuranceInfo()));
 		entity.setAreaCode(extractAreaCode(item.getRegionCode()));
+		entity.setHeight(item.getHeight());
 		return entity;
 	}
 
+	/**
+	 * 将设备在线状态转换为模式码
+	 *
+	 * @param status 状态文本
+	 * @return 模式码
+	 */
 	private Long parseModeCode(String status) {
 		if ("在线".equals(status)) {
 			return 0L;
@@ -223,6 +270,12 @@
 		return null;
 	}
 
+	/**
+	 * 安全解析字符串为 Double
+	 *
+	 * @param value 字符串值
+	 * @return Double 或 null
+	 */
 	private Double parseDouble(String value) {
 		if (StringUtil.isBlank(value)) {
 			return null;
@@ -234,6 +287,12 @@
 		}
 	}
 
+	/**
+	 * 提取区域编码中的末级编码
+	 *
+	 * @param regionCode 区域编码
+	 * @return 末级区域编码
+	 */
 	private String extractAreaCode(String regionCode) {
 		if (StringUtil.isBlank(regionCode)) {
 			return null;
@@ -250,6 +309,12 @@
 		return regionCode;
 	}
 
+	/**
+	 * 解析保险信息并获取最新保险日期
+	 *
+	 * @param insuranceInfo 保险信息JSON
+	 * @return 保险日期
+	 */
 	private Date parseInsuranceDate(String insuranceInfo) {
 		if (StringUtil.isBlank(insuranceInfo)) {
 			return null;
@@ -283,6 +348,13 @@
 		}
 	}
 
+	/**
+	 * 解析星图接口返回的列表数据
+	 *
+	 * @param response 接口响应
+	 * @param clazz    目标类型
+	 * @return 列表数据
+	 */
 	private <T> List<T> parseList(R response, Class<T> clazz) {
 		if (response == null || !response.isSuccess() || response.getData() == null) {
 			return Collections.emptyList();

--
Gitblit v1.9.3