|
- using HealthMonitor.Model.Service.Mapper;
- using HealthMonitor.Service.Biz;
- using HealthMonitor.Service.Biz.db;
- using HealthMonitor.WebApi.Configs;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore.Metadata;
-
- namespace HealthMonitor.WebApi.Controllers.HealthMonitor
- {
- [ApiExplorerSettings(GroupName = AppConsts.SWAGGER_DOC_HealthMonitor)]
- [Produces("application/json")]
- [Route("api/HealthMonitor/[controller]/[action]")]
- public class HmFetalController : Controller
- {
- private readonly TDengineService _serviceTDengine;
- private readonly IotApiService _serviceIotApi;
-
- private readonly ILogger<HmFetalController> _logger;
-
- public HmFetalController(IotApiService IotApiService, TDengineService serviceDengine, ILogger<HmFetalController> logger)
- {
- _logger = logger;
- _serviceTDengine = serviceDengine;
- _serviceIotApi = IotApiService;
- }
-
-
- //[HttpGet]
- //public async Task<IActionResult> GetMode(string sn)
- //{
- // var res= await _serviceTDengine.GetBySerialNoAsync<PregnancyCommonHeartRateModel>(sn);
- // return View(res);
- //}
-
- //[HttpPost]
- //public async Task<IActionResult> SetMockMode([FromBody] PregnancyCommonHeartRateModel pchr)
- //{
- // await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", pchr);
-
- // await _serviceIotApi.SetFetalConfig(pchr.SerialNumber, 1, pchr.MaxValue, pchr.MinValue);
-
- // return View(pchr);
- //}
-
- [HttpGet]
- public async Task<List<PregnancyCommonHeartRateModel>> GetMode(string sn)
- {
- var res = await _serviceTDengine.GetBySerialNoAsync<PregnancyCommonHeartRateModel>(sn);
- return res;
- }
-
- [HttpPost]
- public async Task<object> SetMockMode(string sn, int mockMax,int mockMin,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.SetFetalConfig(pchr.SerialNumber, 1, pchr.MaxValue, pchr.MinValue);
- return new {
- flag,
- pchr
- };
- }
-
- [HttpPost]
- public async Task<object> SetMockMode2(string sn, 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 = triggerHighFreqHigh;
- pchr.MinValue = triggerHighFreqLow;
- 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, triggerHighFreqHigh, triggerHighFreqLow,
- highFreqSampleTimes, highFreqSampleInterval, stopHighFreqSampleCount);
- return new
- {
- flag,
- pchr
- };
- }
-
- }
- }
|