123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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
- {
- [Route("eap/api/[controller]/[action]")]
- [ApiController]
- [Authorize]
- public class AAParametersController : ControllerBase
- {
- private IMapper _mapper;
- IDatabase db;
- public AAParametersController(IMapper mapper)
- {
- _mapper = mapper;
- }
- [HttpGet]
- public LayuiModel<AaParametersInfo> 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 AaParametersInfoDal(db);
- return dal.Get(fcode, start.Value, end.Value, recipe, pageIndex, pageSize);
- }
- }
- [HttpPost]
- public async Task<IActionResult> ExportAAParameters(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<AaParametersInfo> dto = Get(fcode, start, end, recipe, pageIndex, pageSize).data;
- var list = _mapper.Map<IEnumerable<ExportAAParameters>>(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;
- }
- }
- }
- }
|