diff --git a/Device/DeviceManager.cs b/Device/DeviceManager.cs
index b13307a..06773b6 100644
--- a/Device/DeviceManager.cs
+++ b/Device/DeviceManager.cs
@@ -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
{
diff --git a/Model/Alarm.cs b/Model/Alarm.cs
index 6a002ce..64d9b0e 100644
--- a/Model/Alarm.cs
+++ b/Model/Alarm.cs
@@ -43,6 +43,8 @@ namespace LY.App.Model
///
[SugarColumn(IsIgnore = true)]
public double distance { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public double centerdistance { get; set; }
///
/// 是否白名单
///
diff --git a/Model/PositionInfo.cs b/Model/PositionInfo.cs
index e1848d2..ff862c9 100644
--- a/Model/PositionInfo.cs
+++ b/Model/PositionInfo.cs
@@ -40,6 +40,10 @@ namespace LY.App.Model
///
[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; }
}
///
/// 添加
@@ -78,6 +82,8 @@ namespace LY.App.Model
/// 备注
///
public string Remarks { get; set; }
+ public double lat { get; set; }
+ public double lon { get; set; }
}
///
diff --git a/Model/Whitelist.cs b/Model/Whitelist.cs
index 19c1777..963656d 100644
--- a/Model/Whitelist.cs
+++ b/Model/Whitelist.cs
@@ -6,6 +6,10 @@ namespace LY.App.Model
[SugarTable("ly_white_list")]
public class Whitelist : BaseEntity
{
+ ///
+ /// 设备型号
+ ///
+ public string model { get; set; }
///
/// 设备序列号
///
@@ -19,6 +23,14 @@ namespace LY.App.Model
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "position_id", ColumnDescription = "阵地id", IsJson = true)]
public List positionId { get; set; }
+ ///
+ /// 所属单位
+ ///
+ public string company { get; set; }
+ ///
+ /// 备注
+ ///
+ public string mark { get; set; }
}
public class AddWhitelist
@@ -43,6 +55,14 @@ namespace LY.App.Model
/// 阵地id
///
public List positionId { get; set; }
+ ///
+ /// 所属单位
+ ///
+ public string company { get; set; }
+ ///
+ /// 备注
+ ///
+ public string mark { get; set; }
}
public class UpdateWhitelist : AddWhitelist
diff --git a/Program.cs b/Program.cs
index 02a0a06..87d5896 100644
--- a/Program.cs
+++ b/Program.cs
@@ -81,11 +81,12 @@ builder.Services.AddTransient(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(it => it.IsDeleted == false);
diff --git a/Service/AlarmService.cs b/Service/AlarmService.cs
index 98c9a17..ebb66f3 100644
--- a/Service/AlarmService.cs
+++ b/Service/AlarmService.cs
@@ -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();
}
+
+ ///
+ /// 防区中心距离
+ ///
+ ///
+ ///
+ ///
+ ///
+ private async Task GetCenterDistance(double lat, double lon, long positioonId)
+ {
+ try
+ {
+ var key = RedisKeyList.PositioinRegion(positioonId);
+ var pontion = await _redisService.GetAsync(key);
+ if (pontion == null)
+ {
+ pontion = await _db.CopyNew().Queryable()
+ .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;
+ }
///
/// 判断 距离是否在范围内
///
@@ -109,17 +139,21 @@ namespace LY.App.Service
{
foreach (var item in entity.positionId)
{
- var region = await _redisService.GetAsync(RedisKeyList.PositioinRegion(item));
- if (region != null && IsPointInGeoJson(lat, lon, region))
+ var region = await _redisService.GetAsync(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);
}
+
///
/// 报表统计
///
diff --git a/Service/DeviceService.cs b/Service/DeviceService.cs
index c2cef66..9ed09f8 100644
--- a/Service/DeviceService.cs
+++ b/Service/DeviceService.cs
@@ -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()
diff --git a/appsettings.json b/appsettings.json
index c573826..4b49c56 100644
--- a/appsettings.json
+++ b/appsettings.json
@@ -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",