InventorysController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using Microsoft.AspNetCore.Mvc;
  2. using Newtonsoft.Json;
  3. using System.Data;
  4. using System.Web;
  5. using WMS.BZModels.Dto.PT.BillInvDtos;
  6. using WMS.BZServices.PT;
  7. using WMS.Info;
  8. using WMS.Util;
  9. namespace WMS.BZWeb.Areas.PTManager.Controllers
  10. {
  11. [Area("PTManager")]
  12. public class InventorysController : MvcControllerBase
  13. {
  14. private readonly BaseInvService baseInvService;
  15. public InventorysController(BaseInvService bll)
  16. {
  17. baseInvService = bll;
  18. }
  19. #region 视图功能
  20. public IActionResult Index()
  21. {
  22. return View();
  23. }
  24. public IActionResult InvManualOut()
  25. {
  26. ViewBag.PTWMSWebAPIUrl = ConfigHelper.GetConfig().PTWMSWebAPIUrl;
  27. return View();
  28. }
  29. public IActionResult Form()
  30. {
  31. ViewBag.PTWMSWebAPIUrl = ConfigHelper.GetConfig().PTWMSWebAPIUrl;
  32. return View();
  33. }
  34. #endregion
  35. public ActionResult GetPageList(string pagination, string queryJson)
  36. {
  37. Pagination paginationobj = InitPagination(pagination);
  38. var query = new BillInvNowQueryDto();
  39. if (!string.IsNullOrEmpty(queryJson))
  40. {
  41. query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
  42. }
  43. var lists = baseInvService.GetPageList(paginationobj, query ?? new BillInvNowQueryDto());
  44. var jsonData = new
  45. {
  46. rows = lists.Result,
  47. total = lists.TotalPage,
  48. page = lists.PageIndex,
  49. records = lists.TotalNum
  50. };
  51. return Success(jsonData);
  52. }
  53. [HttpPost]
  54. public IActionResult ExportExcel(string fileName, string queryJson, string exportField)
  55. {
  56. var query = new BillInvNowQueryDto();
  57. try
  58. {
  59. if (!string.IsNullOrEmpty(queryJson))
  60. {
  61. query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
  62. }
  63. }
  64. catch (Exception ex)
  65. {
  66. }
  67. //设置导出格式
  68. ExcelConfig excelconfig = new ExcelConfig();
  69. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  70. excelconfig.TitleFont = "微软雅黑";
  71. excelconfig.TitlePoint = 15;
  72. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  73. excelconfig.IsAllSizeColumn = true;
  74. excelconfig.ColumnEntity = new List<ColumnModel>();
  75. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  76. if (columnList.Count == 0)
  77. {
  78. throw new Exception("未找到表头");
  79. }
  80. //行数据
  81. var lists = baseInvService.GetList(query ?? new BillInvNowQueryDto());
  82. var dataJson = JsonConvert.SerializeObject(lists);
  83. DataTable rowData = dataJson.ToTable();
  84. //写入Excel表头
  85. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  86. if (!string.IsNullOrEmpty(exportField))
  87. {
  88. string[] exportFields = exportField.Split(',');
  89. foreach (var field in exportFields)
  90. {
  91. if (!exportFieldMap.ContainsKey(field))
  92. {
  93. exportFieldMap.Add(field, "1");
  94. }
  95. }
  96. }
  97. foreach (var columnModel in columnList)
  98. {
  99. excelconfig.ColumnEntity.Add(new ColumnModel()
  100. {
  101. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  102. Column = columnModel.name,
  103. ExcelColumn = columnModel.label,
  104. Alignment = columnModel.align,
  105. Width = columnModel.name.Length
  106. });
  107. }
  108. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  109. }
  110. /// <summary>
  111. /// 解锁
  112. /// </summary>
  113. /// <param name="ids"></param>
  114. /// <returns></returns>
  115. [HttpPost]
  116. public ActionResult UnLock(string ids)
  117. {
  118. if (string.IsNullOrEmpty(ids))
  119. {
  120. return Fail("没有选择数据!");
  121. }
  122. var lists = JsonConvert.DeserializeObject<List<string>>(ids);
  123. var userid = WebUtil.GetItem("userId");
  124. baseInvService.UpdateInvLockState(lists, BZModels.InvLockState.InvState_Normal, userid?.ToString());
  125. return Success("保存成功!");
  126. }
  127. /// <summary>
  128. /// 锁定
  129. /// </summary>
  130. /// <param name="ids"></param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. public ActionResult Lock(string ids)
  134. {
  135. if (string.IsNullOrEmpty(ids))
  136. {
  137. return Fail("没有选择数据!");
  138. }
  139. var lists = JsonConvert.DeserializeObject<List<string>>(ids);
  140. var userid = WebUtil.GetItem("userId");
  141. baseInvService.UpdateInvLockState(lists, BZModels.InvLockState.InvState_Lock, userid?.ToString());
  142. return Success("保存成功!");
  143. }
  144. }
  145. }