分页调整

This commit is contained in:
yanghongwei 2025-07-21 17:36:04 +08:00
parent 8bd8f38962
commit e13559115a
2 changed files with 67 additions and 0 deletions

View File

@ -28,6 +28,17 @@ namespace LY.App.Controllers
var result = await _alarmService.GetPage(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);
}
/// <summary>
/// 新增告警

View File

@ -389,7 +389,63 @@ namespace LY.App.Service
}
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
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} "));
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}%' "));
}
var pageitem = await _db.Ado.SqlQueryAsync<int, long>(string.Format(coutsql, tablesql) + string.Format(page, tablesql, (input.pageNum - 1) * input.pageSize, input.pageSize));
var query = await _db.Queryable<Alarm>()
.Where(s => pageitem.Item2.Contains(s.BatchId)).SplitTable()
.GroupBy(s => new { s.BatchId, s.serial_number, s.device_type, s.positionId, s.PostionName, s.freq })
.Select(st => new AlarmRepDto
{
batchId = st.BatchId.ToString(),
startTime = SqlFunc.AggregateMin(st.CreateTime),
endTime = SqlFunc.AggregateMax(st.CreateTime),
sn = st.serial_number,
Frequency = SqlFunc.AggregateMax(st.freq),
duration = (SqlFunc.AggregateMax(st.CreateTime) - SqlFunc.AggregateMin(st.CreateTime)).TotalSeconds,
model = st.device_type,
IsWhitelist = SqlFunc.AggregateMax(st.IsWhitelist)
}).OrderByDescending(s => s.batchId).ToListAsync();
return new ApiResult()
{
code = 0,
data = new
{
total = pageitem.Item1.First(),
items = query
}
};
}
/// <summary>
/// 报表统计