You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

616 lines
26KB

  1. using GpsCardGatewayPosition.Model.Config;
  2. using GpsCardGatewayPosition.Model.IoT;
  3. using GpsCardGatewayPosition.Service.Resolver.Interface;
  4. using GpsCardGatewayPosition.Service.Resolver.Property.Dto;
  5. using Microsoft.Extensions.Logging;
  6. using Microsoft.Extensions.Options;
  7. using Newtonsoft.Json.Linq;
  8. using Newtonsoft.Json;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using GpsCardGatewayPosition.Service.Biz.Location;
  15. using GpsCardGatewayPosition.Service.Cache;
  16. using GpsCardGatewayPosition.Service.Biz.Location.Dto.Gaode;
  17. using GpsCardGatewayPosition.Service.Biz.Location.Dto.Wayz;
  18. using TelpoDataService.Util.Entities.GpsCard;
  19. using AutoMapper.Internal;
  20. using GpsCardGatewayPosition.Common.Helper;
  21. using GpsCardGatewayPosition.Common;
  22. using GpsCardGatewayPosition.Model.Enum;
  23. using GpsCardGatewayPosition.Service.Biz.Location.Dto;
  24. using GpsCardGatewayPosition.Service.MqProducer.Model;
  25. using GpsCardGatewayPosition.Model.Context;
  26. using GpsCardGatewayPosition.Service.MqProducer;
  27. using System.Data;
  28. using GpsCardGatewayPosition.Service.Biz.Health;
  29. using TelpoDataService.Util.Entities.GpsLocationHistory;
  30. using GpsCardGatewayPosition.Service.Biz.Pay;
  31. using GpsCardGatewayPosition.Service.Biz.Sos;
  32. using GpsCardGatewayPosition.Model.Templates;
  33. using GpsCardGatewayPosition.Service.Biz;
  34. namespace GpsCardGatewayPosition.Service.Resolver.Property
  35. {
  36. public class WifiPositionResolver : IPropertyResolver
  37. {
  38. private readonly ILogger<WifiPositionResolver> _logger;
  39. private readonly WifiParamConfig _configWifiParam;
  40. private readonly DeviceCacheManager _deviceCacheMgr;
  41. private readonly GaodeService _serviceGaode;
  42. private readonly WayzService _serviceWayz;
  43. private readonly LocationLogic _serviceLocation;
  44. private readonly MqProcessLogic _serviceMqProcess;
  45. private readonly HealthLogic _serviceHealth;
  46. private readonly GlobalService _serviceGlobal;
  47. private readonly PayLogic _servicePay;
  48. private readonly SosLogic _serviceSos;
  49. private AsyncLocal<string> _messageId = new AsyncLocal<string>();
  50. private AsyncLocal<PropertyModel> _package = new AsyncLocal<PropertyModel>();
  51. private AsyncLocal<PropertyItemModel<WifiInfoModel>> _propertyValue = new AsyncLocal<PropertyItemModel<WifiInfoModel>>();
  52. public WifiPositionResolver(ILogger<WifiPositionResolver> logger, IOptions<WifiParamConfig> optWifiParamConfig, GlobalService serviceGlobal, PayLogic servicePay, HealthLogic serviceHealth, MqProcessLogic serviceMqProcess,
  53. WayzService serviceWayz, GaodeService serviceGaode, DeviceCacheManager deviceCacheMgr, SosLogic serviceSos, LocationLogic serviceLocation)
  54. {
  55. _serviceGaode = serviceGaode;
  56. _serviceWayz = serviceWayz;
  57. _deviceCacheMgr = deviceCacheMgr;
  58. _serviceLocation = serviceLocation;
  59. _serviceMqProcess = serviceMqProcess;
  60. _serviceHealth = serviceHealth;
  61. _servicePay= servicePay;
  62. _serviceSos = serviceSos;
  63. _serviceGlobal = serviceGlobal;
  64. _logger = logger;
  65. _configWifiParam = optWifiParamConfig.Value;
  66. }
  67. public void SetResolveInfo(PackageMsgModel msg)
  68. {
  69. _messageId.Value = msg.MessageId;
  70. _package.Value = ((JToken)msg.TopicInfo).ToObject<PropertyModel>()!;
  71. _propertyValue.Value = ((JToken)msg.DetailData).ToObject<PropertyItemModel<WifiInfoModel>>()!;
  72. /// throw new NotImplementedException();
  73. }
  74. public override string ToString()
  75. {
  76. return $"{nameof(WifiPositionResolver)}[{_messageId.Value}]";
  77. }
  78. public async Task ExecuteMessageAsync()
  79. {
  80. var package = _package.Value;
  81. string serialno = package?.DeviceName!; //设备序列号
  82. var messageId = _messageId.Value!;
  83. var propertyValue = _propertyValue.Value!;
  84. int IDType = propertyValue!.Value.IDType;
  85. string IDNumber = propertyValue.Value.IDNumber;
  86. string mmac = propertyValue.Value.Mmac;
  87. string macs = propertyValue.Value.macs;
  88. var eachParam = mmac.Split(',');
  89. var signal = Convert.ToInt32(eachParam[1]);
  90. string cityCode = "";
  91. string addr = "";
  92. decimal olat = 0;
  93. decimal olng = 0;
  94. decimal baiduLat = 0;
  95. decimal baiduLng = 0;
  96. decimal gaodeLat = 0;
  97. decimal gaodeLng = 0;
  98. int radius = 0;
  99. string hashParam = Guid.NewGuid().ToString();
  100. string province = null;
  101. string city = null;
  102. string district = null;
  103. var fullAddress = string.Empty;
  104. //throw new NotImplementedException();
  105. //以下时间段,wifi上报信息不过滤
  106. var startOne = TimeSpan.Parse(_configWifiParam.StartOne);
  107. var endOne = TimeSpan.Parse(_configWifiParam.EndOne);
  108. var startTwo = TimeSpan.Parse(_configWifiParam.StartTwo);
  109. var endTwo = TimeSpan.Parse(_configWifiParam.EndTwo);
  110. //var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(messageId!, serialno!).ConfigureAwait(false);
  111. //if (device == null)
  112. //{
  113. // _logger.LogError($"非法设备:{serialno}");
  114. // return;
  115. //}
  116. var device = new GpsDevice()
  117. {
  118. DeviceId = serialno,
  119. };
  120. #region 定位解析
  121. var request = new GaodeWifiRequest
  122. {
  123. //Imei = serialno,
  124. Macs = macs,
  125. Mmac = mmac
  126. };
  127. #region wifi
  128. var wifiItems = new List<WayzRequest.WifiItem>();
  129. // 已经接入的wifi mmac:80:8f:1d:bf:45:b1,-70,
  130. if (mmac.Split(',').Length > 2)
  131. {
  132. wifiItems.Add(new WayzRequest.WifiItem
  133. {
  134. Connected = true,
  135. SignalStrength = Math.Abs(int.Parse(mmac.Split(',')[1])),
  136. MacAddress = mmac.Split(',')[0]
  137. });
  138. }
  139. // wifi 列表 macs:08:9b:4b:b7:b3:5d,-70,|20:6b:e7:7e:4d:30,-70,|8c:a6:df:74:33:15,-74,|74:7d:24:0f:ff:60,-74,|78:44:76:0a:3c:74,-75,|02:0e:5e:ad:5d:d1,-78,|10:a4:be:f6:12:bf,-78,
  140. if (macs.Split('|').Length > 1)
  141. {
  142. macs.Split('|').ForAll(mac =>
  143. {
  144. wifiItems.Add(new WayzRequest.WifiItem
  145. {
  146. Connected = false,
  147. SignalStrength = Math.Abs(int.Parse(mac.Split(',')[1])),
  148. MacAddress = mac.Split(',')[0]
  149. });
  150. });
  151. }
  152. #endregion
  153. var wayzWifiRequest = new WayzWifiRequest
  154. {
  155. Location = new WayzRequest.LocationDetail
  156. {
  157. Wifis = wifiItems
  158. },
  159. Asset = new WayzRequest.AssetDevice
  160. {
  161. Id = serialno,
  162. ImeiMd5 = serialno,
  163. UniqueId = device.DeviceId
  164. }
  165. };
  166. var positionStatus = await _deviceCacheMgr.GetPositionStatusCacheAsync(serialno).ConfigureAwait(false);
  167. //GetGaodePositionServiceResult gaodeResult = null;
  168. GetWayzPositionServiceResult wayzServiceResult = null;
  169. var timeOfNow = DateTime.Now.TimeOfDay;
  170. if ((timeOfNow >= startOne && timeOfNow <= endOne) ||
  171. (timeOfNow >= startTwo && timeOfNow <= endTwo)) //处于以下时间段,wifi信息不过滤
  172. {
  173. //gaodeResult = await _serviceGaode.GetGaodeWifiAddressAsync(serialno, request).ConfigureAwait(false);
  174. wayzServiceResult = await _serviceWayz.GetWayzWifiAddressAsync(serialno, wayzWifiRequest).ConfigureAwait(false);
  175. // if (!wayzServiceResult.Flag)
  176. //{
  177. // if (wayzServiceResult.CanRetry) _serviceWayz.SendRealtimeLocationAsync(serialno, Utils.ConvertToLocalDateTime(propertyValue.Time), RealtimeLocationTypeFlag.All);
  178. // return;
  179. //}
  180. if (wayzServiceResult.Flag)
  181. {
  182. province = wayzServiceResult.Province;
  183. city = wayzServiceResult.City;
  184. district = wayzServiceResult.District;
  185. addr = wayzServiceResult.Address;
  186. cityCode = wayzServiceResult.CityCode;
  187. hashParam = wayzServiceResult.HashParam;
  188. fullAddress = wayzServiceResult.FullAddress;
  189. olat = wayzServiceResult.Lat;
  190. olng = wayzServiceResult.Lon;
  191. radius = wayzServiceResult.Accuracy;
  192. }
  193. else
  194. {
  195. _logger.LogInformation($"维智服务不能解析WIFI地址数据,将采用高德服务解析");
  196. var wifiGaodeRequest = new GaodeWifiRequest()
  197. {
  198. Macs = macs,
  199. Mmac = mmac
  200. };
  201. var gaodeServiceResult = await _serviceGaode.GetGaodeWifiAddressAsync(serialno, wifiGaodeRequest);
  202. if (gaodeServiceResult.Flag)
  203. {
  204. province = gaodeServiceResult.Province;
  205. city = gaodeServiceResult.City;
  206. district = gaodeServiceResult.District;
  207. addr = gaodeServiceResult.Address;
  208. cityCode = gaodeServiceResult.AdCode;
  209. hashParam = gaodeServiceResult.HashParam;
  210. olat = gaodeServiceResult.Lat;
  211. olng = gaodeServiceResult.Lon;
  212. radius = gaodeServiceResult.Accuracy;
  213. fullAddress = string.Format("{0}|{1}", "_Gaode", gaodeServiceResult.Address);
  214. }
  215. else
  216. {
  217. await _serviceWayz.SendRealtimeLocationAsync(serialno, Utils.ConvertToLocalDateTime(propertyValue.Time), RealtimeLocationTypeFlag.All);
  218. _logger.LogInformation($"维智服务和高德服务解析都不能解析WIFI地址定位数据");
  219. return;
  220. }
  221. }
  222. decimal[] latLng = GeoConvert.ConvertGoogleBaiduLatLng(olat, olng);
  223. baiduLng = latLng[3];
  224. baiduLat = latLng[2];
  225. gaodeLng = latLng[1];
  226. gaodeLat = latLng[0];
  227. }
  228. else //以上时间段之外,应用过滤逻辑
  229. {
  230. var cachePosition = positionStatus?.LastPosition;
  231. if (signal > -70 || cachePosition == null)
  232. {
  233. //gaodeResult = await _serviceGaode.GetGaodeWifiAddressAsync(serialno, request).ConfigureAwait(false);
  234. wayzServiceResult = await _serviceWayz.GetWayzWifiAddressAsync(serialno, wayzWifiRequest).ConfigureAwait(false);
  235. // if (!wayzServiceResult.Flag)
  236. //{
  237. // if (wayzServiceResult.CanRetry) _serviceWayz.SendRealtimeLocationAsync(serialno, Utils.ConvertToLocalDateTime(propertyValue.Time), RealtimeLocationTypeFlag.All);
  238. // return;
  239. //}
  240. if (wayzServiceResult.Flag)
  241. {
  242. province = wayzServiceResult.Province;
  243. city = wayzServiceResult.City;
  244. district = wayzServiceResult.District;
  245. addr = wayzServiceResult.Address;
  246. cityCode = wayzServiceResult.CityCode;
  247. hashParam = wayzServiceResult.HashParam;
  248. fullAddress = wayzServiceResult.FullAddress;
  249. olat = wayzServiceResult.Lat;
  250. olng = wayzServiceResult.Lon;
  251. radius = wayzServiceResult.Accuracy;
  252. }
  253. else
  254. {
  255. _logger.LogInformation($"维智服务不能解析WIFI地址数据,将采用高德服务解析");
  256. var wifiGaodeRequest = new GaodeWifiRequest()
  257. {
  258. Macs = macs,
  259. Mmac = mmac
  260. };
  261. var gaodeServiceResult = await _serviceGaode.GetGaodeWifiAddressAsync(serialno, wifiGaodeRequest);
  262. if (gaodeServiceResult.Flag)
  263. {
  264. province = gaodeServiceResult.Province;
  265. city = gaodeServiceResult.City;
  266. district = gaodeServiceResult.District;
  267. addr = gaodeServiceResult.Address;
  268. cityCode = gaodeServiceResult.AdCode;
  269. hashParam = gaodeServiceResult.HashParam;
  270. olat = gaodeServiceResult.Lat;
  271. olng = gaodeServiceResult.Lon;
  272. radius = gaodeServiceResult.Accuracy;
  273. fullAddress = string.Format("{0}|{1}", "_Gaode", gaodeServiceResult.Address);
  274. }
  275. else
  276. {
  277. await _serviceWayz.SendRealtimeLocationAsync(serialno, Utils.ConvertToLocalDateTime(propertyValue.Time), RealtimeLocationTypeFlag.All);
  278. _logger.LogInformation($"维智服务和高德服务解析都不能解析WIFI定位数据");
  279. return;
  280. }
  281. }
  282. decimal[] latLng = GeoConvert.ConvertGoogleBaiduLatLng(olat, olng);
  283. baiduLng = latLng[3];
  284. baiduLat = latLng[2];
  285. gaodeLng = latLng[1];
  286. gaodeLat = latLng[0];
  287. }
  288. ////******2022/04/24 领导决定不采用最后一次有效定位填充当前无效定位值
  289. //else
  290. //{
  291. // addr = cachePosition.Address;
  292. // olat = cachePosition.OriginalLat;
  293. // olng = cachePosition.OriginalLon;
  294. // baiduLng = cachePosition.BaiduLon;
  295. // baiduLat = cachePosition.BaiduLat;
  296. // gaodeLat = cachePosition.GaodeLat;
  297. // gaodeLng = cachePosition.GaodeLon;
  298. // cityCode = cachePosition.CityCode;
  299. // radius = cachePosition.Radius;
  300. //}
  301. }
  302. #endregion
  303. #region 保存历史轨迹
  304. var loc = new LocationInfo
  305. {
  306. LocationId = Guid.NewGuid().ToString("D"),
  307. Address = addr,
  308. BaiduLat = baiduLat,
  309. BaiduLng = baiduLng,
  310. OLat = olat,
  311. OLng = olng,
  312. GLat = gaodeLat,
  313. GLng = gaodeLng,
  314. Course = 0,
  315. DeviceId = device.DeviceId,
  316. DeviceStatus = radius.ToString(),
  317. IsStop = false,
  318. LastUpdate = Utils.ConvertToLocalDateTime(propertyValue.Time),
  319. UtcDate = Utils.ConvertToUtcDateTime(propertyValue.Time),
  320. LocationType = Convert.ToInt32(LocationType.WIFI),
  321. Remarks = cityCode,
  322. SerialNo = serialno,
  323. Speed = 0,
  324. Postcode = cityCode,
  325. IsRedressed = false,
  326. HashParam = hashParam,
  327. Province = province,
  328. City = city,
  329. District = district
  330. };
  331. loc.Remarks = string.Format("Wayz_Wifi|{0}", fullAddress);
  332. if (string.IsNullOrWhiteSpace(loc.Address) || loc.GLng < 1 || loc.GLat < 1)
  333. {
  334. //没有符合定位解析的消息,直接退出
  335. return;
  336. }
  337. var requestPositionData = new RequestLocationInfo<WayzWifiRequest>
  338. {
  339. MapSource = 2,
  340. RequestLocationType = loc.LocationType,
  341. RequestData = wayzWifiRequest
  342. };
  343. //return;
  344. var hisResult = await _serviceLocation.AddLocationAsync(messageId, loc, positionStatus, propertyValue.Time, cityCode, null, requestPositionData).ConfigureAwait(false);
  345. if (!hisResult.IsSuccess)
  346. {
  347. _logger.LogError($"{hisResult.Message}");
  348. return;
  349. }
  350. #endregion
  351. #region 处理围栏
  352. //过滤历史定位消息
  353. if (!hisResult.IsHistoryLocation)
  354. {
  355. //_serviceLocation.ProcessGeofence(loc, messageId);
  356. await _serviceLocation.ProcessGeofenceAsync(loc, messageId);
  357. }
  358. else
  359. {
  360. _logger.LogInformation($"设备{serialno},收到历史定位");
  361. }
  362. #endregion
  363. #region 保存最后位置信息
  364. var context = "online=1";
  365. var deviceStatus = await _deviceCacheMgr.GetDeviceStatusBySerialNoAsync(messageId, serialno).ConfigureAwait(false);
  366. var statusContext = new DeviceStatus();
  367. if (deviceStatus != null)
  368. {
  369. statusContext.Deserlize(deviceStatus.DeviceStatus);
  370. }
  371. statusContext.Deserlize(context);
  372. //重新构造设备状态数据
  373. deviceStatus = new GpsDeviceStatus
  374. {
  375. Address = addr,
  376. IsStop = (bool)loc.IsStop,
  377. BaiduLat = baiduLat,
  378. BaiduLng = baiduLng,
  379. Olat = olat,
  380. Olng = olng,
  381. Glat = gaodeLat,
  382. Glng = gaodeLng,
  383. Course = loc.Course,
  384. DeviceId = loc.DeviceId,
  385. DeviceStatus = statusContext.ToString(),
  386. DeviceUtcTime = loc.UtcDate,
  387. LastUpdate = loc.LastUpdate,
  388. LocationType = loc.LocationType,
  389. Remarks = loc.LocationId,
  390. Serialno = loc.SerialNo,
  391. //Speed = loc.Speed,
  392. Speed = SafeType.SafeInt(loc.DeviceStatus)
  393. };
  394. var result = await _serviceLocation.UpdateDeviceStatusAsync(messageId, deviceStatus).ConfigureAwait(false);
  395. if (!result.IsSuccess)
  396. {
  397. _logger.LogError($"[{_messageId}] {result.Message}");
  398. return;
  399. }
  400. //THOMAS Kafka
  401. var positionData = new LocationDatas()
  402. {
  403. imei = loc.SerialNo,
  404. altitude = 0,
  405. address = loc.Address,
  406. baiduLatitude = loc.BaiduLat,
  407. baiduLongitude = loc.BaiduLng,
  408. gaodeLatitude = loc.GLat,
  409. gaodeLongitude = loc.GLng,
  410. originalLatitude = loc.OLat,
  411. originalLongitude = loc.OLng,
  412. locationType = loc.LocationType,
  413. postcode = loc.Postcode,
  414. hashParam = loc.HashParam,
  415. radius = radius,
  416. province = province,
  417. city = city,
  418. district = district
  419. };
  420. //await _serviceMqProcess.ProcessPositionAsync(messageId, positionData, loc.LastUpdate.Value.ToString("yyyy-MM-dd HH:mm:ss"),string.Join("|", wifiItems.AsEnumerable().Select(i => i.MacAddress)));
  421. await _serviceMqProcess.ProcessPositionAsync(messageId, positionData, loc.LastUpdate.Value.ToString("yyyy-MM-dd HH:mm:ss"), $"{mmac}|{macs}");
  422. #endregion
  423. #region 更新Alarm
  424. if (IDType == (int)IdType.Sos && !string.IsNullOrWhiteSpace(IDNumber))
  425. {
  426. // THOMAS Kafka
  427. //var SOSAlarm = new SoSTemplates()
  428. //{
  429. // imei = serialno,
  430. // sosId = IDNumber,
  431. // address = loc.Address,
  432. // info = "您的宝贝在求救",
  433. // baiduLatitude = loc.BaiduLat,
  434. // baiduLongitude = loc.BaiduLng,
  435. // gaodeLatitude = loc.GLat,
  436. // gaodeLongitude = loc.GLng,
  437. // originalLatitude = loc.OLat,
  438. // originalLongitude = loc.OLng,
  439. //};
  440. //_serviceMqProcess.ProcessAlarmSos(messageId, SOSAlarm, loc.LastUpdate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  441. var sosId = IDNumber;
  442. await _serviceSos.HandleSosAddressAsync(messageId, sosId, propertyValue.Time, () => new HisGpsAlarm
  443. {
  444. DeviceId = device.DeviceId,
  445. MessageId = sosId,
  446. Serialno = serialno,
  447. CreateTime = DateTime.Now,
  448. DeviceUtcTime = Utils.ConvertToUtcDateTime(propertyValue.Time),
  449. Olat = loc.OLat,
  450. Olng = loc.OLng,
  451. BaiduLat = loc.BaiduLat,
  452. BaiduLng = loc.BaiduLng,
  453. Glat = loc.GLat,
  454. Glng = loc.GLng
  455. },
  456. a =>
  457. {
  458. a.Olat = loc.OLat;
  459. a.Olng = loc.OLng;
  460. a.BaiduLat = loc.BaiduLat;
  461. a.BaiduLng = loc.BaiduLng;
  462. a.Glat = loc.GLat;
  463. a.Glng = loc.GLng;
  464. return a;
  465. },
  466. async () => {
  467. var SOSAlarm = new SoSTemplates()
  468. {
  469. imei = serialno,
  470. sosId = IDNumber,
  471. address = loc.Address,
  472. info = "您的宝贝在求救",
  473. baiduLatitude = loc.BaiduLat,
  474. baiduLongitude = loc.BaiduLng,
  475. gaodeLatitude = loc.GLat,
  476. gaodeLongitude = loc.GLng,
  477. originalLatitude = loc.OLat,
  478. originalLongitude = loc.OLng,
  479. };
  480. await _serviceMqProcess.ProcessAlarmSosAsync(messageId, SOSAlarm, loc.LastUpdate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  481. });
  482. }
  483. else if (IDType == (int)IdType.PayLog && !string.IsNullOrWhiteSpace(IDNumber))
  484. {
  485. var payId = propertyValue.Value.IDNumber;
  486. var pay = await _servicePay.GetPayLogAsync(messageId, $"{serialno}-{payId}").ConfigureAwait(false);
  487. if (pay == null)
  488. {
  489. pay = new GpsPayLog
  490. {
  491. Serialno = serialno,
  492. Payid = $"{serialno}-{payId}",
  493. DeviceId = device.DeviceId,
  494. Olat = loc.OLat,
  495. Olng = loc.OLng,
  496. BaiduLat = loc.BaiduLat,
  497. BaiduLng = loc.BaiduLng,
  498. Glat = loc.GLat,
  499. Glng = loc.GLng
  500. };
  501. await _servicePay.AddPayLogAsync(messageId, pay).ConfigureAwait(false);
  502. }
  503. else
  504. {
  505. pay.Olat = loc.OLat;
  506. pay.Olng = loc.OLng;
  507. pay.BaiduLat = loc.BaiduLat;
  508. pay.BaiduLng = loc.BaiduLng;
  509. pay.Glat = loc.GLat;
  510. pay.Glng = loc.GLng;
  511. await _servicePay.UpdatePayLogAsync(messageId, pay).ConfigureAwait(false);
  512. }
  513. }
  514. else if (IDType == (int)IdType.Temperature && !string.IsNullOrWhiteSpace(IDNumber)) //温度上报(带地址)
  515. {
  516. var tempId = propertyValue.Value.IDNumber;
  517. //var hisTemp = await _serviceHealth.GetTemperatureAsync(messageId, $"{serialno}-{tempId}").ConfigureAwait(false);
  518. //if (hisTemp == null)
  519. //{
  520. // hisTemp = new HisGpsTemperature
  521. // {
  522. // Serialno = serialno,
  523. // TemperatureId = $"{serialno}-{tempId}",
  524. // TempId = tempId,
  525. // Address = addr,
  526. // };
  527. // await _serviceHealth.AddTemperatureAsync(messageId, hisTemp).ConfigureAwait(false);
  528. //}
  529. //else
  530. //{
  531. // hisTemp.Address = addr;
  532. // await _serviceHealth.UpdateTemperatureAsync(messageId, hisTemp).ConfigureAwait(false);
  533. //}
  534. await _serviceHealth.HandleTemperatureAddressAsync(messageId, $"{serialno}-{tempId}", () => new HisGpsTemperature
  535. {
  536. TemperatureId = $"{serialno}-{tempId}",
  537. Serialno = serialno,
  538. Address = addr,
  539. Province = province,
  540. City = city,
  541. District = district,
  542. LastUpdate = Utils.ConvertToLocalDateTime(propertyValue.Time),
  543. TempId = tempId
  544. },
  545. a =>
  546. {
  547. a.Address = addr;
  548. a.Province = province;
  549. a.City = city;
  550. a.District = district;
  551. return a;
  552. });
  553. }
  554. #endregion
  555. //推送数据到设备
  556. await _serviceGlobal.PushLocationDataAsync(serialno, olat, olng);
  557. }
  558. }
  559. }