白名单 阵地,功能调整
This commit is contained in:
		
							parent
							
								
									5c0664e830
								
							
						
					
					
						commit
						6514d4824c
					
				| 
						 | 
					@ -1,22 +1,17 @@
 | 
				
			||||||
using System;
 | 
					using GraphQL.Client.Http;
 | 
				
			||||||
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.Serializer.Newtonsoft;
 | 
					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;
 | 
				
			||||||
using MQTTnet.Client;
 | 
					using MQTTnet.Client;
 | 
				
			||||||
using System.Net.Http.Headers;
 | 
					 | 
				
			||||||
using LY.App.Common.Redis;
 | 
					 | 
				
			||||||
using LY.App.Model;
 | 
					 | 
				
			||||||
using Newtonsoft.Json;
 | 
					using Newtonsoft.Json;
 | 
				
			||||||
using StackExchange.Redis;
 | 
					using System.Collections.Concurrent;
 | 
				
			||||||
using LY.App.Common.HttpUtil;
 | 
					using System.Net.Http.Headers;
 | 
				
			||||||
using LY.App.Device.Command;
 | 
					using System.Net.Sockets;
 | 
				
			||||||
using LY.App.Service;
 | 
					using System.Text;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace LY.App.Device
 | 
					namespace LY.App.Device
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,6 +43,8 @@ namespace LY.App.Model
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        [SugarColumn(IsIgnore = true)]
 | 
					        [SugarColumn(IsIgnore = true)]
 | 
				
			||||||
        public double distance { get; set; }
 | 
					        public double distance { get; set; }
 | 
				
			||||||
 | 
					        [SugarColumn(IsIgnore = true)]
 | 
				
			||||||
 | 
					        public double centerdistance { get; set; }
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 是否白名单
 | 
					        /// 是否白名单
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,6 +40,10 @@ namespace LY.App.Model
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        [SugarColumn(IsNullable = true, ColumnDescription = "备注")]
 | 
					        [SugarColumn(IsNullable = true, ColumnDescription = "备注")]
 | 
				
			||||||
        public string Remarks { get; set; }
 | 
					        public string Remarks { get; set; }
 | 
				
			||||||
 | 
					        [SugarColumn(IsNullable = true, ColumnDescription = "中心点")]
 | 
				
			||||||
 | 
					        public double lat { get; set; }
 | 
				
			||||||
 | 
					        [SugarColumn(IsNullable = true, ColumnDescription = "中心点")]
 | 
				
			||||||
 | 
					        public double lon { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// 添加 
 | 
					    /// 添加 
 | 
				
			||||||
| 
						 | 
					@ -78,6 +82,8 @@ namespace LY.App.Model
 | 
				
			||||||
        /// 备注
 | 
					        /// 备注
 | 
				
			||||||
        /// </summary> 
 | 
					        /// </summary> 
 | 
				
			||||||
        public string Remarks { get; set; }
 | 
					        public string Remarks { get; set; }
 | 
				
			||||||
 | 
					        public double lat { get; set; }
 | 
				
			||||||
 | 
					        public double lon { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,10 @@ namespace LY.App.Model
 | 
				
			||||||
    [SugarTable("ly_white_list")]
 | 
					    [SugarTable("ly_white_list")]
 | 
				
			||||||
    public class Whitelist : BaseEntity
 | 
					    public class Whitelist : BaseEntity
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 设备型号
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        public string model { get; set; }
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 设备序列号
 | 
					        /// 设备序列号
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
| 
						 | 
					@ -19,6 +23,14 @@ namespace LY.App.Model
 | 
				
			||||||
        [JsonConverter(typeof(ValueToStringConverter))]
 | 
					        [JsonConverter(typeof(ValueToStringConverter))]
 | 
				
			||||||
        [SugarColumn(ColumnName = "position_id", ColumnDescription = "阵地id", IsJson = true)]
 | 
					        [SugarColumn(ColumnName = "position_id", ColumnDescription = "阵地id", IsJson = true)]
 | 
				
			||||||
        public List<long> positionId { get; set; }
 | 
					        public List<long> positionId { get; set; }
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 所属单位
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        public string company { get; set; }
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 备注
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        public string mark { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    public class AddWhitelist
 | 
					    public class AddWhitelist
 | 
				
			||||||
| 
						 | 
					@ -43,6 +55,14 @@ namespace LY.App.Model
 | 
				
			||||||
        /// 阵地id
 | 
					        /// 阵地id
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public List<long> positionId { get; set; }
 | 
					        public List<long> positionId { get; set; }
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 所属单位
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        public string company { get; set; }
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 备注
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        public string mark { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    public class UpdateWhitelist : AddWhitelist
 | 
					    public class UpdateWhitelist : AddWhitelist
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,11 +81,12 @@ builder.Services.AddTransient<SqlSugarClient>(sp =>
 | 
				
			||||||
#if DEBUG
 | 
					#if DEBUG
 | 
				
			||||||
        db.Aop.OnLogExecuting = (sql, pars) =>
 | 
					        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.DbMaintenance.CreateDatabase();
 | 
				
			||||||
        //db.CodeFirst.SetStringDefaultLength(2000).InitTables(typeof(Whitelist));
 | 
					         db.CodeFirst.SetStringDefaultLength(2000).InitTables(typeof(PositionInfo)); 
 | 
				
			||||||
 | 
					         db.CodeFirst.SetStringDefaultLength(2000).InitTables(typeof(Whitelist)); 
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
        //过滤器写在这儿就行了
 | 
					        //过滤器写在这儿就行了
 | 
				
			||||||
        // db.QueryFilter.AddTableFilter<IDeleted>(it => it.IsDeleted == false);
 | 
					        // db.QueryFilter.AddTableFilter<IDeleted>(it => it.IsDeleted == false);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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.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.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.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 _db.CopyNew().Insertable(entity).SplitTable().ExecuteReturnSnowflakeIdListAsync();
 | 
				
			||||||
                //推送报警信息
 | 
					                //推送报警信息
 | 
				
			||||||
                await _pushService.SendMessageToAll(new { msgType = "event", data = entity });
 | 
					                await _pushService.SendMessageToAll(new { msgType = "event", data = entity });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
            return new ApiResult();
 | 
					            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>
 | 
				
			||||||
        /// 判断 距离是否在范围内
 | 
					        /// 判断 距离是否在范围内
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
| 
						 | 
					@ -109,8 +139,11 @@ namespace LY.App.Service
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    foreach (var item in entity.positionId)
 | 
					                    foreach (var item in entity.positionId)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        var region = await _redisService.GetAsync<string>(RedisKeyList.PositioinRegion(item));
 | 
					                        var region = await _redisService.GetAsync<PositionInfo>(RedisKeyList.PositioinRegion(item));
 | 
				
			||||||
                        if (region != null && IsPointInGeoJson(lat, lon, region))
 | 
					                        if (region != null)
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            region.SetRegionJson();
 | 
				
			||||||
 | 
					                            if (IsPointInGeoJson(lat, lon, region.RegionJson))
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                //判断时间是否在区在
 | 
					                                //判断时间是否在区在
 | 
				
			||||||
                                if (entity.allDay)
 | 
					                                if (entity.allDay)
 | 
				
			||||||
| 
						 | 
					@ -122,6 +155,7 @@ namespace LY.App.Service
 | 
				
			||||||
                                    return entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
 | 
					                                    return entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					@ -353,6 +387,7 @@ namespace LY.App.Service
 | 
				
			||||||
            return Tuple.Create(total.Value, items);
 | 
					            return Tuple.Create(total.Value, items);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 报表统计
 | 
					        /// 报表统计
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -197,7 +197,7 @@ namespace LY.App.Service
 | 
				
			||||||
            foreach (var item in position)
 | 
					            foreach (var item in position)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var key = RedisKeyList.PositioinRegion(item.Id);
 | 
					                var key = RedisKeyList.PositioinRegion(item.Id);
 | 
				
			||||||
                await _redisService.SetAsync(key, item.Region);
 | 
					                await _redisService.SetAsync(key, item);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // 加载白名单信息
 | 
					            // 加载白名单信息
 | 
				
			||||||
            var whithlist = await _db.Queryable<Whitelist>()
 | 
					            var whithlist = await _db.Queryable<Whitelist>()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@
 | 
				
			||||||
  "log2db": true, //是否记录
 | 
					  "log2db": true, //是否记录
 | 
				
			||||||
  "AllowedHosts": "*",
 | 
					  "AllowedHosts": "*",
 | 
				
			||||||
  "ConnectionStrings": {
 | 
					  "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": {
 | 
					  "Token": {
 | 
				
			||||||
    "SecretKey": "HWLSNPM+OhlFe4wwEV/teSWsxGjrWbxKnHonxW5Z+mFlQq3zonv5",
 | 
					    "SecretKey": "HWLSNPM+OhlFe4wwEV/teSWsxGjrWbxKnHonxW5Z+mFlQq3zonv5",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue