添加解析方法
This commit is contained in:
parent
9ace8e92f7
commit
350785234c
|
|
@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -68,6 +69,11 @@ public class RedisSnVendorMappingStore implements SnVendorMappingStore {
|
||||||
// 2. Redis 没有,从 Repository 持久化层获取
|
// 2. Redis 没有,从 Repository 持久化层获取
|
||||||
vendorType = repository.findVendorTypeBySn(sn);
|
vendorType = repository.findVendorTypeBySn(sn);
|
||||||
|
|
||||||
|
if(Objects.isNull(vendorType)) {
|
||||||
|
// 根据 SN 前缀自动判断厂商类型
|
||||||
|
vendorType = detectVendorTypeBySn(sn);
|
||||||
|
}
|
||||||
|
|
||||||
if (vendorType != null) {
|
if (vendorType != null) {
|
||||||
// 3. 获取到后存入 Redis 缓存
|
// 3. 获取到后存入 Redis 缓存
|
||||||
redisTemplate.opsForValue().set(key, vendorType, CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS);
|
redisTemplate.opsForValue().set(key, vendorType, CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS);
|
||||||
|
|
@ -75,6 +81,8 @@ public class RedisSnVendorMappingStore implements SnVendorMappingStore {
|
||||||
return vendorType;
|
return vendorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
log.debug("Repository 中不存在 SN 映射: sn={}", sn);
|
log.debug("Repository 中不存在 SN 映射: sn={}", sn);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -114,4 +122,25 @@ public class RedisSnVendorMappingStore implements SnVendorMappingStore {
|
||||||
// 2. 再检查 Repository
|
// 2. 再检查 Repository
|
||||||
return repository.exists(sn);
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue