平台聚合服务新增平台产品物模型以及产品标准物模型属性更新

This commit is contained in:
ChenYi 2025-12-24 17:20:56 +08:00
parent a60bd1a386
commit fc0d6a8ae1
8 changed files with 248 additions and 2 deletions

View File

@ -0,0 +1,19 @@
using JiShe.ServicePro.Core;
using JiShe.ServicePro.Enums;
using System.ComponentModel.DataAnnotations;
namespace JiShe.IoT.DeviceAggregation
{
/// <summary>
/// 设备属性抄读
/// </summary>
public class DevicePropertyValueForApiInput : IdInput
{
/// <summary>
/// 设备在物联网平台中属性标识符列表
/// </summary>
[Required(ErrorMessage = "属性标识符不能为空")]
public List<string> PropertyList { get; set; }
}
}

View File

@ -46,6 +46,13 @@ namespace JiShe.IoT.DeviceAggregation
/// <returns></returns>
Task<bool> DeviceCommandForApiAsync(DeviceCommandForApiInput input);
/// <summary>
/// 获取设备属性最新值
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<Dictionary<string,object>> GetDevicePropertyValueForApiAsync(DevicePropertyValueForApiInput input);
/// <summary>
/// 删除设备信息
/// </summary>

View File

@ -0,0 +1,28 @@
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.IoTPlatformAggregation.Dto
{
/// <summary>
/// 平台产品属性更新输入
/// </summary>
public class UpdateIoTPlatformProductPropertyInfoInput
{
/// <summary>
/// 物联网平台类型,默认没有指定
/// </summary>
[Required]
public IoTPlatformTypeEnum IoTPlatformType { get; set; }
/// <summary>
/// 物联网平台中对应的产品Id
/// </summary>
[Required]
public string IoTPlatformProductId { get; set; }
}
}

View File

@ -37,5 +37,13 @@ namespace JiShe.IoT.IoTPlatformAggregation
/// <returns></returns>
Task<List<SelectResult>> GetIoTPlatformProductPropertyInfoAsync(IoTPlatformProductPropertyInfoInput input
);
/// <summary>
/// 更新平台产品物模型属性信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<object> UpdateIoTPlatformProductPropertyInfoAsync(UpdateIoTPlatformProductPropertyInfoInput input
);
}
}

View File

@ -334,6 +334,50 @@ namespace JiShe.IoT.DeviceAggregation
}
}
/// <summary>
/// 获取设备属性最新值
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<Dictionary<string, object>> GetDevicePropertyValueForApiAsync(DevicePropertyValueForApiInput input)
{
try
{
if (input.PropertyList == null || input.PropertyList.Count <= 0)
{
throw new UserFriendlyException($"属性标识符参数异常");
}
var deviceInfo = await deviceAppService.FindByIdAsync(input);
if (deviceInfo == null)
{
throw new UserFriendlyException($"设备不存在");
}
//数据写入遥测任务数据存储通道
if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.OneNET)
{
return await DevicePropertyValueToOneNET(deviceInfo, input);
}
else if (deviceInfo.IoTPlatform == IoTPlatformTypeEnum.CTWing)
{
//await redisPubSubService.PublishReliableAsync(DistributedMessageCenterConst.CTWingAepCommandIssuedEventName,commandRequest);
//return true;
throw new UserFriendlyException($"发送设备指令信息失败CTWing暂未实现。");
}
else
{
throw new UserFriendlyException($"发送设备指令信息失败,未找到对应的产品配置信息。");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 业务系统批量创建设备信息
/// </summary>
@ -678,6 +722,56 @@ namespace JiShe.IoT.DeviceAggregation
throw;
}
}
/// <summary>
/// 抄读OneNET平台设备属性数据
/// </summary>
/// <param name="deviceInfo"></param>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public async Task<Dictionary<string, object>> DevicePropertyValueToOneNET(DeviceManagementInfoDto deviceInfo, DevicePropertyValueForApiInput input)
{
try
{
//检查下设备是否在线
var deviceOnlineStatus = await oneNETDeviceService.DeviceInfoDetailAsync(new DeviceInfoDetailInput()
{
DeviceName = deviceInfo.IoTPlatformDeviceOpenInfo,
OneNETAccountId = deviceInfo.IoTPlatformAccountId,
ProductId = deviceInfo.IoTPlatformProductId,
});
if (deviceOnlineStatus == null || deviceOnlineStatus.Code != ResponeResultEnum.Success)
{
throw new UserFriendlyException("获取平台设备信息失败");
}
if (deviceOnlineStatus.Data.Status != 1)
{
throw new UserFriendlyException("设备不在线");
}
var deviceDataResult = await oneNETDeviceService.QueryDevicePropertyDetail(new QueryDevicePropertyDetailInput()
{
DeviceName = deviceInfo.IoTPlatformDeviceOpenInfo,
OneNETAccountId = deviceInfo.IoTPlatformAccountId,
ProductId = deviceInfo.IoTPlatformProductId,
PropertyInfos = input.PropertyList
});
if (deviceDataResult == null || deviceDataResult.Success == false || deviceDataResult.Data == null)
{
throw new UserFriendlyException($"设备{deviceInfo.DeviceName}获取数据失败");
}
return deviceDataResult.Data;
}
catch (Exception)
{
throw;
}
}
#endregion
#region CTWing

