using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System.Data; using System.Web; using WMS.BZModels.Dto.PT.TaskDtos; using WMS.BZServices.PT; using WMS.Core; using WMS.Info; using WMS.Util; namespace WMS.BZWeb.Areas.PTManager.Controllers { [Area("PTManager")] public class TasksController : MvcControllerBase { private readonly WCSTaskOldService _wCSTaskOldService; private readonly TaskInfoService _taskInfoService; private readonly TaskDtlService _taskDtlService; public TasksController(WCSTaskOldService wCSTaskOldService, TaskInfoService taskInfoService, TaskDtlService taskDtlService) { _wCSTaskOldService = wCSTaskOldService; _taskInfoService = taskInfoService; _taskDtlService = taskDtlService; } #region 视图功能 public IActionResult Index() { ViewBag.PTWCSWebAPIUrl = ConfigHelper.GetConfig().PTWCSWebAPIUrl; ViewBag.PTWMSWebAPIUrl = ConfigHelper.GetConfig().PTWMSWebAPIUrl; return View(); } public IActionResult Form() { ViewBag.PTWCSWebAPIUrl = ConfigHelper.GetConfig().PTWCSWebAPIUrl; return View(); } public IActionResult CurrentTaskIndex() { ViewBag.PTWCSWebAPIUrl = ConfigHelper.GetConfig().PTWCSWebAPIUrl; ViewBag.PTWMSWebAPIUrl = ConfigHelper.GetConfig().PTWMSWebAPIUrl; return View(); } #endregion public ActionResult GetPageList(string pagination, string queryJson) { Pagination paginationobj = InitPagination(pagination); var query = new WCSTaskoldQueryDto(); if (!string.IsNullOrEmpty(queryJson)) { query = JsonConvert.DeserializeObject(queryJson); } var lists = _wCSTaskOldService.GetPageList(paginationobj, query ?? new WCSTaskoldQueryDto()); var jsonData = new { rows = lists.Result, total = lists.TotalPage, page = lists.PageIndex, records = lists.TotalNum }; return Success(jsonData); } public ActionResult GetCurrentTaskPageList(string pagination, string queryJson) { Pagination paginationobj = InitPagination(pagination); var query = new WCSTaskinfoQueryDto(); if (!string.IsNullOrEmpty(queryJson)) { query = JsonConvert.DeserializeObject(queryJson); } var lists = _taskInfoService.GetPageList(paginationobj, query ?? new WCSTaskinfoQueryDto()); var jsonData = new { rows = lists.Result, total = lists.TotalPage, page = lists.PageIndex, records = lists.TotalNum }; return Success(jsonData); } [HttpPost] public IActionResult ExportExcel(string fileName, string queryJson, string exportField) { var query = new WCSTaskoldQueryDto(); try { if (!string.IsNullOrEmpty(queryJson)) { query = JsonConvert.DeserializeObject(queryJson); } } catch (Exception ex) { } //设置导出格式 ExcelConfig excelconfig = new ExcelConfig(); excelconfig.Title = HttpUtility.UrlDecode(fileName); excelconfig.TitleFont = "微软雅黑"; excelconfig.TitlePoint = 15; excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls"; excelconfig.IsAllSizeColumn = true; excelconfig.ColumnEntity = new List(); List columnList = exportField.ToList(); if (columnList.Count == 0) { throw new Exception("未找到表头"); } //行数据 var lists = _wCSTaskOldService.GetList(query ?? new WCSTaskoldQueryDto()); var dataJson = JsonConvert.SerializeObject(lists); DataTable rowData = dataJson.ToTable(); //写入Excel表头 Dictionary exportFieldMap = new Dictionary(); if (!string.IsNullOrEmpty(exportField)) { string[] exportFields = exportField.Split(','); foreach (var field in exportFields) { if (!exportFieldMap.ContainsKey(field)) { exportFieldMap.Add(field, "1"); } } } foreach (var columnModel in columnList) { excelconfig.ColumnEntity.Add(new ColumnModel() { // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname, Column = columnModel.name, ExcelColumn = columnModel.label, Alignment = columnModel.align, Width = columnModel.name.Length }); } return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName); } public ActionResult GetTaskItem(string taskid, string adddate) { if (string.IsNullOrEmpty(taskid)) { return Fail("任务号不能为空"); } if (!DateTime.TryParse(adddate, out DateTime date)) { return Fail("任务时间错误"); } var list = _taskDtlService.GetDtlById(Convert.ToInt32(taskid), date); return Success(list); } } }