From c972c6a8bf66849c7c897e43690ff6eaefacac7c Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Tue, 20 Jan 2026 17:29:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=84=E7=90=86=E6=A0=87?= =?UTF-8?q?=E5=87=86=E7=89=A9=E6=A8=A1=E5=9E=8B=E5=80=BC=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E6=89=A9=E5=B1=95=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceAggregationService.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs index 2b7a33d..79cf149 100644 --- a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs +++ b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs @@ -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(); 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(); + 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() { - { upgradeProperty.IoTPlatformRawFieldName, upgradeRecordInput.UpgradeMessage.ToHexString() } + { upgradeProperty.IoTPlatformRawFieldName, upgradeMessageHexString } }; var commandRequest = new OpenApiRequest()