View File

@ -4,6 +4,7 @@ using JiShe.ServicePro.Commons;
using JiShe.ServicePro.Core;
using JiShe.ServicePro.CTWingManagement.CTWingAccounts;
using JiShe.ServicePro.CTWingManagement.CTWingProducts;
using JiShe.ServicePro.DeviceManagement.ThingModels;
using JiShe.ServicePro.Enums;
using JiShe.ServicePro.FreeRedisProvider;
using JiShe.ServicePro.OneNETManagement.OneNETAccounts;
@ -29,18 +30,22 @@ namespace JiShe.IoT.IoTPlatformAggregation
private readonly IOneNETProductService _oneNetProductService;
private readonly ICTWingAccountService _ctwingAccountService;
private readonly IOneNETAccountService _oneNETAccountService;
private readonly IIoTPlatformThingModelInfoAppService _ioTPlatformThingModelInfoAppService;
public IoTPlatformAggregationService(ILogger<IoTPlatformAggregationService> logger,
ICTWingProductService ctwingProductService,
IOneNETProductService oneNetProductService,
ICTWingAccountService ctwingAccountService,
IOneNETAccountService oneNETAccountService)
IOneNETAccountService oneNETAccountService,
IIoTPlatformThingModelInfoAppService ioTPlatformThingModelInfoAppService)
{
_logger = logger;
_ctwingProductService = ctwingProductService;
_oneNetProductService = oneNetProductService;
_ctwingAccountService = ctwingAccountService;
_oneNETAccountService = oneNETAccountService;
_ioTPlatformThingModelInfoAppService = ioTPlatformThingModelInfoAppService;
}
/// <summary>
@ -244,5 +249,66 @@ namespace JiShe.IoT.IoTPlatformAggregation
throw;
}
}
/// <summary>
/// 更新平台产品物模型属性信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<object> UpdateIoTPlatformProductPropertyInfoAsync(UpdateIoTPlatformProductPropertyInfoInput input
)
{
try
{
if (input == null)
{
throw new UserFriendlyException($"{nameof(UpdateIoTPlatformProductPropertyInfoAsync)} 平台产品聚合服务获取产品属性信息失败,参数异常");
}
if (input.IoTPlatformType == IoTPlatformTypeEnum.CTWing)
{
_logger.LogError($"{nameof(UpdateIoTPlatformProductPropertyInfoAsync)}产品聚合服务暂不支持CTWing产品物模型属性信息更新");
return null;
}
if (input.IoTPlatformType == IoTPlatformTypeEnum.OneNET)
{
var oneNetProductInfos = await _oneNetProductService.UpdateThingModelAsync(new IdInput<string>() { Id = input.IoTPlatformProductId });
if (oneNetProductInfos == null || string.IsNullOrWhiteSpace(oneNetProductInfos.ThingModelInfos))
{
_logger.LogError($"{nameof(UpdateIoTPlatformProductPropertyInfoAsync)}产品聚合服务OneNET产品{input.IoTPlatformProductId}物模型属性信息更新失败,-101");
return null;
}
var oneNETAllThingModel = oneNetProductInfos.ThingModelInfos.Deserialize<OneNETAllThingModel>();
if (oneNETAllThingModel == null)
{
_logger.LogError($"{nameof(UpdateIoTPlatformProductPropertyInfoAsync)}产品聚合服务OneNET产品{input.IoTPlatformProductId}物模型属性信息更新失败,-102");
return null;
}
//将平台产品最新物模型信息更新到平台端物模型表中
var selectResults = OneNETAllThingModel.GetAllPropertiesSelectResult(oneNETAllThingModel.Properties);
await _ioTPlatformThingModelInfoAppService.UpdatePlatformThingModelAsync(input.IoTPlatformProductId, input.IoTPlatformType, selectResults);
return oneNetProductInfos;
}
return null;
}
catch (Exception)
{
throw;
}
}
}
}

View File

@ -87,5 +87,17 @@ namespace JiShe.IoT.Controllers
return _deviceAggregationService.DeviceCommandForApiAsync(input);
}
/// <summary>
/// 获取设备属性最新值
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost(nameof(GetDevicePropertyValueForApiAsync))]
[SwaggerOperation(summary: "获取设备属性最新值", Tags = new[] { "AggregationDevice" })]
public Task<Dictionary<string, object>> GetDevicePropertyValueForApiAsync(DevicePropertyValueForApiInput input)
{
return _deviceAggregationService.GetDevicePropertyValueForApiAsync(input);
}
}
}

View File

@ -57,5 +57,17 @@ namespace JiShe.IoT.Controllers
return await _iotPlatformAggregationService.GetIoTPlatformProductPropertyInfoAsync(input);
}
/// <summary>
/// 更新平台产品物模型属性信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost(nameof(UpdateIoTPlatformProductPropertyInfoAsync))]
[SwaggerOperation(summary: "更新平台产品物模型属性信息", Tags = new[] { "AggregationIoTPlatform" })]
public async Task<object> UpdateIoTPlatformProductPropertyInfoAsync(UpdateIoTPlatformProductPropertyInfoInput input)
{
return await _iotPlatformAggregationService.UpdateIoTPlatformProductPropertyInfoAsync(input);
}
}
}