|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- 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;
- using HealthMonitor.Service.Cache;
- using HealthMonitor.Model.Cache;
-
- namespace HealthMonitor.Service.Biz
- {
- public class IotWebApiService
- {
- private readonly ServiceConfig _configService;
- private readonly ILogger<IotWebApiService> _logger;
- private readonly PersonCacheManager _personCacheMgr;
-
- private readonly HttpHelper _httpHelper = default!;
-
- private readonly GpsCardAccessorClient<GpsPerson> _gpsPersonApiClient;
-
- public IotWebApiService(ILogger<IotWebApiService> logger, HttpHelper httpHelper, GpsCardAccessorClient<GpsPerson> gpsPersonApiClient, IOptions<ServiceConfig> optConfigService, PersonCacheManager personCacheMgr)
- {
- _configService = optConfigService.Value;
- _httpHelper=httpHelper;
- _logger = logger;
- _personCacheMgr = personCacheMgr;
- _gpsPersonApiClient = gpsPersonApiClient;
- }
-
-
-
-
-
- public async Task<bool> SetBloodPressCalibrationConfigAsync(BloodPressCalibrationConfigModel bpsCalibrationConfig)
- {
-
- #if DEBUG
- var flag = true;
- #else
-
-
-
-
-
- var flag = false;
- try
- {
- var url = $"{_configService.IotWebApiUrl}Command/SetBloodPressCalibrationConfig";
- List<KeyValuePair<string, string>> headers = new()
- {
- new KeyValuePair<string, string>("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<bool> UpdatePersonRemarksAsync(string imei, int systolicRefValue, int diastolicRefValue, int systolicIncValue, int diastolicIncValue, bool isInitRemakers=false)
- {
- var flag = false;
- try
- {
-
-
- var personCache = await _personCacheMgr.GetDeviceGpsPersonCacheObjectBySerialNoAsync(new Guid().ToString(), imei).ConfigureAwait(false);
-
- if (personCache == null)
- {
- _logger.LogInformation($"{imei} -- Person remarks数据异常,检查缓存和数据库");
- }
- else if (string.IsNullOrWhiteSpace(personCache["person"]!["remarks"]!.ToString()))
- {
- var newRemarkData = new
- {
- imei,
- time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- commandValue = new
- {
- systolicCalibrationValue = systolicRefValue,
- diastolicCalibrationValue = diastolicRefValue,
- systolicIncValue,
- diastolicIncValue
- }
- };
- var newRemarkStr = isInitRemakers ? string.Empty:$"is_blood_press:{JsonConvert.SerializeObject(newRemarkData)}|";
- personCache["person"]!["remarks"] = newRemarkStr;
- bool cacheFlag = await _personCacheMgr.UpdateDeviceGpsPersonCacheObjectBySerialNoAsync(personCache, imei);
- if (cacheFlag)
- {
- GeneralParam condition = new()
- {
- Filters = new List<QueryFilterCondition> {
- new QueryFilterCondition {
- Key=nameof(GpsDevice.Serialno),
- Value=imei,
- Operator= QueryOperatorEnum.Equal,
- ValueType=QueryValueTypeEnum.String
- }
- },
- OrderBys = new List<OrderByCondition> { new OrderByCondition { Key = "serialno", IsDesc = true } }
-
- };
- _logger.LogInformation($"{imei} 更新缓存{nameof(UpdatePersonRemarksAsync)}成功,{JsonConvert.SerializeObject(personCache)}");
-
- var person = await _gpsPersonApiClient.GetFirstAsync(condition, new RequestHeader() { RequestId = $"{imei}" }).ConfigureAwait(false);
-
- person!.Remarks = newRemarkStr;
- await _gpsPersonApiClient.UpdateAsync(person, new RequestHeader() { RequestId = $"{imei}" }).ConfigureAwait(false);
- _logger.LogInformation($"{imei} 更新Person remarks字段|{person.Remarks}");
-
- }
- else
- {
- _logger.LogInformation($"{imei} 更新缓存和数据库{nameof(UpdatePersonRemarksAsync)}失败,{JsonConvert.SerializeObject(personCache)}");
- }
- flag = cacheFlag;
- }
- }
- catch (Exception ex)
- {
- _logger.LogError($"{nameof(UpdatePersonRemarksAsync)} {imei}--更新个人信息异常:{ex.Message}, {ex.StackTrace}");
- }
- return flag;
- }
-
-
-
- }
- }
|