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 { /// /// /// public class AlertService : BaseService { /// /// /// /// public AlertService(IConfiguration config) : base(config, nameof(Alert)) { } /// /// 取前20 /// /// /// public async Task GetToplist(int top = 20) { Expression> 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; } /// ///新加一条数据 /// /// /// public async Task Add(Alert alert) { await base.CreateAsync(alert); return true; } /// /// 分页数据 /// /// /// public async Task GetList(RqeustPaging request) { request.pageSize = request.pageSize == 0 ? 10 : request.pageSize; Expression> 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 } }; } } }