AAParametersController.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using AutoMapper;
  2. using Cksoft.Data;
  3. using Cksoft.Data.Repository;
  4. using DllEapCommon.NPOI;
  5. using DllEapDal;
  6. using DllEapEntity;
  7. using DllEapEntity.Dtos;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Mvc;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. namespace DllEapBll.OFILM
  17. {
  18. [Route("eap/api/[controller]/[action]")]
  19. [ApiController]
  20. [Authorize]
  21. public class AAParametersController : ControllerBase
  22. {
  23. private IMapper _mapper;
  24. IDatabase db;
  25. public AAParametersController(IMapper mapper)
  26. {
  27. _mapper = mapper;
  28. }
  29. [HttpGet]
  30. public LayuiModel<AaParametersInfo> Get(string fcode, DateTime? start, DateTime? end, string recipe, int pageIndex = 1, int pageSize = 20)
  31. {
  32. if (!end.HasValue)
  33. {
  34. end = DateTime.Now;
  35. }
  36. if (!start.HasValue)
  37. {
  38. start = DateTime.Parse(end.Value.ToString("yyyy-MM-dd 00:00:00"));
  39. }
  40. using (IDatabase db = DbFactory.Base("eap"))
  41. {
  42. var dal = new AaParametersInfoDal(db);
  43. return dal.Get(fcode, start.Value, end.Value, recipe, pageIndex, pageSize);
  44. }
  45. }
  46. [HttpPost]
  47. public async Task<IActionResult> ExportAAParameters(IDictionary<string,string> filterInfo)
  48. {
  49. try
  50. {
  51. string fcode = string.Empty;
  52. string recipe = string.Empty;
  53. int pageIndex = 1, pageSize = 100000;
  54. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
  55. DateTime end = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  56. if (filterInfo.ContainsKey("fcode"))
  57. {
  58. fcode = filterInfo["fcode"];
  59. }
  60. if (filterInfo.ContainsKey("recipe"))
  61. {
  62. recipe = filterInfo["recipe"];
  63. }
  64. if (filterInfo.ContainsKey("start"))
  65. {
  66. start = Convert.ToDateTime( filterInfo["start"]);
  67. }
  68. if (filterInfo.ContainsKey("end"))
  69. {
  70. end = Convert.ToDateTime(filterInfo["end"]);
  71. }
  72. IEnumerable<AaParametersInfo> dto = Get(fcode, start, end, recipe, pageIndex, pageSize).data;
  73. var list = _mapper.Map<IEnumerable<ExportAAParameters>>(dto).ToList();
  74. var book = DataExportHelper.EntityToExcel(list);
  75. MemoryStream ms = new MemoryStream();
  76. ms.Position = 0;
  77. book.Write(ms);
  78. ms.Dispose();
  79. ms.Close();
  80. await Task.CompletedTask;
  81. return File(ms.ToArray(), "application/octet-stream");
  82. }
  83. catch (Exception ex)
  84. {
  85. throw;
  86. }
  87. }
  88. }
  89. }