From 350785234c603586c5e575f89dec575b3f502b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B0=8F=E4=BA=91?= Date: Tue, 10 Feb 2026 16:16:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=A3=E6=9E=90=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/RedisSnVendorMappingStore.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/com/ruoyi/device/domain/impl/machine/vendor/store/RedisSnVendorMappingStore.java b/src/main/java/com/ruoyi/device/domain/impl/machine/vendor/store/RedisSnVendorMappingStore.java index 3a09063..1b8ef2c 100644 --- a/src/main/java/com/ruoyi/device/domain/impl/machine/vendor/store/RedisSnVendorMappingStore.java +++ b/src/main/java/com/ruoyi/device/domain/impl/machine/vendor/store/RedisSnVendorMappingStore.java @@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; +import java.util.Objects; import java.util.concurrent.TimeUnit; /** @@ -68,6 +69,11 @@ public class RedisSnVendorMappingStore implements SnVendorMappingStore { // 2. Redis 没有,从 Repository 持久化层获取 vendorType = repository.findVendorTypeBySn(sn); + if(Objects.isNull(vendorType)) { + // 根据 SN 前缀自动判断厂商类型 + vendorType = detectVendorTypeBySn(sn); + } + if (vendorType != null) { // 3. 获取到后存入 Redis 缓存 redisTemplate.opsForValue().set(key, vendorType, CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS); @@ -75,6 +81,8 @@ public class RedisSnVendorMappingStore implements SnVendorMappingStore { return vendorType; } + + log.debug("Repository 中不存在 SN 映射: sn={}", sn); return null; } @@ -114,4 +122,25 @@ public class RedisSnVendorMappingStore implements SnVendorMappingStore { // 2. 再检查 Repository return repository.exists(sn); } + + + /** + * 根据 SN 前缀自动识别厂商类型 + * + * @param sn 设备SN号 + * @return 厂商类型,无法识别返回 null + */ + private String detectVendorTypeBySn(String sn) { + if (sn == null || sn.isEmpty()) { + return null; + } + + // 拓恒设备:SN 以 "TH" 开头 + if (sn.startsWith("TH")) { + return "TUOHENG"; + } + + // 大疆设备:其他情况默认为大疆 + return "DJI"; + } } \ No newline at end of file