diff --git a/HealthMonitor.Model/Config/ServiceConfig.cs b/HealthMonitor.Model/Config/ServiceConfig.cs
index a815163..0febe59 100644
--- a/HealthMonitor.Model/Config/ServiceConfig.cs
+++ b/HealthMonitor.Model/Config/ServiceConfig.cs
@@ -8,6 +8,8 @@
public string TelpoDataUrl { get; set; } = default!;
public string EtcdServerAddress { get; set; } = default!;
+
+ public string IotWebApiUrl { get; set; } = default!;
/////
///// Kafka服务地址
/////
diff --git a/HealthMonitor.Model/Service/BloodPressCalibrationConfigModel.cs b/HealthMonitor.Model/Service/BloodPressCalibrationConfigModel.cs
new file mode 100644
index 0000000..4ddac1b
--- /dev/null
+++ b/HealthMonitor.Model/Service/BloodPressCalibrationConfigModel.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.Model.Service
+{
+ public class BloodPressCalibrationConfigModel
+ {
+ [JsonProperty("imei")]
+ public string Imei { get; set; } = default!;
+ [JsonProperty("systolicCalibrationValue")]
+ public int SystolicRefValue { get; set; }
+
+ [JsonProperty("diastolicCalibrationValue")]
+ public int DiastolicRefValue { get; set; }
+
+ [JsonProperty("systolicIncValue")]
+ public int SystolicIncValue { get; set; }
+
+ [JsonProperty("diastolicIncValue")]
+ public int DiastolicIncValue { get; set; }
+ }
+}
diff --git a/HealthMonitor.Service/Biz/IotWebApiService.cs b/HealthMonitor.Service/Biz/IotWebApiService.cs
new file mode 100644
index 0000000..bb19bb6
--- /dev/null
+++ b/HealthMonitor.Service/Biz/IotWebApiService.cs
@@ -0,0 +1,170 @@
+using HealthMonitor.Common.helper;
+using HealthMonitor.Model.Config;
+using HealthMonitor.Service.Resolver;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HealthMonitor.Model.Service;
+using TelpoDataService.Util.Entities.GpsCard;
+using TelpoDataService.Util;
+using TelpoDataService.Util.Clients;
+using TelpoDataService.Util.Models;
+using TelpoDataService.Util.QueryObjects;
+
+namespace HealthMonitor.Service.Biz
+{
+ public class IotWebApiService
+ {
+ private readonly ServiceConfig _configService;
+ private readonly ILogger _logger;
+
+
+ private readonly HttpHelper _httpHelper = default!;
+
+ private readonly GpsCardAccessorClient _gpsPersonApiClient;
+
+ public IotWebApiService(ILogger logger, HttpHelper httpHelper, GpsCardAccessorClient gpsPersonApiClient, IOptions optConfigService)
+ {
+ _configService = optConfigService.Value;
+ _httpHelper=httpHelper;
+ _logger = logger;
+ _gpsPersonApiClient = gpsPersonApiClient;
+ }
+
+ public async Task SetBloodPressCalibrationConfigAsync(BloodPressCalibrationConfigModel bpsCalibrationConfig)
+ {
+
+#if DEBUG
+ var 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;
+ flag= resJToken?["message"]?.ToString().Equals("ok") ?? false;
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"{nameof(SetBloodPressCalibrationConfigAsync)} 下发血压增量值异常:{ex.Message}, {ex.StackTrace}");
+
+ }
+
+
+#endif
+
+ return flag;
+
+
+ }
+
+ public async Task UpdatePersonInfoCacheAsync(string imei)
+ {
+ var flag = false;
+ try
+ {
+ var url = $"{_configService.IotWebApiUrl}Device/UpdatePersonInfoCache?imei={imei}";
+ List> headers = new()
+ {
+ new KeyValuePair("AuthKey", "key1")
+ };
+ var res = await _httpHelper.HttpToGetAsync(url, headers).ConfigureAwait(false);
+ _logger.LogInformation($"{imei} 更新缓存{nameof(UpdatePersonInfoCacheAsync)},响应:{res}");
+ var resJToken = JsonConvert.DeserializeObject(res ?? string.Empty) as JToken;
+ flag = resJToken?["message"]?.ToString().Equals("ok") ?? false;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"{nameof(UpdatePersonInfoCacheAsync)} 更新缓存异常:{ex.Message}, {ex.StackTrace}");
+
+ }
+ return flag;
+
+
+ }
+
+ ///
+ /// 更新 gps_person remark和缓存
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task UpdatePersonRemarksAsync(string imei,int systolicRefValue,int diastolicRefValue)
+ {
+ var flag = false;
+ try
+ {
+ GeneralParam condition = new ()
+ {
+ Filters = new List {
+ new QueryFilterCondition {
+ Key=nameof(GpsDevice.Serialno),
+ Value=imei,
+ Operator= QueryOperatorEnum.Equal,
+ ValueType=QueryValueTypeEnum.String
+ }
+ },
+ OrderBys = new List { new OrderByCondition { Key = "serialno", IsDesc = true } }
+
+ };
+ var person = await _gpsPersonApiClient.GetFirstAsync(condition, new RequestHeader() { RequestId = $"{imei}" }).ConfigureAwait(false);
+ // 若remark为空,更新person remark字段
+ if (string.IsNullOrWhiteSpace(person?.Remarks))
+ {
+ 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 表示不生效
+ }
+ };
+ person!.Remarks = $"is_blood_press:{JsonConvert.SerializeObject(newRemarkData)}|";
+ await _gpsPersonApiClient.UpdateAsync(person, new RequestHeader() { RequestId = $"{imei}" }).ConfigureAwait(false);
+ _logger.LogInformation($"更新Person remarks字段|{person.Remarks}");
+
+ // 更新缓存
+ var url = $"{_configService.IotWebApiUrl}Device/UpdatePersonInfoCache?imei={imei}";
+ List> headers = new()
+ {
+ new KeyValuePair("AuthKey", "key1")
+ };
+ var res = await _httpHelper.HttpToGetAsync(url, headers).ConfigureAwait(false);
+ _logger.LogInformation($"{imei} 更新缓存{nameof(UpdatePersonInfoCacheAsync)},响应:{res}");
+ var resJToken = JsonConvert.DeserializeObject(res ?? string.Empty) as JToken;
+ flag = resJToken?["message"]?.ToString().Equals("ok") ?? false;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"{nameof(UpdatePersonRemarksAsync)} 更新个人信息异常:{ex.Message}, {ex.StackTrace}");
+ }
+ return flag;
+
+
+ }
+ }
+}
diff --git a/HealthMonitor.WebApi/Controllers/Api/ApiResponse.cs b/HealthMonitor.WebApi/Controllers/Api/ApiResponse.cs
new file mode 100644
index 0000000..ba477b4
--- /dev/null
+++ b/HealthMonitor.WebApi/Controllers/Api/ApiResponse.cs
@@ -0,0 +1,74 @@
+using Newtonsoft.Json.Serialization;
+using Newtonsoft.Json;
+
+namespace HealthMonitor.WebApi.Controllers.Api
+{
+ public class ApiResponse
+ {
+ public string Timestamp { get; set; } = default!;
+
+ public T Data { get; set; } = default!;
+
+ public Result Result { get; set; } = default!;
+
+ //public bool Succeeded { get; set; }
+ // public string Message { get; set; } = String.Empty;
+
+
+ public static ApiResponse Fail(int code, string errorMessage) => new()
+ {
+ //MsgType = msgType,
+ //Signature = signature,
+ Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
+ Result = new()
+ {
+ Status = "failed",
+ Code = code,
+ Message = errorMessage,
+ },
+
+ };
+
+ //public static ApiResponse Success(string msgType,string signature,T data) => new()
+ //{
+ // MsgType= msgType,
+ // Signature = signature,
+ // Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
+ // Data = data,
+ // Result = new()
+ // {
+ // Status = "succeed",
+ // Code = 200,
+ // Message = "请求成功!",
+ // },
+ //};
+ public static ApiResponse Success(T data) => new()
+ {
+ Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
+ Data = data,
+ Result = new()
+ {
+ Status = "succeed",
+ Code = 200,
+ Message = "请求成功!",
+ },
+ };
+ public string ToJsonString()
+ {
+ var settings = new JsonSerializerSettings
+ {
+ DateFormatString = "yyyy-MM-dd HH:mm:ss.fff", // 设置日期格式
+ ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }
+ };
+ return JsonConvert.SerializeObject(this, settings);
+ }
+ }
+
+
+ public class Result
+ {
+ public string Status { get; set; } = default!;
+ public int Code { get; set; }
+ public string Message { get; set; } = default!;
+ }
+}
diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs
index d7bc380..71bf9f9 100644
--- a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs
+++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs
@@ -19,9 +19,17 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using TelpoDataService.Util.Entities.GpsCard;
+using TelpoDataService.Util.Clients;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
+using TelpoDataService.Util;
+using TelpoDataService.Util.Models;
+using TelpoDataService.Util.QueryObjects;
+using HealthMonitor.WebApi.Controllers.Api;
+using HealthMonitor.Service.Biz;
+using HealthMonitor.Model.Service;
namespace HealthMonitor.WebApi.Controllers.HealthMonitor
{
@@ -36,113 +44,275 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor
private readonly TDengineService _serviceTDengine;
private readonly HttpHelper _httpHelper = default!;
+ private readonly IotWebApiService _serviceIotWebApi;
+
+ private readonly GpsCardAccessorClient _deviceApiClient;
+ private readonly GpsCardAccessorClient _gpsPersonApiClient;
+
public HmBloodPressConfigManualCalibrationController
(
TDengineService serviceDengine,
PersonCacheManager personCacheMgr, HttpHelper httpHelper,
-
- ILogger logger
+ GpsCardAccessorClient gpsPersonApiClient,
+ GpsCardAccessorClient deviceApiClient,
+ ILogger logger,
+ IotWebApiService iotWebApiService
)
{
-
+
+
_serviceTDengine = serviceDengine;
_logger = logger;
+
_httpHelper = httpHelper;
+ _gpsPersonApiClient = gpsPersonApiClient;
+ _deviceApiClient = deviceApiClient;
_personCacheMgr = personCacheMgr;
+ _serviceIotWebApi = iotWebApiService;
}
[HttpPost]
- public async Task Put([FromBody] BloodPressManualCalibration model, [FromHeader] string requestId)
+ public async Task> Put([FromBody] BloodPressManualCalibration model, [FromHeader] string requestId)
{
- /**
- 没有血压数据时增量值为0
- */
+ #region 设备合法性
+#if DEBUG
+#else
+ var param = new GeneralParam
+ {
+ Filters = new List
+ {
+ new QueryFilterCondition
+ {
+ Key=nameof(GpsDevice.Serialno),
+ Value=model.Imei,
+ ValueType=QueryValueTypeEnum.String,
+ Operator=QueryOperatorEnum.Equal
+ }
+ }
+ };
- // 保存新的标定值
- // 使用新的标定值计算新的增量值
+ var device = await _deviceApiClient.GetFirstAsync(param, new RequestHeader { RequestId = requestId }).ConfigureAwait(false);
+ if (device == null)
+ {
+ _logger.LogError($"非法设备:{model.Imei}");
+ return ApiResponse