using Admin.Core.Model; using Admin.Core.Common.Resource; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using Admin.Core.Common; using Admin.Core.IService.ISys; using Admin.Core.Model.Sys; namespace Admin.Core.Api { /// /// SysLoginInfoController /// [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class SysLoginInfoController : BaseApiController { /// /// _sysLoginInfoService /// private readonly ISysLoginInfoService _sysLoginInfoService; /// /// 构造方法 /// /// public SysLoginInfoController(ISysLoginInfoService SysLoginInfoService) { _sysLoginInfoService = SysLoginInfoService; } /// /// 分页查询 /// /// /// [HttpPost] public async Task>> GetByPage([FromBody] PageQuery pageQuery) { Expression> whereExpression = x => true; if (pageQuery.Query.IPAddr.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.IPAddr.Contains(pageQuery.Query.IPAddr)); } if (pageQuery.Query.UserName.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.UserName.Contains(pageQuery.Query.UserName) || x.Msg.Contains(pageQuery.Query.Msg)); } if (pageQuery.Query.Status.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.Status == pageQuery.Query.Status); } if (pageQuery.DateRange.IsNotEmptyOrNull() && pageQuery.DateRange.Count > 0) { if (pageQuery.DateRange[0].IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.LoginTime >= pageQuery.DateRange[0]); } if (pageQuery.DateRange.Count > 1 && pageQuery.DateRange[1].IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.LoginTime <= pageQuery.DateRange[1]); } } var orderBy = pageQuery.OrderBy + " " + (pageQuery.IsAsc ? "asc" : "desc"); var data = await _sysLoginInfoService.QueryPageAsync(whereExpression, pageQuery.Page, pageQuery.PageSize, orderBy); return Success(data); } /// /// 根据ID查询 /// /// 主键 /// [HttpGet] public async Task> GetByID(int id) { return new MessageModel() { msg = Resource_SysBase.OprateSuccess, success = true, data = await _sysLoginInfoService.QueryByIdAsync(id) }; } /// /// 新增一条数据 /// /// SysLoginInfo /// [HttpPost] public async Task> Add([FromBody] SysLoginInfo request) { var data = new MessageModel(); data.data = await _sysLoginInfoService.AddAsync(request); if (data.success) { data.success = true; data.msg = Resource_SysBase.OprateSuccess; } else { data.success = false; data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 更新一条数据 /// /// SysLoginInfo /// [HttpPost] public async Task> Update([FromBody] SysLoginInfo request) { var data = new MessageModel(); data.success = await _sysLoginInfoService.UpdateAsync(request); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 删除一条数据 /// /// 主键 /// [HttpPost] public async Task> Del(List ids) { var data = new MessageModel(); data.success = await _sysLoginInfoService.DeleteByIdAsync(ids); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 导出数据 /// /// /// [HttpPost] public MessageModel> Export(SysLoginInfo loginInfo) { return null; } /// /// 清空日志 /// /// [HttpPost] public async Task> Clear() { return Success(await _sysLoginInfoService.Clear()); } } }