Compare commits
21 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
90b3bc70ec | |
|
|
e479ee3337 | |
|
|
a61dfeddb0 | |
|
|
5fb29db7e9 | |
|
|
1175c776bf | |
|
|
a474ded6a1 | |
|
|
5122193a28 | |
|
|
9653eb6f18 | |
|
|
1c9a4afcbc | |
|
|
48b4d35672 | |
|
|
25b9d20cb3 | |
|
|
7574049a3f | |
|
|
6fab2df9fb | |
|
|
b8279ad728 | |
|
|
dceaf4e424 | |
|
|
83df6abc46 | |
|
|
f94bdcc506 | |
|
|
97b9cc06dc | |
|
|
b389dcbf30 | |
|
|
965f987086 | |
|
|
45c19fcdf9 |
|
|
@ -0,0 +1,23 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,7 +25,19 @@ namespace LY.App.Controllers
|
||||||
[HttpGet("list")]
|
[HttpGet("list")]
|
||||||
public async Task<IActionResult> List([FromQuery] AlarmReq input)
|
public async Task<IActionResult> List([FromQuery] AlarmReq input)
|
||||||
{
|
{
|
||||||
var result = await _alarmService.GetPage(input);
|
var result = await _alarmService.CreateHistoryPage(input);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("list1")]
|
||||||
|
public async Task<IActionResult> List1([FromQuery] AlarmReq input)
|
||||||
|
{
|
||||||
|
var result = await _alarmService.CreateHistoryPage(input);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using LY.App.Common.Redis;
|
using LY.App.Common;
|
||||||
|
using LY.App.Common.Redis;
|
||||||
using LY.App.Device;
|
using LY.App.Device;
|
||||||
using LY.App.Model;
|
using LY.App.Model;
|
||||||
using LY.App.Service;
|
using LY.App.Service;
|
||||||
|
|
@ -48,7 +49,7 @@ namespace LY.App.Controllers
|
||||||
var positions = await _positionService.Index();
|
var positions = await _positionService.Index();
|
||||||
var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(),
|
var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(),
|
||||||
async () => await _alarmService.IndexCount(),
|
async () => await _alarmService.IndexCount(),
|
||||||
TimeSpan.FromDays(1));
|
TimeSpan.FromSeconds(DateTimeHelper.GetRemainSeconds()));
|
||||||
var weather = await _redisService.GetOrSetAsync(RedisKeyList.Index_Weather,
|
var weather = await _redisService.GetOrSetAsync(RedisKeyList.Index_Weather,
|
||||||
async () => await _weatherService.GetWeather(),
|
async () => await _weatherService.GetWeather(),
|
||||||
TimeSpan.FromHours(3));
|
TimeSpan.FromHours(3));
|
||||||
|
|
|
||||||
|
|
@ -331,7 +331,7 @@ namespace LY.App.Device
|
||||||
|
|
||||||
private async Task HandleDeviceConnection(Device device)
|
private async Task HandleDeviceConnection(Device device)
|
||||||
{
|
{
|
||||||
int retryDelay = 1000; // 初始重连间隔(1秒)
|
int retryDelay = 10000; // 初始重连间隔(1秒)
|
||||||
int maxDelay = 30000; // 最大重连间隔(30秒)
|
int maxDelay = 30000; // 最大重连间隔(30秒)
|
||||||
var _log = ServiceLocator.Instance.GetService<LogService>();
|
var _log = ServiceLocator.Instance.GetService<LogService>();
|
||||||
await _log?.AddLog(new AddLog { Message = $"设备 {device.Id} 掉线,重新连接中...", Parameters = "", StackTrace = "", url = "" });
|
await _log?.AddLog(new AddLog { Message = $"设备 {device.Id} 掉线,重新连接中...", Parameters = "", StackTrace = "", url = "" });
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ namespace LY.App.Model
|
||||||
[JsonConverter(typeof(ValueToStringConverter))]
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
public long positionId { get; set; }
|
public long positionId { get; set; }
|
||||||
public string positionName { get; set; }
|
public string positionName { get; set; }
|
||||||
|
public int alarmLevel { get; set; }
|
||||||
|
|
||||||
//public long position_id { get; set; }
|
//public long position_id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using LY.App.Device;
|
using GraphQL;
|
||||||
|
using LY.App.Device;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
|
|
@ -75,6 +76,8 @@ namespace LY.App.Model
|
||||||
[SugarColumn(ColumnName = "is_move", ColumnDescription = "是否移动设备", IsNullable = true)]
|
[SugarColumn(ColumnName = "is_move", ColumnDescription = "是否移动设备", IsNullable = true)]
|
||||||
|
|
||||||
public bool isMove { get; set; }
|
public bool isMove { get; set; }
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public bool online { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,16 @@ namespace LY.App.Model
|
||||||
public List<long> positionId { get; set; }
|
public List<long> positionId { get; set; }
|
||||||
[SugarColumn(IsIgnore = true)]
|
[SugarColumn(IsIgnore = true)]
|
||||||
public List<string> positionIds { get; set; }
|
public List<string> positionIds { get; set; }
|
||||||
/// <summary>
|
[SugarColumn(IsNullable = true)]
|
||||||
/// 所属单位
|
|
||||||
/// </summary>
|
|
||||||
public string company { get; set; }
|
public string company { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备注
|
/// 备注
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string mark { get; set; }
|
public string mark { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 创建人
|
||||||
|
/// </summary>
|
||||||
|
public string createBy { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
public class AddWhitelist
|
public class AddWhitelist
|
||||||
|
|
@ -69,6 +71,10 @@ namespace LY.App.Model
|
||||||
/// 备注
|
/// 备注
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string mark { get; set; }
|
public string mark { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 创建人
|
||||||
|
/// </summary>
|
||||||
|
public string createBy { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
public class UpdateWhitelist : AddWhitelist
|
public class UpdateWhitelist : AddWhitelist
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ using Mapster;
|
||||||
using NetTopologySuite.Geometries;
|
using NetTopologySuite.Geometries;
|
||||||
using NetTopologySuite.IO;
|
using NetTopologySuite.IO;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using StackExchange.Redis;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace LY.App.Service
|
namespace LY.App.Service
|
||||||
{
|
{
|
||||||
|
|
@ -54,8 +56,15 @@ namespace LY.App.Service
|
||||||
entity = entity.Where(s => checkDistance(s.drone_lat, s.drone_lon, deviceinfo.Lat, deviceinfo.Lon) == true).ToList();
|
entity = entity.Where(s => checkDistance(s.drone_lat, s.drone_lon, deviceinfo.Lat, deviceinfo.Lon) == true).ToList();
|
||||||
if (O4entity.Any())
|
if (O4entity.Any())
|
||||||
{
|
{
|
||||||
entity.AddRange(O4entity);
|
foreach (var item in O4entity)
|
||||||
|
{
|
||||||
|
if (!entity.Exists(s => s.serial_number == item.serial_number))
|
||||||
|
{
|
||||||
|
entity.Add(item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entity = entity.Distinct().ToList();
|
||||||
if (entity.Any())
|
if (entity.Any())
|
||||||
{
|
{
|
||||||
foreach (var item in entity)
|
foreach (var item in entity)
|
||||||
|
|
@ -134,22 +143,9 @@ namespace LY.App.Service
|
||||||
private async Task<bool> Iswhitlist(string serial_number, double lat, double lon)
|
private async Task<bool> Iswhitlist(string serial_number, double lat, double lon)
|
||||||
{
|
{
|
||||||
string key = RedisKeyList.white_list(serial_number);
|
string key = RedisKeyList.white_list(serial_number);
|
||||||
if (!await _redisService.ExistsAsync(key))
|
if (await _redisService.ExistsAsync(key))
|
||||||
return false;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
var entity = await _redisService.GetAsync<Whitelist>(key);
|
var entity = await _redisService.GetAsync<Whitelist>(key);
|
||||||
//判断 是否在防区内
|
|
||||||
if (entity.positionId.Any())
|
|
||||||
{
|
|
||||||
foreach (var item in entity.positionId)
|
|
||||||
{
|
|
||||||
var region = await _redisService.GetAsync<PositionInfo>(RedisKeyList.PositioinRegion(item));
|
|
||||||
if (region != null)
|
|
||||||
{
|
|
||||||
region.SetRegionJson();
|
|
||||||
if (IsPointInGeoJson(lat, lon, region.RegionJson))
|
|
||||||
{
|
|
||||||
//判断时间是否在区在
|
//判断时间是否在区在
|
||||||
if (entity.allDay)
|
if (entity.allDay)
|
||||||
{
|
{
|
||||||
|
|
@ -160,11 +156,6 @@ namespace LY.App.Service
|
||||||
return entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
|
return entity.startTime <= DateTime.Now && DateTime.Now <= entity.endTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -390,7 +381,70 @@ namespace LY.App.Service
|
||||||
.ToPageListAsync(input.pageNum, input.pageSize, total);
|
.ToPageListAsync(input.pageNum, input.pageSize, total);
|
||||||
return Tuple.Create(total.Value, items);
|
return Tuple.Create(total.Value, items);
|
||||||
}
|
}
|
||||||
|
public async Task<ApiResult> CreateHistoryPage(AlarmReq input)
|
||||||
|
{
|
||||||
|
var tables = _db.SplitHelper<Alarm>().GetTables();
|
||||||
|
|
||||||
|
string coutsql = @" SELECT COUNT(*)
|
||||||
|
FROM (
|
||||||
|
SELECT batch_id
|
||||||
|
FROM (
|
||||||
|
{0}
|
||||||
|
) AS unionTable
|
||||||
|
GROUP BY batch_id
|
||||||
|
) AS CountTable;";
|
||||||
|
|
||||||
|
string page = @" SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT batch_id
|
||||||
|
FROM (
|
||||||
|
{0}
|
||||||
|
) AS unionTable
|
||||||
|
GROUP BY batch_id ORDER BY batch_id desc LIMIT {1},{2}
|
||||||
|
) AS CountTable ";
|
||||||
|
|
||||||
|
string tablesql = string.Join(" UNION ALL ", tables.Select(item => $"SELECT batch_id FROM {item.TableName} GROUP BY batch_id "));
|
||||||
|
if (!string.IsNullOrEmpty(input.sn))
|
||||||
|
{
|
||||||
|
tablesql = string.Join(" UNION ALL ", tables.Select(item => $"SELECT batch_id FROM {item.TableName} where serial_number like '%{input.sn}%' GROUP BY batch_id"));
|
||||||
|
}
|
||||||
|
var pageitem = await _db.Ado.SqlQueryAsync<int, long>(string.Format(coutsql, tablesql) + string.Format(page, tablesql, (input.pageNum - 1) * input.pageSize, input.pageSize));
|
||||||
|
|
||||||
|
var temp = await _db.Queryable<Alarm>()
|
||||||
|
.Where(s => pageitem.Item2.Contains(s.BatchId)).SplitTable().Select(s => new { s.BatchId, s.freq, s.Id, s.positionId, s.PostionName, s.alarmLevel, s.device_type }).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
var query = await _db.Queryable<Alarm>()
|
||||||
|
.Where(s => pageitem.Item2.Contains(s.BatchId)).SplitTable()
|
||||||
|
.GroupBy(s => new { s.BatchId, s.serial_number })
|
||||||
|
.Select(st => new AlarmRepDto
|
||||||
|
{
|
||||||
|
batchId = st.BatchId.ToString(),
|
||||||
|
startTime = SqlFunc.AggregateMin(st.CreateTime),
|
||||||
|
endTime = SqlFunc.AggregateMax(st.CreateTime),
|
||||||
|
sn = st.serial_number,
|
||||||
|
duration = (SqlFunc.AggregateMax(st.CreateTime) - SqlFunc.AggregateMin(st.CreateTime)).TotalSeconds,
|
||||||
|
IsWhitelist = SqlFunc.AggregateMax(st.IsWhitelist),
|
||||||
|
}).OrderByDescending(s => s.batchId).ToListAsync();
|
||||||
|
|
||||||
|
query.ForEach(s =>
|
||||||
|
{
|
||||||
|
s.duration = s.duration == 0 ? 1 : s.duration;
|
||||||
|
s.Frequency = temp.Where(m => m.BatchId == long.Parse(s.batchId)).OrderByDescending(o => o.Id).FirstOrDefault().freq;
|
||||||
|
s.positionId = temp.Where(m => m.BatchId == long.Parse(s.batchId)).OrderByDescending(o => o.Id).FirstOrDefault().positionId;
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
code = 0,
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
total = pageitem.Item1.First(),
|
||||||
|
items = query
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 报表统计
|
/// 报表统计
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,10 @@ namespace LY.App.Service
|
||||||
.WhereIF(!string.IsNullOrEmpty(key), s => s.Name.Contains(key) || s.DeviceSN.Contains(key))
|
.WhereIF(!string.IsNullOrEmpty(key), s => s.Name.Contains(key) || s.DeviceSN.Contains(key))
|
||||||
.OrderByDescending(s => s.Id)
|
.OrderByDescending(s => s.Id)
|
||||||
.ToPageListAsync(pageNum, pageSize, total);
|
.ToPageListAsync(pageNum, pageSize, total);
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
item.online = await _redisService.ExistsAsync(RedisKeyList.DeviceStatus(item.DeviceSN));
|
||||||
|
}
|
||||||
return new ApiResult()
|
return new ApiResult()
|
||||||
{
|
{
|
||||||
data = new
|
data = new
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue