StatisticsreportController.cs 18 KB

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