diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F97_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F97_Analysis.cs index 7b02e9f..0863213 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F97_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F97_Analysis.cs @@ -1,4 +1,5 @@ -using GatherService.WattMeter.AnalysisData.AFN_10H; +using DeviceDetectorNET.Parser.Device; +using GatherService.WattMeter.AnalysisData.AFN_10H; using JiShe.CollectBus.Common.Consts; using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; @@ -46,7 +47,7 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H AnalysisBaseDto data = GenerateFinalResult(datas); // 查询设备信息 - DeviceInfo? deviceInfo = await _dataStorage.GetDeviceInfoAsync(input.A.Code, input.DA.Pn); + DeviceInfo? deviceInfo = await _dataStorage.GetDeviceInfoAsync(input.A.Code, input.DA.Pn, datas[1]); if (deviceInfo != null) { data.ProjectId = deviceInfo.ProjectID; @@ -87,8 +88,8 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H private AnalysisBaseDto GenerateFinalResult(List data) { AnalysisBaseDto meter = new AnalysisBaseDto(); - - var errorCode = data[7].CheckErrorCode(); + meter.DeviceType = MeterTypeEnum.Ammeter; + var errorCode = data[4].CheckErrorCode(); if (errorCode != null) { meter.ValidData = false; @@ -96,7 +97,7 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H } else { - if(decimal.TryParse(data[7], out decimal value)) + if(decimal.TryParse(data[4], out decimal value)) meter.DataValue = value; } @@ -133,7 +134,7 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H string dataMark = string.Join("",dataField.GetRange(0, 4).ReduceHex33(true)); values.Add(dataMark);//数据标识 var readValue = dataField.GetRange(4, len - 4).ReduceHex33(true);//值 - await _analysisStrategyContext.ExecuteAsync>($" Appendix_{dataMark}", readValue, (value) => + await _analysisStrategyContext.ExecuteAsync>($"Appendix_{dataMark}", readValue, (value) => { values.Add(value.ToString()); }); diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs index 38b9eaa..68cfa62 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs @@ -81,11 +81,11 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData /// /// /// - public async Task GetDeviceInfoAsync(string code,int pn=1) + public async Task GetDeviceInfoAsync(string code,int pn=1,string meterAddress=null) { string redisCacheDeviceInfoHashKey = $"{string.Format(RedisConst.CacheDeviceInfoHashKey, _applicationOptions.SystemType, _applicationOptions.ServerTagName)}"; string deviceKey= $"{code}:{pn}"; - return await _imemoryCache.GetOrCreateAsync(deviceKey, async entry => + var deviceInfo= await _imemoryCache.GetOrCreateAsync(deviceKey, async entry => { List devices= await Instance.HGetAsync>(redisCacheDeviceInfoHashKey, code) ?? new List(); var data = devices.Where(s => s.MeteringCode == pn).FirstOrDefault(); @@ -95,6 +95,22 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData entry.SetSlidingExpiration(TimeSpan.FromSeconds(5)); return data ?? default; }); + if (deviceInfo == null && !string.IsNullOrWhiteSpace(meterAddress)) + { + // TODO:透明转发回来的pn为0情况 + string deviceAddressKey = $"{code}:{meterAddress}"; + deviceInfo = await _imemoryCache.GetOrCreateAsync(deviceAddressKey, async entry => + { + List devices = await Instance.HGetAsync>(redisCacheDeviceInfoHashKey, code) ?? new List(); + var data = devices.Where(s => s.MeterAddress == meterAddress).FirstOrDefault(); + if (data != null) + entry.SetSlidingExpiration(TimeSpan.FromMinutes(5)); + else + entry.SetSlidingExpiration(TimeSpan.FromSeconds(5)); + return data ?? default; + }); + } + return deviceInfo; } /// diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs index 8c71343..da699e2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs @@ -19,18 +19,19 @@ namespace JiShe.CollectBus.Protocol.T37612012.Appendix { try { - if (data.Count != 2) - return null; - var value = string.Join(".", data); - var values= new List() { "电网频率", "10_97", "1", value }; - result?.Invoke(values); - return Task.FromResult(true); + if (data.Count == 2) + { + var value = string.Join(".", data); + //电网频率 + result?.Invoke(value); + return Task.FromResult(true); + } } catch (Exception ex) { _logger.LogError(ex, $"Appendix_02800002解析失败:{ex.Message}"); - return Task.FromResult(false); } + return Task.FromResult(false); } } } diff --git a/web/JiShe.CollectBus.Host/appsettings.json b/web/JiShe.CollectBus.Host/appsettings.json index d7ebf50..d5129e3 100644 --- a/web/JiShe.CollectBus.Host/appsettings.json +++ b/web/JiShe.CollectBus.Host/appsettings.json @@ -141,7 +141,7 @@ } }, "ServerApplicationOptions": { - "ServerTagName": "JiSheCollectBus8", + "ServerTagName": "JiSheCollectBus99", "SystemType": "Energy", "FirstCollectionTime": "2025-04-28 15:07:00", "AutomaticVerificationTime": "16:07:00",