|
@@ -23,6 +23,7 @@ using Newtonsoft.Json; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using System; |
|
|
using System; |
|
|
using System.Reflection; |
|
|
using System.Reflection; |
|
|
|
|
|
using System.Text.RegularExpressions; |
|
|
using System.Threading.Channels; |
|
|
using System.Threading.Channels; |
|
|
using TDengineDriver; |
|
|
using TDengineDriver; |
|
|
using TDengineTMQ; |
|
|
using TDengineTMQ; |
|
@@ -157,7 +158,13 @@ namespace HealthMonitor.WebApi |
|
|
|
|
|
|
|
|
// var key = $"health_monitor/schedule_push/imei/{bp.Serialno}"; |
|
|
// var key = $"health_monitor/schedule_push/imei/{bp.Serialno}"; |
|
|
var key = e.Kv.Key.ToStringUtf8(); |
|
|
var key = e.Kv.Key.ToStringUtf8(); |
|
|
var imeiDel = key.Split('/')[^1]; |
|
|
|
|
|
|
|
|
//var imeiDel = key.Split('/')[^1]; |
|
|
|
|
|
var imeiDel = ExtractImei(key); |
|
|
|
|
|
if (string.IsNullOrEmpty(imeiDel)) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogWarning("定时器不能抽取imei"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false); |
|
|
var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false); |
|
|
if (string.IsNullOrWhiteSpace(schedule_push)) |
|
|
if (string.IsNullOrWhiteSpace(schedule_push)) |
|
|
{ |
|
|
{ |
|
@@ -1426,7 +1433,7 @@ namespace HealthMonitor.WebApi |
|
|
|
|
|
|
|
|
#region 相隔1小时胎动延时计算(实时now是2小时,计算 lastupdate 0~1范围的数据,) |
|
|
#region 相隔1小时胎动延时计算(实时now是2小时,计算 lastupdate 0~1范围的数据,) |
|
|
/** |
|
|
/** |
|
|
0~1->2 |
|
|
|
|
|
|
|
|
0~1->2,0~1 的lastupdate数据,sample_time 是1点,计算时间2点 |
|
|
1~2->3 |
|
|
1~2->3 |
|
|
2~3->4 |
|
|
2~3->4 |
|
|
3~4->5 |
|
|
3~4->5 |
|
@@ -1455,7 +1462,7 @@ namespace HealthMonitor.WebApi |
|
|
if (!string.IsNullOrEmpty(trigger)) |
|
|
if (!string.IsNullOrEmpty(trigger)) |
|
|
{ |
|
|
{ |
|
|
var triggerHeartRate = JsonConvert.DeserializeObject<HisGpsHeartRate>(trigger); |
|
|
var triggerHeartRate = JsonConvert.DeserializeObject<HisGpsHeartRate>(trigger); |
|
|
using (_logger.BeginScope(new Dictionary<string, object> { ["RequestId"] = $"FM-{imeiDel}-{DateTime.Now.ToString("yyyyMMddHHmmss")}" })) |
|
|
|
|
|
|
|
|
using (_logger.BeginScope(new Dictionary<string, object> { ["RequestId"] = $"FM-{imeiDel}-{triggerHeartRate?.MessageId}" })) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
@@ -2715,53 +2722,64 @@ namespace HealthMonitor.WebApi |
|
|
|
|
|
|
|
|
var daysPhr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(heartRate.Serialno, 7); |
|
|
var daysPhr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(heartRate.Serialno, 7); |
|
|
|
|
|
|
|
|
//var start = ""; |
|
|
|
|
|
//var end = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime fmNow = DateTime.Now; |
|
|
DateTime fmNow = DateTime.Now; |
|
|
int fmNowHour = fmNow.Hour; |
|
|
int fmNowHour = fmNow.Hour; |
|
|
DateTime startHour; |
|
|
DateTime startHour; |
|
|
DateTime endHour; |
|
|
DateTime endHour; |
|
|
|
|
|
|
|
|
// 跨天 |
|
|
|
|
|
if (fmNowHour == 1) |
|
|
|
|
|
|
|
|
if (fmNow.Subtract((DateTime)heartRate.LastUpdate!).Hours>2) |
|
|
{ |
|
|
{ |
|
|
// last_update 23~0 |
|
|
|
|
|
startHour = fmNow.Date.AddDays(-1).AddHours(((DateTime)heartRate.LastUpdate!).Hour); |
|
|
|
|
|
endHour = fmNow.Date; |
|
|
|
|
|
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 当前计算时间与lastUpdate 时差超过2小时,将从当前触发心率到当天的所有心率计算对应的胎动"); |
|
|
|
|
|
startHour = ((DateTime)heartRate.LastUpdate!).Date.AddHours(((DateTime)heartRate.LastUpdate!).Hour); |
|
|
|
|
|
endHour = ((DateTime)heartRate.LastUpdate!).Date.AddDays(1); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
// last_update 0~1->2,1~2->3,2~3->4...21~22->23 |
|
|
|
|
|
startHour = fmNow.Date.AddHours(((DateTime)heartRate.LastUpdate!).Hour); |
|
|
|
|
|
endHour = fmNow.Date.AddHours(fmNowHour - 1); |
|
|
|
|
|
|
|
|
// 跨天 |
|
|
|
|
|
if (fmNowHour == 1) |
|
|
|
|
|
{ |
|
|
|
|
|
// last_update 23~0 |
|
|
|
|
|
startHour = fmNow.Date.AddDays(-1).AddHours(((DateTime)heartRate.LastUpdate!).Hour); |
|
|
|
|
|
endHour = fmNow.Date; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
// last_update 0~1->2,1~2->3,2~3->4...21~22->23 |
|
|
|
|
|
startHour = fmNow.Date.AddHours(((DateTime)heartRate.LastUpdate!).Hour); |
|
|
|
|
|
endHour = fmNow.Date.AddHours(fmNowHour - 1); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var filterPhr = daysPhr |
|
|
|
|
|
.Where(i => i.LastUpdate >= startHour && i.LastUpdate<= endHour) |
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var filterPhr = daysPhr |
|
|
|
|
|
.Where(i => i.LastUpdate >= startHour && i.LastUpdate <= endHour) |
|
|
.OrderBy(i => i.LastUpdate).ToList(); |
|
|
.OrderBy(i => i.LastUpdate).ToList(); |
|
|
|
|
|
|
|
|
var startPhr = filterPhr.First(); |
|
|
|
|
|
var endPhr = filterPhr.Last(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (filterPhr.Count < 2) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 胎动统计数据少于2条,不统计,{string.Join('-', filterPhr.Select(i=>i.LastUpdate))}"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var startPhr = filterPhr.First(); |
|
|
|
|
|
var endPhr = filterPhr.Last(); |
|
|
|
|
|
|
|
|
// 数据统计边界 |
|
|
|
|
|
var boundaryStatStartTime = startPhr.LastUpdate.Date.AddHours(startPhr.LastUpdate.Hour); |
|
|
|
|
|
var boundaryStatEndTime = endPhr.LastUpdate.Date.AddHours(endPhr.LastUpdate.Hour + 1); |
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 胎动统计边界{boundaryStatStartTime}-{boundaryStatEndTime}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 数据统计边界 |
|
|
|
|
|
var boundaryStatStartTime = startPhr.LastUpdate.Date.AddHours(startPhr.LastUpdate.Hour); |
|
|
|
|
|
var boundaryStatEndTime = endPhr.LastUpdate.Date.AddHours(endPhr.LastUpdate.Hour + 1); |
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 胎动统计边界{boundaryStatStartTime}-{boundaryStatEndTime}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
if (filterPhr.Count<2) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 胎动统计边界{boundaryStatStartTime}-{boundaryStatEndTime},数据少于2条,不统计"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var c = 0; |
|
|
var c = 0; |
|
|
while (true) |
|
|
while (true) |
|
|
{ |
|
|
{ |
|
@@ -2795,8 +2813,8 @@ namespace HealthMonitor.WebApi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 当前胎动统计周期{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}-{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")},对应的常规心率ID{string.Join(",", segmentPhr.Select(i => i.MessageId))}"); |
|
|
_logger.LogInformation($"{heartRate.Serialno} 当前胎动统计周期{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}-{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")},对应的常规心率ID{string.Join(",", segmentPhr.Select(i => i.MessageId))}"); |
|
|
|
|
|
|
|
|
var fetalMovementSampleTime = DateTimeUtil.ConvertToTimeStamp(statStartTime).ToString()[..10]; |
|
|
|
|
|
|
|
|
// 0~1 点的lastUpdate数据sample_time是1点,计算是2点 |
|
|
|
|
|
var fetalMovementSampleTime = DateTimeUtil.ConvertToTimeStamp(statEndTime).ToString()[..10]; |
|
|
var isFetalMovementExisted = await _deviceCacheMgr.FetalMovementIsExistedAsync(heartRate.Serialno, fetalMovementSampleTime); |
|
|
var isFetalMovementExisted = await _deviceCacheMgr.FetalMovementIsExistedAsync(heartRate.Serialno, fetalMovementSampleTime); |
|
|
|
|
|
|
|
|
if (!isFetalMovementExisted) |
|
|
if (!isFetalMovementExisted) |
|
@@ -3197,5 +3215,22 @@ namespace HealthMonitor.WebApi |
|
|
// 返回当前时间刻度下的 DateTime,保留小时和新计算的分钟,秒和毫秒设为0 |
|
|
// 返回当前时间刻度下的 DateTime,保留小时和新计算的分钟,秒和毫秒设为0 |
|
|
return new DateTime(lastUpdate.Year, lastUpdate.Month, lastUpdate.Day, lastUpdate.Hour, intervalStartMinute, 0, 0); |
|
|
return new DateTime(lastUpdate.Year, lastUpdate.Month, lastUpdate.Day, lastUpdate.Hour, intervalStartMinute, 0, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static string ExtractImei(string input) |
|
|
|
|
|
{ |
|
|
|
|
|
// 提取 'imei/' 后的数字 |
|
|
|
|
|
string pattern = @"imei/(\d+)"; |
|
|
|
|
|
|
|
|
|
|
|
Match match = Regex.Match(input, pattern); |
|
|
|
|
|
|
|
|
|
|
|
if (match.Success) |
|
|
|
|
|
{ |
|
|
|
|
|
return match.Groups[1].Value; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return string.Empty; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |