@@ -27,6 +27,7 @@ using TDengineTMQ; | |||
using HealthMonitor.Service.Cache; | |||
using System.Text.RegularExpressions; | |||
using Etcdserverpb; | |||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory; | |||
namespace HealthMonitor.Service.Biz.db | |||
{ | |||
@@ -824,16 +825,30 @@ namespace HealthMonitor.Service.Biz.db | |||
} | |||
public async Task<int> DeleteAllBySerialNoCMDAsync<T>(string serialNo) where T : class | |||
public async Task DeleteAllBySerialNoCMDAsync<T>(string serialNo) where T : class | |||
{ | |||
var records = await GetBySerialNoAsync<T>(serialNo, 365); | |||
var stbName = typeof(T) | |||
.GetCustomAttribute<STableAttribute>()? | |||
.STableName; | |||
var endTime=DateTime.Now; | |||
var startTime = DateTime.Now.AddYears(-1); | |||
var sql = $"DELETE FROM {stbName} WHERE ts >= '{startTime:yyyy-MM-dd HH:mm:ss}' AND ts <= '{endTime:yyyy-MM-dd HH:mm:ss}' AND serialno='{serialNo}'"; | |||
return await _clientSqlSugar.Ado.ExecuteCommandAsync(sql); | |||
var tasks = records.Select(async r => | |||
{ | |||
Type modelType = typeof(T); | |||
PropertyInfo timestampProperty = typeof(T).GetProperty("Timestamp")!; | |||
object timestampValue = timestampProperty.GetValue(r)!; | |||
var ts = ((DateTime)timestampValue); | |||
var startTimestamp = ts.ToString("yyyy-MM-dd HH:mm:ss.fff"); | |||
var endTimestamp = ts.AddMilliseconds(1).ToString("yyyy-MM-dd HH:mm:ss.fff"); | |||
var sql = $"DELETE FROM {stbName} WHERE ts >= '{startTimestamp}' AND ts < '{endTimestamp}'"; | |||
var res= await _clientSqlSugar.Ado.ExecuteCommandAsync(sql); | |||
Console.WriteLine(res); | |||
}); | |||
await Task.WhenAll(tasks); | |||
} | |||
#endregion | |||
#region 胎心算法 | |||
@@ -295,7 +295,7 @@ namespace HealthMonitor.Service.Resolver | |||
} | |||
#endregion | |||
} | |||
// 高频心率结束或平常心率 | |||
// 高频心率结束或常规心率 | |||
else | |||
{ | |||
var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); | |||
@@ -435,17 +435,17 @@ namespace HealthMonitor.Service.Resolver | |||
_logger.LogInformation($"{heartRate.Serialno} 超时结束高频心率状态 timeDiffInSeconds {timeDiffInSeconds},highFreqSampleInterval:{highFreqSampleInterval},高频状态持续{(firstTwoPhr[1] - phrFreqstatus!.LastUpdate).TotalSeconds} 秒"); | |||
// 计算本次平常心率的胎心数据 | |||
// 计算本次常规心率的胎心数据 | |||
//await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); | |||
// 使用延后计算 | |||
var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}"; | |||
var fhrScheduleTTL = 60; | |||
await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate); | |||
} | |||
// 平常心率 | |||
// 常规心率 | |||
else | |||
{ | |||
// 计算本次平常心率的胎心数据 | |||
// 计算本次常规心率的胎心数据 | |||
//await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); | |||
// 使用延后计算 | |||
var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}"; | |||
@@ -472,7 +472,7 @@ namespace HealthMonitor.Service.Resolver | |||
} | |||
/// <summary> | |||
/// 平常心率计算胎心数据 | |||
/// 常规心率计算胎心数据 | |||
/// </summary> | |||
/// <param name="heartRate"></param> | |||
/// <param name="upperAlarmThreshold"></param> | |||
@@ -570,7 +570,7 @@ namespace HealthMonitor.Service.Resolver | |||
var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0); | |||
var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); | |||
if (phrFreqstatus == null) isAbnormal = 0; | |||
var statsusDesc = (phrFreqstatus == null) ? "平常" : "高频"; | |||
var statsusDesc = (phrFreqstatus == null) ? "常规" : "高频"; | |||
_logger.LogInformation($"{heartRate.Serialno} 在 {statsusDesc} 状态,生成胎心值:{fetalHeartRate},统计周期:{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}----{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); | |||
//if (!isFreq) | |||
//{ | |||
@@ -110,7 +110,7 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor | |||
// 删除孕妇心率 | |||
await _serviceTDengine.DeleteAllBySerialNoCMDAsync<PregnancyHeartRateModel>(req.Serialno); | |||
// 删除一般心率(建模数据) | |||
await _serviceTDengine.DeleteAllBySerialNoCMDAsync<PregnancyCommonHeartRateModel>(req.Serialno); | |||
// await _serviceTDengine.DeleteAllBySerialNoCMDAsync<PregnancyCommonHeartRateModel>(req.Serialno); | |||
var data = $"{req.Serialno} 清理胎心胎动建模数据成功"; | |||
return ApiResponse<object>.Success(data); | |||
@@ -274,7 +274,7 @@ namespace HealthMonitor.WebApi | |||
using (_logger.BeginScope(new Dictionary<string, object> { ["RequestId"] = triggerHeartRate?.MessageId! })) | |||
{ | |||
var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); | |||
_logger.LogInformation($"触发平常心率计算胎心"); | |||
_logger.LogInformation($"触发常规心率计算胎心"); | |||
var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; | |||
if (isFetalHeartEnable) | |||
@@ -327,10 +327,10 @@ namespace HealthMonitor.WebApi | |||
#endregion | |||
} | |||
// 不在高频状态状态,但触发孕妇心率与最后一条孕妇心率不一致, | |||
// 平常心率数据是批量上报,需要计算每条心率对应的胎心数据 | |||
// 常规心率数据是批量上报,需要计算每条心率对应的胎心数据 | |||
else | |||
{ | |||
_logger.LogInformation($"{imeiDel} 平常心率数据是批量上报,需要计算每条心率对应的胎心数据"); | |||
_logger.LogInformation($"{imeiDel} 常规心率数据是批量上报,需要计算每条心率对应的胎心数据"); | |||
#region 计算每条心率对应的胎心数据 | |||
@@ -1075,7 +1075,7 @@ namespace HealthMonitor.WebApi | |||
var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0); | |||
var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); | |||
if (phrFreqstatus == null) isAbnormal = 0; | |||
var statsusDesc = (phrFreqstatus == null) ? $"MSG ID: {heartRate.MessageId} 平常" : "高频"; | |||
var statsusDesc = (phrFreqstatus == null) ? $"MSG ID: {heartRate.MessageId} 常规" : "高频"; | |||
_logger.LogInformation($"{heartRate.Serialno} 在 {statsusDesc} 状态,生成胎心值:{fetalHeartRate},统计周期:{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}----{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); | |||
//if (!isFreq) | |||
//{ | |||
@@ -1101,7 +1101,7 @@ namespace HealthMonitor.WebApi | |||
await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false); | |||
// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig | |||
// 推送最后一条平常心率到iot设备 | |||
// 推送最后一条常规心率计算的胎心数据到iot设备 | |||
var lastPhr = await _serviceTDengine.GetLastAsync<PregnancyHeartRateModel>(heartRate.Serialno); | |||
if (lastPhr.MessageId== heartRate.MessageId) | |||
{ | |||