From 15a66c1275aea6111103d71f3feee98202c86dc1 Mon Sep 17 00:00:00 2001 From: zenghongyao <873884283@qq.com> Date: Mon, 23 Jun 2025 11:21:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98iotdb=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=BF=A1=E6=81=AF=E5=92=8C=E9=9B=86=E4=B8=AD?= =?UTF-8?q?=E5=99=A8=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnalysisData/DataStorage.cs | 89 ++++++++++++++++++- ...ceCommunicationChannelSubscriberService.cs | 11 +-- .../Consts/T37612012PacketItemCodeConst.cs | 10 +++ 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs index 2721c07..9c0f8b1 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs @@ -222,6 +222,32 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData SingleMeasuring = (IotDbFieldConst.DatabaseBusiID, data.DatabaseBusiID) }; await _dbProvider.GetSessionPool(false).InsertAsync(meterIsDatabaseBusiID); + + // 表地址 + var meterAddress = new TreeModelSingleMeasuringEntity() + { + SystemName = _applicationOptions.SystemType, + DeviceId = $"{data.DeviceId}", + DeviceType = $"{data.DeviceType}", + ProjectId = $"{data.ProjectId}", + IoTDataType = analysisBaseDto.DataType, + Timestamps = meter.Timestamps, + SingleMeasuring = (IotDbFieldConst.MeterAddress, data.DeviceAddress) + }; + await _dbProvider.GetSessionPool(false).InsertAsync(meterAddress); + + // 集中器地址 + var focusAddress = new TreeModelSingleMeasuringEntity() + { + SystemName = _applicationOptions.SystemType, + DeviceId = $"{data.DeviceId}", + DeviceType = $"{data.DeviceType}", + ProjectId = $"{data.ProjectId}", + IoTDataType = analysisBaseDto.DataType, + Timestamps = meter.Timestamps, + SingleMeasuring = (IotDbFieldConst.FocusAddress, analysisBaseDto.Code) + }; + await _dbProvider.GetSessionPool(false).InsertAsync(focusAddress); } return await Task.FromResult(true); } @@ -241,6 +267,9 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData List> treeModelSingleMeasuringEntities = new List>(); List> meterIsSyncs = new List>(); List> meterDataBaseIDs = new List>(); + List> meterAddresss = new List>(); + List> focusAddresss = new List>(); + foreach (var item in data) { @@ -362,7 +391,35 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData }; if (!meterDataBaseIDs.Any(a => a.IoTDataType == meterIsSync.IoTDataType && a.ProjectId == meterIsSync.ProjectId && a.SystemName == meterIsSync.SystemName && a.DeviceId == meterIsSync.DeviceId && a.Timestamps == meterIsSync.Timestamps)) meterDataBaseIDs.Add(meterIsDatabaseBusiID); - + + // 表地址 + var meterAddress = new TreeModelSingleMeasuringEntity() + { + SystemName = _applicationOptions.SystemType, + DeviceId = $"{item.DeviceId}", + DeviceType = $"{item.DeviceType}", + ProjectId = $"{item.ProjectId}", + IoTDataType = analysisBaseDto.DataType, + Timestamps = meter.Timestamps, + SingleMeasuring = (IotDbFieldConst.MeterAddress, item.DeviceAddress) + }; + if (!meterAddresss.Any(a => a.IoTDataType == meterAddress.IoTDataType && a.ProjectId == meterAddress.ProjectId && a.SystemName == meterAddress.SystemName && a.DeviceId == meterAddress.DeviceId && a.Timestamps == meterAddress.Timestamps)) + meterAddresss.Add(meterAddress); + + // 集中器地址 + var focusAddress = new TreeModelSingleMeasuringEntity() + { + SystemName = _applicationOptions.SystemType, + DeviceId = $"{item.DeviceId}", + DeviceType = $"{item.DeviceType}", + ProjectId = $"{item.ProjectId}", + IoTDataType = analysisBaseDto.DataType, + Timestamps = meter.Timestamps, + SingleMeasuring = (IotDbFieldConst.FocusAddress, analysisBaseDto.Code) + }; + if (!focusAddresss.Any(a => a.IoTDataType == focusAddress.IoTDataType && a.ProjectId == focusAddress.ProjectId && a.SystemName == focusAddress.SystemName && a.DeviceId == focusAddress.DeviceId && a.Timestamps == focusAddress.Timestamps)) + focusAddresss.Add(focusAddress); + } } // 批量保存数据 @@ -374,7 +431,8 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData // 报存标识字段 await _dbProvider.GetSessionPool(false).BatchInsertAsync(meterIsSyncs); await _dbProvider.GetSessionPool(false).BatchInsertAsync(meterDataBaseIDs); - + await _dbProvider.GetSessionPool(false).BatchInsertAsync(meterAddresss); + await _dbProvider.GetSessionPool(false).BatchInsertAsync(focusAddresss); } return await Task.FromResult(true); } @@ -410,6 +468,19 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData SingleMeasuring = (data.FiledName!, data.DataValue!) }; await _dbProvider.GetSessionPool(false).InsertAsync(treeData); + + var focusAddressData = new TreeModelSingleMeasuringEntity() + { + SystemName = _applicationOptions.SystemType, + DeviceId = $"{data.DeviceId}", + DeviceType = $"{data.DeviceType}", + ProjectId = $"{data.ProjectId}", + IoTDataType = IOTDBDataTypeConst.Status, + Timestamps = timestamps, + SingleMeasuring = (IotDbFieldConst.FocusAddress, data.DataValue!) + }; + await _dbProvider.GetSessionPool(false).InsertAsync(focusAddressData); + // 数据帧 var treeFrameData = new TreeModelSingleMeasuringEntity() { @@ -512,6 +583,20 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData SingleMeasuring = (item.FiledName!, item.DataValue!) }; await _dbProvider.GetSessionPool(false).InsertAsync(treeData); + + + var focusAddressData = new TreeModelSingleMeasuringEntity() + { + SystemName = _applicationOptions.SystemType, + DeviceId = $"{item.DeviceId}", + DeviceType = $"{item.DeviceType}", + ProjectId = $"{item.ProjectId}", + IoTDataType = IOTDBDataTypeConst.Status, + Timestamps = timestamps, + SingleMeasuring = (IotDbFieldConst.FocusAddress, item.DataValue!) + }; + await _dbProvider.GetSessionPool(false).InsertAsync(focusAddressData); + // 数据帧 var treeFrameData = new TreeModelSingleMeasuringEntity() { diff --git a/services/JiShe.CollectBus.Application/Subscribers/ServiceCommunicationChannelSubscriberService.cs b/services/JiShe.CollectBus.Application/Subscribers/ServiceCommunicationChannelSubscriberService.cs index d753ddc..97b6fc0 100644 --- a/services/JiShe.CollectBus.Application/Subscribers/ServiceCommunicationChannelSubscriberService.cs +++ b/services/JiShe.CollectBus.Application/Subscribers/ServiceCommunicationChannelSubscriberService.cs @@ -80,15 +80,14 @@ namespace JiShe.CollectBus.Subscribers switch (input.MeterType) { case MeterTypeEnum.Ammeter: - await SendArchivalDataIssued(input); + tempResult = await SendArchivalDataIssued(input); break; case MeterTypeEnum.WaterMeter: - await SendArchivalDataIssued(input); + tempResult = await SendArchivalDataIssued(input); break; } } - //tempResult = await SendArchivalDataIssued(focusCacheInfo); } break; case ServiceCommunicationTypeEnum.SetItemCodeTask: @@ -96,7 +95,7 @@ namespace JiShe.CollectBus.Subscribers SetItemCodeTaskInput? input = tempFirstKeyInfo.Value!.Deserialize(); if(input != null) { - await AutoCollectionItemsSetAsync(input); + tempResult = await AutoCollectionItemsSetAsync(input); } } break; @@ -135,7 +134,7 @@ namespace JiShe.CollectBus.Subscribers Pn =deviceCacheInfo.MeteringCode, BaudRate = Build3761SendData.GetBaudreate($"{deviceCacheInfo.Baudrate}"), Port = deviceCacheInfo.MeteringPort, - ProtocolType = deviceCacheInfo.Protocol.Value, + ProtocolType = deviceCacheInfo.Protocol ?? 30, Address = deviceCacheInfo.MeterAddress, Password = deviceCacheInfo.Password, RateNumber = deviceCacheInfo.SingleRate == true ? 1 : 4, @@ -151,6 +150,8 @@ namespace JiShe.CollectBus.Subscribers reqParameter = returnParameter; }); + string frame = bytes.ToHexString(); + // TODO: 需要插入iotdb 日志 await SaveLogTodIotDbAsync(deviceCacheInfo, reqParameter); diff --git a/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs b/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs index d703059..98db13e 100644 --- a/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs +++ b/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs @@ -210,6 +210,16 @@ namespace JiShe.CollectBus.Common.Consts /// public const string DatabaseBusiID= "DatabaseBusiID"; + /// + /// 集中器地址 + /// + public const string FocusAddress = "FocusAddress"; + + /// + /// 表地址 + /// + public const string MeterAddress = "MeterAddress"; + } #endregion