|
- using GpsCardGatewayPosition.Common;
- using GpsCardGatewayPosition.Model.Config;
- using GpsCardGatewayPosition.Model.Enum;
- using GpsCardGatewayPosition.Model.IoT;
- using GpsCardGatewayPosition.Service.MqProducer.Model;
- using GpsCardGatewayPosition.Service.Resolver.Interface;
- using GpsCardGatewayPosition.Service.Resolver.Property;
- using GpsCardGatewayPosition.Service.Resolver.Property.Dto;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace GpsCardGatewayPosition.Service.Resolver.Factory
- {
- public class ResolverFactory : IResolverFactory
- {
- private readonly ILogger<ResolverFactory> _logger;
- private readonly AppsettingsConfig _configAppsettings;
- private readonly WifiPositionResolver _resolverWifiPosition;
- public ResolverFactory(ILogger<ResolverFactory> logger, WifiPositionResolver wifiPositionResolver,IOptions<AppsettingsConfig> optConfigAppsettings)
- {
- _logger = logger;
- _configAppsettings = optConfigAppsettings.Value;
- _resolverWifiPosition = wifiPositionResolver;
- }
-
- public PackageMsgModel ParseAndWrap(JObject msg)
- {
- throw new NotImplementedException();
- }
-
- public async void Resolver(MessageModel msg)
- {
- try
- {
- string msgId = msg!.Data["MessageId"]?.ToObject<string>()!;
- string bizId = msg!.Data["BusinessId"]?.ToObject<string>()!;
- IotTopicType topic = msg!.Data["TopicType"]!.ToObject<IotTopicType>();
- int type = msg!.Data["MsgType"]!.ToObject<int>();
- object topicInfo = msg!.Data["TopicInfo"]!.ToObject<object>()!;
- object detailData = msg!.Data["DetailData"]!.ToObject<object>()!;
- var packge = new PackageMsgModel(msgId, bizId, topic, type, topicInfo, detailData);
-
- //return new PackageMsgModel(msgId, bizId, topic, type, topicInfo, detailData);
- var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg!.Data["TopicInfo"]?["items"]?.ToString()!);
- var key = dict?.Keys?.FirstOrDefault() + "";
- switch (key)
- {
- case "GPS": //处理gps位置信息上报
- {
- Console.WriteLine("GPS");
- var data = JsonConvert.DeserializeObject<PropertyItemModel<GpsInfoModel>>(dict?["GPS"] + "");
- if (Utils.GetTimeDeviationMilliseconds(data!.Time) > _configAppsettings.DeviceTimeDeviationMillieconds) throw new ArgumentException($"设备消息时间戳异常[{data.Time}]");
- break;
- //return new PackageMsgModel(msg.MessageId, topicInfo.DeviceName, IotTopicType.Property, (int)IotMessagePropertyType.GpsPosition, topicInfo, data);
- }
-
- case "WIFI": //处理gps位置信息上报
- {
- var data = JsonConvert.DeserializeObject<PropertyItemModel<WifiInfoModel>>(dict?["WIFI"] + "");
- //if (Utils.GetTimeDeviationMilliseconds(data!.Time) > _configAppsettings.DeviceTimeDeviationMillieconds) throw new ArgumentException($"设备消息时间戳异常[{data.Time}]");
-
- Console.WriteLine("WIFI");
- _resolverWifiPosition.SetResolveInfo(packge);
- await _resolverWifiPosition.ExecuteMessageAsync().ConfigureAwait(false);
-
- break;
- }
- case "WIFIPLUS2_0": //处理gps位置信息上报
- {
- var data = JsonConvert.DeserializeObject<PropertyItemModel<List<EachWifiPlus2Model>>>(dict?["WIFIPLUS2_0"] + "");
- // if (Utils.GetTimeDeviationMilliseconds(data!.Time) > _configAppsettings.DeviceTimeDeviationMillieconds) throw new ArgumentException($"设备消息时间戳异常[{data.Time}]");
-
- Console.WriteLine("WIFIPLUS2_0");
-
- break;
- }
- case "LBS": //处理gps位置信息上报
- {
- var data = JsonConvert.DeserializeObject<PropertyItemModel<LbsInfoModel>>(dict?["LBS"] + "");
- if (Utils.GetTimeDeviationMilliseconds(data!.Time) > _configAppsettings.DeviceTimeDeviationMillieconds) throw new ArgumentException($"设备消息时间戳异常[{data.Time}]");
-
- //if (data.Value.Cdma == 0)
- //{
- // return new PackageMsgModel(msg.MessageId, topicInfo.DeviceName, IotTopicType.Property, (int)IotMessagePropertyType.LbsGsmPosition, topicInfo, data);
- //}
- //else if (data.Value.Cdma == 1)
- //{
- // return new PackageMsgModel(msg.MessageId, topicInfo.DeviceName, IotTopicType.Property, (int)IotMessagePropertyType.LbsCdmaPosition, topicInfo, data);
- //}
- Console.WriteLine("WIFIPLUS2_0");
-
- break;
- }
- }
- }
- catch (Exception ex)
- {
- _logger.LogError($"解析Property主题消息发生异常 messageId: {msg!.MessageId}, Message: {ex.Message}, body: {JsonConvert.SerializeObject(msg)}");
- }
- }
- }
- }
|