using Confluent.Kafka; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TelpoDataService.Util.Clients; using TelpoDataService.Util.Entities.GpsLocationHistory; using TelpoDataService.Util.Models; using TelpoDataService.Util.QueryObjects; using TelpoPush.Common; using TelpoPush.Models.MqTemplates; using TelpoPush.Service.Cache; namespace TelpoPush.Service.Biz { public class ZkRealHRMonitorService : IZkRealHRMonitorService { private readonly ILogger _logger; private readonly RedisUtil _redis; private readonly GpsLocationHistoryAccessorClient _messageRealHeartRateAiClient; public ZkRealHRMonitorService( ILogger logger, RedisUtil redis, GpsLocationHistoryAccessorClient messageRealHeartRateAiClient) { _logger = logger; _redis = redis; _messageRealHeartRateAiClient = messageRealHeartRateAiClient; } public async Task Save(ZkRealHeartRateData data, string MessageId) { string deviceKey = await _redis.GetHealthyDeviceKey(data.imei); foreach (var item in data.data) { if (item.isAnomaly == 1) { DateTime lastUpdate = TimeHelper.ConvertToLocalDateTime(item.time.ToString()); HisGpsRealHeartRate model = new HisGpsRealHeartRate() { HeartRateId = item.time.ToString(), MessageId = $"{MessageId}_{item.time}", Serialno = data.imei, ManufactorId = data.agencyid, HeartRate = item.value, IsAnomaly = item.isAnomaly, LastUpdate = lastUpdate, Method = 1, IsDisplay = 1, DeviceKey = deviceKey, CreateTime = DateTime.Now, }; await _messageRealHeartRateAiClient.AddAsync(model); } } } public async Task SaveAnomalyCancel(ZkRealHeartRateAnomalyCancelData data, string MessageId) { string deviceKey = await _redis.GetHealthyDeviceKey(data.imei); DateTime lastUpdate = TimeHelper.ConvertToLocalDateTime(data.time.ToString()); HisGpsRealHeartRate model = new HisGpsRealHeartRate() { HeartRateId = data.time.ToString(), MessageId = $"{MessageId}_{data.time}", Serialno = data.imei, ManufactorId = data.agencyid, HeartRate = 0, IsAnomaly = -1, LastUpdate = lastUpdate, Method = 1, IsDisplay = 1, DeviceKey = deviceKey, CreateTime = DateTime.Now, }; await _messageRealHeartRateAiClient.AddAsync(model); } } }