From 8c9d878816a228a0d69ac60bbc70a50520782d87 Mon Sep 17 00:00:00 2001 From: H Vs Date: Sat, 18 Nov 2023 18:24:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9remark?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...dPressConfigManualCalibrationController.cs | 63 ++++++++++++++++++ HealthMonitor.WebApi/Worker.cs | 66 ++++++++++++++++++- 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs index 0aefb96..6ace4ef 100644 --- a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs +++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs @@ -3,6 +3,7 @@ using Grpc.Core; using HealthMonitor.Common; using HealthMonitor.Common.helper; using HealthMonitor.Core.Dal; +using HealthMonitor.Core.Pipeline; using HealthMonitor.Service.Biz.db; using HealthMonitor.Service.Cache; using HealthMonitor.Service.Etcd; @@ -10,12 +11,15 @@ using HealthMonitor.Service.Resolver; using HealthMonitor.Util.Entities.HealthMonitor; using HealthMonitor.WebApi.Configs; using HealthMonitor.WebApi.Model.Request; +using Microsoft.AspNetCore.DataProtection.KeyManagement; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -74,6 +78,9 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor DateTime endTime = DateTime.Now; //测试 DateTime startTime = endTime - ts; + + + var last = await _serviceTDengine.GetLastAsync("stb_hm_bp_push_ref_inc_value", $"serialno='{imei}' order by ts desc"); if (last?.Count != 0) { @@ -82,6 +89,62 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor startTime = newTs; } } + // 读数据库,remark为空就写commandValue,更新缓存 + else + { + #region 初始化remark + var dataServiceBaseUrl = $"https://id.ssjlai.com/data"; + var DataServicePersionGet = $"{dataServiceBaseUrl}/api/GpsCard/GpsPerson/GetFirst"; + List> Dataheaders = new() + { + new KeyValuePair("requestId", $"{imei}") + }; + var dataPersion = new + { + filters = new List() { new { key = "serialno", value = $"{imei}", valueType = "string", @operator = "Equal" } }, + orderBys = new List() { new { key = "serialno", isDesc = true } } + }; + var res = await _httpHelper.HttpToPostAsync(DataServicePersionGet, dataPersion, Dataheaders).ConfigureAwait(false); + var resObj = JsonConvert.DeserializeObject(res!) 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 = systolicRefValue, //收缩压标定值,值为0 表示不生效 + diastolicCalibrationValue = diastolicRefValue, //舒张压标定值,值为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> headersCache = new() + { + new KeyValuePair("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 lastBP = await _serviceTDengine.GetLastAsync("stb_hm_bloodpress", $"serialno='{imei}' order by ts desc"); diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index 2cfea16..5c08427 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -154,7 +154,9 @@ namespace HealthMonitor.WebApi var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(schedule_push)) { - var startTime=DateTime.Now; + + + var startTime =DateTime.Now; // 下发增量值 #region 定时下发增量值 var last= await _serviceTDengine.GetLastAsync("stb_hm_bloodpress_stats_inc", $"serialno='{imeiDel}' order by last_update desc"); @@ -170,6 +172,62 @@ namespace HealthMonitor.WebApi var systolic_inc_value = last?[10]; var diastolic_inc_value = last?[17]; + #region 判断是否初始化remark + var imei = imeiDel; + // 判断是否初始化remark + 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> Dataheaders = new() + { + new KeyValuePair("requestId", $"{imei}") + }; + var dataPersion = new + { + filters = new List() { new { key = "serialno", value = $"{imei}", valueType = "string", @operator = "Equal" } }, + orderBys = new List() { 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> headersCache = new() + { + new KeyValuePair("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, @@ -213,6 +271,10 @@ namespace HealthMonitor.WebApi // 注册下次下推 var endTime = DateTime.Now; + + + + #if DEBUG @@ -277,6 +339,8 @@ namespace HealthMonitor.WebApi var result = JsonConvert.SerializeObject(data); await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); #endif + + } else {