1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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<LHAParametersnew> 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<IActionResult> ExportLHAParametersnew(IDictionary<string, string> 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<LHAParametersnew> dto = Get(fcode, start, end, recipe, pageIndex, pageSize).data;
- var list = _mapper.Map<IEnumerable<ExportLHAParametersnew>>(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;
- }
- }
- }
- }
|