fix: 新增只依据deviceName查询设备信息(暂时使用,后续调整)
All checks were successful
aiot-platform CI/CD / build-and-deploy (push) Successful in 7m4s
All checks were successful
aiot-platform CI/CD / build-and-deploy (push) Successful in 7m4s
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* 获得设备分页
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user