白名单 阵地,功能调整

This commit is contained in:
yanghongwei 2025-04-13 13:55:26 +08:00
parent 5c0664e830
commit 6514d4824c
8 changed files with 88 additions and 29 deletions

View File

@ -1,22 +1,17 @@
using System;
using System.Collections.Concurrent;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using GraphQL.Client.Http;
using GraphQL.Transport;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using GraphQL.Client.Abstractions;
using LY.App.Common.HttpUtil;
using LY.App.Common.Redis;
using LY.App.Device.Command;
using LY.App.Model;
using LY.App.Service;
using MQTTnet;
using MQTTnet.Client;
using System.Net.Http.Headers;
using LY.App.Common.Redis;
using LY.App.Model;
using Newtonsoft.Json;
using StackExchange.Redis;
using LY.App.Common.HttpUtil;
using LY.App.Device.Command;
using LY.App.Service;
using System.Collections.Concurrent;
using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Text;
namespace LY.App.Device
{

View File

@ -43,6 +43,8 @@ namespace LY.App.Model
/// </summary>
[SugarColumn(IsIgnore = true)]
public double distance { get; set; }
[SugarColumn(IsIgnore = true)]
public double centerdistance { get; set; }
/// <summary>
/// 是否白名单
/// </summary>

View File

@ -40,6 +40,10 @@ namespace LY.App.Model
/// </summary>
[SugarColumn(IsNullable = true, ColumnDescription = "备注")]
public string Remarks { get; set; }
[SugarColumn(IsNullable = true, ColumnDescription = "中心点")]
public double lat { get; set; }
[SugarColumn(IsNullable = true, ColumnDescription = "中心点")]
public double lon { get; set; }
}
/// <summary>
/// 添加
@ -78,6 +82,8 @@ namespace LY.App.Model
/// 备注
/// </summary>
public string Remarks { get; set; }
public double lat { get; set; }
public double lon { get; set; }
}
/// <summary>

View File

@ -6,6 +6,10 @@ namespace LY.App.Model
[SugarTable("ly_white_list")]
public class Whitelist : BaseEntity
{
/// <summary>
/// 设备型号
/// </summary>
public string model { get; set; }
/// <summary>
/// 设备序列号
/// </summary>
@ -19,6 +23,14 @@ namespace LY.App.Model
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "position_id", ColumnDescription = "阵地id", IsJson = true)]
public List<long> positionId { get; set; }
/// <summary>
/// 所属单位
/// </summary>
public string company { get; set; }
/// <summary>
/// 备注
/// </summary>
public string mark { get; set; }
}
public class AddWhitelist
@ -43,6 +55,14 @@ namespace LY.App.Model
/// 阵地id
/// </summary>
public List<long> positionId { get; set; }
/// <summary>
/// 所属单位
/// </summary>
public string company { get; set; }
/// <summary>
/// 备注
/// </summary>
public string mark { get; set; }
}
public class UpdateWhitelist : AddWhitelist

View File

@ -81,11 +81,12 @@ builder.Services.AddTransient<SqlSugarClient>(sp =>
#if DEBUG
db.Aop.OnLogExecuting = (sql, pars) =>
{
// Console.WriteLine(sql + "参数值:" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
Console.WriteLine(sql + "参数值:" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
};
//创建数据库和表的语句仅执行一次
//db.DbMaintenance.CreateDatabase();
//db.CodeFirst.SetStringDefaultLength(2000).InitTables(typeof(Whitelist));
db.CodeFirst.SetStringDefaultLength(2000).InitTables(typeof(PositionInfo));
db.CodeFirst.SetStringDefaultLength(2000).InitTables(typeof(Whitelist));
#endif
//过滤器写在这儿就行了
// db.QueryFilter.AddTableFilter<IDeleted>(it => it.IsDeleted == false);

View File

@ -66,14 +66,44 @@ namespace LY.App.Service
item.distance = GisHelper.HaversineDistance(item.drone_lat, item.drone_lon, item.app_lat, item.app_lon);
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);
item.centerdistance = await GetCenterDistance(item.drone_lat, item.drone_lon, item.positionId);
}
await _db.CopyNew().Insertable(entity).SplitTable().ExecuteReturnSnowflakeIdListAsync();
//推送报警信息
await _pushService.SendMessageToAll(new { msgType = "event", data = entity });
}
return new ApiResult();
}
/// <summary>
/// 防区中心距离
/// </summary>
/// <param name="lat"></param>
/// <param name="lon"></param>
/// <param name="positioonId"></param>
/// <returns></returns>
private async Task<double> GetCenterDistance(double lat, double lon, long positioonId)
{
try
{
var key = RedisKeyList.PositioinRegion(positioonId);
var pontion = await _redisService.GetAsync<PositionInfo>(key);
if (pontion == null)
{
pontion = await _db.CopyNew().Queryable<PositionInfo>()
.Where(s => s.Id == positioonId)
.FirstAsync();
await _redisService.SetAsync(key, pontion);
}
var distance = GisHelper.HaversineDistance(lat, lon, pontion.lat, pontion.lat);
return distance;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return 0;
}
/// <summary>
/// 判断 距离是否在范围内
/// </summary>
@ -109,17 +139,21 @@ namespace LY.App.Service
{
foreach (var item in entity.positionId)
{
var region = await _redisService.GetAsync<string>(RedisKeyList.PositioinRegion(item));
if (region != null && IsPointInGeoJson(lat, lon, region))
var region = await _redisService.GetAsync<PositionInfo>(RedisKeyList.PositioinRegion(item));
if (region != null)
{
//判断时间是否在区在
if (entity.allDay)
region.SetRegionJson();
if (IsPointInGeoJson(lat, lon, region.RegionJson))
{
return true;
}
else
{
return entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
//判断时间是否在区在
if (entity.allDay)
{
return true;
}
else
{
return entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
}
}
}
@ -353,6 +387,7 @@ namespace LY.App.Service
return Tuple.Create(total.Value, items);
}
/// <summary>
/// 报表统计
/// </summary>

View File

@ -197,7 +197,7 @@ namespace LY.App.Service
foreach (var item in position)
{
var key = RedisKeyList.PositioinRegion(item.Id);
await _redisService.SetAsync(key, item.Region);
await _redisService.SetAsync(key, item);
}
// 加载白名单信息
var whithlist = await _db.Queryable<Whitelist>()

View File

@ -8,7 +8,7 @@
"log2db": true, //
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "server=101.43.201.20;port=3307;database=lyapp;user=root;password=Aa123;Pooling=true;"
"DefaultConnection": "server=114.66.57.139;port=13306;database=lyapp;user=root;password=dklymysql;Pooling=true;"
},
"Token": {
"SecretKey": "HWLSNPM+OhlFe4wwEV/teSWsxGjrWbxKnHonxW5Z+mFlQq3zonv5",