80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using LangGuan.Command.Model;
|
|
using LangGuan.Command.Model.EntityModel;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LangGuan.Services
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class AlertService : BaseService<Alert>
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="config"></param>
|
|
public AlertService(IConfiguration config) : base(config, nameof(Alert))
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// 取前20
|
|
/// </summary>
|
|
/// <param name="top"></param>
|
|
/// <returns></returns>
|
|
public async Task<object> GetToplist(int top = 20)
|
|
{
|
|
Expression<Func<Alert, bool>> exp = num => true;
|
|
var query = await base.GetListWithExp(exp);
|
|
var reslut = query.OrderByDescending(s => s.CreateDateTime).Take(top)
|
|
.Select(s => new { s.Id, s.NickName, s.content, }).ToList();
|
|
if (reslut.Count > 0)
|
|
{
|
|
return reslut;
|
|
}
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
///新加一条数据
|
|
/// </summary>
|
|
/// <param name="alert"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> Add(Alert alert)
|
|
{
|
|
await base.CreateAsync(alert);
|
|
return true;
|
|
}
|
|
/// <summary>
|
|
/// 分页数据
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public async Task<ApiResult> GetList(RqeustPaging request)
|
|
{
|
|
request.pageSize = request.pageSize == 0 ? 10 : request.pageSize;
|
|
Expression<Func<Alert, bool>> exp = num => true;
|
|
var query = await base.GetListWithExp(exp);
|
|
var total = query.Count();
|
|
var items = query.OrderByDescending(s => s.CreateDateTime)
|
|
.Skip(request.pageSize * (request.current - 1)).Take(request.pageSize)
|
|
.Select(s => new
|
|
{
|
|
s.Id,
|
|
s.deviceId,
|
|
s.NickName,
|
|
s.content,
|
|
CreateDateTime = s.CreateDateTime
|
|
}).ToList();
|
|
return new ApiResult()
|
|
{
|
|
code = 0,
|
|
data = new { total = total, items = items }
|
|
};
|
|
}
|
|
}
|
|
}
|