|
|
@@ -18,7 +18,11 @@ using System.Text; |
|
|
|
using System.Text.Json.Serialization; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using TDengineTMQ; |
|
|
|
using TelpoDataService.Util.Entities.GpsCard; |
|
|
|
using TelpoDataService.Util; |
|
|
|
using TelpoDataService.Util.Entities.GpsLocationHistory; |
|
|
|
using HealthMonitor.Service.Biz; |
|
|
|
using HealthMonitor.Model.Service; |
|
|
|
|
|
|
|
namespace HealthMonitor.Service.Resolver |
|
|
|
{ |
|
|
@@ -32,6 +36,9 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
|
|
|
|
private readonly HttpHelper _httpHelper = default!; |
|
|
|
|
|
|
|
private readonly GpsCardAccessorClient<GpsPerson> _gpsPersonApiClient; |
|
|
|
private readonly IotWebApiService _serviceIotWebApi; |
|
|
|
|
|
|
|
private readonly AsyncLocal<string> _messageId = new(); |
|
|
|
private readonly AsyncLocal<HisGpsBloodPress> _msgData = new(); |
|
|
|
|
|
|
@@ -41,15 +48,21 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
TDengineService serviceDengine, |
|
|
|
BloodPressReferenceValueCacheManager bpRefValCacheManager, |
|
|
|
PersonCacheManager personCacheMgr, HttpHelper httpHelper, |
|
|
|
GpsCardAccessorClient<GpsPerson> gpsPersonApiClient, |
|
|
|
IotWebApiService iotWebApiService, |
|
|
|
EtcdService serviceEtcd, |
|
|
|
|
|
|
|
ILogger<BloodpressResolver> logger) |
|
|
|
{ |
|
|
|
_httpHelper = httpHelper; |
|
|
|
_serviceTDengine = serviceDengine; |
|
|
|
_bpRefValCacheManager = bpRefValCacheManager; |
|
|
|
_gpsPersonApiClient = gpsPersonApiClient; |
|
|
|
_serviceIotWebApi = iotWebApiService; |
|
|
|
_logger = logger; |
|
|
|
_personCacheMgr = personCacheMgr; |
|
|
|
_serviceEtcd = serviceEtcd; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void SetResolveInfo(PackageMsgModel msg) |
|
|
@@ -113,6 +126,12 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
var diastolicRefValue = bpRef?.Diastolic;//? |
|
|
|
long duration = 7 * 24 * 3600 * 1000; |
|
|
|
|
|
|
|
int systolicInc; |
|
|
|
int diastolicInc; |
|
|
|
string sql = string.Empty; |
|
|
|
|
|
|
|
var remarkFlag = false; |
|
|
|
|
|
|
|
// 曾经有下发记录 |
|
|
|
if (last?.Count!=0) |
|
|
|
{ |
|
|
@@ -153,6 +172,13 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
var diastolicMin = diastolicAggregate.Min; |
|
|
|
|
|
|
|
|
|
|
|
// 偏移参数 |
|
|
|
var avgOffset = 0.25M; |
|
|
|
|
|
|
|
var systolicAvgOffset = avgOffset; |
|
|
|
var diastolicAvgOffset = avgOffset; |
|
|
|
|
|
|
|
|
|
|
|
// 计算去除最大值和最小值和异常值的平均值 |
|
|
|
var systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and systolic_value < {systolicRefValue} "); |
|
|
|
var diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and diastolic_value < {diastolicRefValue}"); |
|
|
@@ -160,6 +186,47 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
if (systolicAvg.Equals(0) || diastolicAvg.Equals(0)) |
|
|
|
{ |
|
|
|
_logger.LogWarning("平均值为0不保存"); |
|
|
|
systolicAvg = bp.SystolicValue; |
|
|
|
diastolicAvg = bp.DiastolicValue; |
|
|
|
systolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)! > 0? (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!:0; |
|
|
|
diastolicInc = (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)! >0? (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!:0; |
|
|
|
|
|
|
|
// 初始化 remark |
|
|
|
remarkFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(bp.Serialno, (int)systolicRefValue!, (int)diastolicRefValue!, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
if (remarkFlag) |
|
|
|
{ |
|
|
|
// 下推 |
|
|
|
BloodPressCalibrationConfigModel bpIncData = new() |
|
|
|
{ |
|
|
|
|
|
|
|
Imei = bp.Serialno, |
|
|
|
SystolicRefValue = (int)systolicRefValue!, //收缩压标定值,值为0 表示不生效 |
|
|
|
DiastolicRefValue = (int)diastolicRefValue!, //舒张压标定值,值为0表示不生效 |
|
|
|
SystolicIncValue = systolicInc, //收缩压显示增量,值为0 表示不生效 |
|
|
|
DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效 |
|
|
|
}; |
|
|
|
// 下发 IOT 增量值 |
|
|
|
var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); |
|
|
|
if (flagIot) |
|
|
|
{ |
|
|
|
#region 保存下推记录 stb_hm_bp_push_ref_inc_value |
|
|
|
sql = $"INSERT INTO health_monitor.hm_bp_push_ref_inc_value_{bp.Serialno.Substring(bp.Serialno.Length - 2)} " + |
|
|
|
$"USING health_monitor.stb_hm_bp_push_ref_inc_value " + |
|
|
|
$"TAGS ('{bp.Serialno.Substring(bp.Serialno.Length - 2)}') " + |
|
|
|
$"VALUES(" + |
|
|
|
$"'{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}'," + |
|
|
|
$"'{bp.Serialno}'," + |
|
|
|
$"{systolicRefValue}," + |
|
|
|
$"{diastolicRefValue}," + |
|
|
|
$"{systolicInc}," + |
|
|
|
$"{diastolicInc}," + |
|
|
|
$"{true})"; |
|
|
|
|
|
|
|
_serviceTDengine.ExecuteInsertSQL(sql); |
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@@ -169,27 +236,18 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 偏移参数 |
|
|
|
var avgOffset = 0.25M; |
|
|
|
|
|
|
|
var systolicAvgOffset = avgOffset; |
|
|
|
var diastolicAvgOffset = avgOffset; |
|
|
|
|
|
|
|
|
|
|
|
// 增量值=(标定值-平均值)* 0.25 |
|
|
|
var systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; |
|
|
|
var diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; |
|
|
|
systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; |
|
|
|
diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 插入BP增量值 hm_bloodpress_stats_inc |
|
|
|
// 自动建表 |
|
|
|
var sql = $"INSERT INTO health_monitor.hm_bp_stats_inc_{bp.Serialno.Substring(bp.Serialno.Length - 2)} " + |
|
|
|
sql = $"INSERT INTO health_monitor.hm_bp_stats_inc_{bp.Serialno.Substring(bp.Serialno.Length - 2)} " + |
|
|
|
$"USING health_monitor.stb_hm_bloodpress_stats_inc " + |
|
|
|
$"TAGS ('{bp.Serialno.Substring(bp.Serialno.Length - 2)}') " + |
|
|
|
$"VALUES(" + |
|
|
@@ -226,6 +284,41 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
// 发送到 设置设备血压标定参数 |
|
|
|
|
|
|
|
#endregion |
|
|
|
// 初始化 remark |
|
|
|
remarkFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(bp.Serialno, (int)systolicRefValue!, (int)diastolicRefValue!, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
if (remarkFlag) |
|
|
|
{ |
|
|
|
// 下推 |
|
|
|
BloodPressCalibrationConfigModel bpIncData = new() |
|
|
|
{ |
|
|
|
|
|
|
|
Imei = bp.Serialno, |
|
|
|
SystolicRefValue = (int)systolicRefValue!, //收缩压标定值,值为0 表示不生效 |
|
|
|
DiastolicRefValue = (int)diastolicRefValue!, //舒张压标定值,值为0表示不生效 |
|
|
|
SystolicIncValue = systolicInc, //收缩压显示增量,值为0 表示不生效 |
|
|
|
DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效 |
|
|
|
}; |
|
|
|
// 下发 IOT 增量值 |
|
|
|
var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); |
|
|
|
if (flagIot) |
|
|
|
{ |
|
|
|
#region 保存下推记录 stb_hm_bp_push_ref_inc_value |
|
|
|
sql = $"INSERT INTO health_monitor.hm_bp_push_ref_inc_value_{bp.Serialno.Substring(bp.Serialno.Length - 2)} " + |
|
|
|
$"USING health_monitor.stb_hm_bp_push_ref_inc_value " + |
|
|
|
$"TAGS ('{bp.Serialno.Substring(bp.Serialno.Length - 2)}') " + |
|
|
|
$"VALUES(" + |
|
|
|
$"'{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}'," + |
|
|
|
$"'{bp.Serialno}'," + |
|
|
|
$"{systolicRefValue}," + |
|
|
|
$"{diastolicRefValue}," + |
|
|
|
$"{systolicInc}," + |
|
|
|
$"{diastolicInc}," + |
|
|
|
$"{true})"; |
|
|
|
|
|
|
|
_serviceTDengine.ExecuteInsertSQL(sql); |
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 注册定时下发事件 |
|
|
|
// 获取当前时间 |
|
|
@@ -266,7 +359,7 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
|
|
|
|
//var result = JsonConvert.SerializeObject(data); |
|
|
|
//var result = bp.Serialno; |
|
|
|
|
|
|
|
|
|
|
|
var key = $"health_moniter/schedule_push/imei/{bp.Serialno}"; |
|
|
|
var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false); |
|
|
|
if (string.IsNullOrWhiteSpace(schedule_push)) |
|
|
|