You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PLT-PDA/Admin.Core.Api/Controllers/Sys/SysLoginInfoController.cs

187 lines
5.7 KiB
C#

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
{
/// <summary>
/// SysLoginInfoController
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize(Permissions.Name)]
public class SysLoginInfoController : BaseApiController
{
/// <summary>
/// _sysLoginInfoService
/// </summary>
private readonly ISysLoginInfoService _sysLoginInfoService;
/// <summary>
/// 构造方法
/// </summary>
/// <param name="SysLoginInfoService"></param>
public SysLoginInfoController(ISysLoginInfoService SysLoginInfoService)
{
_sysLoginInfoService = SysLoginInfoService;
}
/// <summary>
/// 分页查询
/// </summary>
/// <param name="pageQuery"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<PageModel<SysLoginInfo>>> GetByPage([FromBody] PageQuery<SysLoginInfo> pageQuery)
{
Expression<Func<SysLoginInfo, bool>> 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);
}
/// <summary>
/// 根据ID查询
/// </summary>
/// <param name="id">主键</param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<SysLoginInfo>> GetByID(int id)
{
return new MessageModel<SysLoginInfo>()
{
msg = Resource_SysBase.OprateSuccess,
success = true,
data = await _sysLoginInfoService.QueryByIdAsync(id)
};
}
/// <summary>
/// 新增一条数据
/// </summary>
/// <param name="request">SysLoginInfo</param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<int>> Add([FromBody] SysLoginInfo request)
{
var data = new MessageModel<int>();
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;
}
/// <summary>
/// 更新一条数据
/// </summary>
/// <param name="request">SysLoginInfo</param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> Update([FromBody] SysLoginInfo request)
{
var data = new MessageModel<bool>();
data.success = await _sysLoginInfoService.UpdateAsync(request);
if (data.success)
{
data.msg = Resource_SysBase.OprateSuccess;
}
else
{
data.msg = Resource_SysBase.OprateFail;
}
return data;
}
/// <summary>
/// 删除一条数据
/// </summary>
/// <param name="ids">主键</param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> Del(List<int> ids)
{
var data = new MessageModel<bool>();
data.success = await _sysLoginInfoService.DeleteByIdAsync(ids);
if (data.success)
{
data.msg = Resource_SysBase.OprateSuccess;
}
else
{
data.msg = Resource_SysBase.OprateFail;
}
return data;
}
/// <summary>
/// 导出数据
/// </summary>
/// <param name="loginInfo"></param>
/// <returns></returns>
[HttpPost]
public MessageModel<List<SysLoginInfo>> Export(SysLoginInfo loginInfo)
{
return null;
}
/// <summary>
/// 清空日志
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> Clear()
{
return Success(await _sysLoginInfoService.Clear());
}
}
}