您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

104 行
3.7KB

  1. using HealthMonitor.Model.Service.Mapper;
  2. using HealthMonitor.Service.Biz;
  3. using HealthMonitor.Service.Biz.db;
  4. using HealthMonitor.WebApi.Configs;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.EntityFrameworkCore.Metadata;
  7. namespace HealthMonitor.WebApi.Controllers.HealthMonitor
  8. {
  9. [ApiExplorerSettings(GroupName = AppConsts.SWAGGER_DOC_HealthMonitor)]
  10. [Produces("application/json")]
  11. [Route("api/HealthMonitor/[controller]/[action]")]
  12. public class HmFetalController : Controller
  13. {
  14. private readonly TDengineService _serviceTDengine;
  15. private readonly IotApiService _serviceIotApi;
  16. private readonly ILogger<HmFetalController> _logger;
  17. public HmFetalController(IotApiService IotApiService, TDengineService serviceDengine, ILogger<HmFetalController> logger)
  18. {
  19. _logger = logger;
  20. _serviceTDengine = serviceDengine;
  21. _serviceIotApi = IotApiService;
  22. }
  23. //[HttpGet]
  24. //public async Task<IActionResult> GetMode(string sn)
  25. //{
  26. // var res= await _serviceTDengine.GetBySerialNoAsync<PregnancyCommonHeartRateModel>(sn);
  27. // return View(res);
  28. //}
  29. //[HttpPost]
  30. //public async Task<IActionResult> SetMockMode([FromBody] PregnancyCommonHeartRateModel pchr)
  31. //{
  32. // await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", pchr);
  33. // await _serviceIotApi.SetFetalConfig(pchr.SerialNumber, 1, pchr.MaxValue, pchr.MinValue);
  34. // return View(pchr);
  35. //}
  36. [HttpGet]
  37. public async Task<List<PregnancyCommonHeartRateModel>> GetMode(string sn)
  38. {
  39. var res = await _serviceTDengine.GetBySerialNoAsync<PregnancyCommonHeartRateModel>(sn);
  40. return res;
  41. }
  42. [HttpPost]
  43. public async Task<object> SetMockMode(string sn, int mockMax,int mockMin,string remark="mock")
  44. {
  45. var res= await _serviceTDengine.GetBySerialNoAsync<PregnancyCommonHeartRateModel>(sn);
  46. var pchr = res.FirstOrDefault();
  47. if (pchr == null)
  48. {
  49. return "NULL";
  50. }
  51. pchr.MaxValue = mockMax;
  52. pchr.MinValue = mockMin;
  53. pchr.Remark = remark;
  54. pchr.Timestamp = DateTime.Now;
  55. pchr.SerialTailNumber = sn[^2..];
  56. await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", pchr);
  57. var flag = await _serviceIotApi.SetFetalConfig(pchr.SerialNumber, 1, pchr.MaxValue, pchr.MinValue);
  58. return new {
  59. flag,
  60. pchr
  61. };
  62. }
  63. [HttpPost]
  64. public async Task<object> SetMockMode2(string sn, int highFreqSampleTimes , int highFreqSampleInterval , int stopHighFreqSampleCount , int triggerHighFreqHigh , int triggerHighFreqLow,string remark = "mock")
  65. {
  66. var res = await _serviceTDengine.GetBySerialNoAsync<PregnancyCommonHeartRateModel>(sn);
  67. var pchr = res.FirstOrDefault();
  68. if (pchr == null)
  69. {
  70. return "NULL";
  71. }
  72. pchr.MaxValue = triggerHighFreqHigh;
  73. pchr.MinValue = triggerHighFreqLow;
  74. pchr.Remark = remark;
  75. pchr.Timestamp = DateTime.Now;
  76. pchr.SerialTailNumber = sn[^2..];
  77. await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", pchr);
  78. var flag = await _serviceIotApi.SetFetalConfigMockAsync(pchr.SerialNumber, 1, triggerHighFreqHigh, triggerHighFreqLow,
  79. highFreqSampleTimes, highFreqSampleInterval, stopHighFreqSampleCount);
  80. return new
  81. {
  82. flag,
  83. pchr
  84. };
  85. }
  86. }
  87. }