diff --git a/src/JiShe.IoT.Application.Contracts/BusinessSystemAggregation/Dto/BatchCreateDeviceInfoInput.cs b/src/JiShe.IoT.Application.Contracts/BusinessSystemAggregation/Dto/BatchCreateDeviceInfoInput.cs
new file mode 100644
index 0000000..aeca877
--- /dev/null
+++ b/src/JiShe.IoT.Application.Contracts/BusinessSystemAggregation/Dto/BatchCreateDeviceInfoInput.cs
@@ -0,0 +1,36 @@
+using JiShe.ServicePro.Enums;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JiShe.IoT.BusinessSystemAggregation.Dto
+{
+ ///
+ /// 批量创建设备信息输入
+ ///
+ public class BatchCreateDeviceInfoInput
+ {
+ ///
+ /// 设备来源类型,只接收 预付费业务系统推送、能耗业务系统推送
+ ///
+ public DeviceSourceTypeEnum DeviceSourceType { get; set; }
+
+ ///
+ /// 物联网平台类型
+ ///
+ public IoTPlatformTypeEnum IoTPlatform { get; set; }
+
+ ///
+ /// 集中器在物联网平台中对应的产品Id
+ ///
+ public string IoTPlatformProductId { get; set; }
+
+ ///
+ /// 设备地址集合
+ ///
+ public List DeviceAddresses { get; set; }
+ }
+}
diff --git a/src/JiShe.IoT.Application.Contracts/BusinessSystemAggregation/IBusinessSystemAggregationService.cs b/src/JiShe.IoT.Application.Contracts/BusinessSystemAggregation/IBusinessSystemAggregationService.cs
index cd225e0..4cb7c5b 100644
--- a/src/JiShe.IoT.Application.Contracts/BusinessSystemAggregation/IBusinessSystemAggregationService.cs
+++ b/src/JiShe.IoT.Application.Contracts/BusinessSystemAggregation/IBusinessSystemAggregationService.cs
@@ -21,10 +21,17 @@ namespace JiShe.IoT.BusinessSystemAggregation
Task ReceiveCommandInfoAsync(OpenApiRequest input);
///
- /// 业务系统批量查询设备数据,Msg 字段为 BatchQueryDeviceInfoInput 实体
+ /// 业务系统批量查询设备数据,Msg 字段为 BatchQueryDeviceDataInfoInput 实体
///
///
///
- Task>> BatchQueryDeviceInfoAsync(OpenApiRequest input);
+ Task>> BatchQueryDeviceDataInfoAsync(OpenApiRequest input);
+
+ ///
+ /// 业务系统批量新增设备数据,Msg 字段为 BatchCreateDeviceInfoInput 实体
+ ///
+ ///
+ ///
+ Task BatchCreateDeviceInfoAsync(OpenApiRequest input);
}
}
diff --git a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs
index c089d76..f51fa15 100644
--- a/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs
+++ b/src/JiShe.IoT.Application.Contracts/DeviceAggregation/IDeviceAggregationService.cs
@@ -69,5 +69,11 @@ namespace JiShe.IoT.DeviceAggregation
///
Task RepushDeviceInfoToIoTPlatform(IdInput input);
+ ///
+ /// 业务系统批量创建设备信息
+ ///
+ ///
+ ///
+ Task BatchCreateDeviceBusinessSystemAsync(BatchCreateDeviceAggregationInput input);
}
}
diff --git a/src/JiShe.IoT.Application/BusinessSystemAggregation/BusinessSystemAggregationService.cs b/src/JiShe.IoT.Application/BusinessSystemAggregation/BusinessSystemAggregationService.cs
index 506f189..5329868 100644
--- a/src/JiShe.IoT.Application/BusinessSystemAggregation/BusinessSystemAggregationService.cs
+++ b/src/JiShe.IoT.Application/BusinessSystemAggregation/BusinessSystemAggregationService.cs
@@ -1,4 +1,5 @@
using JiShe.IoT.BusinessSystemAggregation.Dto;
+using JiShe.IoT.DeviceAggregation;
using JiShe.ServicePro;
using JiShe.ServicePro.ApacheIoTDB.Provider.Model;
using JiShe.ServicePro.ApacheIoTDB.Provider.Options;
@@ -21,7 +22,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
///
/// 业务系统聚合服务
///
- public class BusinessSystemAggregationService(IOptions options, IReliableRedisPubSubService redisPubSubService, IDeviceAppService deviceAppService, IIoTDBDataChannelManageService ioTDBDataChannelManageService, IOptions _ioTDBOptions, ITreeModelService treeModelService, ILogger _logger) : IoTAppService, IBusinessSystemAggregationService
+ public class BusinessSystemAggregationService(IOptions options, IReliableRedisPubSubService redisPubSubService, IDeviceAppService deviceAppService, IIoTDBDataChannelManageService ioTDBDataChannelManageService, IOptions _ioTDBOptions, ITreeModelService treeModelService, IDeviceAggregationService deviceAggregationService, ILogger _logger) : IoTAppService, IBusinessSystemAggregationService
{
ServerApplicationOptions srverOptions = options.Value;
IoTDBOptions ioTDBOptions = _ioTDBOptions.Value;
@@ -122,7 +123,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
///
///
[AllowAnonymous]
- public async Task>> BatchQueryDeviceInfoAsync(OpenApiRequest input)
+ public async Task>> BatchQueryDeviceDataInfoAsync(OpenApiRequest input)
{
try
{
@@ -171,7 +172,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
if (deviceCacheInfo == null)
{
- _logger.LogError($"{nameof(BatchQueryDeviceInfoAsync)} 业务系统批量查询设备数据,设备地址:{deviceAddress}未找到设备地址缓存信息,消息体为:{input.Serialize()}");
+ _logger.LogError($"{nameof(BatchQueryDeviceDataInfoAsync)} 业务系统批量查询设备数据,设备地址:{deviceAddress}未找到设备地址缓存信息,消息体为:{input.Serialize()}");
continue;
}
@@ -190,7 +191,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
}
}
- return HttpDataResultExtensions.Success(queryResult,"查询成功");
+ return HttpDataResultExtensions.Success(queryResult, "查询成功");
}
@@ -203,6 +204,51 @@ namespace JiShe.IoT.BusinessSystemAggregation
}
+ ///
+ /// 业务系统批量新增设备数据,Msg 字段为 BatchCreateDeviceInfoInput 实体
+ ///
+ ///
+ ///
+ [AllowAnonymous]
+ public async Task BatchCreateDeviceInfoAsync(OpenApiRequest input)
+ {
+ try
+ {
+ var handleResult = HandleOpenApiRequest(input);
+ if (handleResult.Success == false)
+ {
+ return HttpDataResultExtensions.Failed(handleResult.Message, handleResult.LocationCode);
+ }
+ var messageBody = handleResult.Data;
+
+ if (messageBody.DeviceAddresses == null || messageBody.DeviceAddresses.Count <= 0)
+ {
+ return HttpDataResultExtensions.Failed("设备地址不能为空", -101);
+ }
+
+ var createResult = await deviceAggregationService.BatchCreateDeviceBusinessSystemAsync(new BatchCreateDeviceAggregationInput()
+ {
+ DeviceSourceTypeEnum = messageBody.DeviceSourceType,
+ IoTPlatform = messageBody.IoTPlatform,
+ IoTPlatformProductId = messageBody.IoTPlatformProductId,
+ AddressList = messageBody.DeviceAddresses
+ });
+
+ if (createResult == false)
+ {
+ _logger.LogError($"{nameof(BatchCreateDeviceInfoAsync)} 业务系统批量新增设备数据没有成功,消息体为:{input.Serialize()}");
+ return HttpDataResultExtensions.Failed("新增设备失败", -102);
+ }
+
+ return HttpDataResultExtensions.Success("新增设备成功");
+ }
+ catch (Exception ex)
+ {
+ return HttpDataResultExtensions.Failed($"查询设备数据失败,发送异常:{ex.Message}", -106);
+ }
+ }
+
+
///
/// 处理开放接口请求
///
diff --git a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs
index 4b1ca88..a445794 100644
--- a/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs
+++ b/src/JiShe.IoT.Application/DeviceAggregation/DeviceAggregationService.cs
@@ -333,6 +333,48 @@ namespace JiShe.IoT.DeviceAggregation
}
}
+ ///
+ /// 业务系统批量创建设备信息
+ ///
+ ///
+ ///
+ public async Task BatchCreateDeviceBusinessSystemAsync(BatchCreateDeviceAggregationInput input)
+ {
+ try
+ {
+ if (input.AddressList == null || input.AddressList.Count <= 0)
+ {
+ throw new UserFriendlyException($"业务系统批量创建设备信息,设备信息不能为空。");
+ }
+
+ if (input.AddressList.Count > 100)
+ {
+ throw new UserFriendlyException($"业务系统批量创建设备信息,设备信息不能超过100个。");
+ }
+
+ if (input.DeviceSourceTypeEnum != DeviceSourceTypeEnum.Prepay && input.DeviceSourceTypeEnum != DeviceSourceTypeEnum.Energy)
+ {
+ throw new UserFriendlyException($"业务系统批量创建设备信息,设备来源异常。");
+ }
+
+ 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;
+ }
+ }
+
#region OneNET 设备操作
///
diff --git a/src/JiShe.IoT.HttpApi/Controllers/BusinessSystemAggregationController.cs b/src/JiShe.IoT.HttpApi/Controllers/BusinessSystemAggregationController.cs
index 62889cb..dc8b9ff 100644
--- a/src/JiShe.IoT.HttpApi/Controllers/BusinessSystemAggregationController.cs
+++ b/src/JiShe.IoT.HttpApi/Controllers/BusinessSystemAggregationController.cs
@@ -24,5 +24,26 @@ namespace JiShe.IoT.Controllers
{
return await _businessSystemAggregationService.ReceiveCommandInfoAsync(input);
}
+
+ ///
+ /// 业务系统批量查询设备数据
+ ///
+ [HttpPost(nameof(BatchQueryDeviceDataInfoAsync))]
+ [SwaggerOperation(summary: "业务系统批量查询设备数据", Tags = new[] { "AggregationBusiness" })]
+ public async Task BatchQueryDeviceDataInfoAsync(OpenApiRequest input)
+ {
+ return await _businessSystemAggregationService.BatchQueryDeviceDataInfoAsync(input);
+ }
+
+
+ ///
+ /// 业务系统批量新增设备数据
+ ///
+ [HttpPost(nameof(BatchCreateDeviceInfoAsync))]
+ [SwaggerOperation(summary: "业务系统批量新增设备数据", Tags = new[] { "AggregationBusiness" })]
+ public async Task BatchCreateDeviceInfoAsync(OpenApiRequest input)
+ {
+ return await _businessSystemAggregationService.BatchCreateDeviceInfoAsync(input);
+ }
}
}