业务系统批量新增设备数据
This commit is contained in:
parent
3cc29ee4c7
commit
ec698add74
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 批量创建设备信息输入
|
||||
/// </summary>
|
||||
public class BatchCreateDeviceInfoInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备来源类型,只接收 预付费业务系统推送、能耗业务系统推送
|
||||
/// </summary>
|
||||
public DeviceSourceTypeEnum DeviceSourceType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物联网平台类型
|
||||
/// </summary>
|
||||
public IoTPlatformTypeEnum IoTPlatform { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 集中器在物联网平台中对应的产品Id
|
||||
/// </summary>
|
||||
public string IoTPlatformProductId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备地址集合
|
||||
/// </summary>
|
||||
public List<string> DeviceAddresses { get; set; }
|
||||
}
|
||||
}
|
||||
@ -21,10 +21,17 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
Task<HttpDataResult> ReceiveCommandInfoAsync(OpenApiRequest input);
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量查询设备数据,Msg 字段为 BatchQueryDeviceInfoInput 实体
|
||||
/// 业务系统批量查询设备数据,Msg 字段为 BatchQueryDeviceDataInfoInput 实体
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<HttpDataResult<List<IoTDBDynamicObject>>> BatchQueryDeviceInfoAsync(OpenApiRequest input);
|
||||
Task<HttpDataResult<List<IoTDBDynamicObject>>> BatchQueryDeviceDataInfoAsync(OpenApiRequest input);
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量新增设备数据,Msg 字段为 BatchCreateDeviceInfoInput 实体
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<HttpDataResult> BatchCreateDeviceInfoAsync(OpenApiRequest input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,5 +69,11 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
Task<DeviceManagementInfoDto> RepushDeviceInfoToIoTPlatform(IdInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> BatchCreateDeviceBusinessSystemAsync(BatchCreateDeviceAggregationInput input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
/// <summary>
|
||||
/// 业务系统聚合服务
|
||||
/// </summary>
|
||||
public class BusinessSystemAggregationService(IOptions<ServerApplicationOptions> options, IReliableRedisPubSubService redisPubSubService, IDeviceAppService deviceAppService, IIoTDBDataChannelManageService ioTDBDataChannelManageService, IOptions<IoTDBOptions> _ioTDBOptions, ITreeModelService treeModelService, ILogger<BusinessSystemAggregationService> _logger) : IoTAppService, IBusinessSystemAggregationService
|
||||
public class BusinessSystemAggregationService(IOptions<ServerApplicationOptions> options, IReliableRedisPubSubService redisPubSubService, IDeviceAppService deviceAppService, IIoTDBDataChannelManageService ioTDBDataChannelManageService, IOptions<IoTDBOptions> _ioTDBOptions, ITreeModelService treeModelService, IDeviceAggregationService deviceAggregationService, ILogger<BusinessSystemAggregationService> _logger) : IoTAppService, IBusinessSystemAggregationService
|
||||
{
|
||||
ServerApplicationOptions srverOptions = options.Value;
|
||||
IoTDBOptions ioTDBOptions = _ioTDBOptions.Value;
|
||||
@ -122,7 +123,7 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
public async Task<HttpDataResult<List<IoTDBDynamicObject>>> BatchQueryDeviceInfoAsync(OpenApiRequest input)
|
||||
public async Task<HttpDataResult<List<IoTDBDynamicObject>>> 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;
|
||||
}
|
||||
|
||||
@ -203,6 +204,51 @@ namespace JiShe.IoT.BusinessSystemAggregation
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量新增设备数据,Msg 字段为 BatchCreateDeviceInfoInput 实体
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
public async Task<HttpDataResult> BatchCreateDeviceInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var handleResult = HandleOpenApiRequest<BatchCreateDeviceInfoInput>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 处理开放接口请求
|
||||
/// </summary>
|
||||
|
||||
@ -333,6 +333,48 @@ namespace JiShe.IoT.DeviceAggregation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> 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 设备操作
|
||||
/// <summary>
|
||||
|
||||
@ -24,5 +24,26 @@ namespace JiShe.IoT.Controllers
|
||||
{
|
||||
return await _businessSystemAggregationService.ReceiveCommandInfoAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量查询设备数据
|
||||
/// </summary>
|
||||
[HttpPost(nameof(BatchQueryDeviceDataInfoAsync))]
|
||||
[SwaggerOperation(summary: "业务系统批量查询设备数据", Tags = new[] { "AggregationBusiness" })]
|
||||
public async Task<HttpDataResult> BatchQueryDeviceDataInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
return await _businessSystemAggregationService.BatchQueryDeviceDataInfoAsync(input);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 业务系统批量新增设备数据
|
||||
/// </summary>
|
||||
[HttpPost(nameof(BatchCreateDeviceInfoAsync))]
|
||||
[SwaggerOperation(summary: "业务系统批量新增设备数据", Tags = new[] { "AggregationBusiness" })]
|
||||
public async Task<HttpDataResult> BatchCreateDeviceInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
return await _businessSystemAggregationService.BatchCreateDeviceInfoAsync(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user