redis 阵地区域
This commit is contained in:
parent
86e73f4ef6
commit
6d9acac89d
|
|
@ -39,5 +39,9 @@
|
|||
{
|
||||
return $"device_token_{id}";
|
||||
}
|
||||
public static string PositioinRegion(long id)
|
||||
{
|
||||
return $"position_region_{id}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,4 +150,15 @@ namespace LY.App.Model
|
|||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 阵地下所有区域
|
||||
/// </summary>
|
||||
public class GeoRegion
|
||||
{
|
||||
/// <summary>
|
||||
/// 识别区
|
||||
/// </summary>
|
||||
public string Region { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@ using LY.App.Extensions.DI;
|
|||
using LY.App.Model;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using NetTopologySuite.Geometries;
|
||||
using NetTopologySuite.IO;
|
||||
using SqlSugar;
|
||||
using StackExchange.Redis;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
|
||||
namespace LY.App.Service
|
||||
{
|
||||
|
|
@ -57,7 +61,8 @@ namespace LY.App.Service
|
|||
item.positionId = deviceinfo.PositionId;
|
||||
item.PostionName = deviceinfo.PositionName;
|
||||
item.Time = input.time;
|
||||
item.distance = GisHelper.HaversineDistance(item.drone_lat, item.drone_lon, item.app_lat,item.app_lon);
|
||||
item.distance = GisHelper.HaversineDistance(item.drone_lat, item.drone_lon, item.app_lat, item.app_lon);
|
||||
item.alarmLevel = await GetAlarmLevel(deviceinfo.PositionId, item.drone_lon, item.drone_lat);
|
||||
}
|
||||
await _db.CopyNew().Insertable(entity).SplitTable().ExecuteReturnSnowflakeIdListAsync();
|
||||
//推送报警信息
|
||||
|
|
@ -65,6 +70,34 @@ namespace LY.App.Service
|
|||
}
|
||||
return new ApiResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算入侵级别
|
||||
/// </summary>
|
||||
/// <param name="positionId"></param>
|
||||
/// <param name="lon"></param>
|
||||
/// <param name="lat"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<int> GetAlarmLevel(long positionId, double lon, double lat)
|
||||
{
|
||||
int result = 0;
|
||||
if (positionId > 0 && lon > 0 && lat > 0)
|
||||
{
|
||||
var key = RedisKeyList.PositioinRegion(positionId);
|
||||
var geodata = await _redisService.GetAsync<string>(key);
|
||||
WKTReader reader = new WKTReader();
|
||||
Geometry point = reader.Read($"POINT ({lon} {lat})");
|
||||
if (!string.IsNullOrEmpty(geodata))
|
||||
{
|
||||
Geometry multipolygon = reader.Read(geodata);
|
||||
if (multipolygon.Contains(point))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 推送消息
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -160,32 +160,17 @@ namespace LY.App.Service
|
|||
foreach (var item in devices)
|
||||
{
|
||||
var key = RedisKeyList.DeviceInfo(item.DeviceSN);
|
||||
await _redisService.SetAsync(key, item, TimeSpan.FromDays(10));
|
||||
await _redisService.SetAsync(key, item, TimeSpan.FromDays(100));
|
||||
await AddDevice2Manager(item);
|
||||
}
|
||||
//deviceManager.AddDevice(new Device.Device()
|
||||
//{
|
||||
// Id = 1111,
|
||||
// Port = 1883,
|
||||
// GraphQlEndpoint = "http://localhost:5000/graphql",
|
||||
// Topic = "F010/uav_dynamic_data/beijing",
|
||||
// IpAddress = "110.42.53.32",
|
||||
// Protocol = ProtocolType.MQTT,
|
||||
// username = "yangzi",
|
||||
// password = "64B7qvztS38l",
|
||||
// DataReceived = async (data) =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var input = JsonConvert.DeserializeObject<RevData>(data);
|
||||
// await _alarmService.AddAlarm(input);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine($"error:{ex.Message},data:{data}");
|
||||
// }
|
||||
// }
|
||||
//});
|
||||
// 加载阵地信息
|
||||
var position = await _db.Queryable<PositionInfo>()
|
||||
.Where(s=>s.IsDeleted==false).ToListAsync();
|
||||
foreach (var item in position)
|
||||
{
|
||||
var key = RedisKeyList.PositioinRegion(item.Id);
|
||||
await _redisService.SetAsync(key, item.Region, TimeSpan.FromDays(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue