InventorysController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.KLHC.BillInvDtos;
  9. using WMS.BZServices.KLHC;
  10. using WMS.Core;
  11. using WMS.Info;
  12. using WMS.Util;
  13. namespace WMS.BZWeb.Areas.KLHCManager.Controllers
  14. {
  15. [Area("KLHCManager")]
  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.FJWMSWebAPIUrl = ConfigHelper.GetConfig().FJWMSWebAPIUrl;
  31. return View();
  32. }
  33. public IActionResult Form()
  34. {
  35. ViewBag.FJWMSWebAPIUrl = ConfigHelper.GetConfig().FJWMSWebAPIUrl;
  36. return View();
  37. }
  38. public IActionResult SetGrpForm()
  39. {
  40. return View();
  41. }
  42. #endregion 视图功能
  43. public ActionResult GetPageList(string pagination, string queryJson)
  44. {
  45. Pagination paginationobj = InitPagination(pagination);
  46. var query = new BillInvNowQueryDto();
  47. if (!string.IsNullOrEmpty(queryJson))
  48. {
  49. query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
  50. }
  51. var lists = baseInvService.GetPageList(paginationobj, query ?? new BillInvNowQueryDto());
  52. var jsonData = new
  53. {
  54. rows = lists.Result,
  55. total = lists.TotalPage,
  56. page = lists.PageIndex,
  57. records = lists.TotalNum
  58. };
  59. return Success(jsonData);
  60. }
  61. [HttpPost]
  62. public IActionResult ExportExcel(string fileName, string queryJson, string exportField)
  63. {
  64. var query = new BillInvNowQueryDto();
  65. try
  66. {
  67. if (!string.IsNullOrEmpty(queryJson))
  68. {
  69. query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
  70. }
  71. }
  72. catch (Exception ex)
  73. {
  74. }
  75. //设置导出格式
  76. ExcelConfig excelconfig = new ExcelConfig();
  77. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  78. excelconfig.TitleFont = "微软雅黑";
  79. excelconfig.TitlePoint = 15;
  80. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  81. excelconfig.IsAllSizeColumn = true;
  82. excelconfig.ColumnEntity = new List<ColumnModel>();
  83. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  84. if (columnList.Count == 0)
  85. {
  86. throw new Exception("未找到表头");
  87. }
  88. //行数据
  89. var lists = baseInvService.GetList(query ?? new BillInvNowQueryDto());
  90. var dataJson = JsonConvert.SerializeObject(lists);
  91. DataTable rowData = dataJson.ToTable();
  92. //写入Excel表头
  93. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  94. if (!string.IsNullOrEmpty(exportField))
  95. {
  96. string[] exportFields = exportField.Split(',');
  97. foreach (var field in exportFields)
  98. {
  99. if (!exportFieldMap.ContainsKey(field))
  100. {
  101. exportFieldMap.Add(field, "1");
  102. }
  103. }
  104. }
  105. foreach (var columnModel in columnList)
  106. {
  107. excelconfig.ColumnEntity.Add(new ColumnModel()
  108. {
  109. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  110. Column = columnModel.name,
  111. ExcelColumn = columnModel.label,
  112. Alignment = columnModel.align,
  113. Width = columnModel.name.Length
  114. });
  115. }
  116. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  117. }
  118. [HttpPost]
  119. public ActionResult ChangeSetGrp(ChangeSetGrpModel Data)
  120. {
  121. LoginUserInfo LoginUser = GetLoginUser();
  122. baseInvService.ChangeSetGrp(LoginUser, Data);
  123. return Success("保存成功。");
  124. }
  125. [HttpPost]
  126. public ActionResult UpdateStockState(string Code, string InvStateCode)
  127. {
  128. if (string.IsNullOrWhiteSpace(Code))
  129. {
  130. return Fail("条码不能为空!");
  131. }
  132. if (!int.TryParse(InvStateCode, out var status))
  133. {
  134. return Fail("状态值不对!");
  135. }
  136. var userid = WebUtil.GetItem("userId");
  137. baseInvService.UpdateStockState(Code, status, userid?.ToString());
  138. return Success("保存成功。");
  139. }
  140. [HttpPost]
  141. public ActionResult Deletes(string[] keyValue)
  142. {
  143. if (keyValue == null || keyValue.Length == 0)
  144. {
  145. return Fail("跺型Id不能为空");
  146. }
  147. var userid = WebUtil.GetItem("userId");
  148. baseInvService.Deletes(keyValue, userid?.ToString());
  149. return Success("删除成功。");
  150. }
  151. }
  152. }