|
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json.Linq;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using TDengineTMQ;
- using System.Web;
- using HealthMonitor.Model.Service.Mapper;
-
- namespace HealthMonitor.Service.Cache
- {
- public class DeviceCacheManager
- {
- private readonly ILogger<DeviceCacheManager> _logger;
- private const string CACHE_KEY_GPSDEVICE_WATCH_CONFIG = "#GPSDEVICE_WATCH_CONFIG_HASH";
-
-
- public DeviceCacheManager(ILogger<DeviceCacheManager> logger)
- {
- _logger = logger;
- }
-
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="sn"></param>
- /// <param name="bizCode">
- /// 业务码
- /// 0067 胎心启动配置
- /// </param>
- /// <returns></returns>
- public async Task<JObject?> GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(string sn, string bizCode)
- {
- if (string.IsNullOrWhiteSpace(sn)) return null;
-
- try
- {
- var config = await RedisHelperDb7.HGetAsync(CACHE_KEY_GPSDEVICE_WATCH_CONFIG, $"{sn}_{bizCode}").ConfigureAwait(false);
-
- if (config == null) return null;
- return (JObject)JsonConvert.DeserializeObject(config)!;
- }
- catch (Exception ex)
- {
- _logger.LogWarning($"Redis DB7发生异常:{ex.Message}, {ex.StackTrace}");
- }
-
- return null;
- }
-
-
- #region 心率状态
- /// <summary>
- /// 读取高频状态
- /// </summary>
- /// <param name="sn"></param>
- /// <returns></returns>
- public async Task<PregnancyHeartRateModel?> GetPregnancyHeartRateFreqStatusAsync(string sn)
- {
- try
- {
- var key = $"PregnancyHeartRateFreqStatus_{sn}";
- var status = await RedisHelper.GetAsync(key).ConfigureAwait(false);
- if (string.IsNullOrEmpty(status)) return null;
- return JsonConvert.DeserializeObject<PregnancyHeartRateModel>(status);
- }
- catch (Exception ex)
- {
- _logger.LogWarning($"Redis 发生异常:{ex.Message}, {ex.StackTrace}");
- }
- return null;
- }
-
- public async Task SetPregnancyHeartRateFreqStatusAsync(string sn, PregnancyHeartRateModel status,int expire=-1)
- {
- try
- {
- var key = $"PregnancyHeartRateFreqStatus_{sn}";
- var data=JsonConvert.SerializeObject(status);
- await RedisHelper.SetAsync(key, data, expire).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- _logger.LogWarning($"Redis 发生异常:{ex.Message}, {ex.StackTrace}");
- }
- }
-
- public async Task DelPregnancyHeartRateFreqStatusAsync(string sn)
- {
- try
- {
- var key = $"PregnancyHeartRateFreqStatus_{sn}";
- await RedisHelper.DelAsync(key).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- _logger.LogWarning($"Redis 发生异常:{ex.Message}, {ex.StackTrace}");
- }
-
- }
- #endregion
- }
- }
|