BillInvflowHistoryController.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using Microsoft.AspNetCore.Mvc;
  2. using Newtonsoft.Json;
  3. using ServiceStack;
  4. using System.Data;
  5. using System.Net;
  6. using System.Web;
  7. using WMS.BZModels;
  8. using WMS.BZModels.Dto.SX.BillInvDtos;
  9. using WMS.BZModels.Dto.SX.BillInvflowHistoryDtos;
  10. using WMS.BZServices.SX;
  11. using WMS.Core;
  12. using WMS.Info;
  13. using WMS.Util;
  14. namespace WMS.BZWeb.Areas.SXManager.Controllers
  15. {
  16. [Area("SXManager")]
  17. public class BillInvflowHistoryController : MvcControllerBase
  18. {
  19. private readonly BillInvflowHistoryService billInvflowHistoryService;
  20. public BillInvflowHistoryController(BillInvflowHistoryService billInvflowHistoryService)
  21. {
  22. this.billInvflowHistoryService = billInvflowHistoryService;
  23. }
  24. #region 视图功能
  25. public IActionResult Index()
  26. {
  27. return View();
  28. }
  29. #endregion
  30. public ActionResult GetPageList(string pagination, string queryJson)
  31. {
  32. Pagination paginationobj = InitPagination(pagination);
  33. var query = new BillInvflowHistoryQueryDto();
  34. if (!string.IsNullOrEmpty(queryJson))
  35. {
  36. query = JsonConvert.DeserializeObject<BillInvflowHistoryQueryDto>(queryJson);
  37. }
  38. var lists = billInvflowHistoryService.GetPageList(paginationobj, query ?? new BillInvflowHistoryQueryDto());
  39. var jsonData = new
  40. {
  41. rows = lists.Result,
  42. total = lists.TotalPage,
  43. page = lists.PageIndex,
  44. records = lists.TotalNum
  45. };
  46. return Success(jsonData);
  47. }
  48. [HttpPost]
  49. public IActionResult ExportExcel(string fileName, string queryJson, string exportField)
  50. {
  51. var query = new BillInvflowHistoryQueryDto();
  52. try
  53. {
  54. if (!string.IsNullOrEmpty(queryJson))
  55. {
  56. query = JsonConvert.DeserializeObject<BillInvflowHistoryQueryDto>(queryJson);
  57. }
  58. }
  59. catch (Exception ex)
  60. {
  61. }
  62. //设置导出格式
  63. ExcelConfig excelconfig = new ExcelConfig();
  64. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  65. excelconfig.TitleFont = "微软雅黑";
  66. excelconfig.TitlePoint = 15;
  67. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  68. excelconfig.IsAllSizeColumn = true;
  69. excelconfig.ColumnEntity = new List<ColumnModel>();
  70. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  71. if (columnList.Count == 0)
  72. {
  73. throw new Exception("未找到表头");
  74. }
  75. //行数据
  76. var lists = billInvflowHistoryService.GetList(query ?? new BillInvflowHistoryQueryDto());
  77. var dataJson = JsonConvert.SerializeObject(lists);
  78. DataTable rowData = dataJson.ToTable();
  79. //写入Excel表头
  80. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  81. if (!string.IsNullOrEmpty(exportField))
  82. {
  83. string[] exportFields = exportField.Split(',');
  84. foreach (var field in exportFields)
  85. {
  86. if (!exportFieldMap.ContainsKey(field))
  87. {
  88. exportFieldMap.Add(field, "1");
  89. }
  90. }
  91. }
  92. foreach (var columnModel in columnList)
  93. {
  94. excelconfig.ColumnEntity.Add(new ColumnModel()
  95. {
  96. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  97. Column = columnModel.name,
  98. ExcelColumn = columnModel.label,
  99. Alignment = columnModel.align,
  100. Width = columnModel.name.Length
  101. });
  102. }
  103. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  104. }
  105. }
  106. }