LHAParametersController.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. [ApiController]
  19. [Route("eap/api/[controller]/[action]")]
  20. [Authorize]
  21. public class LHAParametersController:ControllerBase
  22. {
  23. private IMapper _mapper;
  24. IDatabase db;
  25. public LHAParametersController(IMapper mapper)
  26. {
  27. _mapper = mapper;
  28. }
  29. [HttpGet]
  30. public LayuiModel<LHAParametersnew> 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 LHAParametersDal(db);
  43. return dal.Get(fcode, start.Value, end.Value, recipe, pageIndex, pageSize);
  44. }
  45. }
  46. [HttpPost]
  47. public async Task<IActionResult> ExportLHAParametersnew(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<LHAParametersnew> dto = Get(fcode, start, end, recipe, pageIndex, pageSize).data;
  73. var list = _mapper.Map<IEnumerable<ExportLHAParametersnew>>(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. }