Compare commits
	
		
			21 Commits
		
	
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								 | 
						ad16758252 | |
| 
							
							
								 | 
						21a381cb9e | |
| 
							
							
								 | 
						09785d909a | |
| 
							
							
								 | 
						23a128ef0f | |
| 
							
							
								 | 
						8c4fca828d | |
| 
							
							
								 | 
						f1ebaa68c7 | |
| 
							
							
								 | 
						e13559115a | |
| 
							
							
								 | 
						8bd8f38962 | |
| 
							
							
								 | 
						6c31a6a72d | |
| 
							
							
								 | 
						1d9da8d6e6 | |
| 
							
							
								 | 
						64853e5ffe | |
| 
							
							
								 | 
						70ebc1868d | |
| 
							
							
								 | 
						af98ca3e72 | |
| 
							
							
								 | 
						c4aff6eac0 | |
| 
							
							
								 | 
						4762ea002b | |
| 
							
							
								 | 
						c8600c6bd7 | |
| 
							
							
								 | 
						41df54cebc | |
| 
							
							
								 | 
						a32912a460 | |
| 
							
							
								 | 
						bca6baef65 | |
| 
							
							
								 | 
						b21479beed | |
| 
							
							
								 | 
						629075f38b | 
| 
						 | 
				
			
			@ -1,23 +0,0 @@
 | 
			
		|||
