From 72c50311b6ad493d932e6c183280987034b7b762 Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Thu, 22 May 2025 17:29:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B0=B4=E8=A1=A8=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Provider/IoTDBProvider.cs | 2 +- .../SendData/Telemetry1882018PacketBuilder.cs | 26 +- .../T1882018ProtocolPlugin.cs | 5 +- .../T6452007ProtocolPlugin.cs | 32 --- .../RedisDataCache/IRedisDataCacheService.cs | 12 +- .../CollectBusApplicationModule.cs | 1 + .../RedisDataCache/RedisDataCacheService.cs | 91 ++++--- .../BasicScheduledMeterReadingService.cs | 183 +++++++------ ...nergySystemScheduledMeterReadingService.cs | 251 ++++++++++-------- .../IotSystems/Devices/DeviceInfo.cs | 3 +- .../Consts/T1882018PacketItemCodeConst.cs | 17 +- .../Consts/T37612012PacketItemCodeConst.cs | 34 ++- 12 files changed, 371 insertions(+), 286 deletions(-) diff --git a/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs b/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs index a42aaf3..1d22c33 100644 --- a/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs +++ b/modules/JiShe.CollectBus.IoTDB/Provider/IoTDBProvider.cs @@ -1087,7 +1087,7 @@ namespace JiShe.CollectBus.IoTDB.Provider stringBuilder.Append(string.Join(",", tempColumInfos.Where(d => !string.IsNullOrWhiteSpace(d)))); stringBuilder.Append($" ) COMMENT '{item.Name}' "); - _logger.LogError($"{dynamicAccessor.EntityName} 初始化语句:{stringBuilder.ToString()}"); + _logger.LogWarning($"{dynamicAccessor.EntityName} 初始化语句:{stringBuilder.ToString()}"); await CurrentSession.ExecuteNonQueryStatementAsync($"{stringBuilder.ToString()}"); } diff --git a/protocols/JiShe.CollectBus.Protocol.T1882018/SendData/Telemetry1882018PacketBuilder.cs b/protocols/JiShe.CollectBus.Protocol.T1882018/SendData/Telemetry1882018PacketBuilder.cs index 7dc8e43..362fd08 100644 --- a/protocols/JiShe.CollectBus.Protocol.T1882018/SendData/Telemetry1882018PacketBuilder.cs +++ b/protocols/JiShe.CollectBus.Protocol.T1882018/SendData/Telemetry1882018PacketBuilder.cs @@ -38,16 +38,19 @@ namespace JiShe.CollectBus.Protocol.T1882018.SendData #region 读数据 /// - /// 读取计量数据 + /// 读取计量数据,CTR0_控制码(01H/09H)_DI1_DI0_SER /// /// /// - public static Telemetry1882018PacketResponse CTR_01_Send(Telemetry1882018PacketRequest request) + public static Telemetry1882018PacketResponse CTR0_01_Send(Telemetry1882018PacketRequest request) { var itemCodeArr = request.ItemCode.Split('_'); - var c_data = itemCodeArr[0];//01 - var d_data = itemCodeArr[2];//91 或者 90 - var dataUnit = new List() { "1F", d_data, "00" }; + var ctr = itemCodeArr[0];//CTR0 + var c_data = itemCodeArr[1];//01 + var DI1 = itemCodeArr[2];//91 或者 90 + var DI0 = itemCodeArr[3];//1F + var SER = itemCodeArr[4];//00 + var dataUnit = new List() { DI1, DI0, SER }; var dataList = Build188SendData.Build188SendCommand(request.MeterAddress, c_data, dataUnit); return new Telemetry1882018PacketResponse() { Data = dataList }; @@ -56,16 +59,19 @@ namespace JiShe.CollectBus.Protocol.T1882018.SendData #region 写数据 /// - /// 阀控 + /// 写数据,CTR3_控制码(04H/0CH)_DI1_DI0_SER /// /// /// - public static Telemetry1882018PacketResponse CTR_04_Send(Telemetry1882018PacketRequest request) + public static Telemetry1882018PacketResponse CTR3_04_Send(Telemetry1882018PacketRequest request) { var itemCodeArr = request.ItemCode.Split('_'); - var c_data = itemCodeArr[0];//01 - var d_data = itemCodeArr[2];//55 或者 99 - var dataUnit = new List() { "A0", "17", "00", d_data }; + var ctr = itemCodeArr[0];//CTR3 + var c_data = itemCodeArr[1];//04 + var DI1 = itemCodeArr[2];//A0 + var DI0 = itemCodeArr[3];//17 + var SER = itemCodeArr[4];//55 或者 99 + var dataUnit = new List() { DI1, DI0, SER }; var dataList = Build188SendData.Build188SendCommand(request.MeterAddress, c_data, dataUnit); return new Telemetry1882018PacketResponse() { Data = dataList }; diff --git a/protocols/JiShe.CollectBus.Protocol.T1882018/T1882018ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.T1882018/T1882018ProtocolPlugin.cs index 7b0edbe..c245fb0 100644 --- a/protocols/JiShe.CollectBus.Protocol.T1882018/T1882018ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.T1882018/T1882018ProtocolPlugin.cs @@ -93,9 +93,9 @@ namespace JiShe.CollectBus.Protocol.T1882018 //数据转发场景 10H_F1 if (request.ItemCode == T37612012PacketItemCodeConst.AFN10HFN01H && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false) { - //var subItemCodeArr = request.SubProtocolRequest.ItemCode.Split("_"); + var subItemCodeArr = request.SubProtocolRequest.ItemCode.Split("_"); - var t188PacketHandlerName = $"{T1882018PacketItemCodeConst.BasicT1882018}_{request.SubProtocolRequest.ItemCode}_Send"; + var t188PacketHandlerName = $"{subItemCodeArr[0]}_{subItemCodeArr[1]}_Send"; Telemetry1882018PacketResponse t645PacketResponse = null; if (T188ControlHandlers != null && T188ControlHandlers.TryGetValue(t188PacketHandlerName @@ -124,6 +124,7 @@ namespace JiShe.CollectBus.Protocol.T1882018 FocusAddress = request.FocusAddress, Fn = fn, Pn = request.Pn, + SubRequest = request.SubProtocolRequest, DataUnit = dataUnit, }); } diff --git a/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs index 98b1e7f..8b76942 100644 --- a/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs @@ -36,38 +36,6 @@ namespace JiShe.CollectBus.Protocol.T6452007 public override async Task AnalyzeAsync(ITcpSessionClient client, string messageReceived, Action? sendAction = null) { - //TODO:645解析报文 - //TB3761? tB3761 = Analysis3761(messageReceived); - //if (tB3761 != null) - //{ - // if (tB3761.AFN_FC?.AFN == (int)AFN.链路接口检测) - // { - // if (tB3761.A == null || tB3761.A.Code.IsNullOrWhiteSpace() || tB3761.A.A3?.D1_D7 == null || tB3761.SEQ?.PSEQ == null) - // { - // _logger.LogError($"解析AFN.链路接口检测报文失败,报文:{messageReceived},TB3761:{tB3761.Serialize()}"); - // } - // else - // { - // if (tB3761.DT?.Fn == (int)FN.登录) - // { - // // 登录回复 - // if (tB3761.SEQ.CON == (int)CON.需要对该帧进行确认) - // await LoginAsync(client, messageReceived, tB3761.A.Code, tB3761.A.A3?.D1_D7, tB3761.SEQ?.PSEQ); - // } - // else if (tB3761.DT?.Fn == (int)FN.心跳) - // { - // // 心跳回复 - // //心跳帧有两种情况: - // //1. 集中器先有登录帧,再有心跳帧 - // //2. 集中器没有登录帧,只有心跳帧 - // await HeartbeatAsync(client, messageReceived, tB3761.A.Code, tB3761.A.A3?.D1_D7, tB3761.SEQ?.PSEQ); - // } - // } - - // } - // await OnTcpNormalReceived(client, tB3761); - //} - //return (tB3761 as T)!; return null; } diff --git a/services/JiShe.CollectBus.Application.Contracts/RedisDataCache/IRedisDataCacheService.cs b/services/JiShe.CollectBus.Application.Contracts/RedisDataCache/IRedisDataCacheService.cs index 5ed2924..e28417b 100644 --- a/services/JiShe.CollectBus.Application.Contracts/RedisDataCache/IRedisDataCacheService.cs +++ b/services/JiShe.CollectBus.Application.Contracts/RedisDataCache/IRedisDataCacheService.cs @@ -17,15 +17,13 @@ namespace JiShe.CollectBus.Application.Contracts /// 单个添加数据 /// /// - /// 主数据存储Hash缓存Key /// Set索引缓存Key - /// ZSET索引缓存Key + /// hash缓存Key /// 待缓存数据 /// Task InsertDataAsync( - string redisHashCacheKey, string redisSetIndexCacheKey, - string redisZSetScoresIndexCacheKey, + string redisDeviceInfoHashCacheKey, T data) where T : DeviceCacheBasicModel; @@ -47,15 +45,13 @@ namespace JiShe.CollectBus.Application.Contracts /// 删除缓存信息 /// /// - /// 主数据存储Hash缓存Key /// Set索引缓存Key - /// ZSET索引缓存Key + /// hash缓存Key /// 已缓存数据 /// Task RemoveCacheDataAsync( - string redisHashCacheKey, string redisSetIndexCacheKey, - string redisZSetScoresIndexCacheKey, + string redisDeviceInfoHashCacheKey, T data) where T : DeviceCacheBasicModel; /// diff --git a/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs b/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs index 1d41ad4..b146d6f 100644 --- a/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs +++ b/services/JiShe.CollectBus.Application/CollectBusApplicationModule.cs @@ -95,5 +95,6 @@ public class CollectBusApplicationModule : AbpModule //默认初始化表计信息 var dbContext = context.ServiceProvider.GetRequiredService(); await dbContext.InitAmmeterCacheData("V4-Gather-8890"); + await dbContext.InitWatermeterCacheData("V4-Gather-8890"); } } \ No newline at end of file diff --git a/services/JiShe.CollectBus.Application/RedisDataCache/RedisDataCacheService.cs b/services/JiShe.CollectBus.Application/RedisDataCache/RedisDataCacheService.cs index cc64378..c59fb4f 100644 --- a/services/JiShe.CollectBus.Application/RedisDataCache/RedisDataCacheService.cs +++ b/services/JiShe.CollectBus.Application/RedisDataCache/RedisDataCacheService.cs @@ -17,6 +17,7 @@ using static FreeSql.Internal.GlobalFilter; using static System.Runtime.InteropServices.JavaScript.JSType; using static Volo.Abp.UI.Navigation.DefaultMenuNames.Application; using JiShe.CollectBus.IotSystems.Ammeters; +using System.IO.Pipelines; namespace JiShe.CollectBus.RedisDataCache { @@ -47,21 +48,18 @@ namespace JiShe.CollectBus.RedisDataCache /// 单个添加数据 /// /// - /// 主数据存储Hash缓存Key /// Set索引缓存Key - /// ZSET索引缓存Key + /// hash缓存Key /// 待缓存数据 /// public async Task InsertDataAsync( - string redisHashCacheKey, string redisSetIndexCacheKey, - string redisZSetScoresIndexCacheKey, + string redisDeviceInfoHashCacheKey, T data) where T : DeviceCacheBasicModel { // 参数校验增强 - if (data == null || string.IsNullOrWhiteSpace(redisHashCacheKey) - || string.IsNullOrWhiteSpace(redisSetIndexCacheKey) - || string.IsNullOrWhiteSpace(redisZSetScoresIndexCacheKey)) + if (data == null || string.IsNullOrWhiteSpace(redisSetIndexCacheKey) + || string.IsNullOrWhiteSpace(redisDeviceInfoHashCacheKey)) { _logger.LogError($"{nameof(InsertDataAsync)} 参数异常,-101"); return; @@ -70,14 +68,27 @@ namespace JiShe.CollectBus.RedisDataCache // 使用事务保证原子性 using (var trans = Instance.Multi()) { - // 主数据存储Hash - trans.HSet(redisHashCacheKey, data.MemberId, data.Serialize()); + // Set索引缓存 + trans.SAdd(redisSetIndexCacheKey, $"{data.TimeDensity.ToString().PadLeft(2, '0')}:{data.FocusAddress}"); - // 集中器号分组索引Set缓存 - trans.SAdd(redisSetIndexCacheKey, data.MemberId); + //检查HSet是否存在对应的信息,如果存在,需要进一步检查value是否已经存在,如果存在则更新,不存在则添加 + var oldValue = Instance.HGet>(redisDeviceInfoHashCacheKey, data.FocusAddress); + if (oldValue == null || oldValue.Count <= 0)//直接添加 + { + //设备信息缓存 + trans.HSet(redisDeviceInfoHashCacheKey, data.FocusAddress, data); + } + else + { + // 移除缓存中同类型旧数据 + oldValue.RemoveAll(device => device.MeterType == data.MeterType); - // 集中器与表计信息排序索引ZSET缓存Key - trans.ZAdd(redisZSetScoresIndexCacheKey, data.ScoreValue, data.MemberId); + //添加新数据 + oldValue.Add(data); + + //设备信息缓存 + trans.HSet(redisDeviceInfoHashCacheKey, data.FocusAddress, oldValue); + } var results = trans.Exec(); @@ -125,13 +136,28 @@ namespace JiShe.CollectBus.RedisDataCache using (var pipe = Instance.StartPipe()) { foreach (var item in batch) - { + { // Set索引缓存 pipe.SAdd(redisSetIndexCacheKey, $"{item.Value.First().TimeDensity.ToString().PadLeft(2, '0')}:{item.Value.First().FocusAddress}"); - - //设备信息缓存 - pipe.HSet(redisDeviceInfoHashCacheKey, item.Key, item.Value.Serialize()); + //检查HSet是否存在对应的信息,如果存在,需要进一步检查value是否已经存在,如果存在则更新,不存在则添加 + var oldValue = Instance.HGet>(redisDeviceInfoHashCacheKey, item.Key); + if (oldValue == null || oldValue.Count <= 0)//直接添加 + { + //设备信息缓存 + pipe.HSet(redisDeviceInfoHashCacheKey, item.Key, item.Value); + } + else + { + // 移除缓存中同类型旧数据 + oldValue.RemoveAll(device => device.MeterType == item.Value[0].MeterType); + + //添加新数据 + oldValue.AddRange(item.Value); + + //设备信息缓存 + pipe.HSet(redisDeviceInfoHashCacheKey, item.Key, oldValue); + } } pipe.EndPipe(); } @@ -146,21 +172,18 @@ namespace JiShe.CollectBus.RedisDataCache /// 删除缓存信息 /// /// - /// 主数据存储Hash缓存Key /// Set索引缓存Key - /// ZSET索引缓存Key + /// hash缓存Key /// 已缓存数据 /// public async Task RemoveCacheDataAsync( - string redisHashCacheKey, string redisSetIndexCacheKey, - string redisZSetScoresIndexCacheKey, + string redisDeviceInfoHashCacheKey, T data) where T : DeviceCacheBasicModel { if (data == null - || string.IsNullOrWhiteSpace(redisHashCacheKey) - || string.IsNullOrWhiteSpace(redisSetIndexCacheKey) - || string.IsNullOrWhiteSpace(redisZSetScoresIndexCacheKey)) + || string.IsNullOrWhiteSpace(redisDeviceInfoHashCacheKey) + || string.IsNullOrWhiteSpace(redisSetIndexCacheKey) ) { _logger.LogError($"{nameof(RemoveCacheDataAsync)} 参数异常,-101"); return; @@ -168,32 +191,30 @@ namespace JiShe.CollectBus.RedisDataCache const string luaScript = @" local hashCacheKey = KEYS[1] - local setIndexCacheKey = KEYS[2] - local zsetScoresIndexCacheKey = KEYS[3] - local member = ARGV[1] + local setIndexCacheKey = KEYS[2] + local focusAddress = ARGV[1] + local scoreValue = ARGV[2] local deleted = 0 - if redis.call('HDEL', hashCacheKey, member) > 0 then + if redis.call('HDEL', hashCacheKey, focusAddress) > 0 then deleted = 1 end - redis.call('SREM', setIndexCacheKey, member) - redis.call('ZREM', zsetScoresIndexCacheKey, member) + redis.call('SREM', setIndexCacheKey, scoreValue) return deleted "; var keys = new[] { - redisHashCacheKey, - redisSetIndexCacheKey, - redisZSetScoresIndexCacheKey + redisDeviceInfoHashCacheKey, + redisSetIndexCacheKey }; - var result = await Instance.EvalAsync(luaScript, keys, new[] { data.MemberId }); + var result = await Instance.EvalAsync(luaScript, keys, new object[] { data.FocusAddress , data.ScoreValue}); if ((int)result == 0) { - _logger.LogError($"{nameof(RemoveCacheDataAsync)} 删除指定Key{redisHashCacheKey}的{data.MemberId}数据失败,-102"); + _logger.LogError($"{nameof(RemoveCacheDataAsync)} 删除指定Key{redisDeviceInfoHashCacheKey}的{data.MemberId}数据失败,-102"); } } diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs index 5ec68a6..f53b21a 100644 --- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs @@ -8,6 +8,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Common.Helpers; using JiShe.CollectBus.Common.Models; using JiShe.CollectBus.DataChannels; +using JiShe.CollectBus.EnergySystems.Entities; using JiShe.CollectBus.GatherItem; using JiShe.CollectBus.IoTDB.Interface; using JiShe.CollectBus.IoTDB.Model; @@ -28,6 +29,9 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Volo.Abp.Guids; +using static FreeSql.Internal.GlobalFilter; +using static Microsoft.AspNetCore.Razor.Language.TagHelperMetadata; +using static Thrift.Protocol.Utilities.TJSONProtocolConstants; namespace JiShe.CollectBus.ScheduledMeterReading { @@ -129,12 +133,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading var tempArryay = item.Split(":"); string meteryType = tempArryay[4];//表计类别 int timeDensity = Convert.ToInt32(tempArryay[5]);//采集频率 - if (timeDensity > 15) - { - timeDensity = 15; - } - - + //电表定时广播校时,一天一次。 string currentTimeStr = $"{currentTime:HH:mm:00}"; if (string.Equals(currentTimeStr, _applicationOptions.AutomaticVerificationTime, StringComparison.CurrentCultureIgnoreCase))//自动校时 @@ -243,6 +242,12 @@ namespace JiShe.CollectBus.ScheduledMeterReading if (meteryType == MeterTypeEnum.Ammeter.ToString()) { + //电表最大采集频率为15分钟 + if (timeDensity > 15) + { + timeDensity = 15; + } + _ = CreateMeterPublishTask( timeDensity: timeDensity, nextTaskTime: currentTaskTime, @@ -418,8 +423,10 @@ namespace JiShe.CollectBus.ScheduledMeterReading deviceIds.Add(ammeter.MeterId.ToString()); //处理ItemCode - if (string.IsNullOrWhiteSpace(ammeter.ItemCodes) && !string.IsNullOrWhiteSpace(ammeter.DataTypes)) + if (ammeter.ItemCodes == null && !string.IsNullOrWhiteSpace(ammeter.DataTypes)) { + ammeter.ItemCodes = new List(); + var itemArr = ammeter.DataTypes.Split(',').ToList(); #region 拼接采集项 @@ -432,7 +439,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading { if (!excludeItemCode.Contains(gatherItem.ItemCode)) { - itemCodeList.Add(gatherItem.ItemCode); + itemCodeList.Add(gatherItem.ItemCode.Replace("WAVE_109", "10_109")); } } @@ -451,16 +458,11 @@ namespace JiShe.CollectBus.ScheduledMeterReading - ammeter.ItemCodes = itemCodeList.Serialize();//转换成JSON字符串 - - if (!string.IsNullOrWhiteSpace(ammeter.ItemCodes)) - { - ammeter.ItemCodes = ammeter.ItemCodes.Replace("WAVE_109", "10_109"); - } + ammeter.ItemCodes = itemCodeList; } - var tempItemCodeList = new List() { "10_97" }; - ammeter.ItemCodes = tempItemCodeList.Serialize(); + //var tempItemCodeList = new List() { "10_97" }; + //ammeter.ItemCodes = tempItemCodeList.Serialize(); if (!keyValuePairs.ContainsKey(ammeter.FocusAddress)) { @@ -628,7 +630,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading return null; } - if (string.IsNullOrWhiteSpace(ammeterInfo.ItemCodes)) + if (ammeterInfo.ItemCodes == null || ammeterInfo.ItemCodes.Count <=0) { //_logger.LogError($"{nameof(AmmerterCreatePublishTaskAction)} 集中器{ammeterInfo.FocusAddress}的电表{ammeterInfo.Name}数据采集指令生成失败,采集项为空,-101"); return null; @@ -675,7 +677,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading return null; } - List tempCodes = ammeterInfo.ItemCodes.Deserialize>()!; + List tempCodes = ammeterInfo.ItemCodes!; //TODO:自动上报数据只主动采集1类数据。 if (ammeterInfo.AutomaticReport.Equals(1)) @@ -1151,6 +1153,42 @@ namespace JiShe.CollectBus.ScheduledMeterReading throw new NullReferenceException($"{nameof(InitAmmeterCacheData)} 初始化水表缓存数据时,采集项类型数据为空"); } + if (meterInfos != null && meterInfos.Count > 0) + { + foreach (var item in meterInfos) + { + + if (item.MeterTypeName.Equals("水表") && (item.Protocol.Equals((int)MeterLinkProtocol.CJT_188_2018) || item.Protocol.Equals((int)MeterLinkProtocol.DLT_645_1997) || item.Protocol.Equals((int)MeterLinkProtocol.DLT_645_2007))) + { + if (item.BrandType.Contains("炬华有线")) + { + item.ItemCodes = new List() { T37612012PacketItemCodeConst.AFN0CHFN188H }; + } + else + { + item.ItemCodes = new List() { T37612012PacketItemCodeConst.AFN0CHFN129H }; + } + } + else if (item.MeterTypeName.Trim().Equals("西恩超声波流量计")) + { + item.ItemCodes = new List() { T37612012PacketItemCodeConst.AFN09HFN01H }; + } + else if (item.MeterTypeName.Trim().Equals("江苏华海涡街流量计积算仪")) + { + item.ItemCodes = new List() { T37612012PacketItemCodeConst.AFN09HFN01H }; + } + else if (item.MeterTypeName.Trim().Equals("V880BR涡街流量计")) + { + item.ItemCodes = new List() { T37612012PacketItemCodeConst.AFN09HFN01H }; + } + else if (item.MeterTypeName.Trim().Equals("拓思特涡街流量计H880BR")) + { + item.ItemCodes = new List() { T37612012PacketItemCodeConst.AFN09HFN01H }; + } + + } + } + List deviceIds = new List();//用于处理Kafka主题分区数据的分发和处理。 //根据采集频率分组,获得采集频率分组 @@ -1301,68 +1339,65 @@ namespace JiShe.CollectBus.ScheduledMeterReading var protocolPlugin = await _protocolService.GetProtocolServiceAsync(watermeter.BrandType); if (protocolPlugin == null) { - //_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有找到对应的协议组件,-105"); - //return; + _logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 创建水表待发送的任务数据时{currentTime}没有找到对应的协议组件,-101"); + return null; } - string itemCode = T37612012PacketItemCodeConst.AFN10HFN01H; - string subItemCode = T1882018PacketItemCodeConst.CTR0190; - - ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest() + if (watermeter.ItemCodes == null || watermeter.ItemCodes.Count <=0) { - FocusAddress = watermeter.FocusAddress, - Pn = watermeter.MeteringCode, - ItemCode = itemCode, - SubProtocolRequest = new SubProtocolBuildRequest() + _logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 创建水表待发送的任务数据时{watermeter.Name}没有相应的采集项,-102"); + return null; + } + + foreach (var item in watermeter.ItemCodes) + { + var tempRequest = new ProtocolBuildRequest() { - MeterAddress = watermeter.MeterAddress, - Password = watermeter.Password, - ItemCode = subItemCode, + FocusAddress = watermeter.FocusAddress, + Pn = watermeter.MeteringCode, + ItemCode = item, + }; + + if (item == T37612012PacketItemCodeConst.AFN09HFN01H) + { + //var itemCodeInfo = T37612012PacketItemCodeConst.MappingItemCodeTo188SubCodeRelationship(T37612012PacketItemCodeConst.AFN10HFN99H, true);//阀控 + tempRequest.SubProtocolRequest = new SubProtocolBuildRequest() + { + MeterAddress = watermeter.MeterAddress, + Password = watermeter.Password, + ItemCode = T1882018PacketItemCodeConst.CTR01901F00, + MeteringPort = watermeter.MeteringPort, + Baudrate = watermeter.Baudrate, + }; } - }); - if (builderResponse == null || builderResponse.Data.Length <= 0) - { - //_logger.LogWarning($"{nameof(AmmerterCreatePublishTask)} 集中器{ammeterInfo.FocusAddress}的电表{ammeterInfo.Name}采集项{tempItem}未能正确获取报文。"); - return null; + + ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(tempRequest); + + if (builderResponse == null || builderResponse.Data.Length <= 0) + { + //_logger.LogWarning($"{nameof(AmmerterCreatePublishTask)} 集中器{ammeterInfo.FocusAddress}的电表{ammeterInfo.Name}采集项{tempItem}未能正确获取报文。"); + return null; + } + + if (builderResponse == null || builderResponse.Data.Length <= 0) + { + _logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的水表{watermeter.Name} 水表采抄读采集项{T1882018PacketItemCodeConst.CTR01901F00}未能正确获取报文。"); + return null; + } + + var meterReadingRecords = CreateAmmeterPacketInfo( + ammeterInfo: watermeter, + timestamps: currentTime.GetDateTimeOffset().ToUnixTimeNanoseconds(), + builderResponse: builderResponse, + itemCode: T37612012PacketItemCodeConst.AFN10HFN01H, + subItemCode: T1882018PacketItemCodeConst.CTR01901F00, + pendingCopyReadTime: currentTime, + creationTime: currentTime, + packetType: TelemetryPacketTypeEnum.WatermeterAutoReadding, + _guidGenerator); + taskList.Add(meterReadingRecords); } - - if (builderResponse == null || builderResponse.Data.Length <= 0) - { - _logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的水表{watermeter.Name}采集项{itemCode}未能正确获取报文。"); - return null; - } - - - string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, watermeter.MeteringCode, builderResponse.MSA, builderResponse.Seq); - var meterReadingRecords = new MeterReadingTelemetryPacketInfo() - { - SystemName = SystemType, - ProjectId = $"{watermeter.ProjectID}", - DeviceType = $"{MeterTypeEnum.Ammeter}", - DeviceId = $"{watermeter.MeterId}", - Timestamps = DateTimeOffset.Now.ToUnixTimeNanoseconds(), - DatabaseBusiID = watermeter.DatabaseBusiID, - PacketType = (int)TelemetryPacketTypeEnum.WatermeterAutoReadding, - PendingCopyReadTime = timestamps, - CreationTime = currentTime, - MeterAddress = watermeter.MeterAddress, - AFN = builderResponse.AFn, - Fn = builderResponse.Fn, - Seq = builderResponse.Seq, - MSA = builderResponse.MSA, - ItemCode = itemCode, - SubItemCode = subItemCode, - TaskMark = taskMark, - IsSend = false, - ManualOrNot = false, - Pn = watermeter.MeteringCode, - IssuedMessageId = GuidGenerator.Create().ToString(), - IssuedMessageHexString = Convert.ToHexString(builderResponse.Data), - IsReceived = false, - ScoreValue = $"{watermeter.FocusAddress}.{taskMark}".Md5Fun(), - }; - - taskList.Add(meterReadingRecords); + return taskList; diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs index c5fb86b..f13a158 100644 --- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs @@ -96,125 +96,144 @@ namespace JiShe.CollectBus.ScheduledMeterReading //[Route($"ammeter/list")] public override async Task> GetAmmeterInfoList(string gatherCode = "V4-Gather-8890") { - //#if DEBUG - // var redisCacheDeviceInfoHashKeyTemp = $"CollectBus:Energy:JiSheCollectBus109:DeviceInfo"; +#if DEBUG + var redisCacheDeviceInfoHashKeyTemp = $"CollectBus:Energy:JiSheCollectBus109:DeviceInfo"; - // List ammeterInfos = FreeRedisProvider.Instance.Get>(redisCacheDeviceInfoHashKeyTemp);//542400504 + List ammeterInfos = FreeRedisProvider.Instance.Get>(redisCacheDeviceInfoHashKeyTemp);//542400504 - // if (ammeterInfos == null || ammeterInfos.Count <= 0) - // { - // ammeterInfos = new List(); - // //ammeterInfos.Add(new DeviceInfo() - // //{ - // // Baudrate = 2400, - // // FocusAddress = "442400040", - // // Name = "保利单箱电表1", - // // FocusId = 95780, - // // DatabaseBusiID = 1, - // // MeteringCode = 0, - // // MeterAddress = "442405000040", - // // MeterId = 127035, - // // TypeName = 1, - // // DataTypes = "581,589,592,597,601", - // // TimeDensity = 15, - // // BrandType = "DTS1980", - // // MeterType = MeterTypeEnum.Ammeter, - // // ProjectID = 1, - // // MeteringPort = MeteringPortConst.MeteringPortTwo, - // // Password = "000000", - // //}); + if (ammeterInfos == null || ammeterInfos.Count <= 0) + { + ammeterInfos = new List(); + //ammeterInfos.Add(new DeviceInfo() + //{ + // Baudrate = 2400, + // FocusAddress = "442400040", + // Name = "保利单箱电表1", + // FocusId = 95780, + // DatabaseBusiID = 1, + // MeteringCode = 0, + // MeterAddress = "442405000040", + // MeterId = 127035, + // TypeName = 1, + // DataTypes = "581,589,592,597,601", + // TimeDensity = 15, + // BrandType = "DTS1980", + // MeterType = MeterTypeEnum.Ammeter, + // ProjectID = 1, + // MeteringPort = MeteringPortConst.MeteringPortTwo, + // Password = "000000", + //}); - // //ammeterInfos.Add(new DeviceInfo() - // //{ - // // Baudrate = 2400, - // // FocusAddress = "442400039", - // // Name = "保利单箱电表2", - // // FocusId = 69280, - // // DatabaseBusiID = 1, - // // MeteringCode = 0, - // // MeterAddress = "442405000039", - // // MeterId = 95594, - // // TypeName = 1, - // // DataTypes = "581,589,592,597,601", - // // TimeDensity = 15, - // // BrandType = "DTS1980", - // // MeterType = MeterTypeEnum.Ammeter, - // // ProjectID = 1, - // // MeteringPort = MeteringPortConst.MeteringPortTwo, - // // Password = "000000", - // //}); + //ammeterInfos.Add(new DeviceInfo() + //{ + // Baudrate = 2400, + // FocusAddress = "442400039", + // Name = "保利单箱电表2", + // FocusId = 69280, + // DatabaseBusiID = 1, + // MeteringCode = 0, + // MeterAddress = "442405000039", + // MeterId = 95594, + // TypeName = 1, + // DataTypes = "581,589,592,597,601", + // TimeDensity = 15, + // BrandType = "DTS1980", + // MeterType = MeterTypeEnum.Ammeter, + // ProjectID = 1, + // MeteringPort = MeteringPortConst.MeteringPortTwo, + // Password = "000000", + //}); - // //ammeterInfos.Add(new DeviceInfo() - // //{ - // // Baudrate = 2400, - // // FocusAddress = "402440506", - // // Name = "中环半导体9#冷却泵-220KW(三相电表)", - // // FocusId = 106857, - // // DatabaseBusiID = 1, - // // MeteringCode = 0, - // // MeterAddress = "402410040506", - // // MeterId = 139059, - // // TypeName = 3, - // // DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", - // // TimeDensity = 15, - // // BrandType = "DTS1980", - // // Password = "000000", - // // ProjectID = 1, - // // MeterType = MeterTypeEnum.Ammeter, - // // MeteringPort = MeteringPortConst.MeteringPortTwo, - // //}); + //ammeterInfos.Add(new DeviceInfo() + //{ + // Baudrate = 2400, + // FocusAddress = "402440506", + // Name = "中环半导体9#冷却泵-220KW(三相电表)", + // FocusId = 106857, + // DatabaseBusiID = 1, + // MeteringCode = 0, + // MeterAddress = "402410040506", + // MeterId = 139059, + // TypeName = 3, + // DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", + // TimeDensity = 15, + // BrandType = "DTS1980", + // Password = "000000", + // ProjectID = 1, + // MeterType = MeterTypeEnum.Ammeter, + // MeteringPort = MeteringPortConst.MeteringPortTwo, + //}); - // ammeterInfos.Add(new DeviceInfo() - // { - // Baudrate = 2400, - // FocusAddress = "942411321", - // Name = "DDS1980-T4(5-60) ML307A 长稳 942408011321", - // FocusId = 57682, - // DatabaseBusiID = 1, - // MeteringCode = 0, - // MeterAddress = "942408011321", - // MeterId = 78970, - // TypeName = 3, - // DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", - // TimeDensity = 15, - // BrandType = "DTS1980", - // Password = "000000", - // ProjectID = 1, - // MeterType = MeterTypeEnum.Ammeter, - // MeteringPort = MeteringPortConst.MeteringPortTwo, - // }); + //ammeterInfos.Add(new DeviceInfo() + //{ + // Baudrate = 2400, + // FocusAddress = "942411321", + // Name = "DDS1980-T4(5-60) ML307A 长稳 942408011321", + // FocusId = 57682, + // DatabaseBusiID = 1, + // MeteringCode = 0, + // MeterAddress = "942408011321", + // MeterId = 78970, + // TypeName = 3, + // DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", + // TimeDensity = 15, + // BrandType = "DTS1980", + // Password = "000000", + // ProjectID = 1, + // MeterType = MeterTypeEnum.Ammeter, + // MeteringPort = MeteringPortConst.MeteringPortTwo, + //}); - // ammeterInfos.Add(new DeviceInfo() - // { - // Baudrate = 2400, - // FocusAddress = "942411319", - // Name = "DDS1980-T4(5-60) ML307A 长稳 942408011319", - // FocusId = 57685, - // DatabaseBusiID = 1, - // MeteringCode = 0, - // MeterAddress = "942408011319", - // MeterId = 78973, - // TypeName = 3, - // DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", - // TimeDensity = 15, - // BrandType = "DTS1980", - // Password = "000000", - // ProjectID = 1, - // MeterType = MeterTypeEnum.Ammeter, - // MeteringPort = MeteringPortConst.MeteringPortTwo, - // }); + //ammeterInfos.Add(new DeviceInfo() + //{ + // Baudrate = 2400, + // FocusAddress = "942411319", + // Name = "DDS1980-T4(5-60) ML307A 长稳 942408011319", + // FocusId = 57685, + // DatabaseBusiID = 1, + // MeteringCode = 0, + // MeterAddress = "942408011319", + // MeterId = 78973, + // TypeName = 3, + // DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", + // TimeDensity = 15, + // BrandType = "DTS1980", + // Password = "000000", + // ProjectID = 1, + // MeterType = MeterTypeEnum.Ammeter, + // MeteringPort = MeteringPortConst.MeteringPortTwo, + //}); + + ammeterInfos.Add(new DeviceInfo() + { + Baudrate = 2400, + FocusAddress = "322011149", + Name = "DDS1980-T4(5-60) ML307A 长稳 322011149", + FocusId = 57685, + DatabaseBusiID = 1, + MeteringCode = 0, + MeterAddress = "31240010270", + MeterId = 78973, + TypeName = 3, + DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679", + TimeDensity = 15, + BrandType = "DTS1980", + Password = "000000", + ProjectID = 1, + MeterType = MeterTypeEnum.Ammeter, + MeteringPort = MeteringPortConst.MeteringPortTwo, + }); + + FreeRedisProvider.Instance.Set(redisCacheDeviceInfoHashKeyTemp, ammeterInfos); + } + + return ammeterInfos; +#else - // FreeRedisProvider.Instance.Set(redisCacheDeviceInfoHashKeyTemp, ammeterInfos); - // } - - // return ammeterInfos; - //#else - - - //#endif +#endif try @@ -255,9 +274,9 @@ namespace JiShe.CollectBus.ScheduledMeterReading //TODO 记得移除特殊表过滤 - #if DEBUG - //// sql = $@"{sql} and c.Address in('542410000504','442405000040','442405000039','402410040506')"; - //sql = $@"{sql} and c.Address in('402410040506')"; +#if DEBUG + // sql = $@"{sql} and c.Address in('542410000504','442405000040','442405000039','402410040506')"; + sql = $@"{sql} and c.Address in('402410040506')"; #endif if (!string.IsNullOrWhiteSpace(gatherCode)) @@ -561,7 +580,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading try { #if DEBUG - var redisCacheDeviceInfoHashKeyTemp = $"CollectBus:Energy:JiSheCollectBus109:DeviceInfo"; + var redisCacheDeviceInfoHashKeyTemp = $"CollectBus:Energy:JiSheCollectBus119:DeviceInfo"; List deviceInfos = FreeRedisProvider.Instance.Get>(redisCacheDeviceInfoHashKeyTemp); @@ -588,9 +607,11 @@ namespace JiShe.CollectBus.ScheduledMeterReading LinkType = "RS-485", TimesRate = 1.0000m, }); - } - return deviceInfos; + FreeRedisProvider.Instance.Set(redisCacheDeviceInfoHashKeyTemp, deviceInfos); + } + + return deviceInfos; #else string sql = $@"SELECT A.ID as MeterId, diff --git a/services/JiShe.CollectBus.Domain/IotSystems/Devices/DeviceInfo.cs b/services/JiShe.CollectBus.Domain/IotSystems/Devices/DeviceInfo.cs index 11145a7..d21a90f 100644 --- a/services/JiShe.CollectBus.Domain/IotSystems/Devices/DeviceInfo.cs +++ b/services/JiShe.CollectBus.Domain/IotSystems/Devices/DeviceInfo.cs @@ -113,7 +113,8 @@ namespace JiShe.CollectBus.IotSystems.Devices /// /// 该电表方案下采集项,JSON格式,如:["0D_80","0D_80"] /// - public string ItemCodes { get; set; } + [Column(IsIgnore = true)] + public List ItemCodes { get; set; } /// /// State表状态: diff --git a/shared/JiShe.CollectBus.Common/Consts/T1882018PacketItemCodeConst.cs b/shared/JiShe.CollectBus.Common/Consts/T1882018PacketItemCodeConst.cs index 585d3df..c6f34a3 100644 --- a/shared/JiShe.CollectBus.Common/Consts/T1882018PacketItemCodeConst.cs +++ b/shared/JiShe.CollectBus.Common/Consts/T1882018PacketItemCodeConst.cs @@ -14,9 +14,14 @@ namespace JiShe.CollectBus.Common.Consts #region 下行报文编码 /// - /// 基路径 + /// 基路径,表示主站发起读数据 /// - public const string BasicT1882018 = "CTR"; + public const string BasicT1882018Read = "CTR0"; + + /// + /// 基路径,表示主站发起读数据 + /// + public const string BasicT1882018Write = "CTR3"; #region 读数据 @@ -24,12 +29,12 @@ namespace JiShe.CollectBus.Common.Consts /// /// 读取计量数据1 /// - public const string CTR0190 = $"01_90"; + public const string CTR01901F00 = $"{BasicT1882018Read}_01_90_1F_00"; /// /// 读取计量数据2 /// - public const string CTR0191 = $"01_91"; + public const string CTR01911F00 = $"{BasicT1882018Read}_01_91_1F_00"; #endregion @@ -38,12 +43,12 @@ namespace JiShe.CollectBus.Common.Consts /// /// 关阀 /// - public const string CTR30455 = $"_04_55"; + public const string CTR304A01755 = $"{BasicT1882018Write}_04_A0_17_55"; /// /// 开阀 /// - public const string CTR30499 = $"_04_99"; + public const string CTR304A01799 = $"{BasicT1882018Write}_04_A0_17_99"; #endregion diff --git a/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs b/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs index b556524..d703059 100644 --- a/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs +++ b/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs @@ -34,6 +34,21 @@ namespace JiShe.CollectBus.Common.Consts /// 远程通信模块版本信息 /// public const string AFN09HFN09H = $"09_9"; + + /// + /// 水表阀控 + /// + public const string AFN10HFN99H = $"10_99"; + + /// + /// 炬华有线水表抄读 + /// + public const string AFN0CHFN188H = $"0C_188"; + + /// + /// 标准188协议水表抄读 + /// + public const string AFN0CHFN129H = $"0C_129"; #endregion @@ -201,14 +216,29 @@ namespace JiShe.CollectBus.Common.Consts /// /// 特殊645编码关系映射 /// - /// + /// 特殊3761编码 /// public static (string,string) MappingItemCodeTo645SubCodeRelationship(string itemCode) { return itemCode switch { AFN10HFN97H => (AFN10HFN01H,T6452007PacketItemCodeConst.C1102800002), - _=> (itemCode,""), + _ => (itemCode,""), + }; + } + + /// + /// 特殊188编码关系映射 + /// + /// 特殊3761编码 + /// TripState (0 合闸-开阀, 1 关阀);开阀关阀 + /// + public static (string, string) MappingItemCodeTo188SubCodeRelationship(string itemCode,bool tripState) + { + return itemCode switch + { + AFN10HFN99H => (AFN10HFN01H, tripState == true ?T1882018PacketItemCodeConst.CTR304A01799: T1882018PacketItemCodeConst.CTR304A01755), + _ => (itemCode, ""), }; } }