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.

53 line
1.5KB

  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. namespace HealthMonitor.Service.Cache
  10. {
  11. public class DeviceCacheManager
  12. {
  13. private readonly ILogger<DeviceCacheManager> _logger;
  14. private const string CACHE_KEY_GPSDEVICE_WATCH_CONFIG = "#GPSDEVICE_WATCH_CONFIG_HASH";
  15. public DeviceCacheManager(ILogger<DeviceCacheManager> logger)
  16. {
  17. _logger = logger;
  18. }
  19. /// <summary>
  20. ///
  21. /// </summary>
  22. /// <param name="sn"></param>
  23. /// <param name="bizCode">
  24. /// 业务码
  25. /// 0067 胎心启动配置
  26. /// </param>
  27. /// <returns></returns>
  28. public async Task<JObject?> GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(string sn, string bizCode)
  29. {
  30. if (string.IsNullOrWhiteSpace(sn)) return null;
  31. try
  32. {
  33. var config = await RedisHelperDb7.HGetAsync(CACHE_KEY_GPSDEVICE_WATCH_CONFIG, $"{sn}_{bizCode}").ConfigureAwait(false);
  34. if (config == null) return null;
  35. return (JObject)JsonConvert.DeserializeObject(config)!;
  36. }
  37. catch (Exception ex)
  38. {
  39. _logger.LogWarning($"Redis DB7发生异常:{ex.Message}, {ex.StackTrace}");
  40. }
  41. return null;
  42. }
  43. }
  44. }