StatisticsreportController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using Microsoft.AspNetCore.Mvc;
  2. using Newtonsoft.Json;
  3. using System.Data;
  4. using System.Web;
  5. using WMS.BZModels.Dto.KLHC.ReportDtos;
  6. //using WMS.BZModels.Dto.SX.ReportDtos;
  7. using WMS.BZServices.KLHC;
  8. using WMS.Info;
  9. using WMS.Util;
  10. namespace WMS.BZWeb.Areas.KLHCManager.Controllers
  11. {
  12. /// <summary>
  13. /// 统计报表
  14. /// </summary>
  15. [Area("KLHCManager")]
  16. public class StatisticsreportController :MvcControllerBase
  17. {
  18. private readonly StatisticsreportService _statistics;
  19. public StatisticsreportController(StatisticsreportService statistics)
  20. {
  21. _statistics = statistics;
  22. }
  23. public IActionResult Index()
  24. {
  25. return View();
  26. }
  27. public IActionResult HourTaskIndex()
  28. {
  29. return View();
  30. }
  31. public IActionResult InOutReport()
  32. {
  33. ViewBag.beginhour = DateTime.Now.Date.ToString("yyyy-MM-dd") + " 00:00:00";
  34. ViewBag.endhour = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  35. ViewBag.beginday = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") + " 00:00:00";
  36. ViewBag.endday = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  37. return View();
  38. }
  39. public ActionResult GetPageList(string pagination, string queryJson)
  40. {
  41. Pagination paginationobj = InitPagination(pagination);
  42. var query = new StatisticsQueryDto();
  43. if (!string.IsNullOrEmpty(queryJson))
  44. {
  45. query = JsonConvert.DeserializeObject<StatisticsQueryDto>(queryJson);
  46. }
  47. var lists = _statistics.GetPageList(paginationobj, query ?? new StatisticsQueryDto());
  48. var jsonData = new
  49. {
  50. rows = lists.Result,
  51. total = lists.TotalPage,
  52. page = lists.PageIndex,
  53. records = lists.TotalNum
  54. };
  55. return Success(jsonData);
  56. }
  57. [HttpPost]
  58. public IActionResult ExportExcel(string fileName, string queryJson, string exportField)
  59. {
  60. var query = new StatisticsQueryDto();
  61. try
  62. {
  63. if (!string.IsNullOrEmpty(queryJson))
  64. {
  65. query = JsonConvert.DeserializeObject<StatisticsQueryDto>(queryJson);
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. }
  71. //设置导出格式
  72. ExcelConfig excelconfig = new ExcelConfig();
  73. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  74. excelconfig.TitleFont = "微软雅黑";
  75. excelconfig.TitlePoint = 15;
  76. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  77. excelconfig.IsAllSizeColumn = true;
  78. excelconfig.ColumnEntity = new List<ColumnModel>();
  79. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  80. if (columnList.Count == 0)
  81. {
  82. throw new Exception("未找到表头");
  83. }
  84. //行数据
  85. var lists = _statistics.GetList(query ?? new StatisticsQueryDto());
  86. var dataJson = JsonConvert.SerializeObject(lists);
  87. DataTable rowData = dataJson.ToTable();
  88. //写入Excel表头
  89. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  90. if (!string.IsNullOrEmpty(exportField))
  91. {
  92. string[] exportFields = exportField.Split(',');
  93. foreach (var field in exportFields)
  94. {
  95. if (!exportFieldMap.ContainsKey(field))
  96. {
  97. exportFieldMap.Add(field, "1");
  98. }
  99. }
  100. }
  101. foreach (var columnModel in columnList)
  102. {
  103. excelconfig.ColumnEntity.Add(new ColumnModel()
  104. {
  105. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  106. Column = columnModel.name,
  107. ExcelColumn = columnModel.label,
  108. Alignment = columnModel.align,
  109. Width = columnModel.name.Length
  110. });
  111. }
  112. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  113. }
  114. public ActionResult GetHourTaskPageList(string pagination, string queryJson)
  115. {
  116. Pagination paginationobj = InitPagination(pagination);
  117. var query = new HourTaskQueryDto();
  118. if (!string.IsNullOrEmpty(queryJson))
  119. {
  120. query = JsonConvert.DeserializeObject<HourTaskQueryDto>(queryJson);
  121. }
  122. var lists = _statistics.GetHourTask(paginationobj, query ?? new HourTaskQueryDto());
  123. var jsonData = new
  124. {
  125. rows = lists.Result,
  126. total = lists.TotalPage,
  127. page = lists.PageIndex,
  128. records = lists.TotalNum
  129. };
  130. return Success(jsonData);
  131. }
  132. [HttpPost]
  133. public IActionResult ExportHourTaskExcel(string fileName, string queryJson, string exportField)
  134. {
  135. var query = new HourTaskQueryDto();
  136. try
  137. {
  138. if (!string.IsNullOrEmpty(queryJson))
  139. {
  140. query = JsonConvert.DeserializeObject<HourTaskQueryDto>(queryJson);
  141. }
  142. }
  143. catch (Exception ex)
  144. {
  145. }
  146. //设置导出格式
  147. ExcelConfig excelconfig = new ExcelConfig();
  148. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  149. excelconfig.TitleFont = "微软雅黑";
  150. excelconfig.TitlePoint = 15;
  151. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  152. excelconfig.IsAllSizeColumn = true;
  153. excelconfig.ColumnEntity = new List<ColumnModel>();
  154. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  155. if (columnList.Count == 0)
  156. {
  157. throw new Exception("未找到表头");
  158. }
  159. //行数据
  160. Pagination paginationobj = InitPagination("");
  161. paginationobj.rows = 1000000;
  162. var lists = _statistics.GetHourTask(paginationobj, query ?? new HourTaskQueryDto());
  163. var dataJson = JsonConvert.SerializeObject(lists);
  164. DataTable rowData = dataJson.ToTable();
  165. //写入Excel表头
  166. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  167. if (!string.IsNullOrEmpty(exportField))
  168. {
  169. string[] exportFields = exportField.Split(',');
  170. foreach (var field in exportFields)
  171. {
  172. if (!exportFieldMap.ContainsKey(field))
  173. {
  174. exportFieldMap.Add(field, "1");
  175. }
  176. }
  177. }
  178. foreach (var columnModel in columnList)
  179. {
  180. excelconfig.ColumnEntity.Add(new ColumnModel()
  181. {
  182. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  183. Column = columnModel.name,
  184. ExcelColumn = columnModel.label,
  185. Alignment = columnModel.align,
  186. Width = columnModel.name.Length
  187. });
  188. }
  189. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  190. }
  191. public ActionResult GetInOutReportList(string pagination, string queryJson)
  192. {
  193. Pagination paginationobj = InitPagination(pagination);
  194. var query = new InOutReportQueryDto();
  195. if (!string.IsNullOrEmpty(queryJson))
  196. {
  197. query = JsonConvert.DeserializeObject<InOutReportQueryDto>(queryJson);
  198. }
  199. var lists = _statistics.GetInOutReport(paginationobj, query ?? new InOutReportQueryDto());
  200. var jsonData = new
  201. {
  202. rows = lists.Result,
  203. total = lists.TotalPage,
  204. page = lists.PageIndex,
  205. records = lists.TotalNum
  206. };
  207. return Success(jsonData);
  208. }
  209. [HttpPost]
  210. public IActionResult ExportInOutReportExcel(string fileName, string queryJson, string exportField)
  211. {
  212. var query = new InOutReportQueryDto();
  213. try
  214. {
  215. if (!string.IsNullOrEmpty(queryJson))
  216. {
  217. query = JsonConvert.DeserializeObject<InOutReportQueryDto>(queryJson);
  218. }
  219. }
  220. catch (Exception ex)
  221. {
  222. }
  223. //设置导出格式
  224. ExcelConfig excelconfig = new ExcelConfig();
  225. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  226. excelconfig.TitleFont = "微软雅黑";
  227. excelconfig.TitlePoint = 15;
  228. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  229. excelconfig.IsAllSizeColumn = true;
  230. excelconfig.ColumnEntity = new List<ColumnModel>();
  231. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  232. if (columnList.Count == 0)
  233. {
  234. throw new Exception("未找到表头");
  235. }
  236. //行数据
  237. Pagination paginationobj = InitPagination("");
  238. paginationobj.rows = 1000000;
  239. var lists = _statistics.GetInOutReport(paginationobj, query ?? new InOutReportQueryDto());
  240. var dataJson = JsonConvert.SerializeObject(lists.Result);
  241. DataTable rowData = dataJson.ToTable();
  242. //写入Excel表头
  243. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  244. if (!string.IsNullOrEmpty(exportField))
  245. {
  246. string[] exportFields = exportField.Split(',');
  247. foreach (var field in exportFields)
  248. {
  249. if (!exportFieldMap.ContainsKey(field))
  250. {
  251. exportFieldMap.Add(field, "1");
  252. }
  253. }
  254. }
  255. foreach (var columnModel in columnList)
  256. {
  257. excelconfig.ColumnEntity.Add(new ColumnModel()
  258. {
  259. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  260. Column = columnModel.name,
  261. ExcelColumn = columnModel.label,
  262. Alignment = columnModel.align,
  263. Width = columnModel.name.Length
  264. });
  265. }
  266. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  267. }
  268. }
  269. }