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 { /// /// SysOperLogController /// [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class SysOperLogController : BaseApiController { /// /// _sysOperLogService /// private readonly ISysOperLogService _sysOperLogService; /// /// 构造方法 /// /// public SysOperLogController(ISysOperLogService SysOperLogService) { _sysOperLogService = SysOperLogService; } /// /// 分页查询 /// /// /// [HttpPost] public async Task>> GetByPage([FromBody] PageQuery pageQuery) { Expression> 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); } /// /// 根据ID查询 /// /// 主键 /// [HttpGet] public async Task> GetByID(int id) { return new MessageModel() { msg = Resource_SysBase.OprateSuccess, success = true, data = await _sysOperLogService.QueryByIdAsync(id) }; } /// /// 新增一条数据 /// /// SysOperLog /// [HttpPost] public async Task> Add([FromBody] SysOperLog request) { var data = new MessageModel(); 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; } /// /// 更新一条数据 /// /// SysOperLog /// [HttpPost] public async Task> Update([FromBody] SysOperLog request) { var data = new MessageModel(); data.success = await _sysOperLogService.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 _sysOperLogService.DeleteByIdAsync(ids); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 导出数据 /// /// /// [HttpPost] public MessageModel> Export(SysOperLog operLog) { return null; } /// /// 清空日志 /// /// [HttpPost] public async Task> Clear() { return Success(await _sysOperLogService.Clear()); } } }