|
- 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.Enum;
- using TelpoPush.Models.MqTemplates;
- using TelpoPush.Service.Cache;
-
- namespace TelpoPush.Service.Biz
- {
- public class ZkRealHRMonitorService : IZkRealHRMonitorService
- {
-
- private readonly ILogger<ZkRealHRMonitorService> _logger;
- private readonly HttpHelperAsync _httpHelper;
- private readonly RedisUtil _redis;
- private readonly GpsLocationHistoryAccessorClient<HisGpsRealHeartRate> _messageRealHeartRateAiClient;
- public ZkRealHRMonitorService(
- ILogger<ZkRealHRMonitorService> logger, RedisUtil redis, HttpHelperAsync httpHelper,
- GpsLocationHistoryAccessorClient<HisGpsRealHeartRate> messageRealHeartRateAiClient)
- {
- _logger = logger;
- _redis = redis;
- _httpHelper = httpHelper;
- _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);
- var settingInfo = await _redis.GetManufactorPushSettingHash(data.imei, data.agencyid, (int)MqDataType.ZkRealHeartRate);
- if (settingInfo != null)
- {
- Dictionary<string, object> dic = new Dictionary<string, object>();
- dic.Add("imei", data.imei);
- dic.Add("value", item.value);
- dic.Add("alarmType", item.isAnomaly);
- dic.Add("alarmInfo", "异常告警");
- dic.Add("value", item.value);
- dic.Add("dataTime", TimeHelper.ToDateTimeStr(lastUpdate));
- MultipartFormDataContent mfdc = Utils.GetMultipartFormDataContent(dic, data.agencyid, ref dic);
- var result = await _httpHelper.PostFormAsync(settingInfo.pushUrl, mfdc);
- _logger.LogInformation($"[中考实时心率-第三方数据推送<{data.imei}>] url:{settingInfo.pushUrl},参数:{JsonConvert.SerializeObject(dic)},结果:{result}");
- }
- }
- }
- }
-
- //取消 数据保存
- 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);
- }
- }
- }
|