diff --git a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs index f4cd9c1..1af8e56 100644 --- a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs +++ b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs @@ -366,12 +366,12 @@ namespace HealthMonitor.Service.Resolver //.Where(i => i.PregnancyHeartRate < triggerHighFreqLow || i.PregnancyHeartRate > triggerHighFreqHigh) .Select(i => i.PregnancyHeartRate).Average(); - + FreqStatsEnd = firstTwoPhr[1]; _logger.LogInformation($"{heartRate.Serialno} 高频状态已经持续{(FreqStatsEnd - phrFreqstatus!.LastUpdate).TotalSeconds} 秒,超过约定的 {highFreqSampleTimes} 秒,即将结束高频状态,将下发指令"); //计算高频 await SaveAndPushFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); - + // 计算本次常规心率的胎心数据(高频结束后,实时处理) await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); } @@ -458,11 +458,48 @@ namespace HealthMonitor.Service.Resolver { // 计算本次常规心率的胎心数据 //await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); + // 本次心率可能是高频心率的首条,所以要使用本次常规心率延后计算胎心率 - var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}"; - var fhrScheduleTTL = 30; - await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate); - _logger.LogInformation($"{heartRate.Serialno} 延时50秒,判断当前数据是否为高频首条"); + //var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}"; + //var fhrScheduleTTL = 30; + //await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate); + //_logger.LogInformation($"{heartRate.Serialno} 延时50秒,判断当前数据是否为高频首条"); + + // 本次心率可能是高频心率的首条,所以要使用本次常规心率延后计算胎心率 查询30秒后是否有高频缓存 + Thread thread = new(async () => + { + try + { + #region 休眠2秒 + var startTime = DateTime.Now; + var highFreqSampleInterval2 = (int)watchConfig!["highFreqSampleInterval"]!+5; + var during = TimeSpan.FromSeconds(highFreqSampleInterval2); + while (true) + { + if (DateTime.Now - startTime > during) + { + break; + } + await Task.Delay(TimeSpan.FromSeconds(1)); + } + #endregion + var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); + _logger.LogInformation($"phrFreqstatus==null:{phrFreqstatus == null}"); + _logger.LogInformation($"phrFreqstatus.LastUpdate < heartRate.LastUpdate:{phrFreqstatus?.LastUpdate < heartRate.LastUpdate}"); + if (phrFreqstatus==null || phrFreqstatus.LastUpdate < heartRate.LastUpdate) + { + await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); + _logger.LogInformation($"{heartRate.Serialno} 计算常规心率"); + } + + } + catch (Exception ex) + { + + _logger.LogError($"处理延时计算异常:{ex.Message}, {ex.StackTrace}"); + } + + }); } } diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index d73fb4f..6deb6b4 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -266,7 +266,7 @@ namespace HealthMonitor.WebApi // health_monitor/schedule_push/cal_fetal_heart_rate/imei/ else if (key.Contains("health_monitor/schedule_push/cal_fetal_heart_rate/imei/")) { - + /** var triggerValue= (JObject)JsonConvert.DeserializeObject(e.PrevKv.Value.ToStringUtf8())!; var trigger = triggerValue["trigger"]?.ToString(); if (!string.IsNullOrEmpty(trigger)) @@ -407,6 +407,8 @@ namespace HealthMonitor.WebApi _logger.LogWarning($"{imeiDel} trigger is not set"); } + */ +