InventorysController.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.CP.BillInvDtos;
  9. using WMS.BZServices.CP;
  10. using WMS.Core;
  11. using WMS.Info;
  12. using WMS.Util;
  13. namespace WMS.BZWeb.Areas.CPManager.Controllers
  14. {
  15. [Area("CPManager")]
  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.CPWMSWebAPIUrl = ConfigHelper.GetConfig().CPWMSWebAPIUrl;
  31. return View();
  32. }
  33. public IActionResult Form()
  34. {
  35. ViewBag.CPWMSWebAPIUrl = ConfigHelper.GetConfig().CPWMSWebAPIUrl;
  36. return View();
  37. }
  38. public IActionResult FailForm()
  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 UpdatePassStates(string ids)
  120. {
  121. if (string.IsNullOrEmpty(ids))
  122. {
  123. return Fail("没有选择所需放行的物料!");
  124. }
  125. var lists = JsonConvert.DeserializeObject<List<string>>(ids);
  126. var userid = WebUtil.GetItem("userId");
  127. baseInvService.UpdatePassStates(lists, userid?.ToString());
  128. return Success("保存成功!");
  129. }
  130. [HttpPost]
  131. public ActionResult SaveFailForm(string keyValue, string isFail)
  132. {
  133. if(string.IsNullOrEmpty(keyValue) || string.IsNullOrEmpty(isFail) || !int.TryParse(isFail,out var intfail))
  134. {
  135. return Fail("参数错误!");
  136. }
  137. LoginUserInfo LoginUser = GetLoginUser();
  138. bool result = isFail == "1";
  139. baseInvService.UpdateFailForm(keyValue, result, LoginUser.UserName);
  140. return Success("保存成功。");
  141. }
  142. }
  143. }