您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

83 行
3.1KB

  1. using Confluent.Kafka;
  2. using Microsoft.Extensions.Logging;
  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 TelpoDataService.Util.Clients;
  10. using TelpoDataService.Util.Entities.GpsLocationHistory;
  11. using TelpoDataService.Util.Models;
  12. using TelpoDataService.Util.QueryObjects;
  13. using TelpoPush.Common;
  14. using TelpoPush.Models.MqTemplates;
  15. using TelpoPush.Service.Cache;
  16. namespace TelpoPush.Service.Biz
  17. {
  18. public class ZkRealHRMonitorService : IZkRealHRMonitorService
  19. {
  20. private readonly ILogger<ZkRealHRMonitorService> _logger;
  21. private readonly RedisUtil _redis;
  22. private readonly GpsLocationHistoryAccessorClient<HisGpsRealHeartRate> _messageRealHeartRateAiClient;
  23. public ZkRealHRMonitorService(
  24. ILogger<ZkRealHRMonitorService> logger, RedisUtil redis,
  25. GpsLocationHistoryAccessorClient<HisGpsRealHeartRate> messageRealHeartRateAiClient)
  26. {
  27. _logger = logger;
  28. _redis = redis;
  29. _messageRealHeartRateAiClient = messageRealHeartRateAiClient;
  30. }
  31. public async Task Save(ZkRealHeartRateData data, string MessageId)
  32. {
  33. string deviceKey = await _redis.GetHealthyDeviceKey(data.imei);
  34. foreach (var item in data.data)
  35. {
  36. if (item.isAnomaly == 1)
  37. {
  38. DateTime lastUpdate = TimeHelper.ConvertToLocalDateTime(item.time.ToString());
  39. HisGpsRealHeartRate model = new HisGpsRealHeartRate()
  40. {
  41. HeartRateId = item.time.ToString(),
  42. MessageId = $"{MessageId}_{item.time}",
  43. Serialno = data.imei,
  44. ManufactorId = data.agencyid,
  45. HeartRate = item.value,
  46. IsAnomaly = item.isAnomaly,
  47. LastUpdate = lastUpdate,
  48. Method = 1,
  49. IsDisplay = 1,
  50. DeviceKey = deviceKey,
  51. CreateTime = DateTime.Now,
  52. };
  53. await _messageRealHeartRateAiClient.AddAsync(model);
  54. }
  55. }
  56. }
  57. public async Task SaveAnomalyCancel(ZkRealHeartRateAnomalyCancelData data, string MessageId)
  58. {
  59. string deviceKey = await _redis.GetHealthyDeviceKey(data.imei);
  60. DateTime lastUpdate = TimeHelper.ConvertToLocalDateTime(data.time.ToString());
  61. HisGpsRealHeartRate model = new HisGpsRealHeartRate()
  62. {
  63. HeartRateId = data.time.ToString(),
  64. MessageId = $"{MessageId}_{data.time}",
  65. Serialno = data.imei,
  66. ManufactorId = data.agencyid,
  67. HeartRate = 0,
  68. IsAnomaly = -1,
  69. LastUpdate = lastUpdate,
  70. Method = 1,
  71. IsDisplay = 1,
  72. DeviceKey = deviceKey,
  73. CreateTime = DateTime.Now,
  74. };
  75. await _messageRealHeartRateAiClient.AddAsync(model);
  76. }
  77. }
  78. }