白名单 调整
This commit is contained in:
parent
9994a375cc
commit
5c0664e830
|
|
@ -47,5 +47,14 @@
|
|||
{
|
||||
return $"position_region_{id}";
|
||||
}
|
||||
/// <summary>
|
||||
/// 白名单
|
||||
/// </summary>
|
||||
/// <param name="sn"></param>
|
||||
/// <returns></returns>
|
||||
public static string white_list(string sn)
|
||||
{
|
||||
return $"white_list{sn}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,5 +23,6 @@ namespace LY.App.Model
|
|||
/// </summary>
|
||||
public string icon { get; set; }
|
||||
public string Img { get; set; }
|
||||
public bool isMove { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ namespace LY.App.Model
|
|||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? endTime { get; set; }
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName = "position_id", ColumnDescription = "阵地id")]
|
||||
public long positionId { get; set; }
|
||||
public string positionName { get; set; }
|
||||
[SugarColumn(ColumnName = "position_id", ColumnDescription = "阵地id", IsJson = true)]
|
||||
public List<long> positionId { get; set; }
|
||||
|
||||
}
|
||||
public class AddWhitelist
|
||||
{
|
||||
|
|
@ -42,11 +42,8 @@ namespace LY.App.Model
|
|||
/// <summary>
|
||||
/// 阵地id
|
||||
/// </summary>
|
||||
public long positionId { get; set; }
|
||||
/// <summary>
|
||||
/// 阵地名称
|
||||
/// </summary>
|
||||
public string positionName { get; set; }
|
||||
public List<long> positionId { get; set; }
|
||||
|
||||
}
|
||||
public class UpdateWhitelist : AddWhitelist
|
||||
{
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ builder.Services.AddTransient<SqlSugarClient>(sp =>
|
|||
};
|
||||
//创建数据库和表的语句仅执行一次
|
||||
//db.DbMaintenance.CreateDatabase();
|
||||
db.CodeFirst.SetStringDefaultLength(2000).InitTables(typeof(Whitelist));
|
||||
//db.CodeFirst.SetStringDefaultLength(2000).InitTables(typeof(Whitelist));
|
||||
#endif
|
||||
//过滤器写在这儿就行了
|
||||
// db.QueryFilter.AddTableFilter<IDeleted>(it => it.IsDeleted == false);
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ namespace LY.App.Service
|
|||
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.alarmLevel = await GetAlarmLevel(deviceinfo.PositionId, item.drone_lon, item.drone_lat);
|
||||
item.IsWhitelist = Iswhitlist(item.serial_number);
|
||||
item.IsWhitelist = await Iswhitlist(item.serial_number, item.drone_lat, item.drone_lon);
|
||||
item.alarmLevel = item.IsWhitelist == true ? 0 : await GetAlarmLevel(deviceinfo.PositionId, item.drone_lon, item.drone_lat);
|
||||
}
|
||||
await _db.CopyNew().Insertable(entity).SplitTable().ExecuteReturnSnowflakeIdListAsync();
|
||||
//推送报警信息
|
||||
|
|
@ -89,16 +89,59 @@ namespace LY.App.Service
|
|||
return distance < maxDistance;
|
||||
}
|
||||
|
||||
private bool Iswhitlist(string serial_number)
|
||||
/// <summary>
|
||||
/// 判断是否在白名单中
|
||||
/// </summary>
|
||||
/// <param name="serial_number"></param>
|
||||
/// <param name="lat"></param>
|
||||
/// <param name="lon"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> Iswhitlist(string serial_number, double lat, double lon)
|
||||
{
|
||||
var whitelist = _config["Whitelist"].Split(',');
|
||||
if (whitelist.Any())
|
||||
string key = RedisKeyList.white_list(serial_number);
|
||||
if (!await _redisService.ExistsAsync(key))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
return whitelist.Contains(serial_number);
|
||||
var entity = await _redisService.GetAsync<Whitelist>(key);
|
||||
//判断 是否在防区内
|
||||
if (entity.positionId.Any())
|
||||
{
|
||||
foreach (var item in entity.positionId)
|
||||
{
|
||||
var region = await _redisService.GetAsync<string>(RedisKeyList.PositioinRegion(item));
|
||||
if (region != null && IsPointInGeoJson(lat, lon, region))
|
||||
{
|
||||
//判断时间是否在区在
|
||||
if (entity.allDay)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsPointInGeoJson(double latitude, double longitude, string geoJson)
|
||||
{
|
||||
// 使用 NetTopologySuite 解析 GeoJSON
|
||||
var reader = new GeoJsonReader();
|
||||
Geometry geometry = reader.Read<Geometry>(geoJson);
|
||||
// 创建点
|
||||
var point = new Point(longitude, latitude);
|
||||
|
||||
// 判断点是否在几何图形内
|
||||
return geometry.Contains(point);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 计算入侵级别
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ namespace LY.App.Service
|
|||
try
|
||||
{
|
||||
var input = JsonConvert.DeserializeObject<RevData>(data);
|
||||
Console.WriteLine($"rev data:{data}");
|
||||
// Console.WriteLine($"rev data:{data}");
|
||||
await _alarmService.AddAlarm(input);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -191,7 +191,7 @@ namespace LY.App.Service
|
|||
await _redisService.SetAsync(key, item, TimeSpan.FromDays(100));
|
||||
await AddDevice2Manager(item);
|
||||
}
|
||||
// 加载阵地信息
|
||||
// 加载防区信息
|
||||
var position = await _db.Queryable<PositionInfo>()
|
||||
.Where(s => s.IsDeleted == false).ToListAsync();
|
||||
foreach (var item in position)
|
||||
|
|
@ -199,6 +199,14 @@ namespace LY.App.Service
|
|||
var key = RedisKeyList.PositioinRegion(item.Id);
|
||||
await _redisService.SetAsync(key, item.Region);
|
||||
}
|
||||
// 加载白名单信息
|
||||
var whithlist = await _db.Queryable<Whitelist>()
|
||||
.Where(s => s.IsDeleted == false).ToListAsync();
|
||||
foreach (var item in whithlist)
|
||||
{
|
||||
var key = RedisKeyList.white_list(item.sn);
|
||||
await _redisService.SetAsync(key, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using LY.App.Extensions.DI;
|
||||
using LY.App.Common.Redis;
|
||||
using LY.App.Extensions.DI;
|
||||
using LY.App.Model;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
|
|
@ -13,13 +14,15 @@ namespace LY.App.Service
|
|||
public class WhitListService
|
||||
{
|
||||
private readonly SqlSugarClient _db;
|
||||
private readonly RedisService _redisService;
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="sqlSugarClient"></param>
|
||||
public WhitListService(SqlSugarClient sqlSugarClient)
|
||||
public WhitListService(SqlSugarClient sqlSugarClient, RedisService redisService)
|
||||
{
|
||||
_db = sqlSugarClient;
|
||||
_redisService=redisService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 新增白名单
|
||||
|
|
@ -30,7 +33,15 @@ namespace LY.App.Service
|
|||
{
|
||||
var result = new ApiResult();
|
||||
var entity = input.Adapt<Whitelist>();
|
||||
var id = await _db.Insertable(entity).ExecuteReturnIdentityAsync();
|
||||
var exisit = await _db.Queryable<Whitelist>().AnyAsync(x => x.sn == entity.sn);
|
||||
if (exisit)
|
||||
{
|
||||
result.code = 1;
|
||||
result.msg = $"sn:{input.sn}已经存在白名单中";
|
||||
return result;
|
||||
}
|
||||
var id = await _db.Insertable(entity).ExecuteReturnSnowflakeIdAsync();
|
||||
await _redisService.SetAsync(entity.sn, entity);
|
||||
result.data = id.ToString();
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
"Weather": "https://weather.cma.cn/api/now/54511", //天气预报地址,中国气象
|
||||
"Vertify": 5, //登录失败次数
|
||||
"BatchId": 60, //无人机批次连续时间,如果超过这个时间,则变成下一个批次
|
||||
"Whitelist": "sn123,sn234", //白名单sn,用逗号分隔
|
||||
"MaxDistance": 3000, //最大距离,如果超过这个距离,探测到的无人机数据会被丢弃 单位:米
|
||||
|
||||
"SnowFlakeWordId": 1 //雪花算法的wordId,多台服务器时,需要配置不同的wordId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue