From 167cece5dd75b2b4f84cca69420af0e86dd7f56e Mon Sep 17 00:00:00 2001 From: H Vs Date: Thu, 30 Nov 2023 16:04:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E5=87=86=E6=95=B0=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E8=B6=B3=EF=BC=8C=E6=B8=85=E9=9B=B6=E5=90=8E=EF=BC=8C=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=EF=BC=8C=E6=89=8B=E5=8A=A8=E6=A0=87=E5=AE=9A=E5=80=BC?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E9=87=8F=E5=80=BC=3D0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Mapper/ParseTDengineRestResponse.cs | 12 ++++----- HealthMonitor.Service/Biz/IotWebApiService.cs | 13 +++++----- .../Resolver/BloodpressResolver.cs | 2 +- ...dPressConfigManualCalibrationController.cs | 25 +++++++++++++++++++ 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/HealthMonitor.Model/Service/Mapper/ParseTDengineRestResponse.cs b/HealthMonitor.Model/Service/Mapper/ParseTDengineRestResponse.cs index 4a2ecf6..8859f36 100644 --- a/HealthMonitor.Model/Service/Mapper/ParseTDengineRestResponse.cs +++ b/HealthMonitor.Model/Service/Mapper/ParseTDengineRestResponse.cs @@ -150,12 +150,6 @@ namespace HealthMonitor.Model.Service.Mapper public decimal AverageAfterRemovingOneMinMaxRef(Func valueSelector, int refValue) { var values = ParseData.Select(valueSelector).ToList(); - - if (values.Count <= 2) - { - throw new ArgumentException("数据不够不能计算"); - } - // Remove the specified number of minimum and maximum values //values.RemoveAll(_ => _ == values.Min()); //values.RemoveAll(_ => _ == values.Max()); @@ -166,6 +160,12 @@ namespace HealthMonitor.Model.Service.Mapper // Remove values less than the specified threshold values.RemoveAll(_ => _ > refValue); + if (values.Count < 2) + { + // throw new ArgumentException("数据不够不能计算"); + // 平均值为0,说明数据不足,不能计算增量值 + return 0M; + } // Calculate and return the average of the remaining values return values.Average(); } diff --git a/HealthMonitor.Service/Biz/IotWebApiService.cs b/HealthMonitor.Service/Biz/IotWebApiService.cs index dc6cf19..3dabfd3 100644 --- a/HealthMonitor.Service/Biz/IotWebApiService.cs +++ b/HealthMonitor.Service/Biz/IotWebApiService.cs @@ -273,18 +273,20 @@ namespace HealthMonitor.Service.Biz /// /// /// + /// 是否初始化,即清空remakers /// - public async Task UpdatePersonRemarksAsync(string imei, int systolicRefValue, int diastolicRefValue, int systolicIncValue, int diastolicIncValue) + public async Task UpdatePersonRemarksAsync(string imei, int systolicRefValue, int diastolicRefValue, int systolicIncValue, int diastolicIncValue, bool isInitRemakers=false) { var flag = false; try { + // 保证实时性,先更新缓存,再更新数据库 var personCache = await _personCacheMgr.GetDeviceGpsPersonCacheObjectBySerialNoAsync(new Guid().ToString(), imei).ConfigureAwait(false); if (personCache == null) { - _logger.LogInformation($"Person remarks数据异常,检查缓存和数据库"); + _logger.LogInformation($"{imei} -- Person remarks数据异常,检查缓存和数据库"); } else if (string.IsNullOrWhiteSpace(personCache["person"]!["remarks"]!.ToString())) { @@ -300,7 +302,7 @@ namespace HealthMonitor.Service.Biz diastolicIncValue //舒张压显示增量,值为0 表示不生效 } }; - var newRemarkStr = $"is_blood_press:{JsonConvert.SerializeObject(newRemarkData)}|"; + var newRemarkStr = isInitRemakers ? string.Empty:$"is_blood_press:{JsonConvert.SerializeObject(newRemarkData)}|"; personCache["person"]!["remarks"] = newRemarkStr; bool cacheFlag = await _personCacheMgr.UpdateDeviceGpsPersonCacheObjectBySerialNoAsync(personCache, imei); if (cacheFlag) @@ -324,20 +326,19 @@ namespace HealthMonitor.Service.Biz // 更新字段 person!.Remarks = newRemarkStr; await _gpsPersonApiClient.UpdateAsync(person, new RequestHeader() { RequestId = $"{imei}" }).ConfigureAwait(false); - _logger.LogInformation($"更新Person remarks字段|{person.Remarks}"); + _logger.LogInformation($"{imei} 更新Person remarks字段|{person.Remarks}"); } else { _logger.LogInformation($"{imei} 更新缓存和数据库{nameof(UpdatePersonRemarksAsync)}失败,{JsonConvert.SerializeObject(personCache)}"); - } flag = cacheFlag; } } catch (Exception ex) { - _logger.LogError($"{nameof(UpdatePersonRemarksAsync)} 更新个人信息异常:{ex.Message}, {ex.StackTrace}"); + _logger.LogError($"{nameof(UpdatePersonRemarksAsync)} {imei}--更新个人信息异常:{ex.Message}, {ex.StackTrace}"); } return flag; } diff --git a/HealthMonitor.Service/Resolver/BloodpressResolver.cs b/HealthMonitor.Service/Resolver/BloodpressResolver.cs index a65cc4f..a05a9e2 100644 --- a/HealthMonitor.Service/Resolver/BloodpressResolver.cs +++ b/HealthMonitor.Service/Resolver/BloodpressResolver.cs @@ -158,7 +158,7 @@ namespace HealthMonitor.Service.Resolver systolicRefValue = bpRef!.Systolic;//? diastolicRefValue = bpRef!.Diastolic;//? #endregion - _logger.LogInformation($"Person Remarks 值:{person?.Person.Remarks}"); + _logger.LogInformation($"{bp.Serialno} -- Person Remarks 值:{person?.Person.Remarks}"); if (string.IsNullOrWhiteSpace(person?.Person.Remarks)) { _logger.LogInformation($"{bp.Serialno},设备解绑后绑定,首次手工测量了血压值,下发年龄标定值和增量值(测量值=平均值计算得出的)"); diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs index 17a95ba..8fe22d9 100644 --- a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs +++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs @@ -190,6 +190,31 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor systolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.SystolicValue, SafeType.SafeInt(systolicRefValue!)))!; diastolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.DiastolicValue, SafeType.SafeInt(diastolicRefValue!)))!; + // 平均值为0,说明数据不足,不能计算增量值 + // 数据不足等同进行初始化,只下发标定值,增量值为0;remarks恢复到未校准状态,需要基于第一个测量值生成增量值。 + if (systolicAvg.Equals(0)|| diastolicAvg.Equals(0)) + { + _logger.LogInformation($"测量数据样本不足,将进行标定值初始,只下发标定值,增量值为0;remarks恢复到未校准状态。"); + // 重置设备 + var statNow=DateTime.Now; + await IotSetBloodPressCalibrationConfigResponseAsync(imei, 0, 0, 0, 0, 0, 0, 0, 0, statNow, statNow).ConfigureAwait(false); + _logger.LogInformation($"1.测量数据样本不足,重置设备"); + + var initRemarksFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(imei, 0, 0, 0, 0, true).ConfigureAwait(false); + if (initRemarksFlag) + { + _logger.LogInformation($"2.测量数据样本不足,remarks恢复到未校准状态(remarks设置为空),成功"); + } + else + { + _logger.LogInformation($"2.测量数据样本不足,remarks恢复到未校准状态(remarks设置为空),失败"); + } + _logger.LogInformation($"3.测量数据样本不足,只下发手动标定值systolicRefValue:{systolicRefValue} -- diastolicRefValue:{diastolicRefValue},增量值为0"); + statNow = DateTime.Now.AddSeconds(3); + return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, 0, 0, 0, 0, 0, 0, statNow, statNow).ConfigureAwait(false); + + } + // 增量值=(标定值-平均值)* 0.25 var currentSystolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; var currentDiastolicInc = (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;