using JSMachine.WMS.App.Dto; using JSMachine.WMS.Application.Dto; using JSMachine.WMS.Application.IService; using JSMachine.WMS.Domain.Entity; using JSMachine.WMS.Infrastructure.Helper; using JSMachine.WMS.RPC.ErpRPC.Dto.Out; using JSMachine.WMS.WebHost.Models; using Microsoft.AspNetCore.Mvc; using SqlSugar; namespace JSMachine.WMS.WebHost.Controllers { [Route("api/[controller]/[action]")] public class OperationLogController : ControllerBase { private readonly IOperationLogService _operationLogService; public OperationLogController(IOperationLogService operationLogService) { _operationLogService = operationLogService; } /// /// 获取所有操作日志 /// /// 操作日志列表 [HttpGet] public async Task>> GetAll() { var logs = await _operationLogService.GetListByExpression( p => true, nameof(OperationLogDto.CreationTime), OrderByType.Desc); return new ApiResult> { ResultCode = "200", Data = logs }; } /// /// 根据ID获取操作日志 /// /// 操作日志ID /// 单个操作日志 [HttpPost] public async Task> GetById(Guid id) { var log = await _operationLogService.GetSingalByExpression(p => p.Id == id); return new ApiResult { ResultCode = "200", Data = log }; } /// /// 创建操作日志 /// /// 操作日志DTO /// 是否创建成功 [HttpPost] public async Task> Create(OperationLogDto logDto) { if (logDto == null) return new ApiResult { ResultCode = "400", Data = false, ErrorMsg = "参数不能为空" }; bool success = await _operationLogService.Add(logDto); return new ApiResult { ResultCode = success ? "200" : "500", Data = success, ErrorMsg = success ? "创建成功" : "创建失败" }; } /// /// 更新操作日志 /// /// 操作日志DTO /// 是否更新成功 [HttpPost] public async Task> Update(OperationLogDto logDto) { if (logDto == null || logDto.Id == Guid.Empty) return new ApiResult { ResultCode = "400", Data = false, ErrorMsg = "参数无效" }; bool success = await _operationLogService.EditSingal(logDto); return new ApiResult { ResultCode = success ? "200" : "500", Data = success, ErrorMsg = success ? "更新成功" : "更新失败" }; } /// /// 删除操作日志 /// /// 操作日志ID /// 是否删除成功 [HttpPost] public async Task> Delete(Guid id) { bool success = await _operationLogService.DeleteById(id); return new ApiResult { ResultCode = success ? "200" : "500", Data = success, ErrorMsg = success ? "删除成功" : "删除失败" }; } /// /// 分页查询操作日志 /// /// 分页查询条件 /// 分页结果 [HttpPost] public async Task>> QueryByPage([FromBody]OperationLogQueryParam pageQuery) { var condition = pageQuery.BuildConditional(); var result = await _operationLogService.QueryByPage(condition); return new ApiResult> { ResultCode = "200", Data = result }; } } }