Browse Source

调整mock

datasub12_fetal_heart_rate_0
H Vs 7 months ago
parent
commit
eb4cf6c8a0
2 changed files with 89 additions and 1 deletions
  1. +62
    -0
      HealthMonitor.Service/Biz/IotApiService.cs
  2. +27
    -1
      HealthMonitor.WebApi/Controllers/HealthMonitor/HmFetalController.cs

+ 62
- 0
HealthMonitor.Service/Biz/IotApiService.cs View File

@@ -338,6 +338,68 @@ namespace HealthMonitor.Service.Biz
return false;
}
}



public async Task<bool> SetFetalConfigMockAsync(string serialno, int modeStatus = 0, int maxValue = 0, int minValue = 0,
int highFreqSampleTimes=0,int highFreqSampleInterval=0,int stopHighFreqSampleCount=0,int triggerHighFreqHigh=0,int triggerHighFreqLow=0)
{
try
{
#region 读取缓存
// db7.HashGet("TELPO#GPSDEVICE_WATCH_CONFIG_HASH","861281060086083_0067")
var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(serialno, "0067");
if (watchConfig == null)
{
return false;
}
#endregion

#region 获取B端 Token
string tokenAuthData = await getAccessToken2(serialno).ConfigureAwait(false);
if (tokenAuthData == null)
{
return false;
}
#endregion
_logger.LogInformation($" SetFetalConfig Token TelpoManufactorId: {tokenAuthData}");
#region 发送到B端
List<KeyValuePair<string, string>> headers = new()
{
new KeyValuePair<string, string>("AccessToken", tokenAuthData)
};

watchConfig["mode"] = modeStatus;
watchConfig["triggerHighFreqHigh"] = maxValue == 0 ? (int)watchConfig["triggerHighFreqHigh"]! : maxValue;
watchConfig["triggerHighFreqLow"] = minValue == 0 ? (int)watchConfig["triggerHighFreqLow"]! : minValue;
watchConfig["highFreqSampleTimes"]= highFreqSampleTimes == 0 ? (int)watchConfig["highFreqSampleTimes"]! : highFreqSampleTimes;
watchConfig["highFreqSampleInterval"] = highFreqSampleInterval == 0 ? (int)watchConfig["highFreqSampleInterval"]! : highFreqSampleInterval;
watchConfig["stopHighFreqSampleCount"] = stopHighFreqSampleCount == 0 ? (int)watchConfig["stopHighFreqSampleCount"]! : stopHighFreqSampleCount;
watchConfig["triggerHighFreqHigh"] = triggerHighFreqHigh == 0 ? (int)watchConfig["triggerHighFreqHigh"]! : triggerHighFreqHigh;
watchConfig["triggerHighFreqLow"] = triggerHighFreqLow == 0 ? (int)watchConfig["triggerHighFreqLow"]! : triggerHighFreqLow;
var data = watchConfig;

var setUrl = $"{_configService.IotCore}/SetFetalConfig";
_logger.LogInformation($"{setUrl} 请求 {JsonConvert.SerializeObject(JsonConvert.SerializeObject(data))}");
var res = await _httpHelper.HttpToPostAsync(setUrl, data, headers).ConfigureAwait(false);
_logger.LogInformation($"{setUrl} 响应 {res}");
var resJToken = JsonConvert.DeserializeObject(res ?? string.Empty) as JToken;
return resJToken?["message"]?.ToString().Equals("ok") ?? false;
//response.Flag = resJToken?["message"]?.ToString().Equals("ok") ?? false;
//response.Flag = Convert.ToBoolean(resJToken?["succeed"]?.ToString());
//if (!response.Flag)
//{
// response.Message = resJToken?["message"]?.ToString()!;
//}
#endregion
}
catch (Exception ex)
{
_logger.LogError($"{nameof(SetFetalConfig)} 下发胎心检测参数异常:{ex.Message}, {ex.StackTrace}");
return false;
}
}

/// <summary>
/// 下发胎心数据
/// </summary>


+ 27
- 1
HealthMonitor.WebApi/Controllers/HealthMonitor/HmFetalController.cs View File

@@ -66,12 +66,38 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor
pchr.SerialTailNumber = sn[^2..];

await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", pchr);
var flag=await _serviceIotApi.SetFetalConfig(pchr.SerialNumber, 1, pchr.MaxValue, pchr.MinValue);
var flag = await _serviceIotApi.SetFetalConfig(pchr.SerialNumber, 1, pchr.MaxValue, pchr.MinValue);
return new {
flag,
pchr
};
}

[HttpPost]
public async Task<object> SetMockMode2(string sn, int mockMax, int mockMin, int highFreqSampleTimes , int highFreqSampleInterval , int stopHighFreqSampleCount , int triggerHighFreqHigh , int triggerHighFreqLow,string remark = "mock")
{
var res = await _serviceTDengine.GetBySerialNoAsync<PregnancyCommonHeartRateModel>(sn);
var pchr = res.FirstOrDefault();

if (pchr == null)
{
return "NULL";
}
pchr.MaxValue = mockMax;
pchr.MinValue = mockMin;
pchr.Remark = remark;
pchr.Timestamp = DateTime.Now;
pchr.SerialTailNumber = sn[^2..];

await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", pchr);
var flag = await _serviceIotApi.SetFetalConfigMockAsync(pchr.SerialNumber, 1, pchr.MaxValue, pchr.MinValue,
highFreqSampleTimes, highFreqSampleInterval, stopHighFreqSampleCount, triggerHighFreqHigh, triggerHighFreqLow);
return new
{
flag,
pchr
};
}

}
}

Loading…
Cancel
Save