ReportController.cs 18 KB

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