diff --git a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/Dto/BatchCreateDeviceAggregationInput.cs b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/Dto/BatchCreateDeviceAggregationInput.cs new file mode 100644 index 0000000..177b8df --- /dev/null +++ b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/Dto/BatchCreateDeviceAggregationInput.cs @@ -0,0 +1,35 @@ +using JiShe.ServicePro.Enums; +using System.ComponentModel.DataAnnotations; + +namespace JiShe.IoT.DeviceAggregation +{ + /// + /// 批量创建设备信息 + /// + public class BatchCreateDeviceAggregationInput + { + /// + /// 表通信地址集合 + /// + [Required(ErrorMessage = "设备地址不能为空")] + public List AddressList { get; set; } + + /// + /// 物联网平台类型 + /// + [Required(ErrorMessage = "物联网平台类型不能为空")] + public IoTPlatformTypeEnum IoTPlatform { get; set; } + + /// + /// 集中器在物联网平台中对应的产品Id + /// + [Required(ErrorMessage = "产品Id不能为空")] + public string IoTPlatformProductId { get; set; } + + /// + /// 设备来源类型 + /// + + public DeviceSourceTypeEnum? DeviceSourceTypeEnum { get; set; } + } +} \ No newline at end of file diff --git a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/Dto/CreateDeviceAggregationInput.cs b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/Dto/CreateDeviceAggregationInput.cs index 4da6926..512d62a 100644 --- a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/Dto/CreateDeviceAggregationInput.cs +++ b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/Dto/CreateDeviceAggregationInput.cs @@ -25,6 +25,12 @@ namespace JiShe.IoT.DeviceAggregation.Dto /// [Required(ErrorMessage = "产品Id不能为空")] public string IoTPlatformProductId { get; set; } + + /// + /// 设备来源类型 + /// + + public DeviceSourceTypeEnum? DeviceSourceTypeEnum { get; set; } } } \ No newline at end of file diff --git a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs index e63d33b..9aa3655 100644 --- a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs +++ b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs @@ -17,6 +17,13 @@ namespace JiShe.IoT.DeviceAggregation /// Task CreateDeviceForApiAsync(CreateDeviceAggregationInput input); + /// + /// 管理后台批量创建设备信息 + /// + /// + /// + Task BatchCreateDeviceForApiAsync(BatchCreateDeviceAggregationInput input); + /// /// 车间创建设备信息 /// @@ -24,6 +31,13 @@ namespace JiShe.IoT.DeviceAggregation /// Task CreateDeviceWorkshopAsync(CreateDeviceAggregationInput input); + /// + /// 车间批量创建设备信息 + /// + /// + /// + Task BatchCreateDeviceWorkshopAsync(BatchCreateDeviceAggregationInput input); + /// /// 删除设备信息 /// diff --git a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs index 1545892..70f3fbc 100644 --- a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs +++ b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs @@ -1,21 +1,16 @@ using JiShe.IoT.DeviceAggregation.Dto; -using JiShe.IoT.OneNETAggregation.Dto; using JiShe.ServicePro; using JiShe.ServicePro.Core; using JiShe.ServicePro.DeviceManagement.DeviceInfos; using JiShe.ServicePro.DeviceManagement.DeviceInfos.Dto; using JiShe.ServicePro.DeviceManagement.Permissions; +using JiShe.ServicePro.Enums; using JiShe.ServicePro.FreeRedisProvider; +using JiShe.ServicePro.OneNET.Provider.OpenApiModels.Devices; using JiShe.ServicePro.OneNETManagement.OneNETDevices; using JiShe.ServicePro.OneNETManagement.OneNETProducts; using Mapster; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.IO.Pipelines; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Volo.Abp; namespace JiShe.IoT.DeviceAggregation @@ -38,7 +33,7 @@ namespace JiShe.IoT.DeviceAggregation { try { - + input.DeviceSourceTypeEnum = ServicePro.Enums.DeviceSourceTypeEnum.AdminSystem; if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing) { return await CTWingDeviceCreateAsync(input); @@ -58,6 +53,46 @@ namespace JiShe.IoT.DeviceAggregation } + /// + /// 管理后台批量创建设备信息 + /// + /// + /// + public async Task BatchCreateDeviceForApiAsync(BatchCreateDeviceAggregationInput input) + { + try + { + + if (input.AddressList == null || input.AddressList.Count <= 0) + { + throw new UserFriendlyException($"批量创建设备失败,设备信息不能为空。"); + } + + if (input.AddressList.Count > 100) + { + throw new UserFriendlyException($"批量创建设备失败,设备信息不能超过100个。"); + } + + input.DeviceSourceTypeEnum = ServicePro.Enums.DeviceSourceTypeEnum.AdminSystem; + + if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing) + { + return await CTWingDeviceBatchCreateAsync(input); + } + else if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET) + { + return await OneNETDeviceBatchCreateAsync(input); + } + + throw new UserFriendlyException($"不支持的物联网平台"); + } + catch (Exception) + { + + throw; + } + } + /// /// 车间创建设备信息 /// @@ -67,6 +102,7 @@ namespace JiShe.IoT.DeviceAggregation { try { + input.DeviceSourceTypeEnum = DeviceSourceTypeEnum.Workshop; if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing) { @@ -88,64 +124,36 @@ namespace JiShe.IoT.DeviceAggregation } /// - /// OneNET设备创建 + /// 车间批量创建设备信息 /// /// /// - public async Task OneNETDeviceCreateAsync(CreateDeviceAggregationInput input) + public async Task BatchCreateDeviceWorkshopAsync(BatchCreateDeviceAggregationInput input) { try { - CreateDeviceInput createDeviceInput = input.Adapt(); - - var productInfo = await FreeSqlDbContext.Instance.Select() - .Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)//此处不需要过滤产品状态,方便测试产品配置信息是否准确,避免跟车间生产搞混 - .FirstAsync(); - - if (productInfo == null) + if (input.AddressList == null || input.AddressList.Count <= 0) { - throw new UserFriendlyException($"创建设备失败,未找到对应的产品配置信息。"); + throw new UserFriendlyException($"批量创建设备失败,设备信息不能为空。"); } - //检查设备信息是不是已经存在 - var existsDeviceInfo = await deviceAppService.FindDeviceInfosAsync(input.DeviceAddress, createDeviceInput.IoTPlatform); - if (existsDeviceInfo != null) + if (input.AddressList.Count > 100) { - throw new UserFriendlyException($"创建设备失败,当前平台设备信息已经存在。"); + throw new UserFriendlyException($"批量创建设备失败,设备信息不能超过100个。"); } - createDeviceInput.DeviceName = input.DeviceAddress; - createDeviceInput.IoTPlatformAccountId = productInfo.OneNETAccountId; - createDeviceInput.IoTPlatformDeviceOpenInfo = $"{input.IoTPlatformProductId}{input.DeviceAddress}"; - createDeviceInput.PlatformPassword = productInfo.ProductAccesskey; - createDeviceInput.IoTPlatformProductName = productInfo.ProductName; - createDeviceInput.AccountPhoneNumber = productInfo.AccountPhoneNumber; + input.DeviceSourceTypeEnum = DeviceSourceTypeEnum.Workshop; - var insertResult = await deviceAppService.CreateAsync(createDeviceInput); - if (insertResult == null) + if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing) { - logger.LogError($"{nameof(CreateDeviceForApiAsync)} 添加设备信息失败:{input.Serialize()}"); - return false; + return await CTWingDeviceBatchCreateAsync(input); + } + else if (input.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET) + { + return await OneNETDeviceBatchCreateAsync(input); } - //推送至OneNET平台 - var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput() - { - DeviceName = createDeviceInput.IoTPlatformDeviceOpenInfo, - ProductId = productInfo.IoTPlatformProductId, - OneNETAccountId = productInfo.OneNETAccountId, - Description = input.DeviceAddress, - }); - - if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success) - { - logger.LogError($"{nameof(CreateDeviceForApiAsync)} 推送设备信息失败:{pushResult.Serialize()}"); - return false; - } - - await DeviceUpdateHandler(insertResult, pushResult); - - return true; + throw new UserFriendlyException($"不支持的物联网平台"); } catch (Exception) { @@ -154,16 +162,6 @@ namespace JiShe.IoT.DeviceAggregation } } - /// - /// CTWing 设备创建 - /// - /// - /// - public async Task CTWingDeviceCreateAsync(CreateDeviceAggregationInput input) - { - throw new UserFriendlyException($"CTWing 设备创建失败,功能未实现。"); - } - /// /// 删除设备信息 /// @@ -173,8 +171,24 @@ namespace JiShe.IoT.DeviceAggregation [Authorize(DeviceManagementPermissions.DeviceInfoManagement.Delete)] public async Task DeleteAsync(IdInput input) { - return await deviceAppService.DeleteAsync(input); + //检查设备信息是不是已经存在 + var existsDeviceInfo = await deviceAppService.FindByIdAsync(input); + if (existsDeviceInfo == null) + { + throw new UserFriendlyException($"删除设备失败,未找到对应设备信息。"); + } + //根据设备平台调用删除接口 + if (existsDeviceInfo.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.OneNET) + { + return await DeleteDeviceInfoToOneNET(existsDeviceInfo); + } + else if (existsDeviceInfo.IoTPlatform == ServicePro.Enums.IoTPlatformTypeEnum.CTWing) + { + return await DeleteDeviceInfoToCTWing(existsDeviceInfo); + } + + throw new UserFriendlyException($"不支持的物联网平台"); } /// @@ -223,16 +237,90 @@ namespace JiShe.IoT.DeviceAggregation } /// - /// 重新推送设备信息到CTWing物联网平台 + /// 更新设备信息并处理缓存 + /// + /// + /// + /// + /// + private async Task DeviceUpdateHandler(DeviceManagementInfoDto input, HttpDataResult pushResult) + { + UpdateDeviceInput updateDeviceInput = input.Adapt(); + updateDeviceInput.IoTPlatformResponse = pushResult.Serialize(); + updateDeviceInput.IsPlatformPushSuccess = true; + + var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput); + if (updateResult == null) + { + logger.LogError($"{nameof(CreateDeviceForApiAsync)} 更新设备信息失败:{input.Serialize()}"); + throw new UserFriendlyException($"推送结果更新失败。"); + } + + //设备数据缓存到Redis + DeviceCacheInfos deviceCacheInfos = input.Adapt(); + deviceCacheInfos.IoTPlatformResponse = null; + deviceCacheInfos.PlatformPassword = null; + + RedisProvider.Instance.HSet(RedisConst.CacheAllDeviceInfoHashKey, input.DeviceAddress, deviceCacheInfos); + + return input.Adapt(); + } + + + #region OneNET 设备操作 + /// + /// OneNET设备创建 /// /// /// - /// - public async Task RepushDeviceInfoToCTWing(DeviceManagementInfoDto input) + protected async Task OneNETDeviceCreateAsync(CreateDeviceAggregationInput input) { try { - throw new UserFriendlyException($"推送失败,CTWing暂未实现。"); + CreateDeviceInput createDeviceInput = input.Adapt(); + + var productInfo = await FreeSqlDbContext.Instance.Select() + .Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)//此处不需要过滤产品状态,方便测试产品配置信息是否准确,避免跟车间生产搞混 + .WhereIf(input.DeviceSourceTypeEnum == DeviceSourceTypeEnum.Workshop, e => e.IsEnabled == true) + .FirstAsync(); + + if (productInfo == null) + { + throw new UserFriendlyException($"创建设备失败,未找到对应的产品配置信息。"); + } + + createDeviceInput.DeviceName = input.DeviceAddress; + createDeviceInput.IoTPlatformAccountId = productInfo.OneNETAccountId; + createDeviceInput.IoTPlatformDeviceOpenInfo = $"{input.IoTPlatformProductId}{input.DeviceAddress}"; + createDeviceInput.PlatformPassword = productInfo.ProductAccesskey; + createDeviceInput.IoTPlatformProductName = productInfo.ProductName; + createDeviceInput.AccountPhoneNumber = productInfo.AccountPhoneNumber; + + var insertResult = await deviceAppService.CreateAsync(createDeviceInput); + if (insertResult == null) + { + logger.LogError($"{nameof(CreateDeviceForApiAsync)} 添加设备信息失败:{input.Serialize()}"); + return false; + } + + //推送至OneNET平台 + var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput() + { + DeviceName = createDeviceInput.IoTPlatformDeviceOpenInfo, + ProductId = productInfo.IoTPlatformProductId, + OneNETAccountId = productInfo.OneNETAccountId, + Description = input.DeviceAddress, + }); + + if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success) + { + logger.LogError($"{nameof(CreateDeviceForApiAsync)} 推送设备信息失败:{pushResult.Serialize()}"); + return false; + } + + await DeviceUpdateHandler(insertResult, pushResult); + + return true; } catch (Exception) { @@ -241,6 +329,85 @@ namespace JiShe.IoT.DeviceAggregation } } + /// + /// OneNET设备批量创建 + /// + /// + /// + protected async Task OneNETDeviceBatchCreateAsync(BatchCreateDeviceAggregationInput input) + { + try + { + var productInfo = await FreeSqlDbContext.Instance.Select() + .Where(e => e.IoTPlatformProductId == input.IoTPlatformProductId)//此处不需要过滤产品状态,方便测试产品配置信息是否准确,避免跟车间生产搞混 + .WhereIf(input.DeviceSourceTypeEnum == DeviceSourceTypeEnum.Workshop, e => e.IsEnabled == true) + .FirstAsync(); + + if (productInfo == null) + { + throw new UserFriendlyException($"批量创建设备失败,未找到对应的产品配置信息。"); + } + + BatchCreateDeviceInput batchCreateDeviceInput = new BatchCreateDeviceInput() + { + IoTPlatform = input.IoTPlatform, + AddressList = input.AddressList, + DeviceInputs = new List() + }; + foreach (var item in input.AddressList) + { + CreateDeviceInput createDeviceInput = input.Adapt(); + createDeviceInput.DeviceName = item; + createDeviceInput.IoTPlatformAccountId = productInfo.OneNETAccountId; + createDeviceInput.IoTPlatformDeviceOpenInfo = $"{input.IoTPlatformProductId}{item}"; + createDeviceInput.PlatformPassword = productInfo.ProductAccesskey; + createDeviceInput.IoTPlatformProductName = productInfo.ProductName; + createDeviceInput.AccountPhoneNumber = productInfo.AccountPhoneNumber; + } + + + var insertResult = await deviceAppService.BatchCreateAsync(batchCreateDeviceInput); + if (insertResult == null) + { + logger.LogError($"{nameof(OneNETDeviceBatchCreateAsync)} OneNET设备批量创建添加设备信息失败:{input.Serialize()}"); + return false; + } + + //推送至OneNET平台 + var oneNETBatchCreateDeviceInfoInput = new BatchCreateDeviceInfoInput() + { + ProductId = productInfo.IoTPlatformProductId, + OneNETAccountId = productInfo.OneNETAccountId, + DeviceList = batchCreateDeviceInput.DeviceInputs.Select(d => d.IoTPlatformDeviceOpenInfo).ToList(), + }; + + var pushResult = await oneNETDeviceService.BatchCreateDeviceInfoAsync(oneNETBatchCreateDeviceInfoInput); + + if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success) + { + logger.LogError($"{nameof(CreateDeviceForApiAsync)} 推送设备信息失败:{pushResult.Serialize()}"); + return false; + } + + foreach (var item in insertResult) + { + var successEntity = pushResult.Data.Successlist.Where(d => d.DeviceName == item.IoTPlatformDeviceOpenInfo).FirstOrDefault(); + if (successEntity != null) + { + await DeviceUpdateHandler(item, HttpDataResultExtensions.Success(successEntity)); + } + } + + return true; + } + catch (Exception) + { + + throw; + } + } + + /// /// 重新推送设备信息到OneNET物联网平台 /// @@ -288,33 +455,124 @@ namespace JiShe.IoT.DeviceAggregation } /// - /// 更新设备信息并处理缓存 + /// 删除OneNET平台设备 /// /// - /// /// /// - private async Task DeviceUpdateHandler(DeviceManagementInfoDto input, HttpDataResult pushResult) + public async Task DeleteDeviceInfoToOneNET(DeviceManagementInfoDto input) { - UpdateDeviceInput updateDeviceInput = input.Adapt(); - updateDeviceInput.IoTPlatformResponse = pushResult.Serialize(); - updateDeviceInput.IsPlatformPushSuccess = true; - - var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput); - if (updateResult == null) + try { - logger.LogError($"{nameof(CreateDeviceForApiAsync)} 更新设备信息失败:{input.Serialize()}"); - throw new UserFriendlyException($"推送结果更新失败。"); + var productInfo = await FreeSqlDbContext.Instance.Select() + .Where(e => e.IsEnabled == true && e.IoTPlatformProductId == input.IoTPlatformProductId) + .FirstAsync(); + + if (productInfo == null) + { + throw new UserFriendlyException($"删除失败,未找到对应的产品配置信息。"); + } + + + //删除OneNET平台设备信息 + var deleteResult = await oneNETDeviceService.DeleteDeviceInfoAsync(new DeleteDeviceInfoInput() + { + DeviceName = input.IoTPlatformDeviceOpenInfo, + ProductId = productInfo.IoTPlatformProductId, + OneNETAccountId = productInfo.OneNETAccountId, + Description = input.DeviceAddress, + }); + + if (deleteResult == null || deleteResult.Code != ServicePro.Enums.ResponeResultEnum.Success) + { + logger.LogError($"{nameof(CreateDeviceForApiAsync)} 删除设备信息失败:{deleteResult.Serialize()}"); + throw new UserFriendlyException($"删除设备平台请求失败。"); + + } + + var localDeleteReult = await deviceAppService.DeleteAsync(new IdInput() { Id = input.Id }); + if (localDeleteReult == false) + { + throw new UserFriendlyException($"平台设备信息删除成功,系统删除设备失败。"); + } + + return localDeleteReult; } + catch (Exception) + { - //设备数据缓存到Redis - DeviceCacheInfos deviceCacheInfos = input.Adapt(); - deviceCacheInfos.IoTPlatformResponse = null; - deviceCacheInfos.PlatformPassword = null; - - RedisProvider.Instance.HSet(RedisConst.CacheAllDeviceInfoHashKey, input.DeviceAddress, deviceCacheInfos); - - return input.Adapt(); + throw; + } } + #endregion + + #region CTWing 设备操作 + /// + /// CTWing 设备创建 + /// + /// + /// + protected async Task CTWingDeviceCreateAsync(CreateDeviceAggregationInput input) + { + throw new UserFriendlyException($"CTWing 设备创建失败,功能未实现。"); + } + + /// + /// CTWing 批量设备创建 + /// + /// + /// + protected async Task CTWingDeviceBatchCreateAsync(BatchCreateDeviceAggregationInput input) + { + try + { + throw new UserFriendlyException($"CTWing 批量设备创建失败,CTWing暂未实现。"); + } + catch (Exception) + { + + throw; + } + } + + + + /// + /// 重新推送设备信息到CTWing物联网平台 + /// + /// + /// + /// + public async Task RepushDeviceInfoToCTWing(DeviceManagementInfoDto input) + { + try + { + throw new UserFriendlyException($"推送失败,CTWing暂未实现。"); + } + catch (Exception) + { + + throw; + } + } + /// + /// 删除CTWing平台设备 + /// + /// + /// + /// + public async Task DeleteDeviceInfoToCTWing(DeviceManagementInfoDto input) + { + try + { + throw new UserFriendlyException($"删除失败,CTWing暂未实现。"); + } + catch (Exception) + { + + throw; + } + } + #endregion } } diff --git a/src/JiShe.IoT.EntityFrameworkCore/Migrations/20250731021938_InitialCreate.Designer.cs b/src/JiShe.IoT.EntityFrameworkCore/Migrations/20250804031635_InitialCreate.Designer.cs similarity index 99% rename from src/JiShe.IoT.EntityFrameworkCore/Migrations/20250731021938_InitialCreate.Designer.cs rename to src/JiShe.IoT.EntityFrameworkCore/Migrations/20250804031635_InitialCreate.Designer.cs index 8a39c36..1f789aa 100644 --- a/src/JiShe.IoT.EntityFrameworkCore/Migrations/20250731021938_InitialCreate.Designer.cs +++ b/src/JiShe.IoT.EntityFrameworkCore/Migrations/20250804031635_InitialCreate.Designer.cs @@ -13,7 +13,7 @@ using Volo.Abp.EntityFrameworkCore; namespace JiShe.IoT.Migrations { [DbContext(typeof(IoTDbContext))] - [Migration("20250731021938_InitialCreate")] + [Migration("20250804031635_InitialCreate")] partial class InitialCreate { /// @@ -599,6 +599,10 @@ namespace JiShe.IoT.Migrations .HasColumnType("int") .HasComment("设备在线状态"); + b.Property("DeviceSourceTypeEnum") + .HasColumnType("int") + .HasComment("设备来源类型"); + b.Property("ExtraProperties") .HasColumnType("longtext") .HasColumnName("ExtraProperties") diff --git a/src/JiShe.IoT.EntityFrameworkCore/Migrations/20250731021938_InitialCreate.cs b/src/JiShe.IoT.EntityFrameworkCore/Migrations/20250804031635_InitialCreate.cs similarity index 99% rename from src/JiShe.IoT.EntityFrameworkCore/Migrations/20250731021938_InitialCreate.cs rename to src/JiShe.IoT.EntityFrameworkCore/Migrations/20250804031635_InitialCreate.cs index 5af6778..ee929c7 100644 --- a/src/JiShe.IoT.EntityFrameworkCore/Migrations/20250731021938_InitialCreate.cs +++ b/src/JiShe.IoT.EntityFrameworkCore/Migrations/20250804031635_InitialCreate.cs @@ -886,6 +886,7 @@ namespace JiShe.IoT.Migrations DeviceOnlineStatus = table.Column(type: "int", nullable: true, comment: "设备在线状态"), LastOnlineTime = table.Column(type: "datetime(6)", nullable: true, comment: "最后在线时间"), LastOfflineTime = table.Column(type: "datetime(6)", nullable: true, comment: "最后离线时间"), + DeviceSourceTypeEnum = table.Column(type: "int", nullable: true, comment: "设备来源类型"), ConcurrencyStamp = table.Column(type: "varchar(40)", maxLength: 40, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), CreationTime = table.Column(type: "datetime(6)", nullable: false), diff --git a/src/JiShe.IoT.EntityFrameworkCore/Migrations/IoTDbContextModelSnapshot.cs b/src/JiShe.IoT.EntityFrameworkCore/Migrations/IoTDbContextModelSnapshot.cs index e1e9e08..5da23cb 100644 --- a/src/JiShe.IoT.EntityFrameworkCore/Migrations/IoTDbContextModelSnapshot.cs +++ b/src/JiShe.IoT.EntityFrameworkCore/Migrations/IoTDbContextModelSnapshot.cs @@ -596,6 +596,10 @@ namespace JiShe.IoT.Migrations .HasColumnType("int") .HasComment("设备在线状态"); + b.Property("DeviceSourceTypeEnum") + .HasColumnType("int") + .HasComment("设备来源类型"); + b.Property("ExtraProperties") .HasColumnType("longtext") .HasColumnName("ExtraProperties") diff --git a/src/JiShe.IoT.HttpApi/Controllers/DeviceAggregationController.cs b/src/JiShe.IoT.HttpApi/Controllers/DeviceAggregationController.cs index 8ec742c..62b6d1d 100644 --- a/src/JiShe.IoT.HttpApi/Controllers/DeviceAggregationController.cs +++ b/src/JiShe.IoT.HttpApi/Controllers/DeviceAggregationController.cs @@ -29,6 +29,18 @@ namespace JiShe.IoT.Controllers return await _deviceAggregationService.CreateDeviceForApiAsync(input); } + /// + /// 批量创建设备信息 + /// + /// + /// + [HttpPost(nameof(BatchCreateAsync))] + [SwaggerOperation(summary: "批量创建设备信息", Tags = new[] { "AggregationDevice" })] + public async Task BatchCreateAsync(BatchCreateDeviceAggregationInput input) + { + return await _deviceAggregationService.BatchCreateDeviceForApiAsync(input); + } + /// /// 删除设备信息 ///