From ff8fd898f68a7f532bbf731e08493d6e0892feea Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Tue, 5 Aug 2025 11:30:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=B9=E9=87=8F=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AE=BE=E5=A4=87=EF=BC=8C=E5=AE=8C=E6=88=90=E9=87=8D?= =?UTF-8?q?=E6=8E=A8=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceAggregationService.cs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs index e7ceb2a..ba7a5b2 100644 --- a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs +++ b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs @@ -406,11 +406,15 @@ namespace JiShe.IoT.DeviceAggregation { CreateDeviceInput createDeviceInput = input.Adapt(); createDeviceInput.DeviceName = item; + createDeviceInput.DeviceAddress = item; createDeviceInput.IoTPlatformAccountId = productInfo.OneNETAccountId; createDeviceInput.IoTPlatformDeviceOpenInfo = $"{input.IoTPlatformProductId}{item}"; createDeviceInput.PlatformPassword = productInfo.ProductAccesskey; createDeviceInput.IoTPlatformProductName = productInfo.ProductName; createDeviceInput.AccountPhoneNumber = productInfo.AccountPhoneNumber; + createDeviceInput.DeviceSourceTypeEnum = input.DeviceSourceTypeEnum.Value; + + batchCreateDeviceInput.DeviceInputs.Add(createDeviceInput); } @@ -426,9 +430,11 @@ namespace JiShe.IoT.DeviceAggregation { ProductId = productInfo.IoTPlatformProductId, OneNETAccountId = productInfo.OneNETAccountId, - DeviceList = batchCreateDeviceInput.DeviceInputs.Select(d => d.IoTPlatformDeviceOpenInfo).ToList(), + DeviceList = new List() }; + oneNETBatchCreateDeviceInfoInput.DeviceList = batchCreateDeviceInput.DeviceInputs.Select(d => d.IoTPlatformDeviceOpenInfo).ToList(); + var pushResult = await oneNETDeviceService.BatchCreateDeviceInfoAsync(oneNETBatchCreateDeviceInfoInput); if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success) @@ -465,17 +471,28 @@ namespace JiShe.IoT.DeviceAggregation public async Task RepushDeviceInfoToOneNET(DeviceManagementInfoDto input) { try - { - + { var productInfo = await FreeSqlDbContext.Instance.Select() - .Where(e => e.IsEnabled == true && e.IoTPlatformProductId == input.IoTPlatformProductId) + .Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId) .FirstAsync(); if (productInfo == null) { throw new UserFriendlyException($"推送失败,未找到对应的产品配置信息。"); } + + //检查OneNET平台设备是否已经存在 + var oneNETDeviceInfoResult = await oneNETDeviceService.DeviceInfoDetailAsync(new DeviceInfoDetailInput() + { + DeviceName = input.IoTPlatformDeviceOpenInfo, + ProductId = productInfo.IoTPlatformProductId, + OneNETAccountId = productInfo.OneNETAccountId, + }); + if (oneNETDeviceInfoResult != null && oneNETDeviceInfoResult.Code == ServicePro.Enums.ResponeResultEnum.Success) + { + throw new UserFriendlyException($"推送失败,OneNET账号{productInfo.AccountPhoneNumber}的产品下{productInfo.ProductName}已经存在该设备{input.DeviceAddress}。"); + } //推送至OneNET平台 var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput() @@ -527,8 +544,7 @@ namespace JiShe.IoT.DeviceAggregation { DeviceName = input.IoTPlatformDeviceOpenInfo, ProductId = productInfo.IoTPlatformProductId, - OneNETAccountId = productInfo.OneNETAccountId, - Description = input.DeviceAddress, + OneNETAccountId = productInfo.OneNETAccountId, }); if (deleteResult == null || deleteResult.Code != ServicePro.Enums.ResponeResultEnum.Success)