|
@@ -1,20 +1,24 @@ |
|
|
using HealthMonitor.Common; |
|
|
|
|
|
|
|
|
using Etcdserverpb; |
|
|
|
|
|
using HealthMonitor.Common; |
|
|
using HealthMonitor.Common.helper; |
|
|
using HealthMonitor.Common.helper; |
|
|
using HealthMonitor.Model.Service.Mapper; |
|
|
using HealthMonitor.Model.Service.Mapper; |
|
|
using HealthMonitor.Service.Biz; |
|
|
using HealthMonitor.Service.Biz; |
|
|
using HealthMonitor.Service.Biz.db; |
|
|
using HealthMonitor.Service.Biz.db; |
|
|
using HealthMonitor.Service.Cache; |
|
|
using HealthMonitor.Service.Cache; |
|
|
using HealthMonitor.Service.Etcd; |
|
|
using HealthMonitor.Service.Etcd; |
|
|
|
|
|
using HealthMonitor.Service.MessageQueue; |
|
|
using HealthMonitor.Service.Resolver.Interface; |
|
|
using HealthMonitor.Service.Resolver.Interface; |
|
|
using HealthMonitor.Service.Sub; |
|
|
using HealthMonitor.Service.Sub; |
|
|
using HealthMonitor.Service.Sub.Topic.Model; |
|
|
using HealthMonitor.Service.Sub.Topic.Model; |
|
|
using Microsoft.EntityFrameworkCore.Metadata; |
|
|
using Microsoft.EntityFrameworkCore.Metadata; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json; |
|
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
using SqlSugar; |
|
|
using SqlSugar; |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
|
|
|
using System.Net; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using TelpoDataService.Util.Clients; |
|
|
using TelpoDataService.Util.Clients; |
|
@@ -44,11 +48,14 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
|
|
|
|
|
private readonly FetalMovementNormalValueRangeCacheManager _mgrFetalMovementNormalValueRangeCache; |
|
|
private readonly FetalMovementNormalValueRangeCacheManager _mgrFetalMovementNormalValueRangeCache; |
|
|
|
|
|
|
|
|
|
|
|
private readonly MqProcessLogic _serviceMqProcess; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PregnancyHeartRateResolver(ILogger<PregnancyHeartRateResolver> logger, |
|
|
public PregnancyHeartRateResolver(ILogger<PregnancyHeartRateResolver> logger, |
|
|
HttpHelper httpHelper, EtcdService serviceEtcd, DeviceCacheManager deviceCacheMgr, |
|
|
|
|
|
|
|
|
HttpHelper httpHelper, EtcdService serviceEtcd, DeviceCacheManager deviceCacheMgr, |
|
|
|
|
|
MqProcessLogic serviceMqProcess, |
|
|
IotApiService iotApiService, TDengineService serviceDengine, FetalMovementNormalValueRangeCacheManager fetalMovementNormalValueRangeCacheMgr, |
|
|
IotApiService iotApiService, TDengineService serviceDengine, FetalMovementNormalValueRangeCacheManager fetalMovementNormalValueRangeCacheMgr, |
|
|
GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> hisFetalHeartApiClient, |
|
|
GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> hisFetalHeartApiClient, |
|
|
GpsLocationHistoryAccessorClient<HisGpsFetalMovement> hisFetalMovementApiClient |
|
|
GpsLocationHistoryAccessorClient<HisGpsFetalMovement> hisFetalMovementApiClient |
|
@@ -60,6 +67,7 @@ namespace HealthMonitor.Service.Resolver |
|
|
_serviceTDengine = serviceDengine; |
|
|
_serviceTDengine = serviceDengine; |
|
|
_deviceCacheMgr = deviceCacheMgr; |
|
|
_deviceCacheMgr = deviceCacheMgr; |
|
|
_serviceIotApi = iotApiService; |
|
|
_serviceIotApi = iotApiService; |
|
|
|
|
|
_serviceMqProcess= serviceMqProcess; |
|
|
_hisFetalHeartApiClient = hisFetalHeartApiClient; |
|
|
_hisFetalHeartApiClient = hisFetalHeartApiClient; |
|
|
_hisFetalMovementApiClient = hisFetalMovementApiClient; |
|
|
_hisFetalMovementApiClient = hisFetalMovementApiClient; |
|
|
_mgrFetalMovementNormalValueRangeCache = fetalMovementNormalValueRangeCacheMgr; |
|
|
_mgrFetalMovementNormalValueRangeCache = fetalMovementNormalValueRangeCacheMgr; |
|
@@ -452,7 +460,7 @@ namespace HealthMonitor.Service.Resolver |
|
|
{ |
|
|
{ |
|
|
var avgPhr = lastPhr.Select(i => i.PregnancyHeartRate).Average(); |
|
|
var avgPhr = lastPhr.Select(i => i.PregnancyHeartRate).Average(); |
|
|
// 计算一般心率得到胎心系数 |
|
|
// 计算一般心率得到胎心系数 |
|
|
await SaveAndPushFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr); |
|
|
|
|
|
|
|
|
await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString()); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
#endregion |
|
|
#endregion |
|
@@ -474,7 +482,8 @@ namespace HealthMonitor.Service.Resolver |
|
|
.Select(i => i.PregnancyHeartRate).Average(); |
|
|
.Select(i => i.PregnancyHeartRate).Average(); |
|
|
// 推送胎心数据到 api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
// 推送胎心数据到 api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
// 计算一般心率得到胎心系数 |
|
|
// 计算一般心率得到胎心系数 |
|
|
await SaveAndPushFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr); |
|
|
|
|
|
|
|
|
//await SaveAndPushFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr); |
|
|
|
|
|
await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString()); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -490,7 +499,9 @@ namespace HealthMonitor.Service.Resolver |
|
|
.Select(i => i.PregnancyHeartRate).Average(); |
|
|
.Select(i => i.PregnancyHeartRate).Average(); |
|
|
// 推送胎心数据到 api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
// 推送胎心数据到 api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
// 计算一般心率得到胎心系数 |
|
|
// 计算一般心率得到胎心系数 |
|
|
await SaveAndPushFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr); |
|
|
|
|
|
|
|
|
//await SaveAndPushFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr); |
|
|
|
|
|
await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString()); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 删除高频状态的首条记录 |
|
|
// 删除高频状态的首条记录 |
|
@@ -566,6 +577,28 @@ namespace HealthMonitor.Service.Resolver |
|
|
// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTimeFHR, fetalHeartRateIsAbnormal); |
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTimeFHR, fetalHeartRateIsAbnormal); |
|
|
|
|
|
|
|
|
|
|
|
// 推送送微信 |
|
|
|
|
|
var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false); |
|
|
|
|
|
var fhrMsgId = $"{heartRate.Serialno}-{sampleTimeFHR}-{Guid.NewGuid().ToString("D")[^3..]}"; |
|
|
|
|
|
var topic = "topic.push.wx"; |
|
|
|
|
|
var fhrMsg = new |
|
|
|
|
|
{ |
|
|
|
|
|
messageId = fhrMsgId, |
|
|
|
|
|
topic = topic, |
|
|
|
|
|
time = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(sampleTimeFHR.Length < 13 ? sampleTimeFHR.PadRight(13, '0') : sampleTimeFHR)).ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
|
|
data = new |
|
|
|
|
|
{ |
|
|
|
|
|
deviceId = device?.DeviceId, |
|
|
|
|
|
imei = heartRate.Serialno, |
|
|
|
|
|
alarmTypeId = 12, |
|
|
|
|
|
alarmDeviceName = heartRate.Serialno, |
|
|
|
|
|
alarmRemarks = JsonConvert.SerializeObject(new { fetalHeartValue = fetalHeartRate, isAbnormal = fetalHeartRateIsAbnormal }), |
|
|
|
|
|
address = string.Empty, |
|
|
|
|
|
deviceKey = device?.DeviceId |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fhrMsgId, topic,fhrMsg).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -660,8 +693,31 @@ namespace HealthMonitor.Service.Resolver |
|
|
}; |
|
|
}; |
|
|
await _hisFetalMovementApiClient.AddAsync(fm).ConfigureAwait(false); |
|
|
await _hisFetalMovementApiClient.AddAsync(fm).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
// 发送到微信 |
|
|
|
|
|
var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false); |
|
|
|
|
|
var fmMsgId = $"{heartRate.Serialno}-{fetalMovementSampleTime}-{Guid.NewGuid().ToString("D")[^3..]}"; |
|
|
|
|
|
var topic = "topic.push.wx"; |
|
|
|
|
|
var fmMsg = new |
|
|
|
|
|
{ |
|
|
|
|
|
messageId=Guid.NewGuid().ToString("D"), |
|
|
|
|
|
topic= topic, |
|
|
|
|
|
time= DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(fetalMovementSampleTime.Length < 13 ? fetalMovementSampleTime.PadRight(13, '0') : fetalMovementSampleTime)).ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
|
|
data=new { |
|
|
|
|
|
deviceId= device?.DeviceId, |
|
|
|
|
|
imei = heartRate.Serialno, |
|
|
|
|
|
alarmTypeId=12, |
|
|
|
|
|
alarmDeviceName = heartRate.Serialno, |
|
|
|
|
|
alarmRemarks=JsonConvert.SerializeObject(new { fetalMovementValue= fetalMovement, isAbnormal= feltalMovementIsAbnormal }), |
|
|
|
|
|
address=string.Empty, |
|
|
|
|
|
deviceKey=device?.DeviceId |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fmMsgId, topic, fmMsg).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置入库缓存记录 |
|
|
// 设置入库缓存记录 |
|
|
await _deviceCacheMgr.SetFetalMovementAsync(heartRate.Serialno, fetalMovementSampleTime,fm); |
|
|
await _deviceCacheMgr.SetFetalMovementAsync(heartRate.Serialno, fetalMovementSampleTime,fm); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
@@ -855,6 +911,62 @@ namespace HealthMonitor.Service.Resolver |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task SaveAndPushFreqFetalHeartRateAsync(HisGpsHeartRate heartRate, int upperAlarmThreshold, int lowerAlarmThreshold, double avgPhr,string sampleTime) |
|
|
|
|
|
{ |
|
|
|
|
|
var commonPHR = await _serviceTDengine.InitPregnancyCommonHeartRateModeAsync(heartRate.Serialno); |
|
|
|
|
|
if (commonPHR != null) |
|
|
|
|
|
{ |
|
|
|
|
|
// 保存到TDengine数据库 |
|
|
|
|
|
await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", commonPHR); |
|
|
|
|
|
// 计算胎心=孕妇心率*系数 |
|
|
|
|
|
var fetalHeartRate = SafeType.SafeInt(avgPhr * commonPHR?.StatModeAvgFprCoefficient!); |
|
|
|
|
|
var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0); |
|
|
|
|
|
|
|
|
|
|
|
// 保存到 数据服务 MySQL 数据库 |
|
|
|
|
|
HisGpsFetalHeartRate gpsFetalHeartRate = new() |
|
|
|
|
|
{ |
|
|
|
|
|
FetalHeartRateId = Guid.NewGuid().ToString("D"), |
|
|
|
|
|
PersonId = commonPHR!.PersonId, |
|
|
|
|
|
Serialno = heartRate.Serialno, |
|
|
|
|
|
HeartRate = fetalHeartRate, |
|
|
|
|
|
SampleTime = sampleTime.Length > 10 ? sampleTime.Substring(0, 10) : sampleTime, |
|
|
|
|
|
IsAbnormal = isAbnormal, |
|
|
|
|
|
StatStartTime = commonPHR.StatStartTime, |
|
|
|
|
|
StatEndTime = commonPHR.StatEndTime, |
|
|
|
|
|
CreateTime = DateTime.Now, |
|
|
|
|
|
Method = 1, |
|
|
|
|
|
IsDisplay = 1, |
|
|
|
|
|
DeviceKey = commonPHR!.DeviceKey |
|
|
|
|
|
}; |
|
|
|
|
|
await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
|
|
|
|
|
|
|
|
// 推送到微信 |
|
|
|
|
|
var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false); |
|
|
|
|
|
var fhrMsgId = $"{heartRate.Serialno}-{sampleTime}-{Guid.NewGuid().ToString("D")[^3..]}"; |
|
|
|
|
|
var topic = "topic.push.wx"; |
|
|
|
|
|
var fhrMsg = new |
|
|
|
|
|
{ |
|
|
|
|
|
messageId = fhrMsgId, |
|
|
|
|
|
topic = topic, |
|
|
|
|
|
time = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(sampleTime.Length < 13 ? sampleTime.PadRight(13, '0') : sampleTime)).ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
|
|
data = new |
|
|
|
|
|
{ |
|
|
|
|
|
deviceId = device?.DeviceId, |
|
|
|
|
|
imei = heartRate.Serialno, |
|
|
|
|
|
alarmTypeId = 12, |
|
|
|
|
|
alarmDeviceName = heartRate.Serialno, |
|
|
|
|
|
alarmRemarks = JsonConvert.SerializeObject(new { fetalHeartValue = fetalHeartRate, isAbnormal = isAbnormal }), |
|
|
|
|
|
address = string.Empty, |
|
|
|
|
|
deviceKey = device?.DeviceId |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fhrMsgId, topic, fhrMsg).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
private async Task SetIntervalTriggerAsync(string key,string imei, long interval) |
|
|
private async Task SetIntervalTriggerAsync(string key,string imei, long interval) |
|
|
{ |
|
|
{ |
|
|
// var key = $"health_monitor/schedule_push/{type}/imei/{imei}"; |
|
|
// var key = $"health_monitor/schedule_push/{type}/imei/{imei}"; |
|
|