优化处理标准物模型值类型的扩展字段

This commit is contained in:
ChenYi 2026-01-20 17:29:35 +08:00
parent 089faa9842
commit c972c6a8bf

View File

@ -24,6 +24,7 @@ using Microsoft.Extensions.Options;
using StackExchange.Redis;
using Volo.Abp;
using Volo.Abp.Content;
using static FreeSql.Internal.GlobalFilter;
namespace JiShe.IoT.DeviceAggregation
{
@ -674,7 +675,7 @@ namespace JiShe.IoT.DeviceAggregation
}
if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing)
{
{
var batchCreateDeviceInput = input.Adapt<BatchCreateDeviceAggregationInput>();
batchCreateDeviceInput.AddressList = input.DeviceInfos.Select(f => f.DeviceAddress.Trim()).ToList();
@ -835,7 +836,7 @@ namespace JiShe.IoT.DeviceAggregation
createDeviceInput.DeviceType = input.DeviceType.Value;
}
if(item.BusinessSystemDeviceDataId.HasValue)
if (item.BusinessSystemDeviceDataId.HasValue)
{
createDeviceInput.BusinessSystemDeviceDataId = item.BusinessSystemDeviceDataId.Value;
}
@ -844,7 +845,7 @@ namespace JiShe.IoT.DeviceAggregation
}
if(batchCreateDeviceInput.DeviceInputs != null || batchCreateDeviceInput.DeviceInputs.Count > 0)
if (batchCreateDeviceInput.DeviceInputs != null || batchCreateDeviceInput.DeviceInputs.Count > 0)
{
@ -853,7 +854,7 @@ namespace JiShe.IoT.DeviceAggregation
{
logger.LogError($"{nameof(OneNETDeviceBatchCreateAsync)} OneNET设备批量创建添加设备信息失败{input.Serialize()}");
return false;
}
}
//网关或者直连设备 推送至OneNET平台
var oneNETBatchCreateDeviceInfoInput = new BatchCreateDeviceInfoInput()
{
@ -1142,6 +1143,36 @@ namespace JiShe.IoT.DeviceAggregation
upgradeRecordInput.UpgradeMessage = upgradeRequest.Serialize();
upgradeRecordInput.FirmwareSignature = upgradeRequest.SignatureValue;
string upgradeMessageHexString = upgradeRecordInput.UpgradeMessage.ToHexString();
//检查长度是否超过了OneNET平台升级属性标识符的长度限制
var thingModelInfoStr = ((OneNETProductInfos)productInfo).ThingModelInfos;
if (string.IsNullOrWhiteSpace(thingModelInfoStr))
{
logger.LogError($"{nameof(DeviceUpgradeCommandToOneNET)} 通过OneNET产品ID和属性标识符获取属性配置信息失败属性信息为空");
return false;
}
var thingModelInfo = thingModelInfoStr.Deserialize<OneNETAllThingModel>();
if (thingModelInfo.Properties == null)
{
logger.LogError($"{nameof(DeviceUpgradeCommandToOneNET)} 通过OneNET产品ID和属性标识符获取属性配置信息失败属性信息为空");
return false;
}
var property = thingModelInfo.Properties.Where(d => d.Identifier == upgradeProperty.IoTPlatformRawFieldName).FirstOrDefault(); //精准匹配
if (property == null)
{
logger.LogError($"{nameof(DeviceUpgradeCommandToOneNET)} 通过OneNET产品ID和属性标识符获取属性配置信息失败没有找到属性标识升级对应的属性平台信息");
return false;
}
var length = ((OneNETModelStringSpecs)property.DataType.Specs).Length;
if (upgradeMessageHexString.Length > length)
{
throw new UserFriendlyException($"设备{deviceInfo.DeviceAddress}平台端物模型信息属性标识符{upgradeProperty.IoTPlatformRawFieldName}长度超过OneNET平台限制请检查物模型属性标识符长度是否超过了{length}");
}
var insertResult = await deviceUpgradeRecordService.CreateAsync(upgradeRecordInput);
if (insertResult == null)
@ -1152,7 +1183,7 @@ namespace JiShe.IoT.DeviceAggregation
//发送OneNET平台设备升级指令HEX格式字符串
taskInput.Commands = new Dictionary<string, object>()
{
{ upgradeProperty.IoTPlatformRawFieldName, upgradeRecordInput.UpgradeMessage.ToHexString() }
{ upgradeProperty.IoTPlatformRawFieldName, upgradeMessageHexString }
};
var commandRequest = new OpenApiRequest()