StatisticsreportController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. using Microsoft.AspNetCore.Mvc;
  2. using Newtonsoft.Json;
  3. using System.Data;
  4. using System.Web;
  5. using WMS.BZModels.Dto.SX.ReportDtos;
  6. using WMS.BZServices.SX;
  7. using WMS.Info;
  8. using WMS.Util;
  9. namespace WMS.BZWeb.Areas.SXManager.Controllers
  10. {
  11. /// <summary>
  12. /// 统计报表
  13. /// </summary>
  14. [Area("SXManager")]
  15. public class StatisticsreportController : MvcControllerBase
  16. {
  17. private readonly StatisticsreportService _statistics;
  18. public StatisticsreportController(StatisticsreportService statistics)
  19. {
  20. _statistics = statistics;
  21. }
  22. public IActionResult Index()
  23. {
  24. return View();
  25. }
  26. public IActionResult HourTaskIndex()
  27. {
  28. return View();
  29. }
  30. public IActionResult CurStockInfoIndex()
  31. {
  32. return View();
  33. }
  34. public IActionResult CurStockInfoControlIndex()
  35. {
  36. return View();
  37. }
  38. public IActionResult BGradeStatisticsIndex()
  39. {
  40. return View();
  41. }
  42. public IActionResult PalletizingReport()
  43. {
  44. ViewBag.beginhour = DateTime.Now.Date.ToString("yyyy-MM-dd") + " 00:00:00";
  45. ViewBag.endhour = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  46. ViewBag.beginday = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") + " 00:00:00";
  47. ViewBag.endday = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  48. return View();
  49. }
  50. public IActionResult InOutReport()
  51. {
  52. ViewBag.beginhour = DateTime.Now.Date.ToString("yyyy-MM-dd") + " 00:00:00";
  53. ViewBag.endhour = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  54. ViewBag.beginday = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") + " 00:00:00";
  55. ViewBag.endday = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  56. return View();
  57. }
  58. public ActionResult GetPageList(string pagination, string queryJson)
  59. {
  60. Pagination paginationobj = InitPagination(pagination);
  61. var query = new StatisticsQueryDto();
  62. if (!string.IsNullOrEmpty(queryJson))
  63. {
  64. query = JsonConvert.DeserializeObject<StatisticsQueryDto>(queryJson);
  65. }
  66. var lists = _statistics.GetPageList(paginationobj, query ?? new StatisticsQueryDto());
  67. var jsonData = new
  68. {
  69. rows = lists.Result,
  70. total = lists.TotalPage,
  71. page = lists.PageIndex,
  72. records = lists.TotalNum
  73. };
  74. return Success(jsonData);
  75. }
  76. public ActionResult GetBGradeStatisticsPageList(string pagination, string queryJson)
  77. {
  78. Pagination paginationobj = InitPagination(pagination);
  79. var query = new StatisticsQueryDto();
  80. if (!string.IsNullOrEmpty(queryJson))
  81. {
  82. query = JsonConvert.DeserializeObject<StatisticsQueryDto>(queryJson);
  83. }
  84. var lists = _statistics.GetBGradeStatisticesPageList(paginationobj, query ?? new StatisticsQueryDto());
  85. var jsonData = new
  86. {
  87. rows = lists.Result,
  88. total = lists.TotalPage,
  89. page = lists.PageIndex,
  90. records = lists.TotalNum
  91. };
  92. return Success(jsonData);
  93. }
  94. [HttpPost]
  95. public IActionResult ExportExcel(string fileName, string queryJson, string exportField)
  96. {
  97. var query = new StatisticsQueryDto();
  98. try
  99. {
  100. if (!string.IsNullOrEmpty(queryJson))
  101. {
  102. query = JsonConvert.DeserializeObject<StatisticsQueryDto>(queryJson);
  103. }
  104. }
  105. catch (Exception ex)
  106. {
  107. }
  108. //设置导出格式
  109. ExcelConfig excelconfig = new ExcelConfig();
  110. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  111. excelconfig.TitleFont = "微软雅黑";
  112. excelconfig.TitlePoint = 15;
  113. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  114. excelconfig.IsAllSizeColumn = true;
  115. excelconfig.ColumnEntity = new List<ColumnModel>();
  116. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  117. if (columnList.Count == 0)
  118. {
  119. throw new Exception("未找到表头");
  120. }
  121. //行数据
  122. var lists = _statistics.GetList(query ?? new StatisticsQueryDto());
  123. var dataJson = JsonConvert.SerializeObject(lists);
  124. DataTable rowData = dataJson.ToTable();
  125. //写入Excel表头
  126. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  127. if (!string.IsNullOrEmpty(exportField))
  128. {
  129. string[] exportFields = exportField.Split(',');
  130. foreach (var field in exportFields)
  131. {
  132. if (!exportFieldMap.ContainsKey(field))
  133. {
  134. exportFieldMap.Add(field, "1");
  135. }
  136. }
  137. }
  138. foreach (var columnModel in columnList)
  139. {
  140. excelconfig.ColumnEntity.Add(new ColumnModel()
  141. {
  142. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  143. Column = columnModel.name,
  144. ExcelColumn = columnModel.label,
  145. Alignment = columnModel.align,
  146. Width = columnModel.name.Length
  147. });
  148. }
  149. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  150. }
  151. public ActionResult GetHourTaskPageList(string pagination, string queryJson)
  152. {
  153. Pagination paginationobj = InitPagination(pagination);
  154. var query = new HourTaskQueryDto();
  155. if (!string.IsNullOrEmpty(queryJson))
  156. {
  157. query = JsonConvert.DeserializeObject<HourTaskQueryDto>(queryJson);
  158. }
  159. var lists = _statistics.GetHourTask(paginationobj, query ?? new HourTaskQueryDto());
  160. var jsonData = new
  161. {
  162. rows = lists.Result,
  163. total = lists.TotalPage,
  164. page = lists.PageIndex,
  165. records = lists.TotalNum
  166. };
  167. return Success(jsonData);
  168. }
  169. [HttpPost]
  170. public IActionResult ExportHourTaskExcel(string fileName, string queryJson, string exportField)
  171. {
  172. var query = new HourTaskQueryDto();
  173. try
  174. {
  175. if (!string.IsNullOrEmpty(queryJson))
  176. {
  177. query = JsonConvert.DeserializeObject<HourTaskQueryDto>(queryJson);
  178. }
  179. }
  180. catch (Exception ex)
  181. {
  182. }
  183. //设置导出格式
  184. ExcelConfig excelconfig = new ExcelConfig();
  185. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  186. excelconfig.TitleFont = "微软雅黑";
  187. excelconfig.TitlePoint = 15;
  188. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  189. excelconfig.IsAllSizeColumn = true;
  190. excelconfig.ColumnEntity = new List<ColumnModel>();
  191. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  192. if (columnList.Count == 0)
  193. {
  194. throw new Exception("未找到表头");
  195. }
  196. //行数据
  197. Pagination paginationobj = InitPagination("");
  198. paginationobj.rows = 1000000;
  199. var lists = _statistics.GetHourTask(paginationobj, query ?? new HourTaskQueryDto());
  200. var dataJson = JsonConvert.SerializeObject(lists);
  201. DataTable rowData = dataJson.ToTable();
  202. //写入Excel表头
  203. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  204. if (!string.IsNullOrEmpty(exportField))
  205. {
  206. string[] exportFields = exportField.Split(',');
  207. foreach (var field in exportFields)
  208. {
  209. if (!exportFieldMap.ContainsKey(field))
  210. {
  211. exportFieldMap.Add(field, "1");
  212. }
  213. }
  214. }
  215. foreach (var columnModel in columnList)
  216. {
  217. excelconfig.ColumnEntity.Add(new ColumnModel()
  218. {
  219. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  220. Column = columnModel.name,
  221. ExcelColumn = columnModel.label,
  222. Alignment = columnModel.align,
  223. Width = columnModel.name.Length
  224. });
  225. }
  226. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  227. }
  228. public ActionResult GetPalletizingReportList(string pagination, string queryJson)
  229. {
  230. Pagination paginationobj = InitPagination(pagination);
  231. var query = new PalletizingReportQueryDto();
  232. if (!string.IsNullOrEmpty(queryJson))
  233. {
  234. query = JsonConvert.DeserializeObject<PalletizingReportQueryDto>(queryJson);
  235. }
  236. var lists = _statistics.GetPalletizingReport(paginationobj, query ?? new PalletizingReportQueryDto());
  237. var jsonData = new
  238. {
  239. rows = lists.Result,
  240. total = lists.TotalPage,
  241. page = lists.PageIndex,
  242. records = lists.TotalNum
  243. };
  244. return Success(jsonData);
  245. }
  246. [HttpPost]
  247. public IActionResult ExportPalletizingReportExcel(string fileName, string queryJson, string exportField)
  248. {
  249. var query = new PalletizingReportQueryDto();
  250. try
  251. {
  252. if (!string.IsNullOrEmpty(queryJson))
  253. {
  254. query = JsonConvert.DeserializeObject<PalletizingReportQueryDto>(queryJson);
  255. }
  256. }
  257. catch (Exception ex)
  258. {
  259. }
  260. //设置导出格式
  261. ExcelConfig excelconfig = new ExcelConfig();
  262. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  263. excelconfig.TitleFont = "微软雅黑";
  264. excelconfig.TitlePoint = 15;
  265. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  266. excelconfig.IsAllSizeColumn = true;
  267. excelconfig.ColumnEntity = new List<ColumnModel>();
  268. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  269. if (columnList.Count == 0)
  270. {
  271. throw new Exception("未找到表头");
  272. }
  273. //行数据
  274. Pagination paginationobj = InitPagination("");
  275. paginationobj.rows = 1000000;
  276. var lists = _statistics.GetPalletizingReport(paginationobj, query ?? new PalletizingReportQueryDto());
  277. var dataJson = JsonConvert.SerializeObject(lists);
  278. DataTable rowData = dataJson.ToTable();
  279. //写入Excel表头
  280. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  281. if (!string.IsNullOrEmpty(exportField))
  282. {
  283. string[] exportFields = exportField.Split(',');
  284. foreach (var field in exportFields)
  285. {
  286. if (!exportFieldMap.ContainsKey(field))
  287. {
  288. exportFieldMap.Add(field, "1");
  289. }
  290. }
  291. }
  292. foreach (var columnModel in columnList)
  293. {
  294. excelconfig.ColumnEntity.Add(new ColumnModel()
  295. {
  296. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  297. Column = columnModel.name,
  298. ExcelColumn = columnModel.label,
  299. Alignment = columnModel.align,
  300. Width = columnModel.name.Length
  301. });
  302. }
  303. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  304. }
  305. public ActionResult GetInOutReportList(string pagination, string queryJson)
  306. {
  307. Pagination paginationobj = InitPagination(pagination);
  308. var query = new InOutReportQueryDto();
  309. if (!string.IsNullOrEmpty(queryJson))
  310. {
  311. query = JsonConvert.DeserializeObject<InOutReportQueryDto>(queryJson);
  312. }
  313. var lists = _statistics.GetInOutReport(paginationobj, query ?? new InOutReportQueryDto());
  314. var jsonData = new
  315. {
  316. rows = lists.Result,
  317. total = lists.TotalPage,
  318. page = lists.PageIndex,
  319. records = lists.TotalNum
  320. };
  321. return Success(jsonData);
  322. }
  323. [HttpPost]
  324. public IActionResult ExportInOutReportExcel(string fileName, string queryJson, string exportField)
  325. {
  326. var query = new InOutReportQueryDto();
  327. try
  328. {
  329. if (!string.IsNullOrEmpty(queryJson))
  330. {
  331. query = JsonConvert.DeserializeObject<InOutReportQueryDto>(queryJson);
  332. }
  333. }
  334. catch (Exception ex)
  335. {
  336. }
  337. //设置导出格式
  338. ExcelConfig excelconfig = new ExcelConfig();
  339. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  340. excelconfig.TitleFont = "微软雅黑";
  341. excelconfig.TitlePoint = 15;
  342. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  343. excelconfig.IsAllSizeColumn = true;
  344. excelconfig.ColumnEntity = new List<ColumnModel>();
  345. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  346. if (columnList.Count == 0)
  347. {
  348. throw new Exception("未找到表头");
  349. }
  350. //行数据
  351. Pagination paginationobj = InitPagination("");
  352. paginationobj.rows = 1000000;
  353. var lists = _statistics.GetInOutReport(paginationobj, query ?? new InOutReportQueryDto());
  354. var dataJson = JsonConvert.SerializeObject(lists.Result);
  355. DataTable rowData = dataJson.ToTable();
  356. //写入Excel表头
  357. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  358. if (!string.IsNullOrEmpty(exportField))
  359. {
  360. string[] exportFields = exportField.Split(',');
  361. foreach (var field in exportFields)
  362. {
  363. if (!exportFieldMap.ContainsKey(field))
  364. {
  365. exportFieldMap.Add(field, "1");
  366. }
  367. }
  368. }
  369. foreach (var columnModel in columnList)
  370. {
  371. excelconfig.ColumnEntity.Add(new ColumnModel()
  372. {
  373. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  374. Column = columnModel.name,
  375. ExcelColumn = columnModel.label,
  376. Alignment = columnModel.align,
  377. Width = columnModel.name.Length
  378. });
  379. }
  380. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  381. }
  382. public ActionResult GetCurStockInfoList(string pagination, string queryJson)
  383. {
  384. Pagination paginationobj = InitPagination(pagination);
  385. var query = new CurStockInfoQueryDto();
  386. if (!string.IsNullOrEmpty(queryJson))
  387. {
  388. query = JsonConvert.DeserializeObject<CurStockInfoQueryDto>(queryJson);
  389. }
  390. var lists = _statistics.GetCurStockInfo(paginationobj, query ?? new CurStockInfoQueryDto());
  391. var jsonData = new
  392. {
  393. rows = lists.Result,
  394. total = lists.TotalPage,
  395. page = lists.PageIndex,
  396. records = lists.TotalNum
  397. };
  398. return Success(jsonData);
  399. }
  400. public ActionResult GetCurStockInfoControlList(string pagination, string queryJson)
  401. {
  402. Pagination paginationobj = InitPagination(pagination);
  403. var query = new CurStockInfoQueryDto();
  404. if (!string.IsNullOrEmpty(queryJson))
  405. {
  406. query = JsonConvert.DeserializeObject<CurStockInfoQueryDto>(queryJson);
  407. }
  408. var lists = _statistics.GetCurStockInfoControl(paginationobj, query ?? new CurStockInfoQueryDto());
  409. var jsonData = new
  410. {
  411. rows = lists.Result,
  412. total = lists.TotalPage,
  413. page = lists.PageIndex,
  414. records = lists.TotalNum
  415. };
  416. return Success(jsonData);
  417. }
  418. }
  419. }