From cd2090d4a1eb82496d0f2f21c3118b1deee4317b Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Fri, 23 Jan 2026 17:27:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E4=BB=A5=E5=8F=8A=E5=8D=87=E7=BA=A7=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceAggregationService.cs | 23 ++++++++++++++++--- ...ceCommunicationChannelSubscriberService.cs | 11 +++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs index e0da061..efd06ff 100644 --- a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs +++ b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs @@ -729,9 +729,9 @@ namespace JiShe.IoT.DeviceAggregation SourceType = DeviceTelemetrySourceTypeEnum.AdminSystem, DeviceAddress = item.DeviceAddress, IoTPlatform = item.IoTPlatform, - Commands = new Dictionary() { + Commands = new Dictionary() { {ThingModelFixedTypeConst.SpecialCommand, - ""} + ""} }, }, platformThingModelInfos); } @@ -1113,7 +1113,7 @@ namespace JiShe.IoT.DeviceAggregation }; var packetTaskInfo = GetDeviceTelemetryPacketTaskInfo(ioTDBOptions, commandRequest, deviceInfo.Adapt(), input.Commands.Serialize()); - await ioTDBDataChannelManageService.DeviceTelemetryTaskWriterAsync(DataChannelManage.DeviceTelemetryTaskDataChannel.Writer, (DistributedMessageCenterConst.OneNETCommandIssuedEventName, packetTaskInfo)); + await ioTDBDataChannelManageService.DeviceTelemetryTaskWriterAsync(DataChannelManage.DeviceTelemetryTaskDataChannel.Writer, (DistributedMessageCenterConst.OneNETCommandIssuedEventName, packetTaskInfo)); await redisPubSubService.PublishReliableAsync(DistributedMessageCenterConst.OneNETCommandIssuedEventName, packetTaskInfo); return true; @@ -1308,6 +1308,23 @@ namespace JiShe.IoT.DeviceAggregation throw new UserFriendlyException($"设备{deviceInfo.DeviceName}获取数据失败"); } + //获取设备产品平台端物模型信息 + var platformThingModelInfo = await platformThingModelInfoAppService.FindByPlatformProductIdAsync(new IdInput() { Id = deviceInfo.IoTPlatformProductId }); + if (platformThingModelInfo == null || platformThingModelInfo.Count <= 0) + { + return deviceDataResult.Data; + } + + var platformUpdatePropertyInfo = platformThingModelInfo.Where(d => d.StandardFieldName.ToLowerInvariant() == ThingModelFixedTypeConst.FIRMWARE_VERSION.ToLowerInvariant()).FirstOrDefault(); + //抄读结果如果有固件版本号,则更新固件版本号到设备信息中 + var firmwareVersionKey = platformUpdatePropertyInfo?.IoTPlatformRawFieldName.ToLowerInvariant(); + + if (!string.IsNullOrWhiteSpace(firmwareVersionKey) && deviceDataResult.Data.ContainsKey(firmwareVersionKey)) + { + deviceInfo.FirmwareVersion = deviceDataResult.Data[firmwareVersionKey].ToString(); + await deviceAppService.UpdateDeviceFirmwareVersion(deviceInfo); + } + return deviceDataResult.Data; } catch (Exception) diff --git a/src/JiShe.IoT.Application/Subscribers/ServiceCommunicationChannelSubscriberService.cs b/src/JiShe.IoT.Application/Subscribers/ServiceCommunicationChannelSubscriberService.cs index bb4bd07..74c8f63 100644 --- a/src/JiShe.IoT.Application/Subscribers/ServiceCommunicationChannelSubscriberService.cs +++ b/src/JiShe.IoT.Application/Subscribers/ServiceCommunicationChannelSubscriberService.cs @@ -9,6 +9,7 @@ using Mapster; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Polly; using Volo.Abp; using Volo.Abp.Auditing; @@ -172,6 +173,7 @@ namespace JiShe.ServicePro.OneNETManagement.Subscribers throw new UserFriendlyException($"设备升级结果消息处理失败,参数为空"); } + var currentTime = DateTime.Now; var deviceUpgradeRecordEntity = await FreeSqlDbContext.Instance.Select() .Where(d => d.UpgradeIdentifier == input.UpgradeIdentifier && d.DeviceAddress == input.DeviceAddress) .FirstAsync(); @@ -186,6 +188,15 @@ namespace JiShe.ServicePro.OneNETManagement.Subscribers deviceUpgradeRecordEntity.UpgradeResult = input.ResultType; deviceUpgradeRecordEntity.UpgradeStatus = DeviceUpgradeStatusTypeEnum.UpgradeSuccess; deviceUpgradeRecordEntity.UpgradeDate = TimestampHelper.ConvertToDateTime(input.ReceivedTime, TimestampUnit.Milliseconds, DateTimeKind.Local); + + //更新成功后,更新设备固件版本号 + await FreeSqlDbContext.Instance.Update() + .Set(d=>d.FirmwareVersion, deviceUpgradeRecordEntity.NowFirmwareVersion) + .Set(d => d.UpgradeDate, currentTime) + .Set(d => d.LastModificationTime, currentTime) + .Set(d => d.LastModifierId, CurrentUser.Id) + .Where(d=>d.DeviceAddress == deviceUpgradeRecordEntity.DeviceAddress) + .ExecuteAffrowsAsync(); } else {