Browse Source

调整定时下发增量值

datasub12_previous
H Vs 1 year ago
parent
commit
ec17f00151
1 changed files with 460 additions and 214 deletions
  1. +460
    -214
      HealthMonitor.WebApi/Worker.cs

+ 460
- 214
HealthMonitor.WebApi/Worker.cs View File

@@ -6,6 +6,7 @@ using HealthMonitor.Common.helper;
using HealthMonitor.Core.Common.Extensions;
using HealthMonitor.Model.Config;
using HealthMonitor.Model.Service;
using HealthMonitor.Model.Service.Mapper;
using HealthMonitor.Service.Biz;
using HealthMonitor.Service.Biz.db;
using HealthMonitor.Service.Etcd;
@@ -136,7 +137,7 @@ namespace HealthMonitor.WebApi
}


private void WatchEvents(WatchResponse response)
private void WatchEvents(WatchResponse response)
{

response.Events.ToList().ForEach(async e =>
@@ -162,252 +163,497 @@ namespace HealthMonitor.WebApi
var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(schedule_push))
{
int systolicInc;
int diastolicInc;

var startTime =DateTime.Now;
int systolicRefValue;
int diastolicRefValue;

int systolicAvg;
int diastolicAvg;

int systolicMax = 0;
int diastolicMax = 0;
// 最小值
int systolicMin = 0;
int diastolicMin = 0;

// 偏移参数
var avgOffset = 0.25M;
var systolicAvgOffset = avgOffset;
var diastolicAvgOffset = avgOffset;

// 最后一次下发值
int lastPushSystolicInc = 0;
int lastPushDiastolicInc = 0;


var startTime = DateTime.Now;
// 下发增量值
#region 定时下发增量值
var last= await _serviceTDengine.GetLastAsync("stb_hm_bloodpress_stats_inc", $"serialno='{imeiDel}' order by last_update desc");
var ts = last?[0];
if (DateTime.TryParse(ts?.ToString(),out DateTime newTs))
#region 统计定时下发增量值
//var last = await _serviceTDengine.GetLastAsync("stb_hm_bloodpress_stats_inc", $"serialno='{imeiDel}' order by last_update desc");
//var ts = last?[0];

// 最后一条血压数据
var condition = $"serialno='{imeiDel}' order by last_update desc";
var field = "last_row(*)";
var lastHmBpResponse = await _serviceTDengine.ExecuteSelectRestResponseAsync("stb_hm_bloodpress", condition, field);
var lastHmBpParser = JsonConvert.DeserializeObject<ParseTDengineRestResponse<BloodPressureModel>>(lastHmBpResponse!);
var lastHmBp = lastHmBpParser?.Select().FirstOrDefault();
if (lastHmBpParser?.Select()?.ToList().Count < 2)
{
// 7 天有效数据
if (newTs.AddDays(7) > DateTime.Now)
_logger.LogInformation($"{imeiDel} -- {nameof(Worker)} --{nameof(WatchEvents)} -- 血压数据条目不足");
break;
}

// 7 天有效数据
if (lastHmBp?.Timestamp.AddDays(7) > DateTime.Now)
{
// 计算增量值
condition= $"serialno='{imeiDel}' order by ts desc";
var lastPushResponse = await _serviceTDengine.ExecuteSelectRestResponseAsync("stb_hm_bp_push_ref_inc_value", condition, field);
if (lastPushResponse == null)
{
_logger.LogInformation($"{imeiDel}--没有下发记录");
break;
}
var lastPushParser = JsonConvert.DeserializeObject<ParseTDengineRestResponse<BloodPressurePushRefIncModel>>(lastPushResponse);
var lastPush = lastPushParser!.Select().FirstOrDefault();

systolicRefValue = lastPush!.SystolicRefValue;
diastolicRefValue = lastPush!.DiastolicRefValue;

condition = $"ts between '{startTime:yyyy-MM-dd HH:mm:ss.fff}' and '{lastPush?.Timestamp:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imeiDel}'";
var hmBpResponse = await _serviceTDengine.ExecuteSelectRestResponseAsync("stb_hm_bloodpress", condition);
var hmBpParser = JsonConvert.DeserializeObject<ParseTDengineRestResponse<BloodPressureModel>>(hmBpResponse!);
var hmBp = hmBpParser?.Select();
if (hmBp?.ToList().Count < 2)
{
Console.WriteLine(ts);
var systolic_ref_value = last?[5];
var diastolic_ref_value = last?[12];
var systolic_inc_value = last?[10];
var diastolic_inc_value = last?[17];
_logger.LogInformation($"{imeiDel} -- {nameof(Worker)} --{nameof(WatchEvents)} -- 统计定时下发,计算增量值的数据条目不足");
break;
}

#region 判断是否初始化remark
// 最大值
systolicMax = (int)hmBpParser?.Select(i => i.SystolicValue).Max()!;
diastolicMax = (int)hmBpParser?.Select(i => i.DiastolicValue).Max()!;
// 最小值
systolicMin = (int)hmBpParser?.Select(i => i.SystolicValue).Min()!;
diastolicMin = (int)hmBpParser?.Select(i => i.DiastolicValue).Min()!;

systolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.SystolicValue, SafeType.SafeInt(systolicRefValue!)))!;
diastolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.DiastolicValue, SafeType.SafeInt(diastolicRefValue!)))!;

// 判断是否初始化remark
/**
*
var imei = imeiDel;
var last_push = await _serviceTDengine.GetLastAsync("stb_hm_bp_push_ref_inc_value", $"serialno='{imei}' order by ts desc");
if (last_push?.Count == 0)
{
var dataServiceBaseUrl = $"https://id.ssjlai.com/data";
var DataServicePersionGet = $"{dataServiceBaseUrl}/api/GpsCard/GpsPerson/GetFirst";
List<KeyValuePair<string, string>> Dataheaders = new()
{
new KeyValuePair<string, string>("requestId", $"{imei}")
};
var dataPersion = new
{
filters = new List<object>() { new { key = "serialno", value = $"{imei}", valueType = "string", @operator = "Equal" } },
orderBys = new List<object>() { new { key = "serialno", isDesc = true } }
};
var resRef = await _httpHelper.HttpToPostAsync(DataServicePersionGet, dataPersion, Dataheaders).ConfigureAwait(false);
var resObj = JsonConvert.DeserializeObject(resRef!) as JToken;
var remark = resObj?["remarks"]?.ToString();
// 增量值=(标定值-平均值)* 0.25
var currentSystolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!;
var currentDiastolicInc = (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;

// 修改数据库
if (string.IsNullOrWhiteSpace(remark))
{
var newRemarkData = new
{
imei,
time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
commandValue = new
{
systolicCalibrationValue = systolic_ref_value, //收缩压标定值,值为0 表示不生效
diastolicCalibrationValue = diastolic_ref_value, //舒张压标定值,值为0表示不生效
systolicIncValue = 0, //收缩压显示增量,值为0 表示不生效
diastolicIncValue = 0 //舒张压显示增量,值为0 表示不生效
}
};
resObj!["remarks"] = $"is_blood_press:{JsonConvert.SerializeObject(newRemarkData)}|";
var DataServicePersionUpdate = $"{dataServiceBaseUrl}/api/GpsCard/GpsPerson/Update";
var resUpdate = await _httpHelper.HttpToPostAsync(DataServicePersionUpdate, resObj, Dataheaders).ConfigureAwait(false);
_logger.LogInformation($"更新Person数据库|{resUpdate}");

//更新缓存
List<KeyValuePair<string, string>> headersCache = new()
// 累计增量
systolicInc = currentSystolicInc + lastPushSystolicInc;
diastolicInc = currentDiastolicInc + lastPushDiastolicInc;

_logger.LogInformation($"{nameof(Worker)} 开启血压标定值下发: {_configBoodPressResolver.EnableBPRefPush}");
if (_configBoodPressResolver.EnableBPRefPush)
// if (false) // 临时关闭
{
BloodPressCalibrationConfigModel bpIncData = new()
{
new KeyValuePair<string, string>("AuthKey", "key1")

Imei = imeiDel,
SystolicRefValue = SafeType.SafeInt(((int)systolicRefValue!)), //收缩压标定值,值为0 表示不生效
DiastolicRefValue = SafeType.SafeInt(((int)diastolicRefValue!)), //舒张压标定值,值为0表示不生效
SystolicIncValue = SafeType.SafeInt(((int)systolicInc!)), //收缩压显示增量,值为0 表示不生效
DiastolicIncValue = SafeType.SafeInt(((int)diastolicInc!)) //舒张压显示增量,值为0 表示不生效
};
var pushedBP = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false);
if (pushedBP)
{

var cacheUrl = $"http://id.ssjlai.com/webapi/api/Device/UpdatePersonInfoCache?imei={imei}";
var updateCache = await _httpHelper.HttpToGetAsync(cacheUrl, headersCache);
_logger.LogInformation($"更新Person缓存|{updateCache}");
}
}
*/
#endregion

//var bpData = new
//{
// imei = imeiDel,
// //systolicCalibrationValue = last?[5], //收缩压标定值,值为0 表示不生效
// //diastolicCalibrationValue = last?[12], //舒张压标定值,值为0表示不生效
// //systolicIncValue = last?[10], //收缩压显示增量,值为0 表示不生效
// //diastolicIncValue = last?[17] //舒张压显示增量,值为0 表示不生效

// systolicCalibrationValue = systolic_ref_value, //收缩压标定值,值为0 表示不生效
// diastolicCalibrationValue = diastolic_ref_value, //舒张压标定值,值为0表示不生效
// systolicIncValue = systolic_inc_value, //收缩压显示增量,值为0 表示不生效
// diastolicIncValue = diastolic_inc_value //舒张压显示增量,值为0 表示不生效
//};
//var str = JsonConvert.SerializeObject(bpData);
//var url = $"http://id.ssjlai.com/webapi/api/Command/SetBloodPressCalibrationConfig";
//List<KeyValuePair<string, string>> headers = new()
//{
// new KeyValuePair<string, string>("AuthKey", "key1")
//};
//var res = await _httpHelper.HttpToPostAsync(url, bpData, headers).ConfigureAwait(false);
//_logger.LogInformation($"向{imeiDel}下发增量值数据:{str},响应:{res}");
//var resJToken = JsonConvert.DeserializeObject(res!) as JToken;


//if (resJToken!["message"]!.ToString().Equals("ok"))
Console.WriteLine($"{nameof(Worker)} 开启血压标定值下发: {_configBoodPressResolver.EnableBPRefPush}");
// if (_configBoodPressResolver.EnableBPRefPush)
if (false) // 临时关闭
{
BloodPressCalibrationConfigModel bpIncData = new()
#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(" +
$"'{startTime:yyyy-MM-dd HH:mm:ss.fff}'," +
$"'{imeiDel}'," +
$"{bpIncData.SystolicRefValue}," +
$"{bpIncData.DiastolicRefValue}," +
$"{bpIncData.SystolicIncValue}," +
$"{bpIncData.DiastolicIncValue}," +
$"{true}," +
$"{systolicAvg}," +
$"{diastolicAvg}," +
$"{systolicAvgOffset}," +
$"{diastolicAvgOffset}," +
$"'{lastPush?.Timestamp:yyyy-MM-dd HH:mm:ss.fff}'," +
$"'{startTime:yyyy-MM-dd HH:mm:ss.fff}'" +
$")";
_serviceTDengine.ExecuteInsertSQL(sql);
#endregion

#region 注册定时下发
// 注册下次下推
var endTime = DateTime.Now;

#if DEBUG


//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;

// 计算距离下一个$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;
}

Imei = imeiDel,
SystolicRefValue = SafeType.SafeInt(((int)systolic_ref_value!)), //收缩压标定值,值为0 表示不生效
DiastolicRefValue = SafeType.SafeInt(((int)diastolic_ref_value!)), //舒张压标定值,值为0表示不生效
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 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);

#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


//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;

// 计算距离下一个$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;
}

// 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);


#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;

// 如果当前时间已经超过了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
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false);


}
else
#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;

// 如果当前时间已经超过了8点,将等待到明天后的8点
if (timeUntilNextRun < TimeSpan.Zero)
{
_logger.LogInformation($"错误响应,没有下推数据");
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
#endregion

}
else
{
_logger.LogInformation($"错误响应,没有下推数据");
}
}
}
else
{
_logger.LogInformation($"向{imeiDel}准备下推的数据已经失效ts,{ts}");
_logger.LogInformation($"向{imeiDel}统计数据已经失效");
}


