H Vs před 1 rokem
rodič
revize
8b1ffde840
13 změnil soubory, kde provedl 364 přidání a 200 odebrání
  1. +102
    -0
      HealthMonitor.Core/Context/Taos/HealthMonitorTaosDataContext.cs
  2. +3
    -0
      HealthMonitor.Core/HealthMonitor.Core.csproj
  3. +9
    -6
      HealthMonitor.Service/Biz/db/TDengineService.cs
  4. +4
    -1
      HealthMonitor.Service/HealthMonitor.Service.csproj
  5. +2
    -2
      HealthMonitor.Service/Resolver/BloodpressResolver.cs
  6. +3
    -2
      HealthMonitor.Service/Resolver/Factory/ResolverFactory.cs
  7. +0
    -1
      HealthMonitor.Service/Resolver/Interface/IResolver.cs
  8. +0
    -1
      HealthMonitor.Service/Resolver/Interface/IResolverFactory.cs
  9. +4
    -3
      HealthMonitor.Service/Sub/TDengineDataSubcribe.cs
  10. +36
    -0
      HealthMonitor.Util/Entities/HealthMonitor/Taos/StbHmBloodPress.cs
  11. +4
    -0
      HealthMonitor.Util/HealthMonitor.Util.csproj
  12. +194
    -183
      HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs
  13. +3
    -1
      HealthMonitor.WebApi/Program.cs

+ 102
- 0
HealthMonitor.Core/Context/Taos/HealthMonitorTaosDataContext.cs Zobrazit soubor

@@ -0,0 +1,102 @@

using HealthMonitor.Core.Dal;
using HealthMonitor.Core.Map;
using HealthMonitor.Util.Entities.HealthMonitor.Taos;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace HealthMonitor.Core.Context.Taos
{
public class HealthMonitorTaosDataContext : DbContext, IWithDataSchema
{

public DbSet<StbHmBloodPress> StbHmBloodPress { get; set; } = default!;
public string DataSchema { get; }
public HealthMonitorTaosDataContext(DbContextOptions<HealthMonitorTaosDataContext> options)
: base(options)
{
DataSchema = "health_monitor";
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// base.OnConfiguring(optionsBuilder);
optionsBuilder.UseTaos(@"Data Source=172.16.255.180;DataBase=health_monitor;Username=root;Password=taosdata;Port=6030;PoolSize=20;Protocol=Native");
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//modelBuilder.HasDefaultSchema(DataSchema);

//var typesToRegister = Assembly.GetExecutingAssembly().GetTypes()
// .Where(type => !string.IsNullOrEmpty(type.Namespace) && type.Namespace.StartsWith("HealthMonitor.Core.Map.HealthMonitor.Taos"))
// .Where(type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(GenericEntityTypeConfiguration<>));

//foreach (var t in typesToRegister)
//{
// dynamic configurationInstance = Activator.CreateInstance(t)!;
// modelBuilder.ApplyConfiguration(configurationInstance);
//}

//base.OnModelCreating(modelBuilder);

modelBuilder.Entity<StbHmBloodPress>().HasKey(e => e.Ts)
.HasName("PRIMARY");

modelBuilder.Entity<StbHmBloodPress>().ToTable("stb_hm_bloodpress");

modelBuilder.Entity<StbHmBloodPress>().Property(e => e.Ts)
.HasColumnName("ts")
.HasColumnType("timestamp");

modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.Serialno)
.HasColumnName("serialno");

modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.BloodPressId)
.HasColumnName("bloodpress_id");

modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.MessageId)
.HasColumnName("message_id");

modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.SystolicValue)
.HasColumnName("systolic_value");

modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.DiastolicValue)
.HasColumnName("diastolic_value");


modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.LastUpdate)
.HasColumnName("last_update");


modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.CreateTime)
.HasColumnName("create_time");


modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.Method)
.HasColumnName("method");


modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.IsDisplay)
.HasColumnName("is_display");

modelBuilder.Entity<StbHmBloodPress>()
.Property(e => e.TailNo)
.HasColumnName("serial_tail_no");
}
}
}

+ 3
- 0
HealthMonitor.Core/HealthMonitor.Core.csproj Zobrazit soubor

@@ -9,10 +9,13 @@
<ItemGroup>
<PackageReference Include="AspectCore.Extensions.DependencyInjection" Version="2.3.0" />
<PackageReference Include="CSRedisCore" Version="3.6.8" />
<PackageReference Include="IoTSharp.EntityFrameworkCore.Taos" Version="3.0.21.90" />

<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Map\HealthMonitor\Taos\" />
<Folder Include="Operator\Default\" />
</ItemGroup>



+ 9
- 6
HealthMonitor.Service/Biz/db/TDengineService.cs Zobrazit soubor

@@ -1,4 +1,5 @@
using HealthMonitor.Common;
extern alias CustomTypes;
using HealthMonitor.Common;
using HealthMonitor.Common.helper;
using HealthMonitor.Model.Config;
using HealthMonitor.Service.Biz.db.Dto;
@@ -11,8 +12,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TDengineDriver;
using TDengineDriver.Impl;

using CustomTypes.TDengineDriver;
using CustomTypes.TDengineDriver.Impl;

namespace HealthMonitor.Service.Biz.db
{
@@ -44,7 +46,7 @@ namespace HealthMonitor.Service.Biz.db
// //TDengine.Options((int)TDengineInitOption.TSDB_OPTION_CONFIGDIR, configDir);
// TDengine.Options((int)TDengineInitOption.TSDB_OPTION_TIMEZONE, "Asia/Beijing");
//#endif
IntPtr conn = TDengine.Connect(host, user, password, db, port);
IntPtr conn = TDengineDriver.TDengine.Connect(host, user, password, db, port);


if (conn == IntPtr.Zero)
@@ -72,6 +74,7 @@ namespace HealthMonitor.Service.Biz.db
}
else
{
Console.Write(sql + " success, {0} rows affected", TDengine.AffectRows(res));
//... do something with res ...

@@ -98,7 +101,7 @@ namespace HealthMonitor.Service.Biz.db
Console.Write(sql + " success, {0} rows affected", TDengine.AffectRows(res));
//... do something with res ...

List<TDengineDriver.TDengineMeta> resMeta = LibTaos.GetMeta(res);
List<TDengineMeta> resMeta = LibTaos.GetMeta(res);
List<object> resData = LibTaos.GetData(res);

foreach (var meta in resMeta)
@@ -210,7 +213,7 @@ namespace HealthMonitor.Service.Biz.db
{
var conn = Connection();
QueryAsyncCallback queryAsyncCallback = new QueryAsyncCallback(QueryCallback);
TDengine.QueryAsync(conn, sql, queryAsyncCallback, IntPtr.Zero);
CustomTypes.TDengineDriver.TDengine.QueryAsync(conn, sql, queryAsyncCallback, IntPtr.Zero);
}

//public void ExecuteQuery(string sql)


+ 4
- 1
HealthMonitor.Service/HealthMonitor.Service.csproj Zobrazit soubor

@@ -11,7 +11,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="TDengine.Connector" Version="3.0.2" />
<PackageReference Include="TDengine.Connector" Version="3.0.2" >
<Aliases>CustomTypes</Aliases>
</PackageReference>

<PackageReference Include="TelpoDataService.Util" Version="1.6.9.16-beta1" />
</ItemGroup>



+ 2
- 2
HealthMonitor.Service/Resolver/BloodpressResolver.cs Zobrazit soubor

@@ -1,4 +1,4 @@

extern alias CustomTypes;
using HealthMonitor.Common;
using HealthMonitor.Service.Biz.db;
using HealthMonitor.Service.Cache;
@@ -14,7 +14,7 @@ using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using TDengineTMQ;
using CustomTypes.TDengineTMQ;
using TelpoDataService.Util.Entities.GpsLocationHistory;

namespace HealthMonitor.Service.Resolver


+ 3
- 2
HealthMonitor.Service/Resolver/Factory/ResolverFactory.cs Zobrazit soubor

@@ -1,4 +1,5 @@
using HealthMonitor.Service.Resolver.Interface;
extern alias CustomTypes;
using HealthMonitor.Service.Resolver.Interface;
using HealthMonitor.Service.Sub;
using HealthMonitor.Service.Sub.Topic.Model;
using Microsoft.Extensions.Logging;
@@ -8,7 +9,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TDengineTMQ;
using CustomTypes.TDengineTMQ;
using TelpoDataService.Util.Entities.GpsLocationHistory;

namespace HealthMonitor.Service.Resolver.Factory


+ 0
- 1
HealthMonitor.Service/Resolver/Interface/IResolver.cs Zobrazit soubor

@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TDengineTMQ;

namespace HealthMonitor.Service.Resolver.Interface
{


+ 0
- 1
HealthMonitor.Service/Resolver/Interface/IResolverFactory.cs Zobrazit soubor

@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TDengineTMQ;

namespace HealthMonitor.Service.Resolver.Interface
{


+ 4
- 3
HealthMonitor.Service/Sub/TDengineDataSubcribe.cs Zobrazit soubor

@@ -1,4 +1,5 @@
using HealthMonitor.Common;
extern alias CustomTypes;
using HealthMonitor.Common;
using HealthMonitor.Core.Dal;
using HealthMonitor.Model.Config;
using HealthMonitor.Service.Biz.db;
@@ -17,8 +18,8 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TDengineDriver;
using TDengineTMQ;
using CustomTypes.TDengineDriver;
using CustomTypes.TDengineTMQ;
using TelpoDataService.Util.Entities.GpsLocationHistory;

namespace HealthMonitor.Service.Sub


+ 36
- 0
HealthMonitor.Util/Entities/HealthMonitor/Taos/StbHmBloodPress.cs Zobrazit soubor

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

namespace HealthMonitor.Util.Entities.HealthMonitor.Taos
{
public class StbHmBloodPress
{
[JsonProperty("ts")]
public DateTime Ts { get; set; } = default!;
[JsonProperty("bloodpress_id")]
public string BloodPressId { get; set; } = default!;
[JsonProperty("message_id")]
public string MessageId { get; set; } = default!;
[JsonProperty("serialno")]
public string Serialno { get; set; } = default!;
[JsonProperty("systolic_value")]
public int SystolicValue { get; set; }
[JsonProperty("diastolic_value")]
public int DiastolicValue { get; set; }
[JsonProperty("last_update")]
public DateTime LastUpdate { get; set; }
[JsonProperty("create_time")]
public DateTime CreateTime { get; set; }
[JsonProperty("method")]
public sbyte Method { get; set; }
[JsonProperty("is_display")]
public bool IsDisplay { get; set; }

[JsonProperty("serial_tail_no")]
public string TailNo { get; set; }=string.Empty;
}
}

+ 4
- 0
HealthMonitor.Util/HealthMonitor.Util.csproj Zobrazit soubor

@@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>

+ 194
- 183
HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs Zobrazit soubor

@@ -1,4 +1,5 @@
using HealthMonitor.Common;
using HealthMonitor.Core.Context.Taos;
using HealthMonitor.Core.Dal;
using HealthMonitor.Model.Cache;
using HealthMonitor.Service.Biz.db;
@@ -6,6 +7,7 @@ using HealthMonitor.Service.Cache;
using HealthMonitor.Util.Entities.HealthMonitor;
using HealthMonitor.WebApi.Configs;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -18,187 +20,196 @@ using TelpoDataService.Util.Entities.GpsLocationHistory;

namespace HealthMonitor.WebApi.Controllers.HealthMonitor
{
//[ApiExplorerSettings(GroupName = AppConsts.SWAGGER_DOC_HealthMonitor)]
//[Produces("application/json")]
//[Route("api/HealthMonitor/[controller]/[action]")]
//[ApiController]
//public class HmBloodPressController:ControllerBase
//{

// protected readonly ILogger _logger;
// private readonly TDengineService _serviceTDengine;
// private readonly PersonCacheManager _personCacheMgr;
// private readonly BloodPressReferenceValueCacheManager _bpRefValCacheManager;
// protected readonly IHealthMonitorDataAccessor _dataAccessor;


// public HmBloodPressController
// (
// ILogger<HmBloodPressController> logger,
// TDengineService serviceDengine,
// PersonCacheManager personCacheMgr,
// BloodPressReferenceValueCacheManager bpRefValCacheManager,
// IHealthMonitorDataAccessor dataAccessor
// )
// {
// _logger = logger;
// _serviceTDengine = serviceDengine;
// _personCacheMgr = personCacheMgr;
// _dataAccessor = dataAccessor;
// _bpRefValCacheManager = bpRefValCacheManager;
// }

// [HttpPost]
// public async Task<IActionResult> AddAsync([FromHeader] string requestId,[FromBody] HisGpsBloodPress bp)
// {
// //
// //HisGpsBloodPress bp = new()
// //{
// // BloodPressId = "261850cb-ce91-4003-8c63-a1f8f50d6495",
// // MessageId = "1670682284342246914",
// // Serialno = "861281060083627",
// // SystolicValue = 114,
// // DiastolicValue = 79,
// // CreateTime = DateTime.Parse("2023-06-19 14:37:53"),
// // LastUpdate = DateTime.Parse("2023-06-19 14:26:52"),
// // Method = 1,
// // IsDisplay = 1
// //};

// //
// //861281060081969
// //HisGpsBloodPress bp = new()
// //{
// // BloodPressId = "7df62202-8d49-4f91-90da-25a4036c26fb",
// // MessageId = "1670992704491900929",
// // Serialno = "861281060081969",
// // SystolicValue = 110,
// // DiastolicValue = 72,
// // CreateTime = DateTime.Parse("2023-06-20 11:11:31"),
// // LastUpdate = DateTime.Parse("2023-06-20 10:20:40"),
// // Method = 1,
// // IsDisplay = 1
// //};

// // 861281060086380


// //var aggregate = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "hm_bloodpress", $"ts>='{DateTime.Now.AddDays(-7):yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{DateTime.Now:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='861281060083627' and systolic_value < {120} and diastolic_value >{80}");

// //+++++++++++++++++++++++++++++++



// #region 获取个人信息

// var person = await _personCacheMgr.GetDeviceGpsPersonCacheBySerialNoAsync(bp.MessageId, bp.Serialno).ConfigureAwait(false);
// // 验证这个信息是否存在
// if (person == null || person?.Person.BornDate == null) return Ok(false);
// // 验证年龄是否在范围 (2 - 120)
// var age = SafeType.SafeInt(DateTime.Today.Year - person?.Person.BornDate!.Value.Year!);
// if (age < 1 || age > 120) return Ok(false);

// var gender = person?.Person.Gender == true ? 1 : 2;
// var isHypertension = SafeType.SafeBool(person?.Person.Ishypertension!);
// var height = SafeType.SafeDouble(person?.Person.Height!);
// var weight = SafeType.SafeDouble(person?.Person.Weight!);
// #endregion

// #region 插入当次BP数据
// // 保存到TDengine

// var bpSql = $"INSERT INTO health_monitor.hm_bloodpress VALUES(" +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{bp.BloodPressId}'," +
// $"'{bp.MessageId}'," +
// $"'{bp.Serialno}'," +
// $"{bp.SystolicValue}," +
// $"{bp.DiastolicValue}," +
// $"'{bp.CreateTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"{bp.Method}," +
// $"{bp.IsDisplay == 1})";

// await _serviceTDengine.GernalRestSql(bpSql);

// #endregion

// #region 计算增量值
// var bpRef = await _bpRefValCacheManager.GetBloodPressReferenceValueAsync(age, gender, isHypertension);

// var systolicRefValue = bpRef?.Systolic;//?
// var diastolicRefValue = bpRef?.Diastolic;//?
// int duration = 30;
// // 获取历史数据
// DateTime now = DateTime.Now;
// DateTime startTime = now.AddDays(-duration);
// DateTime endTime = now;

// //
// var systolicAggregate = await _serviceTDengine.GetAggregateValueAsync("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
// var diastolicAggregate = await _serviceTDengine.GetAggregateValueAsync("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");

// // 最大值
// var systolicMax = systolicAggregate.Max;
// var diastolicMax = diastolicAggregate.Max;
// // 最小值
// var systolicMin = systolicAggregate.Min;
// var diastolicMin = diastolicAggregate.Min;


// // 计算去除最大值和最小值和异常值的平均值
// var systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "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} and diastolic_value >{diastolicRefValue}");
// var diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "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} and diastolic_value >{diastolicRefValue}");

// // 偏移参数
// 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)!;

// #endregion

// #region 插入BP增量值
// var sql = $"INSERT INTO health_monitor.hm_bloodpress_stats_inc VALUES(" +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{bp.BloodPressId}'," +
// $"'{bp.MessageId}'," +
// $"'{bp.Serialno}'," +
// $"{bp.SystolicValue}," +
// $"{systolicRefValue}," +
// $"{systolicAvg}," +
// $"{systolicMax}," +
// $"{systolicMin}," +
// $"{systolicAvgOffset}," +
// $"{systolicInc}," +
// $"{bp.DiastolicValue}," +
// $"{diastolicRefValue}," +
// $"{diastolicAvg}," +
// $"{diastolicMax}," +
// $"{diastolicMin}," +
// $"{diastolicAvgOffset}," +
// $"{diastolicInc}," +
// $"{gender}," +
// $"{age}," +
// $"{height}," +
// $"{weight}," +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"{duration}," +
// $"'{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{string.Empty}')";
// var res = await _serviceTDengine.GernalRestSql(sql);
// #endregion

// return Ok(res);
// }
//}
[ApiExplorerSettings(GroupName = AppConsts.SWAGGER_DOC_HealthMonitor)]
[Produces("application/json")]
[Route("api/HealthMonitor/[controller]/[action]")]
[ApiController]
public class HmBloodPressController : ControllerBase
{


protected readonly ILogger _logger;
private readonly TDengineService _serviceTDengine;
private readonly PersonCacheManager _personCacheMgr;
private readonly BloodPressReferenceValueCacheManager _bpRefValCacheManager;
protected readonly IHealthMonitorDataAccessor _dataAccessor;
private readonly HealthMonitorTaosDataContext _db;


public HmBloodPressController
(
ILogger<HmBloodPressController> logger,
TDengineService serviceDengine,
PersonCacheManager personCacheMgr,
BloodPressReferenceValueCacheManager bpRefValCacheManager,
IHealthMonitorDataAccessor dataAccessor,
HealthMonitorTaosDataContext db

)
{
_logger = logger;
_serviceTDengine = serviceDengine;
_personCacheMgr = personCacheMgr;
_dataAccessor = dataAccessor;
_bpRefValCacheManager = bpRefValCacheManager;
_db = db;

}
[HttpGet]
public async Task<IActionResult> GetAsync([FromHeader] string requestId)
{
var aa = await _db.StbHmBloodPress.FirstOrDefaultAsync();
return Ok(aa);
}

//[HttpPost]
//public async Task<IActionResult> AddAsync([FromHeader] string requestId, [FromBody] HisGpsBloodPress bp)
//{
// //
// //HisGpsBloodPress bp = new()
// //{
// // BloodPressId = "261850cb-ce91-4003-8c63-a1f8f50d6495",
// // MessageId = "1670682284342246914",
// // Serialno = "861281060083627",
// // SystolicValue = 114,
// // DiastolicValue = 79,
// // CreateTime = DateTime.Parse("2023-06-19 14:37:53"),
// // LastUpdate = DateTime.Parse("2023-06-19 14:26:52"),
// // Method = 1,
// // IsDisplay = 1
// //};

// //
// //861281060081969
// //HisGpsBloodPress bp = new()
// //{
// // BloodPressId = "7df62202-8d49-4f91-90da-25a4036c26fb",
// // MessageId = "1670992704491900929",
// // Serialno = "861281060081969",
// // SystolicValue = 110,
// // DiastolicValue = 72,
// // CreateTime = DateTime.Parse("2023-06-20 11:11:31"),
// // LastUpdate = DateTime.Parse("2023-06-20 10:20:40"),
// // Method = 1,
// // IsDisplay = 1
// //};

// // 861281060086380


// //var aggregate = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "hm_bloodpress", $"ts>='{DateTime.Now.AddDays(-7):yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{DateTime.Now:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='861281060083627' and systolic_value < {120} and diastolic_value >{80}");

// //+++++++++++++++++++++++++++++++



// #region 获取个人信息

// var person = await _personCacheMgr.GetDeviceGpsPersonCacheBySerialNoAsync(bp.MessageId, bp.Serialno).ConfigureAwait(false);
// // 验证这个信息是否存在
// if (person == null || person?.Person.BornDate == null) return Ok(false);
// // 验证年龄是否在范围 (2 - 120)
// var age = SafeType.SafeInt(DateTime.Today.Year - person?.Person.BornDate!.Value.Year!);
// if (age < 1 || age > 120) return Ok(false);

// var gender = person?.Person.Gender == true ? 1 : 2;
// var isHypertension = SafeType.SafeBool(person?.Person.Ishypertension!);
// var height = SafeType.SafeDouble(person?.Person.Height!);
// var weight = SafeType.SafeDouble(person?.Person.Weight!);
// #endregion

// #region 插入当次BP数据
// // 保存到TDengine

// var bpSql = $"INSERT INTO health_monitor.hm_bloodpress VALUES(" +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{bp.BloodPressId}'," +
// $"'{bp.MessageId}'," +
// $"'{bp.Serialno}'," +
// $"{bp.SystolicValue}," +
// $"{bp.DiastolicValue}," +
// $"'{bp.CreateTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"{bp.Method}," +
// $"{bp.IsDisplay == 1})";

// await _serviceTDengine.GernalRestSql(bpSql);

// #endregion

// #region 计算增量值
// var bpRef = await _bpRefValCacheManager.GetBloodPressReferenceValueAsync(age, gender, isHypertension);

// var systolicRefValue = bpRef?.Systolic;//?
// var diastolicRefValue = bpRef?.Diastolic;//?
// int duration = 30;
// // 获取历史数据
// DateTime now = DateTime.Now;
// DateTime startTime = now.AddDays(-duration);
// DateTime endTime = now;

// //
// var systolicAggregate = await _serviceTDengine.GetAggregateValueAsync("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
// var diastolicAggregate = await _serviceTDengine.GetAggregateValueAsync("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");

// // 最大值
// var systolicMax = systolicAggregate.Max;
// var diastolicMax = diastolicAggregate.Max;
// // 最小值
// var systolicMin = systolicAggregate.Min;
// var diastolicMin = diastolicAggregate.Min;


// // 计算去除最大值和最小值和异常值的平均值
// var systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "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} and diastolic_value >{diastolicRefValue}");
// var diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "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} and diastolic_value >{diastolicRefValue}");

// // 偏移参数
// 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)!;

// #endregion

// #region 插入BP增量值
// var sql = $"INSERT INTO health_monitor.hm_bloodpress_stats_inc VALUES(" +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{bp.BloodPressId}'," +
// $"'{bp.MessageId}'," +
// $"'{bp.Serialno}'," +
// $"{bp.SystolicValue}," +
// $"{systolicRefValue}," +
// $"{systolicAvg}," +
// $"{systolicMax}," +
// $"{systolicMin}," +
// $"{systolicAvgOffset}," +
// $"{systolicInc}," +
// $"{bp.DiastolicValue}," +
// $"{diastolicRefValue}," +
// $"{diastolicAvg}," +
// $"{diastolicMax}," +
// $"{diastolicMin}," +
// $"{diastolicAvgOffset}," +
// $"{diastolicInc}," +
// $"{gender}," +
// $"{age}," +
// $"{height}," +
// $"{weight}," +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"{duration}," +
// $"'{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{string.Empty}')";
// var res = await _serviceTDengine.GernalRestSql(sql);
// #endregion

// return Ok(res);
//}
}
}

+ 3
- 1
HealthMonitor.WebApi/Program.cs Zobrazit soubor

@@ -31,6 +31,7 @@ using Serilog.Core;
using HealthMonitor.WebApi.HttpLog;
using Microsoft.Extensions.Http;
using Microsoft.Extensions.DependencyInjection.Extensions;
using HealthMonitor.Core.Context.Taos;

namespace HealthMonitor.WebApi
{
@@ -121,6 +122,7 @@ namespace HealthMonitor.WebApi

#endregion


#region AOP
//builder.Services.Configure<RedisConfig>(builder.Configuration.GetSection("Redis"));

@@ -191,7 +193,7 @@ namespace HealthMonitor.WebApi
.AddSingleton<TDengineDataSubcribe>()
.AddHostedService<Worker>();
#endregion
builder.Services.AddDbContext<HealthMonitorTaosDataContext>();

builder.Host.UseSerilog();



Načítá se…
Zrušit
Uložit