diff --git a/HealthMonitor.Core/Map/HealthMonitor/BloodPressReferenceValueMap.cs b/HealthMonitor.Core/Map/HealthMonitor/HmBloodPressReferenceValueMap.cs similarity index 88% rename from HealthMonitor.Core/Map/HealthMonitor/BloodPressReferenceValueMap.cs rename to HealthMonitor.Core/Map/HealthMonitor/HmBloodPressReferenceValueMap.cs index bd11f4e..9bb2877 100644 --- a/HealthMonitor.Core/Map/HealthMonitor/BloodPressReferenceValueMap.cs +++ b/HealthMonitor.Core/Map/HealthMonitor/HmBloodPressReferenceValueMap.cs @@ -10,9 +10,9 @@ using System.Threading.Tasks; namespace HealthMonitor.Core.Map.HealthMonitor { - public partial class BloodPressReferenceValueMap : GenericEntityTypeConfiguration + public partial class HmBloodPressReferenceValueMap : GenericEntityTypeConfiguration { - public override void Configure(EntityTypeBuilder entity) + public override void Configure(EntityTypeBuilder entity) { entity.HasKey(e => e.Id) .HasName("PRIMARY"); diff --git a/HealthMonitor.Model/Cache/GpsDevicePerson.cs b/HealthMonitor.Model/Cache/GpsDevicePerson.cs new file mode 100644 index 0000000..6b415c8 --- /dev/null +++ b/HealthMonitor.Model/Cache/GpsDevicePerson.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HealthMonitor.Model.Cache +{ + public class Person + { + [JsonProperty("personId")] + public string PersonId { get; set; } = default!; + + [JsonProperty("deviceId")] + public string DeviceId { get; set; } = default!; + + [JsonProperty("serialno")] + public string SerialNo { get; set; } = default!; + + [JsonProperty("remarks")] + public string Remarks { get; set; } = default!; + + [JsonProperty("ishypertension")] + public bool Ishypertension { get; set; } = default!; + + [JsonProperty("personName")] + public string PersonName { get; set; } = default!; + + [JsonProperty("gender")] + public bool Gender { get; set; } = default!; + + [JsonProperty("age")] + public int Age { get; set; } = default!; + + [JsonProperty("bornDate")] + public string BornDate { get; set; } = default!; + + } + public class GpsDevicePerson + { + + [JsonProperty("person")] + public Person Person { get; set; } = default!; + + [JsonProperty("time")] + public DateTime Time { get; set; } = default!; + } +} diff --git a/HealthMonitor.WebApi/Configs/RedisConfig.cs b/HealthMonitor.Model/Config/RedisConfig.cs similarity index 98% rename from HealthMonitor.WebApi/Configs/RedisConfig.cs rename to HealthMonitor.Model/Config/RedisConfig.cs index 630d07c..88ba559 100644 --- a/HealthMonitor.WebApi/Configs/RedisConfig.cs +++ b/HealthMonitor.Model/Config/RedisConfig.cs @@ -1,7 +1,7 @@ using System; using System.Text; -namespace HealthMonitor.WebApi.Configs +namespace HealthMonitor.Model.Config { /// /// Redis配置模板类 diff --git a/HealthMonitor.Model/Config/ServiceConfig.cs b/HealthMonitor.Model/Config/ServiceConfig.cs new file mode 100644 index 0000000..56b355a --- /dev/null +++ b/HealthMonitor.Model/Config/ServiceConfig.cs @@ -0,0 +1,22 @@ +namespace HealthMonitor.Model.Config +{ + public class ServiceConfig + { + /// + /// 数据服务Host Url + /// + public string TelpoDataUrl { get; set; } = default!; + ///// + ///// Kafka服务地址 + ///// + //public string MqServerAddress { get; set; } + ///// + ///// 服务守护消息kafka服务地址 + ///// + //public string ServiceGuardMqAddress { get; set; } + ///// + ///// 服务守护消息主题 + ///// + //public string ServiceGuardMqTopic { get; set; } + } +} diff --git a/HealthMonitor.Model/Config/TDengineServiceConfig.cs b/HealthMonitor.Model/Config/TDengineServiceConfig.cs index f2b575e..cdd2224 100644 --- a/HealthMonitor.Model/Config/TDengineServiceConfig.cs +++ b/HealthMonitor.Model/Config/TDengineServiceConfig.cs @@ -18,6 +18,10 @@ namespace HealthMonitor.Model.Config public string DB { get; set; } = default!; + public short RestPort { get; set; } = default!; + + public string Token {get; set; } = default!; + } } diff --git a/HealthMonitor.Model/HealthMonitor.Model.csproj b/HealthMonitor.Model/HealthMonitor.Model.csproj index 132c02c..f958b97 100644 --- a/HealthMonitor.Model/HealthMonitor.Model.csproj +++ b/HealthMonitor.Model/HealthMonitor.Model.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/HealthMonitor.Service/Biz/db/Dto/Aggregate.cs b/HealthMonitor.Service/Biz/db/Dto/Aggregate.cs new file mode 100644 index 0000000..f276e8a --- /dev/null +++ b/HealthMonitor.Service/Biz/db/Dto/Aggregate.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HealthMonitor.Service.Biz.db.Dto +{ + public class Aggregate: TDengineRestResBase + { + + public int Max { get; set; } + + public int Min { get; set; } + } +} diff --git a/HealthMonitor.Service/Biz/db/Dto/TDengineRestResBase.cs b/HealthMonitor.Service/Biz/db/Dto/TDengineRestResBase.cs new file mode 100644 index 0000000..bae7d69 --- /dev/null +++ b/HealthMonitor.Service/Biz/db/Dto/TDengineRestResBase.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HealthMonitor.Service.Biz.db.Dto +{ + public class TDengineRestResBase + { + [JsonProperty("code")] + public int Code { get; set; } + + + [JsonProperty("desc")] + public string? Desc { get; set; } + + [JsonProperty("column_meta")] + public List? ColumnMeta { get; set; } + + [JsonProperty("data")] + public List? Data { get; set; } + + } +} diff --git a/HealthMonitor.Service/Biz/db/TDengineService.cs b/HealthMonitor.Service/Biz/db/TDengineService.cs index 8c62d40..6b4f78f 100644 --- a/HealthMonitor.Service/Biz/db/TDengineService.cs +++ b/HealthMonitor.Service/Biz/db/TDengineService.cs @@ -1,6 +1,9 @@ -using HealthMonitor.Model.Config; +using HealthMonitor.Common.helper; +using HealthMonitor.Model.Config; +using HealthMonitor.Service.Biz.db.Dto; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -15,11 +18,16 @@ namespace HealthMonitor.Service.Biz.db { private readonly ILogger _logger; + private readonly HttpHelper _httpHelper=default!; private readonly TDengineServiceConfig _configTDengineService; - public TDengineService(ILogger logger, IOptions configTDengineService) + public TDengineService(ILogger logger, + IOptions configTDengineService, + HttpHelper httpHelper + ) { _logger = logger; _configTDengineService = configTDengineService.Value; + _httpHelper = httpHelper; } public IntPtr Connection() { @@ -113,7 +121,6 @@ namespace HealthMonitor.Service.Biz.db } } - public void CheckRes(IntPtr conn, IntPtr res, String errorMsg) { if (TDengine.ErrorNo(res) != 0) @@ -122,7 +129,6 @@ namespace HealthMonitor.Service.Biz.db } } - public void ExecuteInsertSQL(IntPtr conn, string sql) { try @@ -143,6 +149,82 @@ namespace HealthMonitor.Service.Biz.db } } + public async Task GernalRestSql(string sql) + { + + //"http://{server}:{port}/rest/sql/{db}" + var url = $"http://{_configTDengineService.Host}:{_configTDengineService.RestPort}/rest/sql/{_configTDengineService.DB}"; + List> headers = new() + { + new KeyValuePair("Authorization", "Basic " + _configTDengineService.Token) + }; + var result = await _httpHelper.HttpToPostAsync(url, sql, headers).ConfigureAwait(false); + var res = JsonConvert.DeserializeObject(result!); + if (result != null) + { + if (res?.Code == 0) + { + _logger.LogInformation($"{nameof(GernalRestSql)},SQL 语句执行成功|{sql}"); + return true; + } + else + { + _logger.LogWarning($"{nameof(GernalRestSql)},SQL 语句执行失败||{sql}"); + return false; + } + } + else + { + _logger.LogError($"{nameof(GernalRestSql)},TDengine 服务器IP:{_configTDengineService.Host} 错误,请联系运维人员"); + return false; + } + //return res.Code==0; + } + + public async Task GernalRestSqlResText(string sql) + { + var url = $"http://{_configTDengineService.Host}:{_configTDengineService.RestPort}/rest/sql/{_configTDengineService.DB}"; + List> headers = new() + { + new KeyValuePair("Authorization", "Basic " + _configTDengineService.Token) + }; + var result = await _httpHelper.HttpToPostAsync(url, sql, headers).ConfigureAwait(false); + return result; + } + + public async Task GetAggregateValue(string field,string tbName,string? condition) + { + var sql = $"SELECT MAX({field}), MIN({field}) FROM {_configTDengineService.DB}.{tbName} WHERE {condition}"; + + var result = await GernalRestSqlResText(sql); + var res = JsonConvert.DeserializeObject(result!); + List data = res?.Data!; + + return new Aggregate + { + Max = data[0][0], + Min = data[0][1], + }; + } + + public async Task GetAvgExceptMaxMinValue(string field, string tbName, string? condition) + { + + var sql = $"SELECT MAX({field}), MIN({field}) FROM {_configTDengineService.DB}.{tbName} WHERE {condition}"; + + var result = await GernalRestSqlResText(sql); + var res = JsonConvert.DeserializeObject(result!); + List data = res?.Data!; + + sql = $"SELECT AVG({field}) FROM {_configTDengineService.DB}.{tbName} WHERE {condition} AND {field} < {data[0][0]} and {field} > {data[0][1]}"; + result = await GernalRestSqlResText(sql); + res = JsonConvert.DeserializeObject(result!); + data = res?.Data!; + + return data.Count.Equals(0)?0:data[0][0]; + } + + } } diff --git a/HealthMonitor.Service/Cache/PersonCacheManager.cs b/HealthMonitor.Service/Cache/PersonCacheManager.cs new file mode 100644 index 0000000..03e7aa5 --- /dev/null +++ b/HealthMonitor.Service/Cache/PersonCacheManager.cs @@ -0,0 +1,125 @@ +using CSRedis; +using HealthMonitor.Model.Cache; +using HealthMonitor.Model.Config; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Net.NetworkInformation; +using System.Threading.Tasks; +using TelpoDataService.Util; +using TelpoDataService.Util.Clients; +using TelpoDataService.Util.Entities.GpsCard; +using TelpoDataService.Util.Models; +using TelpoDataService.Util.QueryObjects; + +namespace HealthMonitor.Service.Cache +{ + public abstract class MyHelper2 : RedisHelper { } + public class PersonCacheManager + { + private const int DEFAULT_DURATION_SECONDS = 1200; //20分钟 + private const string CACHE_KEY_PERSON = "Person_"; + //注意要改用 redis DB7 数据库 ,Prefix=TELPO + private const string CACHE_HASH_KEY_GPSDEVICEPERSON = "#GPSDEVICE_PERSON_HASH"; + //注意要改用 redis DB7 数据库 ,Prefix=TELPO + + + private readonly GpsCardAccessorClient _personApiClient; + private readonly ILogger _logger; + private readonly IOptions _optConfigRedis; + + public PersonCacheManager(GpsCardAccessorClient personApiClient, + ILogger logger, IOptions optConfigRedis) + { + _optConfigRedis = optConfigRedis; + _personApiClient = personApiClient; + _logger = logger; + } + public async Task GetPersonBySerialNoAsync(string messageId, string sn) + { + if (string.IsNullOrWhiteSpace(sn)) return null; + // 切换redis DB7 数据库和前缀 "TELPO" + _optConfigRedis.Value.DefaultDatabase = 7; + _optConfigRedis.Value.Prefix = "TELPO"; + + // 增加容错,防止Redis宕机造成业务中断 + try + { + using var csRedisDb7 = new CSRedisClient(_optConfigRedis.Value.ToString()); + return await csRedisDb7.HGetAsync(CACHE_HASH_KEY_GPSDEVICEPERSON, sn); + } + catch (Exception ex) + { + _logger.LogWarning($"Redis发生异常,将直接读取MySQL数据库,构造新实例:{ex.Message}, {ex.StackTrace}"); + var param = new GeneralParam + { + Filters = new List + { + new QueryFilterCondition + { + Key=nameof(GpsPerson.Serialno), + Value=sn, + ValueType=QueryValueTypeEnum.String, + Operator=QueryOperatorEnum.Equal + } + } + }!; + return await _personApiClient.GetFirstAsync(param, new RequestHeader { RequestId = messageId }).ConfigureAwait(false); + } + } + + /// + /// 读取个人信息(血压使用)注意要改用 redis DB7 + /// + /// + /// + /// + public async Task GetDeviceGpsPersonCacheBySerialNoAsync(string messageId, string sn) + { + if (string.IsNullOrWhiteSpace(sn)) return null; + // 切换redis DB7 数据库和前缀 "TELPO" + _optConfigRedis.Value.DefaultDatabase = 7; + _optConfigRedis.Value.Prefix = "TELPO"; + + + // 增加容错,防止Redis宕机造成业务中断 + try + { + var person = await RedisHelperDb7.HGetAsync(CACHE_HASH_KEY_GPSDEVICEPERSON, sn).ConfigureAwait(false); + return person; + } + catch(Exception ex) + { + _logger.LogWarning($"Redis发生异常,将直接读取MySQL数据库,构造新实例:{ex.Message}, {ex.StackTrace}"); + var param = new GeneralParam + { + Filters = new List + { + new QueryFilterCondition + { + Key=nameof(GpsPerson.Serialno), + Value=sn, + ValueType=QueryValueTypeEnum.String, + Operator=QueryOperatorEnum.Equal + } + } + }!; + var person = await _personApiClient.GetFirstAsync(param, new RequestHeader { RequestId = messageId }).ConfigureAwait(false); + // 读取数据库,构造新实例 + return new GpsDevicePerson { + Time = DateTime.Now, + Person=new Person { + DeviceId=person.DeviceId, + PersonId=person.PersonId, + Remarks=person.Remarks, + SerialNo=person.Serialno + } + }; + } + + + } + + } +} diff --git a/HealthMonitor.Service/Cache/RedisHelperDb7.cs b/HealthMonitor.Service/Cache/RedisHelperDb7.cs new file mode 100644 index 0000000..5bbf3a0 --- /dev/null +++ b/HealthMonitor.Service/Cache/RedisHelperDb7.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HealthMonitor.Service.Cache +{ + public abstract class RedisHelperDb7 : RedisHelper { } + +} diff --git a/HealthMonitor.Service/HealthMonitor.Service.csproj b/HealthMonitor.Service/HealthMonitor.Service.csproj index 20432ee..e390a0f 100644 --- a/HealthMonitor.Service/HealthMonitor.Service.csproj +++ b/HealthMonitor.Service/HealthMonitor.Service.csproj @@ -7,13 +7,17 @@ + + + + diff --git a/HealthMonitor.Util/Entities/HealthMonitor/BloodPressReferenceValue.cs b/HealthMonitor.Util/Entities/HealthMonitor/HmBloodPressReferenceValue.cs similarity index 92% rename from HealthMonitor.Util/Entities/HealthMonitor/BloodPressReferenceValue.cs rename to HealthMonitor.Util/Entities/HealthMonitor/HmBloodPressReferenceValue.cs index 32080f5..3b44e0b 100644 --- a/HealthMonitor.Util/Entities/HealthMonitor/BloodPressReferenceValue.cs +++ b/HealthMonitor.Util/Entities/HealthMonitor/HmBloodPressReferenceValue.cs @@ -10,7 +10,7 @@ using HealthMonitor.Util.Entities.Interfaces; namespace HealthMonitor.Util.Entities.HealthMonitor { - public partial class BloodPressReferenceValue : HealthMonitorEntityBase, IKeyIntType + public partial class HmBloodPressReferenceValue : HealthMonitorEntityBase, IKeyIntType { [Key] diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs new file mode 100644 index 0000000..d482e78 --- /dev/null +++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs @@ -0,0 +1,167 @@ +using HealthMonitor.Core.Dal; +using HealthMonitor.Model.Cache; +using HealthMonitor.Service.Biz.db; +using HealthMonitor.Service.Cache; +using HealthMonitor.Util.Entities.HealthMonitor; +using HealthMonitor.WebApi.Configs; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +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; + protected readonly IHealthMonitorDataAccessor _dataAccessor; + + public HmBloodPressController + ( + ILogger logger, + TDengineService serviceDengine, + PersonCacheManager personCacheMgr, + IHealthMonitorDataAccessor dataAccessor + ) + { + _logger = logger; + _serviceTDengine = serviceDengine; + _personCacheMgr = personCacheMgr; + _dataAccessor = dataAccessor; + } + + [HttpPost] + public async Task AddAsync([FromHeader] string requestId, HisGpsBloodPress bp1) + { + 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 + + }; + //var aggregate = await _serviceTDengine.GetAvgExceptMaxMinValue("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 插入当次BP数据 + // 保存到TDengine + /** + var sql = $"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})"; + + // var sql = "select * from health_monitor.hm_bloodpress order by last_update desc"; + + + var res=await _serviceTDengine.GernalRestSql(sql); + */ + #endregion + + #region 获取个人信息 + + var person = await _personCacheMgr.GetDeviceGpsPersonCacheBySerialNoAsync(bp.MessageId, bp.Serialno).ConfigureAwait(false); + + //var person = new GpsDevicePerson() + //{ + // Time = DateTime.Now, + // Person = new Person() + // { + // Age = 43, + // DeviceId = "111111", + // Gender = true, + // Ishypertension = false, + // SerialNo = bp.Serialno + // } + //}; + #endregion + + #region 计算增量值 + // 获取个人资料 redis + var age = person?.Person.Age; + var gender = person?.Person.Gender == true ? 1 : 2; + var isHypertension = person?.Person.Ishypertension; + var height = 0f; + var weight = 0f; + // 获取标定值 mysql + var bpRef = _dataAccessor + .GetFirstOrDefault( + i => + i.Age.Equals(age) && + i.Gender.Equals(gender) && + i.Hypertension.Equals(isHypertension) + ); + var systolicRefValue = bpRef.Systolic;//? + var diastolicRefValue = bpRef.Diastolic;//? + + // 获取历史数据 + DateTime now = DateTime.Now; + DateTime startTime = now.AddDays(-2); + DateTime endTime = now; + + // 计算去除最大值和最小值和异常值的平均值 + var systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValue("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.GetAvgExceptMaxMinValue("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 systolicInc = (int)(systolicRefValue - systolicAvg * avgOffset); + var diastolicInc = (int)(diastolicRefValue - systolicAvg * avgOffset); + + #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}," + + $"{bp.DiastolicValue}," + + $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," + + $"{systolicInc}," + + $"{diastolicInc}," + + $"{avgOffset}," + + $"{gender}," + + $"{age}," + + $"{height}," + + $"{weight}," + + $"'{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," + + $"'{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}')"; + var res = await _serviceTDengine.GernalRestSql(sql); + #endregion + + + return Ok(true); + } + + + + } +} diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/BloodPressReferenceValueController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressReferenceValueController.cs similarity index 75% rename from HealthMonitor.WebApi/Controllers/HealthMonitor/BloodPressReferenceValueController.cs rename to HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressReferenceValueController.cs index cf4a28a..4d6f688 100644 --- a/HealthMonitor.WebApi/Controllers/HealthMonitor/BloodPressReferenceValueController.cs +++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressReferenceValueController.cs @@ -9,14 +9,14 @@ using Microsoft.AspNetCore.Mvc; namespace HealthMonitor.WebApi.Controllers.HealthMonitor { [ApiExplorerSettings(GroupName = AppConsts.SWAGGER_DOC_HealthMonitor)] - public class BloodPressReferenceValueController : HealthMonitorControllerBase + public class HmBloodPressReferenceValueController : HealthMonitorControllerBase { - public BloodPressReferenceValueController( + public HmBloodPressReferenceValueController( // IHealthMonitorDataAccessor dataAccessor, IHealthMonitorDataAccessor dataAccessor, IHealthMonitorOperatorManager operatorManager, IDurableEntityManager durableManager, - ILogger logger) + ILogger logger) : base(dataAccessor, operatorManager, durableManager, logger) { diff --git a/HealthMonitor.WebApi/HealthMonitor.WebApi.csproj b/HealthMonitor.WebApi/HealthMonitor.WebApi.csproj index 08bac24..64a0a6b 100644 --- a/HealthMonitor.WebApi/HealthMonitor.WebApi.csproj +++ b/HealthMonitor.WebApi/HealthMonitor.WebApi.csproj @@ -9,6 +9,7 @@ + diff --git a/HealthMonitor.WebApi/Program.cs b/HealthMonitor.WebApi/Program.cs index 963e716..cf95a7c 100644 --- a/HealthMonitor.WebApi/Program.cs +++ b/HealthMonitor.WebApi/Program.cs @@ -20,6 +20,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; using HealthMonitor.WebApi.Swagger; +using HealthMonitor.Service.Cache; +using TelpoDataService.Util.Clients; namespace HealthMonitor.WebApi { @@ -44,13 +46,6 @@ namespace HealthMonitor.WebApi builder.Services.AddSingleton(); builder.Services.AddSingleton(); - - - - - - - builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); @@ -110,7 +105,8 @@ namespace HealthMonitor.WebApi options.SuppressModelStateInvalidFilter = true; }) .Configure(builder.Configuration.GetSection("Redis")) - .Configure(builder.Configuration.GetSection("TDengineServiceConfig")); ; + .Configure(builder.Configuration.GetSection("TDengineServiceConfig")) + .Configure(builder.Configuration.GetSection("ServiceConfig")); builder.Services @@ -144,6 +140,21 @@ namespace HealthMonitor.WebApi builder.Host.UseServiceProviderFactory(new DynamicProxyServiceProviderFactory()); #endregion + #region Cache + builder.Services + .AddSingleton(); + + #endregion + + #region + + builder.Services.AddTelpoDataServices(opt => + { + opt.TelpoDataUrl = builder.Configuration.GetSection("ServiceConfig:TelpoDataUrl").Value; + }); + + #endregion + // Register the Swagger generator, defining 1 or more Swagger documents builder.Services.AddSwaggerGen(c => { @@ -203,10 +214,17 @@ namespace HealthMonitor.WebApi - // redis + // redis default var csredis = new CSRedis.CSRedisClient(app.Services.GetService>()!.Value.ToString()); RedisHelper.Initialization(csredis); + // redis db7 + var csredisDb7Con = app.Services.GetService>()!.Value; + csredisDb7Con.DefaultDatabase = 7; + csredisDb7Con.Prefix = "TELPO"; + var csredisDb7 = new CSRedis.CSRedisClient(csredisDb7Con.ToString()); + RedisHelperDb7.Initialization(csredisDb7); + app.UseHttpsRedirection(); app.UseAuthorization(); diff --git a/HealthMonitor.WebApi/appsettings.Development.json b/HealthMonitor.WebApi/appsettings.Development.json index 66dde48..eb9bf8b 100644 --- a/HealthMonitor.WebApi/appsettings.Development.json +++ b/HealthMonitor.WebApi/appsettings.Development.json @@ -9,20 +9,29 @@ "Host": "47.116.142.20", "UserName": "root", "Password": "taosdata", + "Token": "cm9vdDp0YW9zZGF0YQ==", "Port": 6030, + "RestPort": 6041, "DB": "health_monitor" }, "Redis": { //"Server": "172.16.192.26:8090", - "Server": "47.116.142.20:8090", + //"Server": "47.116.142.20:8090", // 测试环境 + "Server": "139.224.254.18:8090", // 正式环境 "Password": "telpo#1234", //"Server": "127.0.0.1:6379", "DefaultDatabase": 2, + "Prefix": "_HM_", + //"DefaultDatabase": 7, + // "Prefix": "TELPO", "Poolsize": 50, - "Prefix": "_HW_", + "ConnectTimeout": 5000, "IdleTimeout": 20000 }, + "ServiceConfig": { + "TelpoDataUrl": "https://id.ssjlai.com/data/" + }, "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",