#endregion
//if (imeiDel.Equals("861281060086216"))
//{
// var result = await _httpHelper.HttpToPostAsync(url, data, headers).ConfigureAwait(false);
// _logger.LogInformation($"向{imeiDel}下发增量值数据:{str},响应:{result}");
// Console.WriteLine(str);

//}
//Console.BackgroundColor = ConsoleColor.Black;

}

break;
}

});
//if (response.Events.Count == 0)
//{
// Console.WriteLine(response);
//}
//else
//{
// Console.WriteLine($"{response.Events[0].Kv.Key.ToStringUtf8()}:{response.Events.Kv.Value.ToStringUtf8()}");
//}
}

// private void WatchEvents(WatchResponse response)
// {

// response.Events.ToList().ForEach(async e =>
// {

// switch (e.Type.ToString())
// {
// case "Put":
// // 获取时间点计算TTL
// Console.BackgroundColor = ConsoleColor.Blue;
// Console.WriteLine($"--- {e.Type}--{e.Kv.Key.ToStringUtf8()}--{e.Kv.Value.ToStringUtf8()}---{DateTime.Now}");
// Console.BackgroundColor = ConsoleColor.Black;
// break;

// case "Delete":
// // TTL到了重新计算TTL,下发
// Console.BackgroundColor = ConsoleColor.Green;
// Console.WriteLine($"--- {e.Type}--{e.Kv.Key.ToStringUtf8()}--{e.Kv.Value.ToStringUtf8()}---{DateTime.Now}");

// // var key = $"health_moniter/schedule_push/imei/{bp.Serialno}";
// var key = e.Kv.Key.ToStringUtf8();
// var imeiDel = key.Split('/')[3];
// var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false);
// if (string.IsNullOrWhiteSpace(schedule_push))
// {


// var startTime =DateTime.Now;
// // 下发增量值
// #region 定时下发增量值
// var last= await _serviceTDengine.GetLastAsync("stb_hm_bloodpress_stats_inc", $"serialno='{imeiDel}' order by last_update desc");
// var ts = last?[0];
// if (DateTime.TryParse(ts?.ToString(),out DateTime newTs))
// {
// // 7 天有效数据
// if (newTs.AddDays(7) > DateTime.Now)
// {
// Console.WriteLine(ts);
// var systolic_ref_value = last?[5];
// var diastolic_ref_value = last?[12];
// var systolic_inc_value = last?[10];
// var diastolic_inc_value = last?[17];

// #region 判断是否初始化remark


// // 判断是否初始化remark
// /**
// *
// var imei = imeiDel;
// var last_push = await _serviceTDengine.GetLastAsync("stb_hm_bp_push_ref_inc_value", $"serialno='{imei}' order by ts desc");
// if (last_push?.Count == 0)
// {
// var dataServiceBaseUrl = $"https://id.ssjlai.com/data";
// var DataServicePersionGet = $"{dataServiceBaseUrl}/api/GpsCard/GpsPerson/GetFirst";
// List<KeyValuePair<string, string>> Dataheaders = new()
// {
// new KeyValuePair<string, string>("requestId", $"{imei}")
// };
// var dataPersion = new
// {
// filters = new List<object>() { new { key = "serialno", value = $"{imei}", valueType = "string", @operator = "Equal" } },
// orderBys = new List<object>() { new { key = "serialno", isDesc = true } }
// };
// var resRef = await _httpHelper.HttpToPostAsync(DataServicePersionGet, dataPersion, Dataheaders).ConfigureAwait(false);
// var resObj = JsonConvert.DeserializeObject(resRef!) as JToken;
// var remark = resObj?["remarks"]?.ToString();

// // 修改数据库
// if (string.IsNullOrWhiteSpace(remark))
// {
// var newRemarkData = new
// {
// imei,
// time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
// commandValue = new
// {
// systolicCalibrationValue = systolic_ref_value, //收缩压标定值,值为0 表示不生效
// diastolicCalibrationValue = diastolic_ref_value, //舒张压标定值,值为0表示不生效
// systolicIncValue = 0, //收缩压显示增量,值为0 表示不生效
// diastolicIncValue = 0 //舒张压显示增量,值为0 表示不生效
// }
// };
// resObj!["remarks"] = $"is_blood_press:{JsonConvert.SerializeObject(newRemarkData)}|";
// var DataServicePersionUpdate = $"{dataServiceBaseUrl}/api/GpsCard/GpsPerson/Update";
// var resUpdate = await _httpHelper.HttpToPostAsync(DataServicePersionUpdate, resObj, Dataheaders).ConfigureAwait(false);
// _logger.LogInformation($"更新Person数据库|{resUpdate}");

