|
|
@@ -4,6 +4,7 @@ using Google.Protobuf.WellKnownTypes; |
|
|
|
using HealthMonitor.Common; |
|
|
|
using HealthMonitor.Common.helper; |
|
|
|
using HealthMonitor.Core.Common.Extensions; |
|
|
|
using HealthMonitor.Model.Config; |
|
|
|
using HealthMonitor.Model.Service; |
|
|
|
using HealthMonitor.Service.Biz; |
|
|
|
using HealthMonitor.Service.Biz.db; |
|
|
@@ -11,6 +12,7 @@ using HealthMonitor.Service.Etcd; |
|
|
|
using HealthMonitor.Service.Sub; |
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages; |
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Internal; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
using System.Reflection; |
|
|
@@ -30,10 +32,11 @@ namespace HealthMonitor.WebApi |
|
|
|
private readonly EtcdService _serviceEtcd; |
|
|
|
private readonly HttpHelper _httpHelper = default!; |
|
|
|
private readonly IotWebApiService _serviceIotWebApi; |
|
|
|
private readonly BoodPressResolverConfig _configBoodPressResolver; |
|
|
|
|
|
|
|
private CancellationTokenSource _tokenSource=default!; |
|
|
|
|
|
|
|
public Worker(ILogger<Worker> logger, IServiceProvider services, IotWebApiService iotWebApiService, PackageProcess processor,TDengineDataSubcribe tdEngineDataSubcribe, TDengineService serviceDengine, HttpHelper httpHelper, EtcdService serviceEtcd) |
|
|
|
public Worker(ILogger<Worker> logger, IServiceProvider services, IotWebApiService iotWebApiService, IOptions<BoodPressResolverConfig> optionBoodPressResolver, PackageProcess processor,TDengineDataSubcribe tdEngineDataSubcribe, TDengineService serviceDengine, HttpHelper httpHelper, EtcdService serviceEtcd) |
|
|
|
{ |
|
|
|
_logger = logger; |
|
|
|
_tdEngineDataSubcribe = tdEngineDataSubcribe; |
|
|
@@ -43,6 +46,7 @@ namespace HealthMonitor.WebApi |
|
|
|
_serviceEtcd = serviceEtcd; |
|
|
|
_serviceTDengine = serviceDengine; |
|
|
|
_httpHelper = httpHelper; |
|
|
|
_configBoodPressResolver = optionBoodPressResolver.Value; |
|
|
|
} |
|
|
|
|
|
|
|
public override Task StartAsync(CancellationToken cancellationToken) |
|
|
@@ -260,8 +264,10 @@ namespace HealthMonitor.WebApi |
|
|
|
|
|
|
|
|
|
|
|
//if (resJToken!["message"]!.ToString().Equals("ok")) |
|
|
|
|
|
|
|
BloodPressCalibrationConfigModel bpIncData = new() |
|
|
|
Console.WriteLine($"{nameof(Worker)} 开启血压标定值下发: {_configBoodPressResolver.EnableBPRefPush}"); |
|
|
|
if (_configBoodPressResolver.EnableBPRefPush) |
|
|
|
{ |
|
|
|
BloodPressCalibrationConfigModel bpIncData = new() |
|
|
|
{ |
|
|
|
|
|
|
|
Imei = imeiDel, |
|
|
@@ -270,104 +276,104 @@ namespace HealthMonitor.WebApi |
|
|
|
SystolicIncValue = SafeType.SafeInt(((int)systolic_inc_value!)), //收缩压显示增量,值为0 表示不生效 |
|
|
|
DiastolicIncValue = SafeType.SafeInt(((int)diastolic_inc_value!)) //舒张压显示增量,值为0 表示不生效 |
|
|
|
}; |
|
|
|
var pushedBP = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); |
|
|
|
if (pushedBP) |
|
|
|
{ |
|
|
|
var pushedBP = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); |
|
|
|
if (pushedBP) |
|
|
|
{ |
|
|
|
|
|
|
|
#region 保存下推记录 stb_hm_bp_push_ref_inc_value |
|
|
|
var sql = $"INSERT INTO health_monitor.hm_bp_push_ref_inc_value_{imeiDel.Substring(imeiDel.Length - 2)} " + |
|
|
|
$"USING health_monitor.stb_hm_bp_push_ref_inc_value " + |
|
|
|
$"TAGS ('{imeiDel.Substring(imeiDel.Length - 2)}') " + |
|
|
|
$"VALUES(" + |
|
|
|
$"'{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}'," + |
|
|
|
$"'{imeiDel}'," + |
|
|
|
$"{systolic_ref_value}," + |
|
|
|
$"{diastolic_ref_value}," + |
|
|
|
$"{systolic_inc_value}," + |
|
|
|
$"{diastolic_inc_value}," + |
|
|
|
$"{false})"; |
|
|
|
|
|
|
|
_serviceTDengine.ExecuteInsertSQL(sql); |
|
|
|
#endregion |
|
|
|
|
|
|
|
// 注册下次下推 |
|
|
|
var endTime = DateTime.Now; |
|
|
|
#region 保存下推记录 stb_hm_bp_push_ref_inc_value |
|
|
|
var sql = $"INSERT INTO health_monitor.hm_bp_push_ref_inc_value_{imeiDel.Substring(imeiDel.Length - 2)} " + |
|
|
|
$"USING health_monitor.stb_hm_bp_push_ref_inc_value " + |
|
|
|
$"TAGS ('{imeiDel.Substring(imeiDel.Length - 2)}') " + |
|
|
|
$"VALUES(" + |
|
|
|
$"'{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}'," + |
|
|
|
$"'{imeiDel}'," + |
|
|
|
$"{systolic_ref_value}," + |
|
|
|
$"{diastolic_ref_value}," + |
|
|
|
$"{systolic_inc_value}," + |
|
|
|
$"{diastolic_inc_value}," + |
|
|
|
$"{false})"; |
|
|
|
|
|
|
|
_serviceTDengine.ExecuteInsertSQL(sql); |
|
|
|
#endregion |
|
|
|
|
|
|
|
// 注册下次下推 |
|
|
|
var endTime = DateTime.Now; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
#if DEBUG |
|
|
|
|
|
|
|
|
|
|
|
//long ttl = (long)((60 * 1000-(endTime-startTime).TotalMilliseconds)/1000); |
|
|
|
//await _serviceEtcd.PutValAsync(key, imeiDel,ttl, false).ConfigureAwait(false); |
|
|
|
//long ttl = (long)((60 * 1000-(endTime-startTime).TotalMilliseconds)/1000); |
|
|
|
//await _serviceEtcd.PutValAsync(key, imeiDel,ttl, false).ConfigureAwait(false); |
|
|
|
|
|
|
|
var interval = 0; |
|
|
|
// 获取当前时间 |
|
|
|
DateTime now = DateTime.Now; |
|
|
|
var interval = 0; |
|
|
|
// 获取当前时间 |
|
|
|
DateTime now = DateTime.Now; |
|
|
|
|
|
|
|
// 计算距离下一个$interval天后的8点的时间间隔 |
|
|
|
DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute + 2, 0).AddDays(interval); |
|
|
|
TimeSpan timeUntilNextRun = nextRunTime - now; |
|
|
|
// 计算距离下一个$interval天后的8点的时间间隔 |
|
|
|
DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute + 2, 0).AddDays(interval); |
|
|
|
TimeSpan timeUntilNextRun = nextRunTime - now; |
|
|
|
|
|
|
|
// 如果当前时间已经超过了8点,将等待到明天后的8点 |
|
|
|
if (timeUntilNextRun < TimeSpan.Zero) |
|
|
|
{ |
|
|
|
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromMinutes(1)); |
|
|
|
nextRunTime += timeUntilNextRun; |
|
|
|
} |
|
|
|
// 如果当前时间已经超过了8点,将等待到明天后的8点 |
|
|
|
if (timeUntilNextRun < TimeSpan.Zero) |
|
|
|
{ |
|
|
|
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromMinutes(1)); |
|
|
|
nextRunTime += timeUntilNextRun; |
|
|
|
} |
|
|
|
|
|
|
|
// var ttl = timeUntilNextRun.TotalMilliseconds; |
|
|
|
long ttl = (long)((timeUntilNextRun.TotalMilliseconds - (endTime - startTime).TotalMilliseconds) / 1000); |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
imei = imeiDel, |
|
|
|
create_time = now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
ttl, |
|
|
|
next_run_time = nextRunTime.ToString("yyyy-MM-dd HH:mm:ss") |
|
|
|
}; |
|
|
|
var result = JsonConvert.SerializeObject(data); |
|
|
|
// var ttl = timeUntilNextRun.TotalMilliseconds; |
|
|
|
long ttl = (long)((timeUntilNextRun.TotalMilliseconds - (endTime - startTime).TotalMilliseconds) / 1000); |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
imei = imeiDel, |
|
|
|
create_time = now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
ttl, |
|
|
|
next_run_time = nextRunTime.ToString("yyyy-MM-dd HH:mm:ss") |
|
|
|
}; |
|
|
|
var result = JsonConvert.SerializeObject(data); |
|
|
|
|
|
|
|
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); |
|
|
|
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
#else |
|
|
|
// 每$interval天,晚上8点 |
|
|
|
var interval = 1; |
|
|
|
// 获取当前时间 |
|
|
|
DateTime now = DateTime.Now; |
|
|
|
#else |
|
|
|
// 每$interval天,晚上8点 |
|
|
|
var interval = 1; |
|
|
|
// 获取当前时间 |
|
|
|
DateTime now = DateTime.Now; |
|
|
|
|
|
|
|
// 计算距离下一个$interval天后的8点的时间间隔 |
|
|
|
DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, 20, 0, 0).AddDays(interval); |
|
|
|
TimeSpan timeUntilNextRun = nextRunTime - now; |
|
|
|
// 计算距离下一个$interval天后的8点的时间间隔 |
|
|
|
DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, 20, 0, 0).AddDays(interval); |
|
|
|
TimeSpan timeUntilNextRun = nextRunTime - now; |
|
|
|
|
|
|
|
// 如果当前时间已经超过了8点,将等待到明天后的8点 |
|
|
|
if (timeUntilNextRun < TimeSpan.Zero) |
|
|
|
{ |
|
|
|
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1)); |
|
|
|
nextRunTime += timeUntilNextRun; |
|
|
|
} |
|
|
|
// 如果当前时间已经超过了8点,将等待到明天后的8点 |
|
|
|
if (timeUntilNextRun < TimeSpan.Zero) |
|
|
|
{ |
|
|
|
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1)); |
|
|
|
nextRunTime += timeUntilNextRun; |
|
|
|
} |
|
|
|
|
|
|
|
// var ttl = timeUntilNextRun.TotalMilliseconds; |
|
|
|
long ttl = (long)((timeUntilNextRun.TotalMilliseconds-(endTime-startTime).TotalMilliseconds)/1000); |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
imei = imeiDel, |
|
|
|
create_time = now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
ttl, |
|
|
|
next_run_time = nextRunTime.ToString("yyyy-MM-dd HH:mm:ss") |
|
|
|
}; |
|
|
|
var result = JsonConvert.SerializeObject(data); |
|
|
|
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); |
|
|
|
#endif |
|
|
|
// var ttl = timeUntilNextRun.TotalMilliseconds; |
|
|
|
long ttl = (long)((timeUntilNextRun.TotalMilliseconds-(endTime-startTime).TotalMilliseconds)/1000); |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
imei = imeiDel, |
|
|
|
create_time = now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
ttl, |
|
|
|
next_run_time = nextRunTime.ToString("yyyy-MM-dd HH:mm:ss") |
|
|
|
}; |
|
|
|
var result = JsonConvert.SerializeObject(data); |
|
|
|
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogInformation($"错误响应,没有下推数据"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogInformation($"错误响应,没有下推数据"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|