Browse Source

调整下发时间

datasub12_previous
H Vs 1 year ago
parent
commit
2ac90bf2db
2 changed files with 88 additions and 13 deletions
  1. +39
    -3
      HealthMonitor.Service/Resolver/BloodpressResolver.cs
  2. +49
    -10
      HealthMonitor.WebApi/Worker.cs

+ 39
- 3
HealthMonitor.Service/Resolver/BloodpressResolver.cs View File

@@ -203,7 +203,7 @@ namespace HealthMonitor.Service.Resolver


_serviceTDengine.ExecuteInsertSQL(sql); _serviceTDengine.ExecuteInsertSQL(sql);
// 发送到 设置设备血压标定参数 // 发送到 设置设备血压标定参数
#endregion #endregion


// 注册定时下发事件 // 注册定时下发事件
@@ -244,14 +244,41 @@ namespace HealthMonitor.Service.Resolver




//var result = JsonConvert.SerializeObject(data); //var result = JsonConvert.SerializeObject(data);
var result = bp.Serialno;
//var result = bp.Serialno;
var key = $"health_moniter/schedule_push/imei/{bp.Serialno}"; var key = $"health_moniter/schedule_push/imei/{bp.Serialno}";
var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false); var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(schedule_push)) if (string.IsNullOrWhiteSpace(schedule_push))
{ {
// 注册首次下推 // 注册首次下推
#if DEBUG #if DEBUG
await _serviceEtcd.PutValAsync(key, result, 60*1, false).ConfigureAwait(false);
// await _serviceEtcd.PutValAsync(key, result, 60*1, 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+1, 58).AddDays(interval);
TimeSpan timeUntilNextRun = nextRunTime - now;

// 如果当前时间已经超过了8点,将等待到明天后的8点
if (timeUntilNextRun < TimeSpan.Zero)
{
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromMinutes(1));
nextRunTime += timeUntilNextRun;
}
var ttl = (long)timeUntilNextRun.TotalSeconds;
var data = new
{
imei = bp.Serialno,
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 #else
//DateTime sNow = DateTime.Now; //DateTime sNow = DateTime.Now;


@@ -278,9 +305,18 @@ namespace HealthMonitor.Service.Resolver
if (timeUntilNextRun < TimeSpan.Zero) if (timeUntilNextRun < TimeSpan.Zero)
{ {
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1)); timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1));
nextRunTime += timeUntilNextRun;
} }


var ttl =(long)timeUntilNextRun.TotalSeconds; var ttl =(long)timeUntilNextRun.TotalSeconds;
var data = new
{
imei = bp.Serialno,
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);
#endif #endif




+ 49
- 10
HealthMonitor.WebApi/Worker.cs View File

@@ -162,7 +162,7 @@ namespace HealthMonitor.WebApi
if (newTs.AddDays(7) > DateTime.Now) if (newTs.AddDays(7) > DateTime.Now)
{ {
Console.WriteLine(ts); Console.WriteLine(ts);
var data = new
var bpData = new
{ {
imei = imeiDel, imei = imeiDel,
systolicCalibrationValue = last?[5], //收缩压标定值,值为0 表示不生效 systolicCalibrationValue = last?[5], //收缩压标定值,值为0 表示不生效
@@ -170,24 +170,54 @@ namespace HealthMonitor.WebApi
systolicIncValue = last?[10], //收缩压显示增量,值为0 表示不生效 systolicIncValue = last?[10], //收缩压显示增量,值为0 表示不生效
diastolicIncValue = last?[17] //舒张压显示增量,值为0 表示不生效 diastolicIncValue = last?[17] //舒张压显示增量,值为0 表示不生效
}; };
var str = JsonConvert.SerializeObject(data);
var str = JsonConvert.SerializeObject(bpData);
var url = $"http://id.ssjlai.com/webapi/api/Command/SetBloodPressCalibrationConfig"; var url = $"http://id.ssjlai.com/webapi/api/Command/SetBloodPressCalibrationConfig";
List<KeyValuePair<string, string>> headers = new() List<KeyValuePair<string, string>> headers = new()
{ {
new KeyValuePair<string, string>("AuthKey", "key1") new KeyValuePair<string, string>("AuthKey", "key1")
}; };
var result = await _httpHelper.HttpToPostAsync(url, data, headers).ConfigureAwait(false);
_logger.LogInformation($"向{imeiDel}下发增量值数据:{str},响应:{result}");
var res=JsonConvert.DeserializeObject(result!) as JToken;
if (res!["message"]!.ToString().Equals("ok"))
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"))
{ {
// 注册下次下推 // 注册下次下推
var endTime = DateTime.Now; 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;

// 计算距离下一个$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 #else
// 每$interval天,晚上8点 // 每$interval天,晚上8点
var interval = 1; var interval = 1;
@@ -202,11 +232,20 @@ namespace HealthMonitor.WebApi
if (timeUntilNextRun < TimeSpan.Zero) if (timeUntilNextRun < TimeSpan.Zero)
{ {
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1)); timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1));
nextRunTime += timeUntilNextRun;
} }


// var ttl = timeUntilNextRun.TotalMilliseconds; // var ttl = timeUntilNextRun.TotalMilliseconds;
long ttl = (long)((timeUntilNextRun.TotalMilliseconds-(endTime-startTime).TotalMilliseconds)/1000);
await _serviceEtcd.PutValAsync(key, imeiDel, ttl, false).ConfigureAwait(false);
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 #endif
} }
else else


Loading…
Cancel
Save