添加解析方法

This commit is contained in:
孙小云 2026-02-10 16:16:53 +08:00
parent 9ace8e92f7
commit 350785234c
1 changed files with 29 additions and 0 deletions

View File

@ -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";
}
}