From 40244c8f6643ff762351d59550a93829a8c8ed08 Mon Sep 17 00:00:00 2001 From: H Vs Date: Tue, 12 Mar 2024 16:07:09 +0800 Subject: [PATCH] =?UTF-8?q?webapi=20iot=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...BloodPressCalibrationConfigModelReponse.cs | 15 +++++++ HealthMonitor.Service/Biz/IotWebApiService.cs | 44 +++++++++++++++++++ .../Resolver/BloodpressResolver.cs | 9 +++- ...dPressConfigManualCalibrationController.cs | 12 +++-- HealthMonitor.WebApi/Worker.cs | 6 ++- 5 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 HealthMonitor.Model/Service/BloodPressCalibrationConfigModelReponse.cs diff --git a/HealthMonitor.Model/Service/BloodPressCalibrationConfigModelReponse.cs b/HealthMonitor.Model/Service/BloodPressCalibrationConfigModelReponse.cs new file mode 100644 index 0000000..fc35720 --- /dev/null +++ b/HealthMonitor.Model/Service/BloodPressCalibrationConfigModelReponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HealthMonitor.Model.Service +{ + public class BloodPressCalibrationConfigModelReponse + { + public bool Flag { get; set; } + + public string Message { get; set; } = default!; + } +} diff --git a/HealthMonitor.Service/Biz/IotWebApiService.cs b/HealthMonitor.Service/Biz/IotWebApiService.cs index 2e40c78..dbbe453 100644 --- a/HealthMonitor.Service/Biz/IotWebApiService.cs +++ b/HealthMonitor.Service/Biz/IotWebApiService.cs @@ -83,6 +83,50 @@ namespace HealthMonitor.Service.Biz } + + public async Task SetBloodPressCalibrationConfig2Async(BloodPressCalibrationConfigModel bpsCalibrationConfig) + { + BloodPressCalibrationConfigModelReponse response = new BloodPressCalibrationConfigModelReponse(); + response.Flag = false; + response.Message = string.Empty; +#if DEBUG + //var flag = true; + response.Flag=true; +#else + //systolicCalibrationValue = 0, //收缩压标定值,值为0 表示不生效 + //diastolicCalibrationValue 0, //舒张压标定值,值为0表示不生效 + //systolicIncValue = 0, //收缩压显示增量,值为0 表示不生效 + //diastolicIncValue = 0 //舒张压显示增量,值为0 表示不生效 + + // var flag = false; + try + { + var url = $"{_configService.IotWebApiUrl}Command/SetBloodPressCalibrationConfig"; + List> headers = new() + { + new KeyValuePair("AuthKey", "key1") + }; + var res = await _httpHelper.HttpToPostAsync(url, bpsCalibrationConfig, headers).ConfigureAwait(false); + _logger.LogInformation($"向{bpsCalibrationConfig.Imei}下发增量值数据:{JsonConvert.SerializeObject(bpsCalibrationConfig)},响应:{res}"); + var resJToken = JsonConvert.DeserializeObject(res ?? string.Empty) as JToken; + //response.Flag= resJToken?["message"]?.ToString().Equals("ok") ?? false; + response.Flag = Convert.ToBoolean(resJToken?["succeed"]?.ToString()); + if (!response.Flag) + { + response.Message = resJToken?["message"]?.ToString()!; + } + } + catch (Exception ex) + { + _logger.LogError($"{nameof(SetBloodPressCalibrationConfigAsync)} 下发血压增量值异常:{ex.Message}, {ex.StackTrace}"); + + } + + +#endif + + return response; + } /** 取消 /// /// 更新 gps_person remark和缓存 diff --git a/HealthMonitor.Service/Resolver/BloodpressResolver.cs b/HealthMonitor.Service/Resolver/BloodpressResolver.cs index 103f27c..d987746 100644 --- a/HealthMonitor.Service/Resolver/BloodpressResolver.cs +++ b/HealthMonitor.Service/Resolver/BloodpressResolver.cs @@ -189,7 +189,10 @@ namespace HealthMonitor.Service.Resolver DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效 }; // 下发 IOT 增量值 - var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + //var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + + var response = await _serviceIotWebApi.SetBloodPressCalibrationConfig2Async(bpIncData).ConfigureAwait(false); + var flagIot = response.Flag; if (flagIot) { startTime = (DateTime)bp.LastUpdate!; @@ -267,7 +270,9 @@ namespace HealthMonitor.Service.Resolver DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效 }; // 下发 IOT 增量值 - var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + //var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + var response = await _serviceIotWebApi.SetBloodPressCalibrationConfig2Async(bpIncData).ConfigureAwait(false); + var flagIot = response.Flag; if (flagIot) { startTime = (DateTime)bp.LastUpdate!; diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs index fcf8c51..52b721d 100644 --- a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs +++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs @@ -276,7 +276,9 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效 }; // 下发 IOT 增量值 - var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + // var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + var response = await _serviceIotWebApi.SetBloodPressCalibrationConfig2Async(bpIncData).ConfigureAwait(false); + var flagIot = response.Flag; if (flagIot) { #region 保存下推记录 stb_hm_bp_push_ref_inc_value @@ -300,7 +302,7 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor } else { - return ApiResponse.Fail(500, "业务出错!下发指令失败"); + return ApiResponse.Fail(500, $"业务出错!下发指令失败:{response.Message}"); } } @@ -316,7 +318,9 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效 }; // 下发 IOT 增量值 - var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + //var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + var response = await _serviceIotWebApi.SetBloodPressCalibrationConfig2Async(bpIncData).ConfigureAwait(false); + var flagIot = response.Flag; if (flagIot) { #region 保存下推记录 stb_hm_bp_push_ref_inc_value @@ -347,7 +351,7 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor } else { - return ApiResponse.Fail(500, "业务出错!下发指令失败"); + return ApiResponse.Fail(500, $"业务出错!下发指令失败:{response.Message}"); } } } diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index ad15c2f..4ee68fb 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -97,7 +97,7 @@ namespace HealthMonitor.WebApi _logger.LogInformation("------_tdEngineDataSubcribe"); while (!_tokenSource.IsCancellationRequested) { - + Console.WriteLine("test"); _tdEngineDataSubcribe.BeginListen(_tokenSource.Token); } }, TaskCreationOptions.LongRunning); @@ -361,7 +361,9 @@ namespace HealthMonitor.WebApi SystolicIncValue = SafeType.SafeInt(((int)systolicInc!)), //收缩压显示增量,值为0 表示不生效 DiastolicIncValue = SafeType.SafeInt(((int)diastolicInc!)) //舒张压显示增量,值为0 表示不生效 }; - var pushedBP = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + //var pushedBP = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); + var response = await _serviceIotWebApi.SetBloodPressCalibrationConfig2Async(bpIncData).ConfigureAwait(false); + var pushedBP = response.Flag; if (pushedBP) { #region 保存下推记录 stb_hm_bp_push_ref_inc_value