From 2ba44b5d302f82769ff2d4bdbe716e5bb67696c0 Mon Sep 17 00:00:00 2001
From: ChenYi <296215406@outlook.com>
Date: Mon, 22 Dec 2025 15:36:35 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=A7=E5=93=81=E8=81=9A?=
=?UTF-8?q?=E5=90=88=E6=9C=8D=E5=8A=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Dto/IoTPlatformProductInfoInput.cs | 2 +
.../IoTPlatformProductPropertyInfoInput.cs | 28 ++++++
.../IIoTPlatformAggregationService.cs | 9 ++
.../IoTPlatformAggregationService.cs | 90 ++++++++++++++++++-
.../IoTPlatformAggregationController.cs | 15 +++-
5 files changed, 140 insertions(+), 4 deletions(-)
create mode 100644 src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/Dto/IoTPlatformProductPropertyInfoInput.cs
diff --git a/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/Dto/IoTPlatformProductInfoInput.cs b/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/Dto/IoTPlatformProductInfoInput.cs
index a303e39..a8d4f0d 100644
--- a/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/Dto/IoTPlatformProductInfoInput.cs
+++ b/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/Dto/IoTPlatformProductInfoInput.cs
@@ -1,6 +1,7 @@
using JiShe.ServicePro.Enums;
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -15,6 +16,7 @@ namespace JiShe.IoT.IoTPlatformAggregation.Dto
///
/// 平台类型
///
+ [Required]
public IoTPlatformTypeEnum IoTPlatformType { get; set; }
}
}
diff --git a/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/Dto/IoTPlatformProductPropertyInfoInput.cs b/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/Dto/IoTPlatformProductPropertyInfoInput.cs
new file mode 100644
index 0000000..e4fb7d8
--- /dev/null
+++ b/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/Dto/IoTPlatformProductPropertyInfoInput.cs
@@ -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
+{
+ ///
+ /// 产品属性信息输入
+ ///
+ public class IoTPlatformProductPropertyInfoInput
+ {
+ ///
+ /// 物联网平台类型,默认没有指定
+ ///
+ [Required]
+ public IoTPlatformTypeEnum IoTPlatformType { get; set; }
+
+ ///
+ /// 物联网平台中对应的产品Id
+ ///
+ [Required]
+ public string IoTPlatformProductId { get; set; }
+ }
+}
diff --git a/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/IIoTPlatformAggregationService.cs b/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/IIoTPlatformAggregationService.cs
index a9a6f08..8ab80d0 100644
--- a/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/IIoTPlatformAggregationService.cs
+++ b/src/JiShe.IoT.Application.Contracts/IoTPlatformAggregation/IIoTPlatformAggregationService.cs
@@ -1,4 +1,5 @@
using JiShe.IoT.IoTPlatformAggregation.Dto;
+using JiShe.ServicePro.Commons;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -19,5 +20,13 @@ namespace JiShe.IoT.IoTPlatformAggregation
///
Task> GetIoTPlatformProductInfoAsync(IoTPlatformProductInfoInput input
);
+
+ ///
+ /// 获取平台产品物模型属性信息
+ ///
+ ///
+ ///
+ Task> GetIoTPlatformProductPropertyInfoAsync(IoTPlatformProductPropertyInfoInput input
+ );
}
}
diff --git a/src/JiShe.IoT.Application/IoTPlatformAggregation/IoTPlatformAggregationService.cs b/src/JiShe.IoT.Application/IoTPlatformAggregation/IoTPlatformAggregationService.cs
index e993146..ae6a17f 100644
--- a/src/JiShe.IoT.Application/IoTPlatformAggregation/IoTPlatformAggregationService.cs
+++ b/src/JiShe.IoT.Application/IoTPlatformAggregation/IoTPlatformAggregationService.cs
@@ -1,8 +1,12 @@
using Castle.Core.Logging;
using JiShe.IoT.IoTPlatformAggregation.Dto;
+using JiShe.ServicePro.Commons;
+using JiShe.ServicePro.Core;
using JiShe.ServicePro.CTWingManagement.CTWingProducts;
using JiShe.ServicePro.Enums;
+using JiShe.ServicePro.FreeRedisProvider;
using JiShe.ServicePro.OneNETManagement.OneNETProducts;
+using Microsoft.AspNetCore.DataProtection.KeyManagement;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -49,7 +53,7 @@ namespace JiShe.IoT.IoTPlatformAggregation
if (input.IoTPlatformType == IoTPlatformTypeEnum.CTWing)
{
var ctwingProductInfos = await _ctwingProductService.GetAllListAsync();
- if(ctwingProductInfos == null)
+ if (ctwingProductInfos == null)
{
return ioTPlatformProductInfoOutputs;
}
@@ -65,10 +69,10 @@ namespace JiShe.IoT.IoTPlatformAggregation
}
}
- if(input.IoTPlatformType == IoTPlatformTypeEnum.OneNET)
+ if (input.IoTPlatformType == IoTPlatformTypeEnum.OneNET)
{
var oneNetProductInfos = await _oneNetProductService.GetAllListAsync();
- if(oneNetProductInfos == null)
+ if (oneNetProductInfos == null)
{
return ioTPlatformProductInfoOutputs;
}
@@ -91,5 +95,85 @@ namespace JiShe.IoT.IoTPlatformAggregation
throw;
}
}
+
+
+ ///
+ /// 获取平台产品物模型属性信息
+ ///
+ ///
+ ///
+ public async Task> GetIoTPlatformProductPropertyInfoAsync(IoTPlatformProductPropertyInfoInput input)
+ {
+ try
+ {
+ if (input == null)
+ {
+ throw new UserFriendlyException($"{nameof(GetIoTPlatformProductPropertyInfoAsync)} 平台产品聚合服务获取产品属性信息失败,参数异常");
+ }
+ var key = string.Format($"{RedisConst.CachePlatformProductThingModelInfoKey}", input.IoTPlatformType);
+ List selectResults = new List();
+
+ List ioTPlatformProductInfoOutputs = new List();
+ if (input.IoTPlatformType == IoTPlatformTypeEnum.CTWing)
+ {
+ //var ctwingProductInfos = await _ctwingProductService.GetAllListAsync();
+ //if (ctwingProductInfos == null)
+ //{
+ // return ioTPlatformProductInfoOutputs;
+ //}
+
+ //foreach (var ctwingProductInfo in ctwingProductInfos)
+ //{
+ // ioTPlatformProductInfoOutputs.Add(new IoTPlatformProductInfoOutput
+ // {
+ // IoTPlatformType = IoTPlatformTypeEnum.CTWing,
+ // IoTPlatformProductId = ctwingProductInfo.IoTPlatformProductId,
+ // ProductName = ctwingProductInfo.ProductName
+ // });
+ //}
+ _logger.LogError($"{nameof(GetIoTPlatformProductPropertyInfoAsync)}产品聚合服务暂不支持CTWing产品物模型属性信息查询");
+
+ return selectResults;
+ }
+
+
+ if (input.IoTPlatformType == IoTPlatformTypeEnum.OneNET)
+ {
+
+ var oneNETAllThingModel = FreeRedisProvider.Instance.HGet(key, input.IoTPlatformProductId);
+ if (oneNETAllThingModel != null)
+ {
+ return OneNETAllThingModel.GetAllPropertiesSelectResult(oneNETAllThingModel.Properties);
+ }
+
+ var oneNetProductInfos = await _oneNetProductService.GetProductInfoAsync(new IdInput() { Id = input.IoTPlatformProductId });
+ if (oneNetProductInfos == null || string.IsNullOrWhiteSpace(oneNetProductInfos.ThingModelInfos))
+ {
+ return selectResults;
+ }
+
+
+
+ oneNETAllThingModel = oneNetProductInfos.ThingModelInfos.Deserialize();
+
+ if (oneNETAllThingModel == null)
+ {
+ return selectResults;
+ }
+
+ await FreeRedisProvider.Instance.HSetAsync(key, input.IoTPlatformProductId, oneNETAllThingModel);
+
+ return OneNETAllThingModel.GetAllPropertiesSelectResult(oneNETAllThingModel.Properties);
+ }
+
+ return selectResults;
+
+ }
+ catch (Exception)
+ {
+
+ throw;
+ }
+ }
}
}
diff --git a/src/JiShe.IoT.HttpApi/Controllers/IoTPlatformAggregationController.cs b/src/JiShe.IoT.HttpApi/Controllers/IoTPlatformAggregationController.cs
index 77ae4d4..e71e67f 100644
--- a/src/JiShe.IoT.HttpApi/Controllers/IoTPlatformAggregationController.cs
+++ b/src/JiShe.IoT.HttpApi/Controllers/IoTPlatformAggregationController.cs
@@ -3,6 +3,7 @@ using JiShe.IoT.DeviceAggregation.Dto;
using JiShe.IoT.IoTPlatformAggregation;
using JiShe.IoT.IoTPlatformAggregation.Dto;
using JiShe.ServicePro;
+using JiShe.ServicePro.Commons;
using JiShe.ServicePro.Core;
using JiShe.ServicePro.DeviceManagement.DeviceInfos;
@@ -31,6 +32,18 @@ namespace JiShe.IoT.Controllers
{
return await _iotPlatformAggregationService.GetIoTPlatformProductInfoAsync(input);
}
-
+
+ ///
+ /// 获取平台产品物模型属性信息
+ ///
+ ///
+ ///
+ [HttpPost(nameof(GetIoTPlatformProductPropertyInfoAsync))]
+ [SwaggerOperation(summary: "获取平台产品物模型属性信息", Tags = new[] { "AggregationIoTPlatform" })]
+ public async Task> GetIoTPlatformProductPropertyInfoAsync(IoTPlatformProductPropertyInfoInput input)
+ {
+ return await _iotPlatformAggregationService.GetIoTPlatformProductPropertyInfoAsync(input);
+ }
+
}
}