namespace LY.App.Common
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 日期时间帮助类
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public static class DateTimeHelper
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///         //当前剩余秒数
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public static int GetRemainSeconds()
 | 
			
		||||
        {
 | 
			
		||||
            // 当前时间
 | 
			
		||||
            DateTime now = DateTime.Now;
 | 
			
		||||
            // 当天结束时间(23:59:59.999)
 | 
			
		||||
            DateTime endOfDay = now.Date.AddDays(1).AddTicks(-1);
 | 
			
		||||
            int remainSeconds = (int)(endOfDay - DateTime.Now).TotalSeconds;
 | 
			
		||||
            return remainSeconds;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -56,5 +56,13 @@
 | 
			
		|||
        {
 | 
			
		||||
            return $"white_list{sn}";
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 所有用户位置
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public static string  UserLocation(long userId)
 | 
			
		||||
        {
 | 
			
		||||
            return $"user_locationbyid_{userId}";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@ namespace LY.App.Common.Redis
 | 
			
		|||
    public class RedisService
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IDatabase _db;
 | 
			
		||||
        private readonly IServer _redis;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 构造函数
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +39,45 @@ namespace LY.App.Common.Redis
 | 
			
		|||
            string jsonData = await _db.StringGetAsync(key);
 | 
			
		||||
            return jsonData is not null ? JsonSerializer.Deserialize<T>(jsonData) : default;
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 模糊 查询所有 Key
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="pattern"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public  Task<List<RedisKey>> GetAllKeysAsync(string pattern)
 | 
			
		||||
        {
 | 
			
		||||
            var redis = _db.Multiplexer;
 | 
			
		||||
            var keys = new List<RedisKey>();
 | 
			
		||||
            foreach (var endPoint in redis.GetEndPoints())
 | 
			
		||||
            {
 | 
			
		||||
                var server = redis.GetServer(endPoint);
 | 
			
		||||
 | 
			
		||||
                if (!server.IsConnected)
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                // 使用 SCAN 获取匹配的 key,避免 KEYS 阻塞
 | 
			
		||||
                var scanKeys = server.Keys(pattern: pattern, pageSize: 1000);
 | 
			
		||||
                keys.AddRange(scanKeys);
 | 
			
		||||
            }
 | 
			
		||||
            return Task.FromResult(keys);
 | 
			
		||||
            //var result = new Dictionary<string, string>();
 | 
			
		||||
 | 
			
		||||
            //if (keys.Count > 0)
 | 
			
		||||
            //{
 | 
			
		||||
            //    // 一次批量获取 value
 | 
			
		||||
            //    var values = await _db.StringGetAsync(keys.ToArray());
 | 
			
		||||
 | 
			
		||||
            //    for (int i = 0; i < keys.Count; i++)
 | 
			
		||||
            //    {
 | 
			
		||||
            //        if (values[i].HasValue)
 | 
			
		||||
            //        {
 | 
			
		||||
            //            result[keys[i]] = values[i];
 | 
			
		||||
            //        }
 | 
			
		||||
            //    }
 | 
			
		||||
            //}
 | 
			
		||||
 | 
			
		||||
            //return result;
 | 
			
		||||
        }
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// 删除 Key
 | 
			
		||||
            /// </summary>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,9 +28,8 @@ namespace LY.App.Controllers
 | 
			
		|||
            var result = await _alarmService.CreateHistoryPage(input);
 | 
			
		||||
            return Ok(result);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///列表
 | 
			
		||||
        ///列表快速分页
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="input"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,11 @@
 | 
			
		|||
using LY.App.Common;
 | 
			
		||||
using LY.App.Common.Redis;
 | 
			
		||||
using LY.App.Common.Redis;
 | 
			
		||||
using LY.App.Device;
 | 
			
		||||
using LY.App.Model;
 | 
			
		||||
using LY.App.Service;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using StackExchange.Redis;
 | 
			
		||||
using System.Reactive.Joins;
 | 
			
		||||
 | 
			
		||||
namespace LY.App.Controllers
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -49,17 +50,58 @@ namespace LY.App.Controllers
 | 
			
		|||
            var positions = await _positionService.Index();
 | 
			
		||||
            var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(),
 | 
			
		||||
                   async () => await _alarmService.IndexCount(),
 | 
			
		||||
                   TimeSpan.FromSeconds(DateTimeHelper.GetRemainSeconds()));
 | 
			
		||||
                   TimeSpan.FromSeconds(GetLeftTime()));
 | 
			
		||||
            var weather = await _redisService.GetOrSetAsync(RedisKeyList.Index_Weather,
 | 
			
		||||
                   async () => await _weatherService.GetWeather(),
 | 
			
		||||
            TimeSpan.FromHours(3));
 | 
			
		||||
 | 
			
		||||
            var data = await GetUserLocation();
 | 
			
		||||
            result.data = new
 | 
			
		||||
            {
 | 
			
		||||
                positions,
 | 
			
		||||
                alarmCount,
 | 
			
		||||
                weather
 | 
			
		||||
                weather,
 | 
			
		||||
                userLocation = data
 | 
			
		||||
            };
 | 
			
		||||
            return Ok(result);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private int GetLeftTime() {
 | 
			
		||||
            DateTime now = DateTime.Now;
 | 
			
		||||
 | 
			
		||||
            // 今天的结束时间 23:59:59
 | 
			
		||||
            DateTime endOfDay = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
 | 
			
		||||
            // 相差时间
 | 
			
		||||
            TimeSpan remaining = endOfDay - now;
 | 
			
		||||
            // 剩余秒数
 | 
			
		||||
           return (int)remaining.TotalSeconds;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private async Task<List<SyncLocation>> GetUserLocation()
 | 
			
		||||
        {
 | 
			
		||||
            var keys = await _redisService.GetAllKeysAsync("user_locationbyid_*");
 | 
			
		||||
            List<SyncLocation> result = new List<SyncLocation>();
 | 
			
		||||
            if (keys.Count > 0)
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var item in keys)
 | 
			
		||||
                {
 | 
			
		||||
                    result.Add(await _redisService.GetAsync<SyncLocation>(item));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 同步移动端位置信息
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="input"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        [HttpPost("syncLocation")]
 | 
			
		||||
        public async Task<IActionResult> SyncLocation(SyncLocation input)
 | 
			
		||||
        {
 | 
			
		||||
            string key = RedisKeyList.UserLocation(input.userId);
 | 
			
		||||
            await _redisService.SetAsync(key, new SyncLocation() { userId = input.userId, lat = input.lat, lon = input.lon }, TimeSpan.FromMinutes(1));
 | 
			
		||||
            return Ok(new ApiResult());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
using LY.App.Model;
 | 
			
		||||
using GraphQL;
 | 
			
		||||
using LY.App.Model;
 | 
			
		||||
using LY.App.Service;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
| 
						 | 
				
			
			@ -27,6 +28,17 @@ namespace LY.App.Controllers
 | 
			
		|||
            return Ok(positions);
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 登陆 后获取当前防区
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ids"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        [HttpPost("Details")]
 | 
			
		||||
        public async Task<IActionResult> detail(IEnumerable<long> ids)
 | 
			
		||||
        {
 | 
			
		||||
            var positions = await _positionService.Detail(ids);
 | 
			
		||||
            return Ok(positions);
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 删除 
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="id"></param>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -331,7 +331,7 @@ namespace LY.App.Device
 | 
			
		|||
 | 
			
		||||
        private async Task HandleDeviceConnection(Device device)
 | 
			
		||||
        {
 | 
			
		||||
            int retryDelay = 10000; // 初始重连间隔(1秒)
 | 
			
		||||
            int retryDelay = 1000; // 初始重连间隔(1秒)
 | 
			
		||||
            int maxDelay = 30000;  // 最大重连间隔(30秒)
 | 
			
		||||
            var _log = ServiceLocator.Instance.GetService<LogService>();
 | 
			
		||||
            await _log?.AddLog(new AddLog { Message = $"设备 {device.Id} 掉线,重新连接中...", Parameters = "", StackTrace = "", url = "" });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,6 +51,12 @@ namespace LY.App.Model
 | 
			
		|||
        [SugarColumn(ColumnName = "is_whitelist", ColumnDescription = "是否白名单")]
 | 
			
		||||
        public bool IsWhitelist { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 白名单id
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [JsonConverter(typeof(ValueToStringConverter))]
 | 
			
		||||
        [SugarColumn(IsIgnore = true)]
 | 
			
		||||
        public long WhiteListId { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// ,#东向速度
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public double speed_E { get; set; }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,6 +37,7 @@
 | 
			
		|||
        /// 每页条数
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int pageSize { get; set; } = 10;
 | 
			
		||||
        public long? positionId { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
using GraphQL;
 | 
			
		||||
using LY.App.Device;
 | 
			
		||||
using LY.App.Device;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using SqlSugar;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -76,8 +75,6 @@ namespace LY.App.Model
 | 
			
		|||
        [SugarColumn(ColumnName = "is_move", ColumnDescription = "是否移动设备", IsNullable = true)]
 | 
			
		||||
 | 
			
		||||
        public bool isMove { get; set; }
 | 
			
		||||
        [SugarColumn(IsIgnore = true)]
 | 
			
		||||
        public bool online { get; set; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
namespace LY.App.Model
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 移动端同步坐标信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class SyncLocation
 | 
			
		||||
    {
 | 
			
		||||
        public long userId { get; set; }
 | 
			
		||||
        public double lon { get; set; }
 | 
			
		||||
        public double lat { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// web 端同步坐标信息
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class Location
 | 
			
		||||
    {
 | 
			
		||||
        public double lon { get; set; }
 | 
			
		||||
        public double lat { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -41,6 +41,16 @@ namespace LY.App.Model
 | 
			
		|||
        /// 是否管理员,如果不是管理员,不可操作
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool IsAdmin { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户关键防区数组
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [SugarColumn(ColumnName = "position_id", ColumnDescription = "阵地ids", IsJson = true)]
 | 
			
		||||
        public List<string> positionId { get; set; }
 | 
			
		||||
        [SugarColumn(IsIgnore = true)]
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 用户关键防区名称数组
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public List<string> positionName { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
    public class AddUser
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +66,7 @@ namespace LY.App.Model
 | 
			
		|||
        /// 是否管理员,如果不是管理员,不可操作
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool IsAdmin { get; set; }
 | 
			
		||||
        public List<long> positionId { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
    public class UpdateUser : AddUser
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,16 +25,14 @@ namespace LY.App.Model
 | 
			
		|||
        public List<long> positionId { get; set; }
 | 
			
		||||
        [SugarColumn(IsIgnore = true)]
 | 
			
		||||
        public List<string> positionIds { get; set; }
 | 
			
		||||
        [SugarColumn(IsNullable = true)]
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 所属单位
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string company { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 备注
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string mark { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 创建人
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string createBy { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    public class AddWhitelist
 | 
			
		||||
| 
						 | 
				
			
			@ -71,10 +69,6 @@ namespace LY.App.Model
 | 
			
		|||
        /// 备注
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string mark { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 创建人
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string createBy { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    public class UpdateWhitelist : AddWhitelist
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,8 +7,7 @@ using Mapster;
 | 
			
		|||
using NetTopologySuite.Geometries;
 | 
			
		||||
using NetTopologySuite.IO;
 | 
			
		||||
using SqlSugar;
 | 
			
		||||
using StackExchange.Redis;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.ComponentModel.DataAnnotations;
 | 
			
		||||
 | 
			
		||||
namespace LY.App.Service
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +75,9 @@ 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.IsWhitelist = await Iswhitlist(item.serial_number, item.drone_lat, item.drone_lon);
 | 
			
		||||
                        var temp = await Iswhitlist(item.serial_number, item.drone_lat, item.drone_lon);
 | 
			
		||||
                        item.IsWhitelist = temp.Item1;
 | 
			
		||||
                        item.WhiteListId = temp.Item2;
 | 
			
		||||
                        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);
 | 
			
		||||
                    }
 | 
			
		||||
| 
						 | 
				
			
			@ -140,7 +141,7 @@ namespace LY.App.Service
 | 
			
		|||
        /// <param name="lat"></param>
 | 
			
		||||
        /// <param name="lon"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        private async Task<bool> Iswhitlist(string serial_number, double lat, double lon)
 | 
			
		||||
        private async Task<Tuple<bool, long>> Iswhitlist(string serial_number, double lat, double lon)
 | 
			
		||||
        {
 | 
			
		||||
            string key = RedisKeyList.white_list(serial_number);
 | 
			
		||||
            if (await _redisService.ExistsAsync(key))
 | 
			
		||||
| 
						 | 
				
			
			@ -149,14 +150,15 @@ namespace LY.App.Service
 | 
			
		|||
                //判断时间是否在区在
 | 
			
		||||
                if (entity.allDay)
 | 
			
		||||
                {
 | 
			
		||||
                    return true;
 | 
			
		||||
                    return new Tuple<bool, long>(true, entity.Id);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    return entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
 | 
			
		||||
                    var has = entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
 | 
			
		||||
                    return new Tuple<bool, long>(has, has ? entity.Id : 0);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
            return new Tuple<bool, long>(false, 0); ;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        static bool IsPointInGeoJson(double latitude, double longitude, string geoJson)
 | 
			
		||||
| 
						 | 
				
			
			@ -359,32 +361,49 @@ namespace LY.App.Service
 | 
			
		|||
        {
 | 
			
		||||
            RefAsync<int> total = 0;
 | 
			
		||||
            var items = await _db.Queryable<Alarm>().SplitTable()
 | 
			
		||||
                .WhereIF(input.Frequency.HasValue, st => st.freq == input.Frequency.Value)
 | 
			
		||||
                .WhereIF(input.positionId.HasValue, st => st.positionId == input.positionId.Value)
 | 
			
		||||
                //   .WhereIF(input.Frequency.HasValue, st => st.freq == input.Frequency.Value)
 | 
			
		||||
                .WhereIF(!string.IsNullOrEmpty(input.sn), s => s.serial_number.Contains(input.sn))
 | 
			
		||||
                .WhereIF(!string.IsNullOrEmpty(input.model), st => st.device_type == input.model)
 | 
			
		||||
                .WhereIF(input.strartDate.HasValue, st => st.CreateTime >= input.strartDate.Value)
 | 
			
		||||
                .WhereIF(input.endDate.HasValue, st => st.CreateTime <= input.endDate.Value.AddDays(1))
 | 
			
		||||
                .OrderBy(s => s.BatchId, OrderByType.Desc)
 | 
			
		||||
                .GroupBy(s => new { s.BatchId, s.serial_number, s.device_type, s.positionId, s.PostionName, s.freq })
 | 
			
		||||
                .GroupBy(s => new { s.BatchId, s.serial_number, s.device_type })
 | 
			
		||||
                .Select(st => new AlarmRepDto
 | 
			
		||||
                {
 | 
			
		||||
                    batchId = st.BatchId.ToString(),
 | 
			
		||||
                    startTime = SqlFunc.AggregateMin(st.CreateTime),
 | 
			
		||||
                    endTime = SqlFunc.AggregateMax(st.CreateTime),
 | 
			
		||||
                    sn = st.serial_number,
 | 
			
		||||
                    Frequency = st.freq,
 | 
			
		||||
                    Frequency = SqlFunc.AggregateMax(st.freq),
 | 
			
		||||
                    duration = (SqlFunc.AggregateMax(st.CreateTime) - SqlFunc.AggregateMin(st.CreateTime)).TotalSeconds,
 | 
			
		||||
                    model = st.device_type,
 | 
			
		||||
                    positionId = st.positionId,
 | 
			
		||||
                    positionName = st.PostionName
 | 
			
		||||
                    positionId = SqlFunc.AggregateMax(st.positionId),
 | 
			
		||||
                }).MergeTable()//合并查询
 | 
			
		||||
                .ToPageListAsync(input.pageNum, input.pageSize, total);
 | 
			
		||||
            var ids = items.Select(s => s.positionId).Distinct().ToList();
 | 
			
		||||
            var positionNames = await _db.Queryable<PositionInfo>()
 | 
			
		||||
               .Where(s => ids.Contains(s.Id))
 | 
			
		||||
               .Select(s => new { s.Id, s.Name })
 | 
			
		||||
               .ToListAsync();
 | 
			
		||||
            foreach (var item in items)
 | 
			
		||||
            {
 | 
			
		||||
                var positionName = positionNames.FirstOrDefault(s => s.Id == item.positionId)?.Name;
 | 
			
		||||
                if (!string.IsNullOrEmpty(positionName))
 | 
			
		||||
                {
 | 
			
		||||
                    item.positionName = positionName;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return Tuple.Create(total.Value, items);
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 快速分页
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="input"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public async Task<ApiResult> CreateHistoryPage(AlarmReq input)
 | 
			
		||||
        {
 | 
			
		||||
            var tables = _db.SplitHelper<Alarm>().GetTables();
 | 
			
		||||
 | 
			
		||||
            string coutsql = @" SELECT COUNT(*) 
 | 
			
		||||
                FROM (
 | 
			
		||||
                    SELECT batch_id 
 | 
			
		||||
| 
						 | 
				
			
			@ -423,6 +442,7 @@ namespace LY.App.Service
 | 
			
		|||
                    startTime = SqlFunc.AggregateMin(st.CreateTime),
 | 
			
		||||
                    endTime = SqlFunc.AggregateMax(st.CreateTime),
 | 
			
		||||
                    sn = st.serial_number,
 | 
			
		||||
                    Frequency = 0,
 | 
			
		||||
                    duration = (SqlFunc.AggregateMax(st.CreateTime) - SqlFunc.AggregateMin(st.CreateTime)).TotalSeconds,
 | 
			
		||||
                    IsWhitelist = SqlFunc.AggregateMax(st.IsWhitelist),
 | 
			
		||||
                }).OrderByDescending(s => s.batchId).ToListAsync();
 | 
			
		||||
| 
						 | 
				
			
			@ -435,7 +455,8 @@ namespace LY.App.Service
 | 
			
		|||
                s.positionName = temp.Where(m => m.BatchId == long.Parse(s.batchId)).OrderByDescending(o => o.Id).FirstOrDefault().PostionName;
 | 
			
		||||
                s.alarmLevel = temp.Where(m => m.BatchId == long.Parse(s.batchId)).Any(o => o.alarmLevel == 1) ? 1 : 0;
 | 
			
		||||
                s.model = temp.Where(m => m.BatchId == long.Parse(s.batchId)).OrderByDescending(o => o.Id).FirstOrDefault().device_type;
 | 
			
		||||
            }); return new ApiResult()
 | 
			
		||||
            });
 | 
			
		||||
            return new ApiResult()
 | 
			
		||||
            {
 | 
			
		||||
                code = 0,
 | 
			
		||||
                data = new
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,10 +47,6 @@ namespace LY.App.Service
 | 
			
		|||
                .WhereIF(!string.IsNullOrEmpty(key), s => s.Name.Contains(key) || s.DeviceSN.Contains(key))
 | 
			
		||||
                .OrderByDescending(s => s.Id)
 | 
			
		||||
                .ToPageListAsync(pageNum, pageSize, total);
 | 
			
		||||
            foreach (var item in items)
 | 
			
		||||
            {
 | 
			
		||||
                item.online = await _redisService.ExistsAsync(RedisKeyList.DeviceStatus(item.DeviceSN));
 | 
			
		||||
            }
 | 
			
		||||
            return new ApiResult()
 | 
			
		||||
            {
 | 
			
		||||
                data = new
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -109,11 +109,27 @@ namespace LY.App.Service
 | 
			
		|||
            var entity = await _db.Queryable<PositionInfo>().FirstAsync(a => a.Id == id && a.IsDeleted != true);
 | 
			
		||||
            if (entity != null)
 | 
			
		||||
            {
 | 
			
		||||
                entity.SetRegionJson();
 | 
			
		||||
                return new ApiResult() { data = entity };
 | 
			
		||||
            }
 | 
			
		||||
            return new ApiResult(false, "未找到要获取的对象");
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Details
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ids"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public async Task<ApiResult> Detail(IEnumerable<long> ids)
 | 
			
		||||
        {
 | 
			
		||||
            var entity = await _db.Queryable<PositionInfo>()
 | 
			
		||||
               .Where(a => ids.Contains(a.Id) && a.IsDeleted != true).ToListAsync();
 | 
			
		||||
            entity.ForEach(a =>
 | 
			
		||||
            {
 | 
			
		||||
                a.SetRegionJson();
 | 
			
		||||
            });
 | 
			
		||||
            return new ApiResult() { data = entity };
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取列表
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="input"></param>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -142,6 +142,7 @@ namespace LY.App.Service
 | 
			
		|||
            //加入redis
 | 
			
		||||
            await _redisService.SetAsync<string>(RedisKeyList.TokenUser(input.username),
 | 
			
		||||
                token, TimeSpan.FromSeconds(60 * 60 * 24 * 7));
 | 
			
		||||
            var positionIds = entity.positionId?.Select(s => s.ToString()).ToList();
 | 
			
		||||
            return new ApiResult()
 | 
			
		||||
            {
 | 
			
		||||
                code = 1,
 | 
			
		||||
| 
						 | 
				
			
			@ -150,7 +151,8 @@ namespace LY.App.Service
 | 
			
		|||
                    token,
 | 
			
		||||
                    expires = DateTime.UtcNow.AddSeconds(60 * 60 * 24 * 7),
 | 
			
		||||
                    isAdmin = entity.IsAdmin,
 | 
			
		||||
                    userid = entity.Id.ToString()
 | 
			
		||||
                    userid = entity.Id.ToString(),
 | 
			
		||||
                    positionIds
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -206,6 +208,13 @@ namespace LY.App.Service
 | 
			
		|||
                .WhereIF(!string.IsNullOrEmpty(key), s => s.Name.Contains(key))
 | 
			
		||||
                .OrderBy(s => s.Id)
 | 
			
		||||
                .ToPageListAsync(pageNum, pageSize, total);
 | 
			
		||||
            query.ForEach(s =>
 | 
			
		||||
            {
 | 
			
		||||
                if (s.positionId is not null && s.positionId.Any())
 | 
			
		||||
                {
 | 
			
		||||
                    s.positionName = _db.Queryable<PositionInfo>().Where(p => s.positionId.Contains(p.Id.ToString())).Select(p => p.Name).ToList();
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
            return new
 | 
			
		||||
            {
 | 
			
		||||
                total = total.Value,
 | 
			
		||||
| 
						 | 
				
			
			@ -242,7 +251,8 @@ namespace LY.App.Service
 | 
			
		|||
                var entity = input.Adapt<UserEntity>();
 | 
			
		||||
                await _db.Updateable(entity).UpdateColumns(it => new
 | 
			
		||||
                {
 | 
			
		||||
                    it.IsAdmin
 | 
			
		||||
                    it.IsAdmin,
 | 
			
		||||
                    it.positionId
 | 
			
		||||
                }).ExecuteCommandAsync();
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@
 | 
			
		|||
  "log2db": true, //是否记录
 | 
			
		||||
  "AllowedHosts": "*",
 | 
			
		||||
  "ConnectionStrings": {
 | 
			
		||||
    "DefaultConnection": "server=114.66.57.139;port=13306;database=lyapp;user=root;password=dklymysql;Pooling=true;"
 | 
			
		||||
    "DefaultConnection": "server=110.42.35.89;port=13306;database=lyapp;user=root;password=dklymysql;Pooling=true;"
 | 
			
		||||
  },
 | 
			
		||||
  "Token": {
 | 
			
		||||
    "SecretKey": "HWLSNPM+OhlFe4wwEV/teSWsxGjrWbxKnHonxW5Z+mFlQq3zonv5",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue