ReportController.cs 18 KB

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