From 69676584dc6bbef4c41b0c3dcac014207b9dcf00 Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Sun, 4 Jan 2026 16:47:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=8F=91=E9=80=81=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=8D=87=E7=BA=A7=E6=8C=87=E4=BB=A4=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IDeviceAggregationService.cs | 4 +-- .../DeviceAggregationService.cs | 32 ++++++++++++++----- .../DeviceAggregationController.cs | 6 ++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs index 0c0d058..8413f49 100644 --- a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs +++ b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs @@ -56,11 +56,11 @@ namespace JiShe.IoT.DeviceAggregation Task DeviceUpgradeForApiAsync(DeviceUpgradeForApiInput input); /// - /// 批量发送设备升级指令信息 + /// 批量发送设备升级指令信息,只对同一个平台下,同一个产品下的设备进行固件升级信息 /// /// /// - Task DeviceBatchUpgradeForApiAsync(DeviceBatchUpgradeForApiInput input); + Task> DeviceBatchUpgradeForApiAsync(DeviceBatchUpgradeForApiInput input); /// /// 下载设备固件文件 diff --git a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs index b24559c..f30318b 100644 --- a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs +++ b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs @@ -409,11 +409,11 @@ namespace JiShe.IoT.DeviceAggregation } /// - /// 批量发送设备升级指令信息 + /// 批量发送设备升级指令信息,只对同一个平台下,同一个产品下的设备进行固件升级信息 /// /// /// - public async Task DeviceBatchUpgradeForApiAsync(DeviceBatchUpgradeForApiInput input) + public async Task> DeviceBatchUpgradeForApiAsync(DeviceBatchUpgradeForApiInput input) { try { @@ -422,27 +422,38 @@ namespace JiShe.IoT.DeviceAggregation throw new UserFriendlyException($"{nameof(DeviceBatchUpgradeForApiAsync)} 设备批量升级时地址列表不能为空","-101"); } + if (input.AddressList.Count >200) + { + throw new UserFriendlyException($"{nameof(DeviceBatchUpgradeForApiAsync)} 设备批量升级时地址列表数量不能超过200", "-102"); + } + //固件信息 var deviceFirmwareVersionInfo = await deviceFirmwareInfoService.FindByIdAsync(new IdInput() { Id = input.NowFirmwareVersionDataId }); if (deviceFirmwareVersionInfo == null) { - throw new UserFriendlyException($"产品Id{input.IoTPlatformProductId}的新固件信息{input.NowFirmwareVersionDataId}不存在"); + throw new UserFriendlyException($"产品Id{input.IoTPlatformProductId}的新固件信息{input.NowFirmwareVersionDataId}不存在", "-103"); } var fileInfo = await fileAppService.GetFileAsync(new IdInput() { Id = deviceFirmwareVersionInfo.FirmwareFileId }); if (fileInfo == null) { - throw new UserFriendlyException($"产品Id{input.IoTPlatformProductId}的新固件信息{deviceFirmwareVersionInfo.FirmwareFileName}固件文件不存在"); + throw new UserFriendlyException($"产品Id{input.IoTPlatformProductId}的新固件信息{deviceFirmwareVersionInfo.FirmwareFileName}固件文件不存在", "-104"); } + var deviceInfoList = await deviceAppService.FindByDeviceAddressAsync(new FindByDeviceAddressInput() { AddressList = input.AddressList ,IoTPlatform = input.IoTPlatform,IoTPlatformProductId = input.IoTPlatformProductId}); + + List deviceAddress = new List();//异常的设备地址集合 + foreach (var item in input.AddressList) { - var deviceInfo = await deviceAppService.FindByDeviceAddressAsync(item); + var deviceInfo = deviceInfoList.Where(d=>d.DeviceAddress== item).FirstOrDefault(); if (deviceInfo == null) { - throw new UserFriendlyException($"{nameof(DeviceBatchUpgradeForApiAsync)} 设备{item}不存在", "-102"); + deviceAddress.Add(item); + + continue; } //将指令存储 @@ -460,7 +471,12 @@ namespace JiShe.IoT.DeviceAggregation //数据写入遥测任务数据存储通道 if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET) { - return await DeviceUpgradeCommandToOneNET(deviceInfo, receiveCommandInfoDto, deviceFirmwareVersionInfo, fileInfo, deviceUpgradeRecordInput); + var oneNETHandleResult = await DeviceUpgradeCommandToOneNET(deviceInfo, receiveCommandInfoDto, deviceFirmwareVersionInfo, fileInfo, deviceUpgradeRecordInput); + + if (!oneNETHandleResult) + { + deviceAddress.Add(item); + } } else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing) { @@ -474,7 +490,7 @@ namespace JiShe.IoT.DeviceAggregation } } - return true; + return deviceAddress; } catch (Exception) { diff --git a/src/JiShe.IoT.HttpApi/Controllers/DeviceAggregationController.cs b/src/JiShe.IoT.HttpApi/Controllers/DeviceAggregationController.cs index ba7f2b2..9f26dd8 100644 --- a/src/JiShe.IoT.HttpApi/Controllers/DeviceAggregationController.cs +++ b/src/JiShe.IoT.HttpApi/Controllers/DeviceAggregationController.cs @@ -114,13 +114,13 @@ namespace JiShe.IoT.Controllers } /// - /// 批量发送设备升级指令信息 + /// 批量发送设备升级指令信息,只对同一个平台下,同一个产品下的设备进行固件升级信息 /// /// /// [HttpPost(nameof(DeviceBatchUpgradeForApiAsync))] - [SwaggerOperation(summary: "批量发送设备升级指令信息", Tags = new[] { "AggregationDevice" })] - public Task DeviceBatchUpgradeForApiAsync(DeviceBatchUpgradeForApiInput input) + [SwaggerOperation(summary: "批量发送设备升级指令信息,只对同一个平台下,同一个产品下的设备进行固件升级信息", Tags = new[] { "AggregationDevice" })] + public Task> DeviceBatchUpgradeForApiAsync(DeviceBatchUpgradeForApiInput input) { return _deviceAggregationService.DeviceBatchUpgradeForApiAsync(input); }