|
|
@@ -74,6 +74,7 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
[HttpPost] |
|
|
|
public async Task<ApiResponse<object>> Put([FromBody] BloodPressManualCalibration model, [FromHeader] string requestId) |
|
|
|
{ |
|
|
|
var imei = model.Imei; |
|
|
|
|
|
|
|
#region 设备合法性 |
|
|
|
|
|
|
@@ -104,12 +105,14 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 重置设备 |
|
|
|
if (model.ManualSystolicRefValue.Equals(0) && model.ManualDiastolicRefValue.Equals(0)) |
|
|
|
{ |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, 0, 0, 0, 0).ConfigureAwait(false); |
|
|
|
//return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, 0, 0, 0, 0).ConfigureAwait(false); |
|
|
|
var statNow= DateTime.Now; |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, 0, 0, 0, 0, 0, 0, 0, 0, statNow, statNow).ConfigureAwait(false); |
|
|
|
|
|
|
|
//return ApiResponse<object>.Success(new |
|
|
|
//{ |
|
|
@@ -131,7 +134,7 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 计算增量值 |
|
|
|
var imei = model.Imei; |
|
|
|
|
|
|
|
// 计算增量值 |
|
|
|
int systolicRefValue = model.ManualSystolicRefValue;//? |
|
|
|
int diastolicRefValue = model.ManualDiastolicRefValue;//? |
|
|
@@ -175,7 +178,13 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
if (count.Equals(0)) |
|
|
|
{ |
|
|
|
_logger.LogInformation("A.1 没有下推记录,没有测量记录,下推增量值 0"); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); |
|
|
|
// return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); |
|
|
|
systolicInc = 0; |
|
|
|
diastolicInc = 0; |
|
|
|
systolicAvg = 0; |
|
|
|
diastolicAvg = 0; |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
// A.2 没有下推记录,测量记录,正常计算增量值 |
|
|
|
else |
|
|
@@ -188,7 +197,10 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
if (systolicAvg.Equals(0) || diastolicAvg.Equals(0)) |
|
|
|
{ |
|
|
|
_logger.LogInformation(" A.2 没有下推记录,有测量记录,正常计算增量值 ,平均值为0, 增量值将按0下发"); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); |
|
|
|
systolicInc = 0; |
|
|
|
diastolicInc = 0; |
|
|
|
//return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
// 数据正常 |
|
|
@@ -204,7 +216,9 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
systolicInc = systolicAvg.Equals(0M) ? 0 : (int)Math.Round((systolicRefValue - systolicAvg) * systolicAvgOffset)!; |
|
|
|
diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)Math.Round((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; |
|
|
|
_logger.LogInformation(" A.2 没有下推记录,有测量记录,正常计算增量值 ,增量值将正常下发"); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -230,7 +244,13 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
if (count.Equals(0)) |
|
|
|
{ |
|
|
|
_logger.LogWarning("B.1.1 设备已经被重新设置, 从重置的ts 到 now 没有测量数据,inc=0"); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); |
|
|
|
systolicInc = 0; |
|
|
|
diastolicInc = 0; |
|
|
|
systolicAvg = 0; |
|
|
|
diastolicAvg = 0; |
|
|
|
// return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
// B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据 |
|
|
|
else |
|
|
@@ -243,8 +263,10 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
if (systolicAvg.Equals(0) || diastolicAvg.Equals(0)) |
|
|
|
{ |
|
|
|
_logger.LogWarning("B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据,平均值为0,增量值将按0下发"); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); |
|
|
|
|
|
|
|
systolicInc = 0; |
|
|
|
diastolicInc = 0; |
|
|
|
//return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false); |
|
|
|
} |
|
|
|
// 数据正常 |
|
|
|
else |
|
|
@@ -257,7 +279,8 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
systolicInc = systolicAvg.Equals(0M) ? 0 : (int)Math.Round((systolicRefValue - systolicAvg) * systolicAvgOffset)!; |
|
|
|
diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)Math.Round((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; |
|
|
|
_logger.LogInformation("B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据 ,增量值将正常下发"); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
//return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@@ -310,8 +333,8 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
diastolicInc = (int)lastPush[5]; |
|
|
|
} |
|
|
|
|
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
|
|
|
|
//return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false); |
|
|
|
} |
|
|
|
// B.2.2 数据正常,按正常计算 |
|
|
|
else |
|
|
@@ -321,7 +344,7 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
systolicInc = systolicAvg.Equals(0M) ? 0 : (int)Math.Round((systolicRefValue - systolicAvg) * systolicAvgOffset)!; |
|
|
|
diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)Math.Round((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; |
|
|
|
_logger.LogInformation("B.2.2 曾经下推过断言有测量记录,数据正常,按正常计算 ,增量值将正常下发"); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false); |
|
|
|
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc,systolicAvg, diastolicAvg,systolicAvgOffset,diastolicAvgOffset,startTime,endTime).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -433,5 +456,52 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor |
|
|
|
return ApiResponse<object>.Fail(500, "业务出错!下发指令失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<ApiResponse<object>> IotSetBloodPressCalibrationConfigResponseAsync(string imei, int systolicRefValue, int diastolicRefValue, int systolicInc, int diastolicInc,int systolicAvgValue,int diastolicAvgValue,decimal systolicAvgOffset, decimal diastolicAvgOffset, DateTime statStartTime,DateTime statEndTime) |
|
|
|
{ |
|
|
|
BloodPressCalibrationConfigModel bpIncData = new() |
|
|
|
{ |
|
|
|
|
|
|
|
Imei = imei, |
|
|
|
SystolicRefValue = systolicRefValue, //收缩压标定值,值为0 表示不生效 |
|
|
|
DiastolicRefValue = diastolicRefValue, //舒张压标定值,值为0表示不生效 |
|
|
|
SystolicIncValue = systolicInc, //收缩压显示增量,值为0 表示不生效 |
|
|
|
DiastolicIncValue = diastolicInc //舒张压显示增量,值为0 表示不生效 |
|
|
|
}; |
|
|
|
// 下发 IOT 增量值 |
|
|
|
var flagIot = await _serviceIotWebApi.SetBloodPressCalibrationConfigAsync(bpIncData).ConfigureAwait(false); |
|
|
|
if (flagIot) |
|
|
|
{ |
|
|
|
#region 保存下推记录 stb_hm_bp_push_ref_inc_value |
|
|
|
var sql = $"INSERT INTO health_monitor.hm_bp_push_ref_inc_value_{imei.Substring(imei.Length - 2)} " + |
|
|
|
$"USING health_monitor.stb_hm_bp_push_ref_inc_value " + |
|
|
|
$"TAGS ('{imei.Substring(imei.Length - 2)}') " + |
|
|
|
$"VALUES(" + |
|
|
|
$"'{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}'," + |
|
|
|
$"'{imei}'," + |
|
|
|
$"{systolicRefValue}," + |
|
|
|
$"{diastolicRefValue}," + |
|
|
|
$"{systolicInc}," + |
|
|
|
$"{diastolicInc}," + |
|
|
|
$"{true}," + |
|
|
|
$"{systolicAvgValue}," + |
|
|
|
$"{diastolicAvgValue}," + |
|
|
|
$"{systolicAvgOffset}," + |
|
|
|
$"{diastolicAvgOffset}," + |
|
|
|
$"'{statStartTime:yyyy-MM-dd HH:mm:ss.fff}'," + |
|
|
|
$"'{statEndTime:yyyy-MM-dd HH:mm:ss.fff}'" + |
|
|
|
$")"; |
|
|
|
|
|
|
|
_serviceTDengine.ExecuteInsertSQL(sql); |
|
|
|
#endregion |
|
|
|
|
|
|
|
// 返回结果 |
|
|
|
return ApiResponse<object>.Success(bpIncData); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return ApiResponse<object>.Fail(500, "业务出错!下发指令失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |