ReportController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. using Microsoft.AspNetCore.Mvc;
  2. using Newtonsoft.Json;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Web;
  6. using WMS.BZModels.Dto.FJ.BaseMatinfoDtos;
  7. using WMS.BZModels.Dto.FJ.BillInvDtos;
  8. using WMS.BZModels.Dto.FJ.ReportDtos;
  9. using WMS.BZModels.Dto.FJ.SysConDtos;
  10. using WMS.BZServices.FJ;
  11. using WMS.Info;
  12. using WMS.Util;
  13. namespace WMS.BZWeb.Areas.FJManager.Controllers
  14. {
  15. [Area("FJManager")]
  16. public class ReportController : MvcControllerBase
  17. {
  18. private readonly ReportService _report;
  19. private readonly SysConService _syscon;
  20. public ReportController(ReportService report, SysConService syscon)
  21. {
  22. _report = report;
  23. _syscon = syscon;
  24. }
  25. #region 页面
  26. public IActionResult Index()
  27. {
  28. return View();
  29. }
  30. public IActionResult cellreportIndex()
  31. {
  32. return View();
  33. }
  34. public IActionResult StockKeepReportIndex()
  35. {
  36. return View();
  37. }
  38. public IActionResult MantuoBarCodeRateIndex()
  39. {
  40. return View();
  41. }
  42. public IActionResult MatNameNetWeightReport()
  43. {
  44. return View();
  45. }
  46. #endregion
  47. public ActionResult GetPageList(string pagination, string queryJson)
  48. {
  49. Pagination paginationobj = InitPagination(pagination);
  50. var query = new ReportQueryDto();
  51. if (!string.IsNullOrEmpty(queryJson))
  52. {
  53. query = JsonConvert.DeserializeObject<ReportQueryDto>(queryJson);
  54. }
  55. var lists = _report.GetPageList(paginationobj, query ?? new ReportQueryDto());
  56. var jsonData = new
  57. {
  58. rows = lists.Result,
  59. total = lists.TotalPage,
  60. page = lists.PageIndex,
  61. records = lists.TotalNum
  62. };
  63. return Success(jsonData);
  64. }
  65. public ActionResult GetLocationUsageReportList()
  66. {
  67. var lists = _report.GetLocationUsageReportList();
  68. Pagination paginationobj = InitPagination("");
  69. var tunnellists = _syscon.GetTunnelList(paginationobj, new TunnelQueryDto());
  70. if (tunnellists != null && tunnellists.Result.Any())
  71. {
  72. //更新巷道状态
  73. lists.ForEach(s =>
  74. {
  75. var conf = tunnellists.Result.Where(m => m.Tunnel == s.Tunnel).ToList();
  76. if (conf != null)
  77. {
  78. if (conf.Where(o => o.Name.Contains("入库")).Any())
  79. {
  80. s.InStates = conf.Where(o => o.Name.Contains("入库")).First().StatuName;
  81. }
  82. if (conf.Where(o => o.Name.Contains("出库")).Any())
  83. {
  84. s.OutStates = conf.Where(o => o.Name.Contains("出库")).First().StatuName;
  85. }
  86. }
  87. });
  88. }
  89. //var totallists= new List<dynamic>(){ new { UnitName="总货位",qty= lists.Sum(s=>s.AllLocationTotal)},
  90. // new { UnitName="有效货位",qty= lists.Sum(s=>s.CanUseLocation)},
  91. // new { UnitName="空余货位",qty= lists.Sum(s=>s.SpareLocation)},
  92. // new { UnitName="锁定货位",qty= lists.Sum(s=>s.LockLocation)},
  93. // new { UnitName="停用货位",qty= lists.Sum(s=>s.StopLocation)},
  94. // new { UnitName="有料货位",qty= lists.Sum(s=>s.MaterilLocation)}};
  95. lists.Add(new LocationUsageReportViewDto()
  96. {
  97. Tunnel = "",
  98. WarehouseName = "合计:",
  99. AllLocationTotal = lists.Sum(s => s.AllLocationTotal),
  100. CanUseLocation = lists.Sum(s => s.CanUseLocation),
  101. SpareLocation = lists.Sum(s => s.SpareLocation),
  102. LockLocation = lists.Sum(s => s.LockLocation),
  103. StopLocation = lists.Sum(s => s.StopLocation),
  104. MaterilLocation = lists.Sum(s => s.MaterilLocation),
  105. });
  106. return Success(lists);
  107. }
  108. public IActionResult GetStockKeepReportList(string pagination, string queryJson)
  109. {
  110. Pagination paginationobj = InitPagination(pagination);
  111. var query = new BillInvNowQueryDto();
  112. if (!string.IsNullOrEmpty(queryJson))
  113. {
  114. query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
  115. }
  116. var lists = _report.GetStockKeepReportList(paginationobj, query ?? new BillInvNowQueryDto());
  117. var jsonData = new
  118. {
  119. rows = lists.Result,
  120. total = lists.TotalPage,
  121. page = lists.PageIndex,
  122. records = lists.TotalNum
  123. };
  124. return Success(jsonData);
  125. }
  126. /// <summary>
  127. /// 获取货位使用率
  128. /// </summary>
  129. /// <param name="pagination"></param>
  130. /// <param name="queryJson"></param>
  131. /// <returns></returns>
  132. public ActionResult GetCellList(string pagination, string queryJson)
  133. {
  134. Pagination paginationobj = InitPagination(pagination);
  135. var query = new ReportQueryDto();
  136. if (!string.IsNullOrEmpty(queryJson))
  137. {
  138. query = JsonConvert.DeserializeObject<ReportQueryDto>(queryJson);
  139. }
  140. var lists = _report.GetPageList(paginationobj, query ?? new ReportQueryDto());
  141. var jsonData = new
  142. {
  143. rows = lists.Result,
  144. total = lists.TotalPage,
  145. page = lists.PageIndex,
  146. records = lists.TotalNum
  147. };
  148. return Success(jsonData);
  149. }
  150. public ActionResult GetMantuoBarCodeRate(string pagination, string queryJson)
  151. {
  152. Pagination paginationobj = InitPagination(pagination);
  153. var query = new MantuoBarCodeRateQueryDto();
  154. if (!string.IsNullOrEmpty(queryJson))
  155. {
  156. query = JsonConvert.DeserializeObject<MantuoBarCodeRateQueryDto>(queryJson);
  157. }
  158. var lists = _report.GetMantuoBarCodeRate(paginationobj, query ?? new MantuoBarCodeRateQueryDto());
  159. var jsonData = new
  160. {
  161. rows = lists.Result,
  162. total = lists.TotalPage,
  163. page = lists.PageIndex,
  164. records = lists.TotalNum
  165. };
  166. return Success(jsonData);
  167. }
  168. public ActionResult GetMatNameNetWeightCategory(string pagination, string queryJson)
  169. {
  170. Pagination paginationobj = InitPagination(pagination);
  171. var query = new BillInvNowQueryDto();
  172. if (!string.IsNullOrEmpty(queryJson))
  173. {
  174. query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
  175. }
  176. var lists = _report.GetMatNameNetWeightCategory(paginationobj, query ?? new BillInvNowQueryDto());
  177. var jsonData = new
  178. {
  179. rows = lists.Result,
  180. total = lists.TotalPage,
  181. page = lists.PageIndex,
  182. records = lists.TotalNum
  183. };
  184. return Success(jsonData);
  185. }
  186. [HttpPost]
  187. public IActionResult ExportExcel(string fileName, string queryJson, string exportField)
  188. {
  189. var query = new ReportQueryDto();
  190. try
  191. {
  192. if (!string.IsNullOrEmpty(queryJson))
  193. {
  194. query = JsonConvert.DeserializeObject<ReportQueryDto>(queryJson);
  195. }
  196. }
  197. catch (Exception ex)
  198. {
  199. }
  200. //设置导出格式
  201. ExcelConfig excelconfig = new ExcelConfig();
  202. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  203. excelconfig.TitleFont = "微软雅黑";
  204. excelconfig.TitlePoint = 15;
  205. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  206. excelconfig.IsAllSizeColumn = true;
  207. excelconfig.ColumnEntity = new List<ColumnModel>();
  208. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  209. if (columnList.Count == 0)
  210. {
  211. throw new Exception("未找到表头");
  212. }
  213. //行数据
  214. var lists = _report.GetList(query ?? new ReportQueryDto());
  215. var dataJson = JsonConvert.SerializeObject(lists);
  216. DataTable rowData = dataJson.ToTable();
  217. //写入Excel表头
  218. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  219. if (!string.IsNullOrEmpty(exportField))
  220. {
  221. string[] exportFields = exportField.Split(',');
  222. foreach (var field in exportFields)
  223. {
  224. if (!exportFieldMap.ContainsKey(field))
  225. {
  226. exportFieldMap.Add(field, "1");
  227. }
  228. }
  229. }
  230. foreach (var columnModel in columnList)
  231. {
  232. excelconfig.ColumnEntity.Add(new ColumnModel()
  233. {
  234. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  235. Column = columnModel.name,
  236. ExcelColumn = columnModel.label,
  237. Alignment = columnModel.align,
  238. Width = columnModel.name.Length
  239. });
  240. }
  241. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  242. }
  243. [HttpPost]
  244. public IActionResult ExportLocationUsageReportExcel(string fileName, string queryJson, string exportField)
  245. {
  246. //设置导出格式
  247. ExcelConfig excelconfig = new ExcelConfig();
  248. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  249. excelconfig.TitleFont = "微软雅黑";
  250. excelconfig.TitlePoint = 15;
  251. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  252. excelconfig.IsAllSizeColumn = true;
  253. excelconfig.ColumnEntity = new List<ColumnModel>();
  254. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  255. if (columnList.Count == 0)
  256. {
  257. throw new Exception("未找到表头");
  258. }
  259. //行数据
  260. var lists = _report.GetLocationUsageReportList();
  261. var dataJson = JsonConvert.SerializeObject(lists);
  262. DataTable rowData = dataJson.ToTable();
  263. //写入Excel表头
  264. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  265. if (!string.IsNullOrEmpty(exportField))
  266. {
  267. string[] exportFields = exportField.Split(',');
  268. foreach (var field in exportFields)
  269. {
  270. if (!exportFieldMap.ContainsKey(field))
  271. {
  272. exportFieldMap.Add(field, "1");
  273. }
  274. }
  275. }
  276. foreach (var columnModel in columnList)
  277. {
  278. excelconfig.ColumnEntity.Add(new ColumnModel()
  279. {
  280. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  281. Column = columnModel.name,
  282. ExcelColumn = columnModel.label,
  283. Alignment = columnModel.align,
  284. Width = columnModel.name.Length
  285. });
  286. }
  287. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  288. }
  289. [HttpPost]
  290. public IActionResult ExportStockKeepReportExcel(string fileName, string queryJson, string exportField)
  291. {
  292. var query = new BillInvNowQueryDto();
  293. try
  294. {
  295. if (!string.IsNullOrEmpty(queryJson))
  296. {
  297. query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
  298. }
  299. }
  300. catch (Exception ex)
  301. {
  302. }
  303. //设置导出格式
  304. ExcelConfig excelconfig = new ExcelConfig();
  305. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  306. excelconfig.TitleFont = "微软雅黑";
  307. excelconfig.TitlePoint = 15;
  308. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  309. excelconfig.IsAllSizeColumn = true;
  310. excelconfig.ColumnEntity = new List<ColumnModel>();
  311. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  312. if (columnList.Count == 0)
  313. {
  314. throw new Exception("未找到表头");
  315. }
  316. //行数据
  317. var lists = _report.GetStockKeepReports(query ?? new BillInvNowQueryDto());
  318. var dataJson = JsonConvert.SerializeObject(lists);
  319. DataTable rowData = dataJson.ToTable();
  320. //写入Excel表头
  321. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  322. if (!string.IsNullOrEmpty(exportField))
  323. {
  324. string[] exportFields = exportField.Split(',');
  325. foreach (var field in exportFields)
  326. {
  327. if (!exportFieldMap.ContainsKey(field))
  328. {
  329. exportFieldMap.Add(field, "1");
  330. }
  331. }
  332. }
  333. foreach (var columnModel in columnList)
  334. {
  335. excelconfig.ColumnEntity.Add(new ColumnModel()
  336. {
  337. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  338. Column = columnModel.name,
  339. ExcelColumn = columnModel.label,
  340. Alignment = columnModel.align,
  341. Width = columnModel.name.Length
  342. });
  343. }
  344. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  345. }
  346. [HttpPost]
  347. public IActionResult ExportCellListReportExcel(string fileName, string queryJson, string exportField)
  348. {
  349. var query = new ReportQueryDto();
  350. try
  351. {
  352. if (!string.IsNullOrEmpty(queryJson))
  353. {
  354. query = JsonConvert.DeserializeObject<ReportQueryDto>(queryJson);
  355. }
  356. }
  357. catch (Exception ex)
  358. {
  359. }
  360. //设置导出格式
  361. ExcelConfig excelconfig = new ExcelConfig();
  362. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  363. excelconfig.TitleFont = "微软雅黑";
  364. excelconfig.TitlePoint = 15;
  365. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  366. excelconfig.IsAllSizeColumn = true;
  367. excelconfig.ColumnEntity = new List<ColumnModel>();
  368. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  369. if (columnList.Count == 0)
  370. {
  371. throw new Exception("未找到表头");
  372. }
  373. //行数据
  374. var lists = _report.GetList(query ?? new ReportQueryDto());
  375. var dataJson = JsonConvert.SerializeObject(lists);
  376. DataTable rowData = dataJson.ToTable();
  377. //写入Excel表头
  378. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  379. if (!string.IsNullOrEmpty(exportField))
  380. {
  381. string[] exportFields = exportField.Split(',');
  382. foreach (var field in exportFields)
  383. {
  384. if (!exportFieldMap.ContainsKey(field))
  385. {
  386. exportFieldMap.Add(field, "1");
  387. }
  388. }
  389. }
  390. foreach (var columnModel in columnList)
  391. {
  392. excelconfig.ColumnEntity.Add(new ColumnModel()
  393. {
  394. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  395. Column = columnModel.name,
  396. ExcelColumn = columnModel.label,
  397. Alignment = columnModel.align,
  398. Width = columnModel.name.Length
  399. });
  400. }
  401. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  402. }
  403. [HttpPost]
  404. public IActionResult ExportMatNameNetWeightCategoryExcel(string fileName, string queryJson, string exportField)
  405. {
  406. var query = new BillInvNowQueryDto();
  407. try
  408. {
  409. if (!string.IsNullOrEmpty(queryJson))
  410. {
  411. query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
  412. }
  413. }
  414. catch (Exception ex)
  415. {
  416. }
  417. //设置导出格式
  418. ExcelConfig excelconfig = new ExcelConfig();
  419. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  420. excelconfig.TitleFont = "微软雅黑";
  421. excelconfig.TitlePoint = 15;
  422. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  423. excelconfig.IsAllSizeColumn = true;
  424. excelconfig.ColumnEntity = new List<ColumnModel>();
  425. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  426. if (columnList.Count == 0)
  427. {
  428. throw new Exception("未找到表头");
  429. }
  430. //行数据
  431. var lists = _report.GetMatNameNetWeightCategorys(query ?? new BillInvNowQueryDto());
  432. var dataJson = JsonConvert.SerializeObject(lists);
  433. DataTable rowData = dataJson.ToTable();
  434. //写入Excel表头
  435. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  436. if (!string.IsNullOrEmpty(exportField))
  437. {
  438. string[] exportFields = exportField.Split(',');
  439. foreach (var field in exportFields)
  440. {
  441. if (!exportFieldMap.ContainsKey(field))
  442. {
  443. exportFieldMap.Add(field, "1");
  444. }
  445. }
  446. }
  447. foreach (var columnModel in columnList)
  448. {
  449. excelconfig.ColumnEntity.Add(new ColumnModel()
  450. {
  451. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  452. Column = columnModel.name,
  453. ExcelColumn = columnModel.label,
  454. Alignment = columnModel.align,
  455. Width = columnModel.name.Length
  456. });
  457. }
  458. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  459. }
  460. [HttpPost]
  461. public IActionResult ExportMantuoBarCodeRateExcel(string fileName, string queryJson, string exportField)
  462. {
  463. var query = new MantuoBarCodeRateQueryDto();
  464. try
  465. {
  466. if (!string.IsNullOrEmpty(queryJson))
  467. {
  468. query = JsonConvert.DeserializeObject<MantuoBarCodeRateQueryDto>(queryJson);
  469. }
  470. }
  471. catch (Exception ex)
  472. {
  473. }
  474. //设置导出格式
  475. ExcelConfig excelconfig = new ExcelConfig();
  476. excelconfig.Title = HttpUtility.UrlDecode(fileName);
  477. excelconfig.TitleFont = "微软雅黑";
  478. excelconfig.TitlePoint = 15;
  479. excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
  480. excelconfig.IsAllSizeColumn = true;
  481. excelconfig.ColumnEntity = new List<ColumnModel>();
  482. List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
  483. if (columnList.Count == 0)
  484. {
  485. throw new Exception("未找到表头");
  486. }
  487. //行数据
  488. var lists = _report.GetMantuoBarCodeRates(query ?? new MantuoBarCodeRateQueryDto());
  489. var dataJson = JsonConvert.SerializeObject(lists);
  490. DataTable rowData = dataJson.ToTable();
  491. //写入Excel表头
  492. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  493. if (!string.IsNullOrEmpty(exportField))
  494. {
  495. string[] exportFields = exportField.Split(',');
  496. foreach (var field in exportFields)
  497. {
  498. if (!exportFieldMap.ContainsKey(field))
  499. {
  500. exportFieldMap.Add(field, "1");
  501. }
  502. }
  503. }
  504. foreach (var columnModel in columnList)
  505. {
  506. excelconfig.ColumnEntity.Add(new ColumnModel()
  507. {
  508. // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
  509. Column = columnModel.name,
  510. ExcelColumn = columnModel.label,
  511. Alignment = columnModel.align,
  512. Width = columnModel.name.Length
  513. });
  514. }
  515. return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  516. }
  517. }
  518. }