分页细节调整
This commit is contained in:
parent
45c19fcdf9
commit
965f987086
|
|
@ -29,6 +29,18 @@ namespace LY.App.Controllers
|
|||
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>
|
||||
/// 新增告警
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ using Mapster;
|
|||
using NetTopologySuite.Geometries;
|
||||
using NetTopologySuite.IO;
|
||||
using SqlSugar;
|
||||
using StackExchange.Redis;
|
||||
using System.Text;
|
||||
|
||||
namespace LY.App.Service
|
||||
{
|
||||
|
|
@ -372,7 +374,64 @@ namespace LY.App.Service
|
|||
.ToPageListAsync(input.pageNum, input.pageSize, total);
|
||||
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} "));
|
||||
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 total = _db.Ado.GetInt(string.Format(coutsql, tablesql));
|
||||
//var ids = _db.Ado.SqlQuery<long>(string.Format(page, tablesql, (input.pageNum - 1) * input.pageSize, input.pageSize));
|
||||
|
||||
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>
|
||||
/// 报表统计
|
||||
|
|
|
|||
Loading…
Reference in New Issue