From 61439bf419e214b12b1ddb7012113b4834773adb Mon Sep 17 00:00:00 2001 From: yanghongwei Date: Wed, 26 Mar 2025 10:54:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/AlarmService.cs | 17 +++++++++++------ Service/DeviceService.cs | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Service/AlarmService.cs b/Service/AlarmService.cs index 659376f..095c61c 100644 --- a/Service/AlarmService.cs +++ b/Service/AlarmService.cs @@ -85,15 +85,20 @@ namespace LY.App.Service { var key = RedisKeyList.PositioinRegion(positionId); var geodata = await _redisService.GetAsync(key); + if (geodata == null) + { + geodata = await _db.CopyNew().Queryable() + .Where(s => s.Id == positionId) + .Select(s => s.Region) + .FirstAsync(); + await _redisService.SetAsync(key, geodata); + } WKTReader reader = new WKTReader(); Geometry point = reader.Read($"POINT ({lon} {lat})"); - if (!string.IsNullOrEmpty(geodata)) + Geometry multipolygon = reader.Read(geodata); + if (multipolygon.Contains(point)) { - Geometry multipolygon = reader.Read(geodata); - if (multipolygon.Contains(point)) - { - return 1; - } + return 1; } } return result; diff --git a/Service/DeviceService.cs b/Service/DeviceService.cs index 8cbae90..f0a1b8b 100644 --- a/Service/DeviceService.cs +++ b/Service/DeviceService.cs @@ -169,7 +169,7 @@ namespace LY.App.Service foreach (var item in position) { var key = RedisKeyList.PositioinRegion(item.Id); - await _redisService.SetAsync(key, item.Region, TimeSpan.FromDays(100)); + await _redisService.SetAsync(key, item.Region); } } }