using Cksoft.Data; using Cksoft.Data.Repository; using DllEapDal; using DllEapEntity.Dtos; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; namespace DllEapBll.Controllers { /// /// 机台Log /// [Authorize] [ApiController] [Route("/eap/api/[controller]/[action]")] public class MachineLogController : ControllerBase { /// /// 获取机台日志列表 /// /// /// /// /// /// /// public async Task> Get(string macCode, DateTime? startTime, DateTime? endTime, int pageIndex = 1, int pageSize = 10) { if (string.IsNullOrEmpty(macCode)) return LayuiModel.CreateEmptyList("机台号是必须的"); if (startTime == null || endTime == null) return LayuiModel.CreateEmptyList("开始时间和结束时间是必须的"); using (IDatabase db = DbFactory.Base("eapslave")) { db.BeginTrans(); var dal = new MachineLogDal(db); var total = 0; string errorinfo = string.Empty; var roles = dal.GetRemotePaged(macCode, startTime, endTime, ref errorinfo, out total, pageIndex, pageSize); return await Task.FromResult(roles); } } /// /// 导出机台日志 /// /// /// public async Task Export([FromBody] dynamic formQuery) { var startTime = Convert.ToDateTime(formQuery.startTime); var endTime = Convert.ToDateTime(formQuery.endTime); var macCode = Convert.ToString(formQuery.macCode); if (string.IsNullOrEmpty(macCode)) throw new ArgumentException("机台号是必须的"); if (startTime == null || endTime == null) throw new ArgumentException("开始时间和结束时间是必须的"); string errorinfo = string.Empty; using (IDatabase db = DbFactory.Base("eapslave")) { var dal = new MachineLogDal(db); byte[] bytes = dal.ExportTxt(macCode, startTime, endTime, ref errorinfo); await Task.CompletedTask; if (bytes == null || bytes.Length <= 0) throw new ArgumentException(errorinfo); return File(bytes, "text/xml"); } } } }