fix: 新增只依据deviceName查询设备信息(暂时使用,后续调整)
All checks were successful
aiot-platform CI/CD / build-and-deploy (push) Successful in 7m4s

This commit is contained in:
lzh
2025-12-26 18:25:44 +08:00
parent 8d52e9e413
commit 1737566245
3 changed files with 36 additions and 2 deletions

View File

@@ -47,8 +47,22 @@ public class IoTDeviceApiImpl implements IotDeviceCommonApi {
@PostMapping(RpcConstants.RPC_API_PREFIX + "/iot/device/get") // 特殊:方便调用,暂时使用 POST实际更推荐 GET
@PermitAll
public CommonResult<IotDeviceRespDTO> getDevice(@RequestBody IotDeviceGetReqDTO getReqDTO) {
IotDeviceDO device = getReqDTO.getId() != null ? deviceService.getDeviceFromCache(getReqDTO.getId())
: deviceService.getDeviceFromCache(getReqDTO.getProductKey(), getReqDTO.getDeviceName());
IotDeviceDO device;
// 查询优先级id > (productKey + deviceName) > deviceName
if (getReqDTO.getId() != null) {
// 通过设备 ID 查询
device = deviceService.getDeviceFromCache(getReqDTO.getId());
} else if (getReqDTO.getProductKey() != null && getReqDTO.getDeviceName() != null) {
// 通过 productKey + deviceName 查询
device = deviceService.getDeviceFromCache(getReqDTO.getProductKey(), getReqDTO.getDeviceName());
} else if (getReqDTO.getDeviceName() != null) {
// 仅通过 deviceName 查询(用于 JT808 等协议,终端手机号应该是全局唯一的)
device = deviceService.getDeviceFromCacheByDeviceName(getReqDTO.getDeviceName());
} else {
device = null;
}
return success(BeanUtils.toBean(device, IotDeviceRespDTO.class, deviceDTO -> {
IotProductDO product = productService.getProductFromCache(deviceDTO.getProductId());
if (product != null) {

View File

@@ -131,6 +131,19 @@ public interface IotDeviceService {
*/
IotDeviceDO getDeviceFromCache(String productKey, String deviceName);
/**
* 【缓存】根据设备名称获得设备信息(仅通过设备名称查询)
* <p>
* 注意:该方法会忽略租户信息,所以调用时,需要确认会不会有跨租户访问的风险!!!
* <p>
* 此方法主要用于 JT808 等协议设备在注册时只知道终端手机号deviceName
* 不知道 productKey。对于 JT808 协议,终端手机号应该是全局唯一的。
*
* @param deviceName 设备名称(如 JT808 的终端手机号)
* @return 设备信息,未找到返回 null
*/
IotDeviceDO getDeviceFromCacheByDeviceName(String deviceName);
/**
* 获得设备分页
*

View File

@@ -259,6 +259,13 @@ public class IotDeviceServiceImpl implements IotDeviceService {
return deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName);
}
@Override
@Cacheable(value = RedisKeyConstants.DEVICE, key = "'deviceName_' + #deviceName", unless = "#result == null")
@TenantIgnore // 忽略租户信息,用于 JT808 等协议,终端手机号应该是全局唯一的
public IotDeviceDO getDeviceFromCacheByDeviceName(String deviceName) {
return deviceMapper.selectByDeviceName(deviceName);
}
@Override
public PageResult<IotDeviceDO> getDevicePage(IotDevicePageReqVO pageReqVO) {
return deviceMapper.selectPage(pageReqVO);