Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

110 Zeilen
5.7KB

  1. using GpsCardGatewayPosition.Common;
  2. using GpsCardGatewayPosition.Model.Config;
  3. using GpsCardGatewayPosition.Model.Enum;
  4. using GpsCardGatewayPosition.Model.IoT;
  5. using GpsCardGatewayPosition.Service.MqProducer.Model;
  6. using GpsCardGatewayPosition.Service.Resolver.Interface;
  7. using GpsCardGatewayPosition.Service.Resolver.Property;
  8. using GpsCardGatewayPosition.Service.Resolver.Property.Dto;
  9. using Microsoft.Extensions.Logging;
  10. using Microsoft.Extensions.Options;
  11. using Newtonsoft.Json;
  12. using Newtonsoft.Json.Linq;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace GpsCardGatewayPosition.Service.Resolver.Factory
  19. {
  20. public class ResolverFactory : IResolverFactory
  21. {
  22. private readonly ILogger<ResolverFactory> _logger;
  23. private readonly AppsettingsConfig _configAppsettings;
  24. private readonly WifiPositionResolver _resolverWifiPosition;
  25. public ResolverFactory(ILogger<ResolverFactory> logger, WifiPositionResolver wifiPositionResolver,IOptions<AppsettingsConfig> optConfigAppsettings)
  26. {
  27. _logger = logger;
  28. _configAppsettings = optConfigAppsettings.Value;
  29. _resolverWifiPosition = wifiPositionResolver;
  30. }
  31. public PackageMsgModel ParseAndWrap(JObject msg)
  32. {
  33. throw new NotImplementedException();
  34. }
  35. public async void Resolver(MessageModel msg)
  36. {
  37. try
  38. {
  39. string msgId = msg!.Data["MessageId"]?.ToObject<string>()!;
  40. string bizId = msg!.Data["BusinessId"]?.ToObject<string>()!;
  41. IotTopicType topic = msg!.Data["TopicType"]!.ToObject<IotTopicType>();
  42. int type = msg!.Data["MsgType"]!.ToObject<int>();
  43. object topicInfo = msg!.Data["TopicInfo"]!.ToObject<object>()!;
  44. object detailData = msg!.Data["DetailData"]!.ToObject<object>()!;
  45. var packge = new PackageMsgModel(msgId, bizId, topic, type, topicInfo, detailData);
  46. //return new PackageMsgModel(msgId, bizId, topic, type, topicInfo, detailData);
  47. var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg!.Data["TopicInfo"]?["items"]?.ToString()!);
  48. var key = dict?.Keys?.FirstOrDefault() + "";
  49. switch (key)
  50. {
  51. case "GPS": //处理gps位置信息上报
  52. {
  53. Console.WriteLine("GPS");
  54. var data = JsonConvert.DeserializeObject<PropertyItemModel<GpsInfoModel>>(dict?["GPS"] + "");
  55. if (Utils.GetTimeDeviationMilliseconds(data!.Time) > _configAppsettings.DeviceTimeDeviationMillieconds) throw new ArgumentException($"设备消息时间戳异常[{data.Time}]");
  56. break;
  57. //return new PackageMsgModel(msg.MessageId, topicInfo.DeviceName, IotTopicType.Property, (int)IotMessagePropertyType.GpsPosition, topicInfo, data);
  58. }
  59. case "WIFI": //处理gps位置信息上报
  60. {
  61. var data = JsonConvert.DeserializeObject<PropertyItemModel<WifiInfoModel>>(dict?["WIFI"] + "");
  62. //if (Utils.GetTimeDeviationMilliseconds(data!.Time) > _configAppsettings.DeviceTimeDeviationMillieconds) throw new ArgumentException($"设备消息时间戳异常[{data.Time}]");
  63. Console.WriteLine("WIFI");
  64. _resolverWifiPosition.SetResolveInfo(packge);
  65. await _resolverWifiPosition.ExecuteMessageAsync().ConfigureAwait(false);
  66. break;
  67. }
  68. case "WIFIPLUS2_0": //处理gps位置信息上报
  69. {
  70. var data = JsonConvert.DeserializeObject<PropertyItemModel<List<EachWifiPlus2Model>>>(dict?["WIFIPLUS2_0"] + "");
  71. // if (Utils.GetTimeDeviationMilliseconds(data!.Time) > _configAppsettings.DeviceTimeDeviationMillieconds) throw new ArgumentException($"设备消息时间戳异常[{data.Time}]");
  72. Console.WriteLine("WIFIPLUS2_0");
  73. break;
  74. }
  75. case "LBS": //处理gps位置信息上报
  76. {
  77. var data = JsonConvert.DeserializeObject<PropertyItemModel<LbsInfoModel>>(dict?["LBS"] + "");
  78. if (Utils.GetTimeDeviationMilliseconds(data!.Time) > _configAppsettings.DeviceTimeDeviationMillieconds) throw new ArgumentException($"设备消息时间戳异常[{data.Time}]");
  79. //if (data.Value.Cdma == 0)
  80. //{
  81. // return new PackageMsgModel(msg.MessageId, topicInfo.DeviceName, IotTopicType.Property, (int)IotMessagePropertyType.LbsGsmPosition, topicInfo, data);
  82. //}
  83. //else if (data.Value.Cdma == 1)
  84. //{
  85. // return new PackageMsgModel(msg.MessageId, topicInfo.DeviceName, IotTopicType.Property, (int)IotMessagePropertyType.LbsCdmaPosition, topicInfo, data);
  86. //}
  87. Console.WriteLine("WIFIPLUS2_0");
  88. break;
  89. }
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. _logger.LogError($"解析Property主题消息发生异常 messageId: {msg!.MessageId}, Message: {ex.Message}, body: {JsonConvert.SerializeObject(msg)}");
  95. }
  96. }
  97. }
  98. }