Selaa lähdekoodia

增加血压标定值下发开关

datasub12_previous
H Vs 1 vuosi sitten
vanhempi
commit
72b2ea50a4
7 muutettua tiedostoa jossa 166 lisäystä ja 115 poistoa
  1. +25
    -0
      HealthMonitor.Model/Config/BoodPressResolverConfig.cs
  2. +40
    -30
      HealthMonitor.Service/Resolver/BloodpressResolver.cs
  3. +2
    -1
      HealthMonitor.WebApi/Program.cs
  4. +87
    -81
      HealthMonitor.WebApi/Worker.cs
  5. +3
    -0
      HealthMonitor.WebApi/appsettings.Development.json
  6. +3
    -0
      HealthMonitor.WebApi/appsettings.production.json
  7. +6
    -3
      HealthMonitor.WebApi/appsettings.test.json

+ 25
- 0
HealthMonitor.Model/Config/BoodPressResolverConfig.cs Näytä tiedosto

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HealthMonitor.Model.Config
{
public class BoodPressResolverConfig
{
/// <summary>
/// 舒张压平均值偏移量
/// </summary>
public decimal SystolicAvgOffset { get; set; }
/// <summary>
/// 收缩雅平均值偏移量
/// </summary>
public decimal DiastolicAvgOffset { get; set; }
/// <summary>
/// 开启血压标定值下发
/// </summary>
public bool EnableBPRefPush { get; set; }

}
}

+ 40
- 30
HealthMonitor.Service/Resolver/BloodpressResolver.cs Näytä tiedosto

@@ -23,6 +23,8 @@ using TelpoDataService.Util;
using TelpoDataService.Util.Entities.GpsLocationHistory;
using HealthMonitor.Service.Biz;
using HealthMonitor.Model.Service;
using Microsoft.Extensions.Options;
using HealthMonitor.Model.Config;

namespace HealthMonitor.Service.Resolver
{
@@ -30,6 +32,7 @@ namespace HealthMonitor.Service.Resolver
public class BloodpressResolver: IResolver
{
private readonly ILogger<BloodpressResolver> _logger;
private readonly BoodPressResolverConfig _configBoodPressResolver;
private readonly PersonCacheManager _personCacheMgr;
private readonly TDengineService _serviceTDengine;
private readonly BloodPressReferenceValueCacheManager _bpRefValCacheManager;
@@ -51,7 +54,7 @@ namespace HealthMonitor.Service.Resolver
GpsCardAccessorClient<GpsPerson> gpsPersonApiClient,
IotWebApiService iotWebApiService,
EtcdService serviceEtcd,
IOptions<BoodPressResolverConfig> optionBoodPressResolver,
ILogger<BloodpressResolver> logger)
{
_httpHelper = httpHelper;
@@ -62,6 +65,7 @@ namespace HealthMonitor.Service.Resolver
_logger = logger;
_personCacheMgr = personCacheMgr;
_serviceEtcd = serviceEtcd;
_configBoodPressResolver= optionBoodPressResolver.Value;

}

@@ -297,37 +301,43 @@ namespace HealthMonitor.Service.Resolver
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)
Console.WriteLine($"{nameof(BloodpressResolver)} 开启血压标定值下发: {_configBoodPressResolver.EnableBPRefPush}");
// 启血压标定值下发开关
if (_configBoodPressResolver.EnableBPRefPush)
{
#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
// 下推
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
}
}
}

#endregion


+ 2
- 1
HealthMonitor.WebApi/Program.cs Näytä tiedosto

@@ -134,7 +134,8 @@ namespace HealthMonitor.WebApi
})
.Configure<RedisConfig>(builder.Configuration.GetSection("Redis"))
.Configure<TDengineServiceConfig>(builder.Configuration.GetSection("TDengineServiceConfig"))
.Configure<ServiceConfig>(builder.Configuration.GetSection("ServiceConfig"));
.Configure<ServiceConfig>(builder.Configuration.GetSection("ServiceConfig"))
.Configure<BoodPressResolverConfig>(builder.Configuration.GetSection("BoodPressResolverConfig"));


builder.Services


+ 87
- 81
HealthMonitor.WebApi/Worker.cs Näytä tiedosto

@@ -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


+ 3
- 0
HealthMonitor.WebApi/appsettings.Development.json Näytä tiedosto

@@ -29,6 +29,9 @@
"EtcdServerAddress": "http://192.168.2.121:2379",
"IotWebApiUrl": "http://id.ssjlai.com/webapi/api/"
},
"BoodPressResolverConfig": {
"EnableBPRefPush": true
}
"ConnectionStrings": {
//"GpsCard_Connection_String": "server=172.16.192.26;port=3304;database=user_operation_platform;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none",
"GpsCard_Connection_String": "server=139.224.254.18;port=3305;database=gps_card;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none",


+ 3
- 0
HealthMonitor.WebApi/appsettings.production.json Näytä tiedosto

@@ -26,6 +26,9 @@
"EtcdServerAddress": "http://172.19.42.40:2379",
"IotWebApiUrl": "http://ai.ssjlai.com/webapi/api/"
},
"BoodPressResolverConfig": {
"EnableBPRefPush": false
},
"ConnectionStrings": {
"GpsCard_Connection_String": "server=rm-uf6j529mu0v6g0btp.mysql.rds.aliyuncs.com;port=3305;database=gps_card;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none",
"HealthMonitor_Connection_String": "server=rm-uf6j529mu0v6g0btp.mysql.rds.aliyuncs.com;port=3305;database=health_monitor;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none"


+ 6
- 3
HealthMonitor.WebApi/appsettings.test.json Näytä tiedosto

@@ -34,12 +34,15 @@
"EtcdServerAddress": "http://172.19.42.44:2379",
"IotWebApiUrl": "http://id.ssjlai.com/webapi/api/"
},
"BoodPressResolverConfig": {
"EnableBPRefPush": true
},
"ConnectionStrings": {
// 测试环境内网
"GpsCard_Connection_String": "server=172.19.42.40;port=3305;database=gps_card;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none",
"HealthMonitor_Connection_String": "server=172.19.42.40;port=3305;database=health_monitor;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none"
"GpsCard_Connection_String": "server=172.19.42.40;port=3305;database=gps_card;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none",
"HealthMonitor_Connection_String": "server=172.19.42.40;port=3305;database=health_monitor;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none"
// 测试环境公网
//"GpsCard_Connection_String": "server=139.224.254.18;port=3305;database=gps_card;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none",
// "HealthMonitor_Connection_String": "server=139.224.254.18;port=3305;database=health_monitor;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none"
// "HealthMonitor_Connection_String": "server=139.224.254.18;port=3305;database=health_monitor;uid=root;pwd=telpo#1234;CharSet=utf8;MinimumPoolSize=10;MaximumPoolSize=1000;SslMode=none"
}
}

Loading…
Peruuta
Tallenna