TasksController.cs 6.8 KB

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