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.
191 lines
5.8 KiB
C#
191 lines
5.8 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>
|
|
/// SysOperLogController
|
|
/// </summary>
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
[Authorize(Permissions.Name)]
|
|
public class SysOperLogController : BaseApiController
|
|
{
|
|
|
|
/// <summary>
|
|
/// _sysOperLogService
|
|
/// </summary>
|
|
private readonly ISysOperLogService _sysOperLogService;
|
|
|
|
/// <summary>
|
|
/// 构造方法
|
|
/// </summary>
|
|
/// <param name="SysOperLogService"></param>
|
|
public SysOperLogController(ISysOperLogService SysOperLogService)
|
|
{
|
|
_sysOperLogService = SysOperLogService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询
|
|
/// </summary>
|
|
/// <param name="pageQuery"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<MessageModel<PageModel<SysOperLog>>> GetByPage([FromBody] PageQuery<SysOperLog> pageQuery)
|
|
{
|
|
Expression<Func<SysOperLog, bool>> whereExpression = x => true;
|
|
if (pageQuery.Query.Title.IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.Title.Contains(pageQuery.Query.Title));
|
|
}
|
|
if (pageQuery.Query.OperName.IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.OperName.Contains(pageQuery.Query.OperName));
|
|
}
|
|
if (pageQuery.Query.BusinessType.IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.BusinessType == pageQuery.Query.BusinessType);
|
|
}
|
|
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.OperTime >= pageQuery.DateRange[0]);
|
|
}
|
|
if (pageQuery.DateRange.Count > 1 && pageQuery.DateRange[1].IsNotEmptyOrNull())
|
|
{
|
|
whereExpression = whereExpression.And(x => x.OperTime <= pageQuery.DateRange[1]);
|
|
}
|
|
}
|
|
|
|
var orderBy = (pageQuery.OrderBy ?? "OperTime") + " " + (pageQuery.IsAsc ? "asc" : "desc");
|
|
var data = await _sysOperLogService.QueryPageAsync(whereExpression, pageQuery.Page, pageQuery.PageSize, orderBy);
|
|
|
|
return Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据ID查询
|
|
/// </summary>
|
|
/// <param name="id">主键</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<MessageModel<SysOperLog>> GetByID(int id)
|
|
{
|
|
return new MessageModel<SysOperLog>()
|
|
{
|
|
msg = Resource_SysBase.OprateSuccess,
|
|
success = true,
|
|
data = await _sysOperLogService.QueryByIdAsync(id)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增一条数据
|
|
/// </summary>
|
|
/// <param name="request">SysOperLog</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<MessageModel<int>> Add([FromBody] SysOperLog request)
|
|
{
|
|
var data = new MessageModel<int>();
|
|
|
|
data.data = await _sysOperLogService.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">SysOperLog</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<MessageModel<bool>> Update([FromBody] SysOperLog request)
|
|
{
|
|
var data = new MessageModel<bool>();
|
|
data.success = await _sysOperLogService.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 _sysOperLogService.DeleteByIdAsync(ids);
|
|
|
|
if (data.success)
|
|
{
|
|
data.msg = Resource_SysBase.OprateSuccess;
|
|
}
|
|
else
|
|
{
|
|
data.msg = Resource_SysBase.OprateFail;
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出数据
|
|
/// </summary>
|
|
/// <param name="operLog"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public MessageModel<List<SysOperLog>> Export(SysOperLog operLog)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清空日志
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<MessageModel<bool>> Clear()
|
|
{
|
|
return Success(await _sysOperLogService.Clear());
|
|
}
|
|
|
|
}
|
|
} |