TasksController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using Microsoft.AspNetCore.Mvc;
  2. using Newtonsoft.Json;
  3. using System.Data;
  4. using System.Web;
  5. using WMS.BZModels.Dto.FJ.BillInvDtos;
  6. using WMS.BZModels.Dto.FJ.TaskDtos;
  7. using WMS.BZServices.FJ;
  8. using WMS.Core;
  9. using WMS.Info;
  10. using WMS.Util;
  11. namespace WMS.BZWeb.Areas.FJManager.Controllers
  12. {
  13. [Area("FJManager")]
  14. public class TasksController : MvcControllerBase
  15. {
  16. private readonly WCSTaskOldService _wCSTaskOldService;
  17. private readonly TaskInfoService _taskInfoService;
  18. private readonly TaskDtlService _taskDtlService;
  19. public TasksController(WCSTaskOldService wCSTaskOldService, TaskInfoService taskInfoService, TaskDtlService taskDtlService)
  20. {
  21. _wCSTaskOldService = wCSTaskOldService;
  22. _taskInfoService = taskInfoService;
  23. _taskDtlService = taskDtlService;
  24. }
  25. #region 视图功能
  26. public IActionResult Index()
  27. {
  28. return View();
  29. }
  30. public IActionResult Form()
  31. {
  32. ViewBag.FJWCSWebAPIUrl = ConfigHelper.GetConfig().FJWCSWebAPIUrl;
  33. return View();
  34. }
  35. public IActionResult CurrentTaskIndex()
  36. {
  37. ViewBag.FJWCSWebAPIUrl = ConfigHelper.GetConfig().FJWCSWebAPIUrl;
  38. return View();
  39. }
  40. public IActionResult StateIndex()
  41. {
  42. return View();
  43. }
  44. #endregion
  45. public ActionResult GetPageList(string pagination, string queryJson)
  46. {
  47. Pagination paginationobj = InitPagination(pagination);
  48. var query = new WCSTaskoldQueryDto();
  49. if (!string.IsNullOrEmpty(queryJson))
  50. {
  51. query = JsonConvert.DeserializeObject<WCSTaskoldQueryDto>(queryJson);
  52. }
  53. var lists = _wCSTaskOldService.GetPageList(paginationobj, query ?? new WCSTaskoldQueryDto());
  54. var jsonData = new
  55. {
  56. rows = lists.Result,
  57. total = lists.TotalPage,
  58. page = lists.PageIndex,
  59. records = lists.TotalNum
  60. };
  61. return Success(jsonData);
  62. }
  63. public ActionResult GetCurrentTaskPageList(string pagination, string queryJson)
  64. {
  65. Pagination paginationobj = InitPagination(pagination);
  66. var query = new WCSTaskinfoQueryDto();
  67. if (!string.IsNullOrEmpty(queryJson))
  68. {
  69. query = JsonConvert.DeserializeObject<WCSTaskinfoQueryDto>(queryJson);
  70. }
  71. var lists = _taskInfoService.GetPageList(paginationobj, query ?? new WCSTaskinfoQueryDto());
  72. var jsonData = new
  73. {
  74. rows = lists.Result,
  75. total = lists.TotalPage,
  76. page = lists.PageIndex,
  77. records = lists.TotalNum
  78. };
  79. return Success(jsonData);
  80. }
  81. [HttpPost]
  82. public IActionResult ExportExcel(string fileName, string queryJson, string exportField)
  83. {
  84. var query = new WCSTaskoldQueryDto();
  85. try
  86. {
  87. if (!string.IsNullOrEmpty(queryJson))
  88. {
  89. query = JsonConvert.DeserializeObject<WCSTaskoldQueryDto>(queryJson);
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. }
  95. //设置导出格式
  96. ExcelConfig excelconfig = new ExcelConfig();
  97. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  98. excelconfig.TitleFont = "微软雅黑";
  99. excelconfig.TitlePoint = 15;
  100. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  101. excelconfig.IsAllSizeColumn = true;
  102. excelconfig.ColumnEntity = new List<ColumnModel>();
  103. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  104. if (columnList.Count == 0)
  105. {
  106. throw new Exception("未找到表头");
  107. }
  108. //行数据
  109. var lists = _wCSTaskOldService.GetList(query ?? new WCSTaskoldQueryDto());
  110. var dataJson = JsonConvert.SerializeObject(lists);
  111. DataTable rowData = dataJson.ToTable();
  112. //写入Excel表头
  113. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  114. if (!string.IsNullOrEmpty(exportField))
  115. {
  116. string[] exportFields = exportField.Split(',');
  117. foreach (var field in exportFields)
  118. {
  119. if (!exportFieldMap.ContainsKey(field))
  120. {
  121. exportFieldMap.Add(field, "1");
  122. }
  123. }
  124. }
  125. foreach (var columnModel in columnList)
  126. {
  127. excelconfig.ColumnEntity.Add(new ColumnModel()
  128. {
  129. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  130. Column = columnModel.name,
  131. ExcelColumn = columnModel.label,
  132. Alignment = columnModel.align,
  133. Width = columnModel.name.Length
  134. });
  135. }
  136. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  137. }
  138. public ActionResult GetTaskItem(string taskid, string adddate)
  139. {
  140. if (string.IsNullOrEmpty(taskid))
  141. {
  142. return Fail("任务号不能为空");
  143. }
  144. if (!DateTime.TryParse(adddate, out DateTime date))
  145. {
  146. return Fail("任务时间错误");
  147. }
  148. var list = _taskDtlService.GetDtlById(Convert.ToInt32(taskid), date);
  149. return Success(list);
  150. }
  151. [HttpPost]
  152. public ActionResult UpdateTaskState(string ids, int state)
  153. {
  154. if (string.IsNullOrEmpty(ids))
  155. {
  156. return Fail("没有选择任务!");
  157. }
  158. var lists = JsonConvert.DeserializeObject<List<string>>(ids);
  159. var userid = WebUtil.GetItem("userId");
  160. _taskInfoService.UpdateTaskState(lists, userid?.ToString(), state);
  161. return Success("修改成功!");
  162. }
  163. [HttpPost]
  164. public ActionResult ReRgvTask(TasksModel model)
  165. {
  166. if (!model.TaskIds.Any())
  167. {
  168. return Fail("没有选择数据!");
  169. }
  170. var userid = WebUtil.GetItem("userId");
  171. var excepts = _taskInfoService.ReRgvTask(model.TaskIds, userid?.ToString(), model.ManualRemarks);
  172. return Success("修改成功!", excepts ?? new List<int>());
  173. }
  174. }
  175. public class TasksModel
  176. {
  177. public List<int> TaskIds { get; set; }
  178. public string User { get; set; }
  179. public string ManualRemarks { get; set; }
  180. }
  181. }