You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 satır
3.3KB

  1. using Microsoft.Extensions.Logging;
  2. using Newtonsoft.Json.Linq;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using TDengineTMQ;
  10. using System.Web;
  11. using HealthMonitor.Model.Service.Mapper;
  12. namespace HealthMonitor.Service.Cache
  13. {
  14. public class DeviceCacheManager
  15. {
  16. private readonly ILogger<DeviceCacheManager> _logger;
  17. private const string CACHE_KEY_GPSDEVICE_WATCH_CONFIG = "#GPSDEVICE_WATCH_CONFIG_HASH";
  18. public DeviceCacheManager(ILogger<DeviceCacheManager> logger)
  19. {
  20. _logger = logger;
  21. }
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. /// <param name="sn"></param>
  26. /// <param name="bizCode">
  27. /// 业务码
  28. /// 0067 胎心启动配置
  29. /// </param>
  30. /// <returns></returns>
  31. public async Task<JObject?> GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(string sn, string bizCode)
  32. {
  33. if (string.IsNullOrWhiteSpace(sn)) return null;
  34. try
  35. {
  36. var config = await RedisHelperDb7.HGetAsync(CACHE_KEY_GPSDEVICE_WATCH_CONFIG, $"{sn}_{bizCode}").ConfigureAwait(false);
  37. if (config == null) return null;
  38. return (JObject)JsonConvert.DeserializeObject(config)!;
  39. }
  40. catch (Exception ex)
  41. {
  42. _logger.LogWarning($"Redis DB7发生异常:{ex.Message}, {ex.StackTrace}");
  43. }
  44. return null;
  45. }
  46. #region 心率状态
  47. /// <summary>
  48. /// 读取高频状态
  49. /// </summary>
  50. /// <param name="sn"></param>
  51. /// <returns></returns>
  52. public async Task<PregnancyHeartRateModel?> GetPregnancyHeartRateFreqStatusAsync(string sn)
  53. {
  54. try
  55. {
  56. var key = $"PregnancyHeartRateFreqStatus_{sn}";
  57. var status = await RedisHelper.GetAsync(key).ConfigureAwait(false);
  58. if (string.IsNullOrEmpty(status)) return null;
  59. return JsonConvert.DeserializeObject<PregnancyHeartRateModel>(status);
  60. }
  61. catch (Exception ex)
  62. {
  63. _logger.LogWarning($"Redis 发生异常:{ex.Message}, {ex.StackTrace}");
  64. }
  65. return null;
  66. }
  67. public async Task SetPregnancyHeartRateFreqStatusAsync(string sn, PregnancyHeartRateModel status,int expire=-1)
  68. {
  69. try
  70. {
  71. var key = $"PregnancyHeartRateFreqStatus_{sn}";
  72. var data=JsonConvert.SerializeObject(status);
  73. await RedisHelper.SetAsync(key, data, expire).ConfigureAwait(false);
  74. }
  75. catch (Exception ex)
  76. {
  77. _logger.LogWarning($"Redis 发生异常:{ex.Message}, {ex.StackTrace}");
  78. }
  79. }
  80. public async Task DelPregnancyHeartRateFreqStatusAsync(string sn)
  81. {
  82. try
  83. {
  84. var key = $"PregnancyHeartRateFreqStatus_{sn}";
  85. await RedisHelper.DelAsync(key).ConfigureAwait(false);
  86. }
  87. catch (Exception ex)
  88. {
  89. _logger.LogWarning($"Redis 发生异常:{ex.Message}, {ex.StackTrace}");
  90. }
  91. }
  92. #endregion
  93. }
  94. }