InventorysController.cs 4.1 KB

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