From 85214ab407ca962bdb872b7c3bb961d9b0d4a77b Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Wed, 23 Jul 2025 11:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E9=97=B4=E7=94=9F=E4=BA=A7=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appsettings.Development.json | 3 +- .../appsettings.Production.json | 2 +- .../Dto/ProductionEquipmentMessageBody.cs | 17 ++-- .../Workshop/IProductionWorkshopService.cs | 4 +- .../Workshop/ProductionWorkshopService.cs | 77 +++++++++++++++++-- src/JiShe.IoT.DbMigrator/appsettings.json | 2 +- .../ProductionWorkshopController.cs | 16 ++-- 7 files changed, 95 insertions(+), 26 deletions(-) diff --git a/host/JiShe.IoT.HttpApi.Host/appsettings.Development.json b/host/JiShe.IoT.HttpApi.Host/appsettings.Development.json index 84989bd..832d9ee 100644 --- a/host/JiShe.IoT.HttpApi.Host/appsettings.Development.json +++ b/host/JiShe.IoT.HttpApi.Host/appsettings.Development.json @@ -37,13 +37,12 @@ "TreeModelClusterList": [ "47.110.53.196:6667", "47.110.60.222:6667", "47.110.62.104:6667" ], "TableModelClusterList": [ "47.110.53.196:6667", "47.110.60.222:6667", "47.110.62.104:6667" ], "PoolSize": 32, - "TableModelDataBaseName": "energy", + "DataBaseName": "jisheiotdata", "OpenDebugMode": true, "UseTableSessionPoolByDefault": false }, "ServerApplicationOptions": { "ServerTagName": "JiSheCollectBus10", - "SystemType": "Energy", "FirstCollectionTime": "2025-04-28 15:07:00", "AutomaticVerificationTime": "16:07:00", "AutomaticTerminalVersionTime": "17:07:00", diff --git a/host/JiShe.IoT.HttpApi.Host/appsettings.Production.json b/host/JiShe.IoT.HttpApi.Host/appsettings.Production.json index 250e986..8099a27 100644 --- a/host/JiShe.IoT.HttpApi.Host/appsettings.Production.json +++ b/host/JiShe.IoT.HttpApi.Host/appsettings.Production.json @@ -56,7 +56,7 @@ "TreeModelClusterList": [ "172.21.40.198:6667", "172.21.40.197:6667", "172.21.40.199:6667" ], "TableModelClusterList": [ "172.21.40.198:6667", "172.21.40.197:6667", "172.21.40.199:6667" ], "PoolSize": 32, - "TableModelDataBaseName": "energy", + "DataBaseName": "jisheiotdata", "OpenDebugMode": false, "UseTableSessionPoolByDefault": false }, diff --git a/src/JiShe.IoT.Application.Contracts/Workshop/Dto/ProductionEquipmentMessageBody.cs b/src/JiShe.IoT.Application.Contracts/Workshop/Dto/ProductionEquipmentMessageBody.cs index cecacca..60b2c04 100644 --- a/src/JiShe.IoT.Application.Contracts/Workshop/Dto/ProductionEquipmentMessageBody.cs +++ b/src/JiShe.IoT.Application.Contracts/Workshop/Dto/ProductionEquipmentMessageBody.cs @@ -18,16 +18,23 @@ namespace JiShe.IoT.Workshop.Dto /// 表计类型 /// 电表= 1,水表= 2,燃气表= 3,热能表= 4,水表流量计=5,燃气表流量计=6,特殊电表=7 /// - public MeterTypeEnum MeterType { get; set; } + public MeterTypeEnum? MeterType { get; set; } /// - /// 集中器地址 + /// 设备地址 /// - public string FocusAddress { get; set; } + public string DeviceAddress { get; set; } /// - /// 表通信地址 + /// 物联网平台唯一设备标识 + /// CTWing唯一设备标识为:设备Id=CTWing产品Id+推送的设备序列号(集中器地址) + /// OneNET唯一设备标识为:推送的设备名称,为了保持统一,因此推送的设备名称=OneNET产品Id+推送的设备序列号(集中器地址) /// - public string MeterAddress { get; set; } + public string DeviceOpenInfo { get; set; } + + /// + /// 物联网平台对应的产品Id + /// + public string IoTPlatformProductId { get; set; } } } diff --git a/src/JiShe.IoT.Application.Contracts/Workshop/IProductionWorkshopService.cs b/src/JiShe.IoT.Application.Contracts/Workshop/IProductionWorkshopService.cs index 7ef9a77..5b061a6 100644 --- a/src/JiShe.IoT.Application.Contracts/Workshop/IProductionWorkshopService.cs +++ b/src/JiShe.IoT.Application.Contracts/Workshop/IProductionWorkshopService.cs @@ -19,13 +19,13 @@ namespace JiShe.IoT.Workshop /// /// /// - Task ReceiveWorkshopProductionEquipment(ProductionEquipmentInput input); + Task ReceiveOneNetProductionEquipmentInfoAsync(ProductionEquipmentInput input); /// /// 生产车间获取OneNET产品列表 /// - Task>> OneNetProductListForWorkshopAsync(OneNetWorkshopProductListInput input); + Task>> GetOneNetProductListAsync(OneNetWorkshopProductListInput input); } } diff --git a/src/JiShe.IoT.Application/Workshop/ProductionWorkshopService.cs b/src/JiShe.IoT.Application/Workshop/ProductionWorkshopService.cs index 42955db..e49e42e 100644 --- a/src/JiShe.IoT.Application/Workshop/ProductionWorkshopService.cs +++ b/src/JiShe.IoT.Application/Workshop/ProductionWorkshopService.cs @@ -1,12 +1,15 @@ using JiShe.IoT.Workshop.Dto; using JiShe.ServicePro; +using JiShe.ServicePro.Core; using JiShe.ServicePro.DeviceManagement.Focuses; using JiShe.ServicePro.DeviceManagement.Meters; using JiShe.ServicePro.Encrypt; using JiShe.ServicePro.Enums; +using JiShe.ServicePro.OneNET.Provider.Interface; using JiShe.ServicePro.OneNETManagement.OneNETProducts; using JiShe.ServicePro.ServerOptions; using Mapster.Utils; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; @@ -20,7 +23,7 @@ namespace JiShe.IoT.Workshop /// /// 生产车间服务 /// - public class ProductionWorkshopService(IFocusAppService focusAppService, IMeterAppService meterAppService, IOptions options ) : IoTAppService,IProductionWorkshopService + public class ProductionWorkshopService(IFocusAppService focusAppService, IMeterAppService meterAppService, IOneNETRequestService oneNETRequestService, IOptions options, ILogger logger) : IoTAppService, IProductionWorkshopService { ServerApplicationOptions srverOptions = options.Value; @@ -30,7 +33,7 @@ namespace JiShe.IoT.Workshop /// /// [AllowAnonymous] - public async Task ReceiveWorkshopProductionEquipment(ProductionEquipmentInput input) + public async Task ReceiveOneNetProductionEquipmentInfoAsync(ProductionEquipmentInput input) { try @@ -40,12 +43,70 @@ namespace JiShe.IoT.Workshop { return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed); } + + ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize(); + + if (productionEquipmentMessageBody.MeterType.HasValue == false) + { + return HttpDataResultExtensions.Failed("设备类型不能为空", -103, ResponeResultEnum.Fail); + } + + if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId)) + { + return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -104, ResponeResultEnum.Fail); + } + + + if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId)) + { + return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -105, ResponeResultEnum.Fail); + } + + if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceAddress)) + { + return HttpDataResultExtensions.Failed("设备地址不能为空", -106, ResponeResultEnum.Fail); + } + + if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceOpenInfo)) + { + return HttpDataResultExtensions.Failed("物联网平台唯一设备标识,不能为空", -107, ResponeResultEnum.Fail); + } + + var productInfo = await FreeSqlDbContext.Instance.Select() + .Where(e => e.IsEnabled == true && e.IoTPlatformProductId == productionEquipmentMessageBody.IoTPlatformProductId) + .FirstAsync(); + + if (productInfo == null) + { + return HttpDataResultExtensions.Failed("没有找到对应的产品信息", -108, ResponeResultEnum.Fail); + } + + FocusInfo focusInfoEntity = new FocusInfo() { + FocusAddress = productionEquipmentMessageBody.DeviceAddress, + Name = productionEquipmentMessageBody.DeviceOpenInfo, + IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId, + BusinessSystem = BusinessSystemEnum.Energy, + IoTPlatform = IoTPlatformTypeEnum.OneNET, + IoTPlatformDeviceOpenInfo = productionEquipmentMessageBody.DeviceOpenInfo, + PlatformPassword = productInfo.ProductAccesskey, + }; + focusInfoEntity.CreateId(GuidGenerator.Create()); + + MeterInfo meterInfoEntity = new MeterInfo() { MeterAddress = productionEquipmentMessageBody.DeviceAddress, + Password = productInfo.ProductAccesskey, + BusinessSystem = BusinessSystemEnum.Energy, + IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId, + IoTPlatformDeviceOpenInfo = productionEquipmentMessageBody.DeviceOpenInfo, + }; + + //oneNETRequestService + return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed); } - catch (Exception) + catch (Exception ex) { - - throw; + logger.LogError($"{nameof(ReceiveOneNetProductionEquipmentInfoAsync)} 生产车间数据推送发生异常:{ex.Serialize()}"); + return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -101, ResponeResultEnum.Exception); } } @@ -53,7 +114,7 @@ namespace JiShe.IoT.Workshop /// 生产车间获取OneNET产品列表 /// [AllowAnonymous] - public async Task>> OneNetProductListForWorkshopAsync(OneNetWorkshopProductListInput input) + public async Task>> GetOneNetProductListAsync(OneNetWorkshopProductListInput input) { try @@ -63,7 +124,9 @@ namespace JiShe.IoT.Workshop { return HttpDataResultExtensions.Failed>("签名校验失败", -101, ResponeResultEnum.NotAllowed); } - + + ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize(); + var pageListQuery = FreeSqlDbContext.Instance.Select() .Where(e => e.IsEnabled == true) .OrderByDescending(e => e.CreationTime); diff --git a/src/JiShe.IoT.DbMigrator/appsettings.json b/src/JiShe.IoT.DbMigrator/appsettings.json index 4b26633..4b7791b 100644 --- a/src/JiShe.IoT.DbMigrator/appsettings.json +++ b/src/JiShe.IoT.DbMigrator/appsettings.json @@ -10,7 +10,7 @@ //"TreeModelClusterList": [ "192.168.111.37:6667" ], //"TableModelClusterList": [ "192.168.111.37:6667" ], "PoolSize": 32, - "TableModelDataBaseName": "energy", + "DataBaseName": "jisheiotdata", "OpenDebugMode": true, "UseTableSessionPoolByDefault": false } diff --git a/src/JiShe.IoT.HttpApi/Controllers/ProductionWorkshopController.cs b/src/JiShe.IoT.HttpApi/Controllers/ProductionWorkshopController.cs index f0ce035..61dc36e 100644 --- a/src/JiShe.IoT.HttpApi/Controllers/ProductionWorkshopController.cs +++ b/src/JiShe.IoT.HttpApi/Controllers/ProductionWorkshopController.cs @@ -26,25 +26,25 @@ namespace JiShe.IoT.Controllers } /// - /// 接收车间生产设备信息 + /// 接收车间生产OneNET设备信息 /// /// /// - [HttpGet("WorkshopProductionEquipment")] - [SwaggerOperation(summary: "车间生产设备信息", Tags = new[] { "Workshop" })] - public async Task ReceiveWorkshopProductionEquipment(ProductionEquipmentInput input) + [HttpPost(nameof(ReceiveOneNetProductionEquipmentInfoAsync))] + [SwaggerOperation(summary: "接收车间生产OneNET设备信息", Tags = new[] { "Workshop" })] + public async Task ReceiveOneNetProductionEquipmentInfoAsync(ProductionEquipmentInput input) { - await _productionWorkshopService.ReceiveWorkshopProductionEquipment(input); + await _productionWorkshopService.ReceiveOneNetProductionEquipmentInfoAsync(input); } /// /// 生产车间获取OneNET产品列表 /// - [HttpPost(nameof(OneNetProductListForWorkshopAsync))] + [HttpPost(nameof(GetOneNetProductListAsync))] [SwaggerOperation(summary: "生产车间获取OneNET产品列表", Tags = new[] { "Workshop" })] - public async Task>> OneNetProductListForWorkshopAsync(OneNetWorkshopProductListInput input) + public async Task>> GetOneNetProductListAsync(OneNetWorkshopProductListInput input) { - return await _productionWorkshopService.OneNetProductListForWorkshopAsync(input); + return await _productionWorkshopService.GetOneNetProductListAsync(input); } } }