using Autofac.Core;
|
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Mvc;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseController;
|
using WIDESEA_DTO.MES;
|
using WIDESEA_IBasicService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_WMSServer.Controllers.Mes
|
{
|
/// <summary>
|
/// MES接口日志控制器
|
/// </summary>
|
[Route("api/MesLog")]
|
[ApiController]
|
[Authorize]
|
public class MesLogController : ApiBaseController<IMesLogService, Dt_MesApiLog>
|
{
|
private readonly IMesLogService _mesLogService;
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public MesLogController(IMesLogService mesLogService) : base(mesLogService)
|
{
|
_mesLogService = mesLogService;
|
}
|
|
/// <summary>
|
/// 分页查询MES日志
|
/// </summary>
|
/// <param name="query">查询条件</param>
|
/// <param name="page">页码,默认1</param>
|
/// <param name="pageSize">每页数量,默认20</param>
|
/// <returns>分页结果</returns>
|
[HttpPost("page")]
|
public async Task<WebResponseContent> GetPage([FromBody] MesLogQueryDto query, [FromQuery] int page = 1, [FromQuery] int pageSize = 20)
|
{
|
var response = new WebResponseContent();
|
try
|
{
|
var (items, total) = await _mesLogService.GetPageAsync(query, page, pageSize);
|
return response.OK(null, new { rows = items, total = total });
|
}
|
catch (Exception ex)
|
{
|
return response.Error($"查询失败: {ex.Message}");
|
}
|
}
|
|
/// <summary>
|
/// 获取日志详情
|
/// </summary>
|
/// <param name="id">日志ID</param>
|
/// <returns>日志详情</returns>
|
[HttpGet("{id}")]
|
public async Task<WebResponseContent> GetDetail(long id)
|
{
|
var response = new WebResponseContent();
|
try
|
{
|
var detail = await _mesLogService.GetDetailAsync(id);
|
if (detail == null)
|
{
|
return response.Error("日志不存在");
|
}
|
return response.OK(null, detail);
|
}
|
catch (Exception ex)
|
{
|
return response.Error($"查询失败: {ex.Message}");
|
}
|
}
|
|
/// <summary>
|
/// 获取统计数据
|
/// </summary>
|
/// <param name="query">查询条件(可选)</param>
|
/// <returns>统计数据</returns>
|
[HttpGet("statistics")]
|
public async Task<WebResponseContent> GetStatistics([FromQuery] MesLogQueryDto query)
|
{
|
var response = new WebResponseContent();
|
try
|
{
|
var statistics = await _mesLogService.GetStatisticsAsync(query ?? new MesLogQueryDto());
|
return response.OK(null, statistics);
|
}
|
catch (Exception ex)
|
{
|
return response.Error($"查询失败: {ex.Message}");
|
}
|
}
|
|
/// <summary>
|
/// 导出日志
|
/// </summary>
|
/// <param name="query">查询条件</param>
|
/// <returns>CSV文件</returns>
|
[HttpPost("export")]
|
public async Task<IActionResult> Export([FromBody] MesLogQueryDto query)
|
{
|
try
|
{
|
var data = await _mesLogService.ExportAsync(query ?? new MesLogQueryDto());
|
var fileName = $"MES接口日志_{DateTime.Now:yyyyMMdd_HHmmss}.csv";
|
return File(data, "text/csv; charset=utf-8", fileName);
|
}
|
catch (Exception ex)
|
{
|
return BadRequest(new { error = ex.Message });
|
}
|
}
|
}
|
}
|