Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

103 linhas
4.4KB

  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.Enum;
  15. using TelpoPush.Models.MqTemplates;
  16. using TelpoPush.Service.Cache;
  17. namespace TelpoPush.Service.Biz
  18. {
  19. public class ZkRealHRMonitorService : IZkRealHRMonitorService
  20. {
  21. private readonly ILogger<ZkRealHRMonitorService> _logger;
  22. private readonly HttpHelperAsync _httpHelper;
  23. private readonly RedisUtil _redis;
  24. private readonly GpsLocationHistoryAccessorClient<HisGpsRealHeartRate> _messageRealHeartRateAiClient;
  25. public ZkRealHRMonitorService(
  26. ILogger<ZkRealHRMonitorService> logger, RedisUtil redis, HttpHelperAsync httpHelper,
  27. GpsLocationHistoryAccessorClient<HisGpsRealHeartRate> messageRealHeartRateAiClient)
  28. {
  29. _logger = logger;
  30. _redis = redis;
  31. _httpHelper = httpHelper;
  32. _messageRealHeartRateAiClient = messageRealHeartRateAiClient;
  33. }
  34. //数据保存、推送
  35. public async Task Save(ZkRealHeartRateData data, string MessageId)
  36. {
  37. string deviceKey = await _redis.GetHealthyDeviceKey(data.imei);
  38. foreach (var item in data.data)
  39. {
  40. if (item.isAnomaly == 1)
  41. {
  42. DateTime lastUpdate = TimeHelper.ConvertToLocalDateTime(item.time.ToString());
  43. HisGpsRealHeartRate model = new HisGpsRealHeartRate()
  44. {
  45. HeartRateId = item.time.ToString(),
  46. MessageId = $"{MessageId}_{item.time}",
  47. Serialno = data.imei,
  48. ManufactorId = data.agencyid,
  49. HeartRate = item.value,
  50. IsAnomaly = item.isAnomaly,
  51. LastUpdate = lastUpdate,
  52. Method = 1,
  53. IsDisplay = 1,
  54. DeviceKey = deviceKey,
  55. CreateTime = DateTime.Now,
  56. };
  57. await _messageRealHeartRateAiClient.AddAsync(model);
  58. var settingInfo = await _redis.GetManufactorPushSettingHash(data.imei, data.agencyid, (int)MqDataType.ZkRealHeartRate);
  59. if (settingInfo != null)
  60. {
  61. Dictionary<string, object> dic = new Dictionary<string, object>();
  62. dic.Add("imei", data.imei);
  63. dic.Add("value", item.value);
  64. dic.Add("alarmType", item.isAnomaly);
  65. dic.Add("alarmInfo", "异常告警");
  66. dic.Add("value", item.value);
  67. dic.Add("dataTime", TimeHelper.ToDateTimeStr(lastUpdate));
  68. MultipartFormDataContent mfdc = Utils.GetMultipartFormDataContent(dic, data.agencyid, ref dic);
  69. var result = await _httpHelper.PostFormAsync(settingInfo.pushUrl, mfdc);
  70. _logger.LogInformation($"[中考实时心率-第三方数据推送<{data.imei}>] url:{settingInfo.pushUrl},参数:{JsonConvert.SerializeObject(dic)},结果:{result}");
  71. }
  72. }
  73. }
  74. }
  75. //取消 数据保存
  76. public async Task SaveAnomalyCancel(ZkRealHeartRateAnomalyCancelData data, string MessageId)
  77. {
  78. string deviceKey = await _redis.GetHealthyDeviceKey(data.imei);
  79. DateTime lastUpdate = TimeHelper.ConvertToLocalDateTime(data.time.ToString());
  80. HisGpsRealHeartRate model = new HisGpsRealHeartRate()
  81. {
  82. HeartRateId = data.time.ToString(),
  83. MessageId = $"{MessageId}_{data.time}",
  84. Serialno = data.imei,
  85. ManufactorId = data.agencyid,
  86. HeartRate = 0,
  87. IsAnomaly = -1,
  88. LastUpdate = lastUpdate,
  89. Method = 1,
  90. IsDisplay = 1,
  91. DeviceKey = deviceKey,
  92. CreateTime = DateTime.Now,
  93. };
  94. await _messageRealHeartRateAiClient.AddAsync(model);
  95. }
  96. }
  97. }