using AutoMapper; using Cksoft.Data; using Cksoft.Data.Repository; using DllEapCommon.NPOI; using DllEapDal; using DllEapEntity; using DllEapEntity.Dtos; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DllEapBll.OFILM { [ApiController] [Route("eap/api/[controller]/[action]")] [Authorize] public class LHAParametersController:ControllerBase { private IMapper _mapper; IDatabase db; public LHAParametersController(IMapper mapper) { _mapper = mapper; } [HttpGet] public LayuiModel Get(string fcode, DateTime? start, DateTime? end, string recipe, int pageIndex = 1, int pageSize = 20) { if (!end.HasValue) { end = DateTime.Now; } if (!start.HasValue) { start = DateTime.Parse(end.Value.ToString("yyyy-MM-dd 00:00:00")); } using (IDatabase db = DbFactory.Base("eap")) { var dal = new LHAParametersDal(db); return dal.Get(fcode, start.Value, end.Value, recipe, pageIndex, pageSize); } } [HttpPost] public async Task ExportLHAParametersnew(IDictionary filterInfo) { try { string fcode = string.Empty; string recipe = string.Empty; int pageIndex = 1, pageSize = 100000; DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")); DateTime end = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (filterInfo.ContainsKey("fcode")) { fcode = filterInfo["fcode"]; } if (filterInfo.ContainsKey("recipe")) { recipe = filterInfo["recipe"]; } if (filterInfo.ContainsKey("start")) { start = Convert.ToDateTime(filterInfo["start"]); } if (filterInfo.ContainsKey("end")) { end = Convert.ToDateTime(filterInfo["end"]); } IEnumerable dto = Get(fcode, start, end, recipe, pageIndex, pageSize).data; var list = _mapper.Map>(dto).ToList(); var book = DataExportHelper.EntityToExcel(list); MemoryStream ms = new MemoryStream(); ms.Position = 0; book.Write(ms); ms.Dispose(); ms.Close(); await Task.CompletedTask; return File(ms.ToArray(), "application/octet-stream"); } catch (Exception ex) { throw; } } } }