// //更新缓存
// List<KeyValuePair<string, string>> headersCache = new()
// {
// new KeyValuePair<string, string>("AuthKey", "key1")
// };

// var cacheUrl = $"http://id.ssjlai.com/webapi/api/Device/UpdatePersonInfoCache?imei={imei}";
// var updateCache = await _httpHelper.HttpToGetAsync(cacheUrl, headersCache);
// _logger.LogInformation($"更新Person缓存|{updateCache}");
// }
// }
// */
// #endregion

// //var bpData = new
// //{
// // imei = imeiDel,
// // //systolicCalibrationValue = last?[5], //收缩压标定值,值为0 表示不生效
// // //diastolicCalibrationValue = last?[12], //舒张压标定值,值为0表示不生效
// // //systolicIncValue = last?[10], //收缩压显示增量,值为0 表示不生效
// // //diastolicIncValue = last?[17] //舒张压显示增量,值为0 表示不生效

// // systolicCalibrationValue = systolic_ref_value, //收缩压标定值,值为0 表示不生效
// // diastolicCalibrationValue = diastolic_ref_value, //舒张压标定值,值为0表示不生效
// // systolicIncValue = systolic_inc_value, //收缩压显示增量,值为0 表示不生效
// // diastolicIncValue = diastolic_inc_value //舒张压显示增量,值为0 表示不生效
// //};
// //var str = JsonConvert.SerializeObject(bpData);
// //var url = $"http://id.ssjlai.com/webapi/api/Command/SetBloodPressCalibrationConfig";
// //List<KeyValuePair<string, string>> headers = new()
// //{
// // new KeyValuePair<string, string>("AuthKey", "key1")
// //};
// //var res = await _httpHelper.HttpToPostAsync(url, bpData, headers).ConfigureAwait(false);
// //_logger.LogInformation($"向{imeiDel}下发增量值数据:{str},响应:{res}");
// //var resJToken = JsonConvert.DeserializeObject(res!) as JToken;


// //if (resJToken!["message"]!.ToString().Equals("ok"))
// Console.WriteLine($"{nameof(Worker)} 开启血压标定值下发: {_configBoodPressResolver.EnableBPRefPush}");
// // if (_configBoodPressResolver.EnableBPRefPush)
// if (false) // 临时关闭
// {
// BloodPressCalibrationConfigModel bpIncData = new()
// {

// Imei = imeiDel,
// SystolicRefValue = SafeType.SafeInt(((int)systolic_ref_value!)), //收缩压标定值,值为0 表示不生效
// DiastolicRefValue = SafeType.SafeInt(((int)diastolic_ref_value!)), //舒张压标定值,值为0表示不生效
// 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)
// {

// #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


// //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;

// // 计算距离下一个$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;
// }

// // 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);


//#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;

// // 如果当前时间已经超过了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


// }
// else
// {
// _logger.LogInformation($"错误响应,没有下推数据");
// }
// }
// }
// }
// else
// {
// _logger.LogInformation($"向{imeiDel}准备下推的数据已经失效ts,{ts}");
// }


// #endregion
// //if (imeiDel.Equals("861281060086216"))
// //{
// // var result = await _httpHelper.HttpToPostAsync(url, data, headers).ConfigureAwait(false);
// // _logger.LogInformation($"向{imeiDel}下发增量值数据:{str},响应:{result}");
// // Console.WriteLine(str);

// //}
// //Console.BackgroundColor = ConsoleColor.Black;

// }

// break;
// }

// });
// //if (response.Events.Count == 0)
// //{
// // Console.WriteLine(response);
// //}
// //else
// //{
// // Console.WriteLine($"{response.Events[0].Kv.Key.ToStringUtf8()}:{response.Events.Kv.Value.ToStringUtf8()}");
// //}
// }

}
}

Loading…
Cancel
Save