完善业务系统数据查询接口

This commit is contained in:
ChenYi 2026-02-28 16:47:20 +08:00
parent d5b6651e56
commit 4d99e9fbe8
2 changed files with 35 additions and 11 deletions

View File

@ -33,8 +33,21 @@ namespace JiShe.IoT.BusinessSystemAggregation.Dto
public DateTime EndTime { get; set; }
/// <summary>
/// 设备地址集合
/// 设备地址集合,items[0]为设备地址,items[1]为子设备地址
/// </summary>
public List<string> DeviceAddresses { get; set; }
public List<BatchQueryDeviceInfoRequestItem> DeviceAddressList { get; set; }
public class BatchQueryDeviceInfoRequestItem
{
/// <summary>
/// 设备地址,
/// </summary>
public string DeviceAddress { get; set; }
/// <summary>
/// 子设备地址
/// </summary>
public string SubDeviceAddress { get; set; }
}
}
}

View File

@ -348,18 +348,25 @@ namespace JiShe.IoT.BusinessSystemAggregation
}
var messageBody = handleResult.Data;
if (messageBody.DeviceAddresses == null || messageBody.DeviceAddresses.Count <= 0)
if (messageBody.DeviceAddressList == null || messageBody.DeviceAddressList.Count <= 0)
{
return HttpDataResultExtensions.Failed<List<IoTDBDynamicObject>>(null, "设备地址不能为空", -103);
}
List<string> deviceAddressDatas = new List<string>();
// 验证设备地址格式,防止注入攻击
foreach (var deviceAddress in messageBody.DeviceAddresses)
foreach (var deviceAddressInfo in messageBody.DeviceAddressList)
{
if (!IsValidDeviceAddress(deviceAddress))
if (!IsValidDeviceAddress(deviceAddressInfo.DeviceAddress))
{
return HttpDataResultExtensions.Failed<List<IoTDBDynamicObject>>(null, $"设备地址格式不正确: {deviceAddress}", -107);
return HttpDataResultExtensions.Failed<List<IoTDBDynamicObject>>(null, $"设备地址格式不正确: {deviceAddressInfo.DeviceAddress}", -107);
}
deviceAddressDatas.Add(deviceAddressInfo.DeviceAddress);
}
if (deviceAddressDatas == null || deviceAddressDatas.Count <= 0)
{
return HttpDataResultExtensions.Failed<List<IoTDBDynamicObject>>(null, $"没有可用的设备地址信息", -1071);
}
//执行脚本
@ -367,7 +374,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
(
LUA_SCRIPT,
new[] { RedisConst.CacheAllDeviceInfoHashKey },
messageBody.DeviceAddresses.ToArray()
deviceAddressDatas.ToArray()
);
List<DeviceCacheInfos> deviceCacheInfos = new List<DeviceCacheInfos>();
@ -390,20 +397,24 @@ namespace JiShe.IoT.BusinessSystemAggregation
}
List<IoTDBDynamicObject> queryResult = new List<IoTDBDynamicObject>();
for (int i = 0; i < messageBody.DeviceAddresses.Count; i++)
for (int i = 0; i < messageBody.DeviceAddressList.Count; i++)
{
var deviceAddress = messageBody.DeviceAddresses[i];
var deviceAddressInfo = messageBody.DeviceAddressList[i];
var deviceCacheInfo = deviceCacheInfos.Count > i ? deviceCacheInfos[i] : null;
logger.LogWarning($"{nameof(BatchQueryDeviceDataInfoAsync)} 业务系统批量查询设备数据,集中器地址为:{deviceAddressInfo.DeviceAddress}");
if (deviceCacheInfo == null)
{
_logger.LogError($"{nameof(BatchQueryDeviceDataInfoAsync)} 业务系统批量查询设备数据,设备地址:{deviceAddress}未找到设备地址缓存信息,消息体为:{input.Serialize()}");
_logger.LogError($"{nameof(BatchQueryDeviceDataInfoAsync)} 业务系统批量查询设备数据,设备地址:{deviceAddressInfo.
DeviceAddress}{input.Serialize()}");
continue;
}
var pageResult = await treeModelService.OpenRequestDeviceDataInfoPageAsync(new DeviceTreeModelDataInfoInput()
{
DeviceAddress = deviceAddress,
DeviceAddress = deviceAddressInfo.DeviceAddress,
SubDeviceAddress = deviceAddressInfo.SubDeviceAddress,
DeviceType = messageBody.DeviceType,
IoTDataType = messageBody.IoTDataType,
IsNeedPaging = false,