123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json;
- using System.Data;
- using System.Web;
- using WMS.BZModels.Dto.KLHC.ReportDtos;
- //using WMS.BZModels.Dto.SX.ReportDtos;
- using WMS.BZServices.KLHC;
- using WMS.Info;
- using WMS.Util;
- namespace WMS.BZWeb.Areas.KLHCManager.Controllers
- {
- /// <summary>
- /// 统计报表
- /// </summary>
- [Area("KLHCManager")]
- public class StatisticsreportController :MvcControllerBase
- {
- private readonly StatisticsreportService _statistics;
- public StatisticsreportController(StatisticsreportService statistics)
- {
- _statistics = statistics;
- }
- public IActionResult Index()
- {
- return View();
- }
- public IActionResult HourTaskIndex()
- {
- return View();
- }
- public IActionResult InOutReport()
- {
- ViewBag.beginhour = DateTime.Now.Date.ToString("yyyy-MM-dd") + " 00:00:00";
- ViewBag.endhour = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
- ViewBag.beginday = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") + " 00:00:00";
- ViewBag.endday = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
- return View();
- }
- public ActionResult GetPageList(string pagination, string queryJson)
- {
- Pagination paginationobj = InitPagination(pagination);
- var query = new StatisticsQueryDto();
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<StatisticsQueryDto>(queryJson);
- }
- var lists = _statistics.GetPageList(paginationobj, query ?? new StatisticsQueryDto());
- 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 StatisticsQueryDto();
- try
- {
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<StatisticsQueryDto>(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<ColumnModel>();
- List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
- if (columnList.Count == 0)
- {
- throw new Exception("未找到表头");
- }
- //行数据
- var lists = _statistics.GetList(query ?? new StatisticsQueryDto());
- var dataJson = JsonConvert.SerializeObject(lists);
- DataTable rowData = dataJson.ToTable();
- //写入Excel表头
- Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
- 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 GetHourTaskPageList(string pagination, string queryJson)
- {
- Pagination paginationobj = InitPagination(pagination);
- var query = new HourTaskQueryDto();
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<HourTaskQueryDto>(queryJson);
- }
- var lists = _statistics.GetHourTask(paginationobj, query ?? new HourTaskQueryDto());
- var jsonData = new
- {
- rows = lists.Result,
- total = lists.TotalPage,
- page = lists.PageIndex,
- records = lists.TotalNum
- };
- return Success(jsonData);
- }
- [HttpPost]
- public IActionResult ExportHourTaskExcel(string fileName, string queryJson, string exportField)
- {
- var query = new HourTaskQueryDto();
- try
- {
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<HourTaskQueryDto>(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<ColumnModel>();
- List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
- if (columnList.Count == 0)
- {
- throw new Exception("未找到表头");
- }
- //行数据
- Pagination paginationobj = InitPagination("");
- paginationobj.rows = 1000000;
- var lists = _statistics.GetHourTask(paginationobj, query ?? new HourTaskQueryDto());
- var dataJson = JsonConvert.SerializeObject(lists);
- DataTable rowData = dataJson.ToTable();
- //写入Excel表头
- Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
- 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 GetInOutReportList(string pagination, string queryJson)
- {
- Pagination paginationobj = InitPagination(pagination);
- var query = new InOutReportQueryDto();
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<InOutReportQueryDto>(queryJson);
- }
- var lists = _statistics.GetInOutReport(paginationobj, query ?? new InOutReportQueryDto());
- var jsonData = new
- {
- rows = lists.Result,
- total = lists.TotalPage,
- page = lists.PageIndex,
- records = lists.TotalNum
- };
- return Success(jsonData);
- }
- [HttpPost]
- public IActionResult ExportInOutReportExcel(string fileName, string queryJson, string exportField)
- {
- var query = new InOutReportQueryDto();
- try
- {
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<InOutReportQueryDto>(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<ColumnModel>();
- List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
- if (columnList.Count == 0)
- {
- throw new Exception("未找到表头");
- }
- //行数据
- Pagination paginationobj = InitPagination("");
- paginationobj.rows = 1000000;
- var lists = _statistics.GetInOutReport(paginationobj, query ?? new InOutReportQueryDto());
- var dataJson = JsonConvert.SerializeObject(lists.Result);
- DataTable rowData = dataJson.ToTable();
- //写入Excel表头
- Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
- 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);
- }
- }
- }
|