DifferentDynamicStatisticsController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.Students;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using EMIS.Utility;
  10. using System.Dynamic;
  11. using EMIS.ViewModel.DifferentDynamic;
  12. using Bowin.Common.Mvc;
  13. using Bowin.Common.Utility;
  14. using Bowin.Common.Linq;
  15. using EMIS.Entities;
  16. namespace EMIS.Web.Controllers.DifferentDynamic
  17. {
  18. /// <summary>
  19. /// 异动统计
  20. /// </summary>
  21. [Authorization]
  22. public class DifferentDynamicStatisticsController : JsonNetController
  23. {
  24. public IDifferentDynamicServices DifferentDynamicServices { get; set; }
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. /// <returns></returns>
  29. public ActionResult List()
  30. {
  31. var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType);
  32. ViewBag.DifferentDynamicTypes = differentDynamicTypes;
  33. return View();
  34. }
  35. /// <summary>
  36. /// 列表查询
  37. /// </summary>
  38. /// <param name="pararms"></param>
  39. /// <returns></returns>
  40. [HttpPost]
  41. public ActionResult List(QueryParamsModel pararms)
  42. {
  43. var configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  44. var campusID = pararms.getExtraGuid("CampusDropdown"); //校区
  45. var collegeID = pararms.getExtraGuid("CollegeDropdown"); //院系所
  46. var schoolYearID = pararms.getExtraGuid("SchoolYearDropdown"); //异动学期
  47. var result = DifferentDynamicServices.GetDifferentDynamicStatistics(configuretView, campusID, collegeID, schoolYearID);
  48. var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType);
  49. var list = WrapResult(result, differentDynamicTypes);
  50. return Json(new { total = list.Count, rows = list });
  51. }
  52. /// <summary>
  53. ///
  54. /// </summary>
  55. /// <param name="result"></param>
  56. /// <param name="differentDynamicTypes"></param>
  57. /// <returns></returns>
  58. private List<ExpandoObject> WrapResult(ICollection<DifferentDynamicStatisticsView> result, IEnumerable<Sys_DictionaryItem> differentDynamicTypes)
  59. {
  60. var list = new List<ExpandoObject>();
  61. if (result == null || result.Count == 0)
  62. {
  63. return list;
  64. }
  65. var colleges = result.Select(s => new { s.CollegeID, s.CollegeName }).OrderBy(o => o.CollegeName).Distinct().ToList();
  66. foreach (var college in colleges)
  67. {
  68. dynamic item = new ExpandoObject();
  69. item.CollegeName = college.CollegeName;
  70. DifferentDynamicStatisticsView covarianceItem = null;
  71. foreach (var differentDynamicType in differentDynamicTypes)
  72. {
  73. covarianceItem = result.FirstOrDefault(w => w.CollegeID == college.CollegeID && w.DifferentDynamicType == differentDynamicType.Value);
  74. var quantity = covarianceItem == null ? 0 : covarianceItem.Quantity;
  75. ((IDictionary<string, object>)item).Add("Item" + differentDynamicType.Value, quantity.ToString());
  76. }
  77. list.Add(item);
  78. }
  79. return list;
  80. }
  81. /// <summary>
  82. ///
  83. /// </summary>
  84. /// <returns></returns>
  85. [HttpPost]
  86. public ActionResult Excel()
  87. {
  88. NpoiExcelHelper neh = new NpoiExcelHelper();
  89. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  90. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>(); //校区
  91. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>(); //院系所
  92. var schoolYearID = Request.Form["SchoolYearDropdown"].ParseStrTo<Guid>(); //异动学期
  93. var result = DifferentDynamicServices.GetDifferentDynamicStatistics(configuretView, campusID, collegeID, schoolYearID);
  94. var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType);
  95. var dt = WrapResult(result, differentDynamicTypes).ToTable();
  96. var columns = new List<string> { RSL.Get("College") };
  97. foreach (var item in differentDynamicTypes)
  98. {
  99. columns.Add(item.Name);
  100. }
  101. neh.Export(dt, columns.ToArray(), "异动统计");
  102. return RedirectToAction("MsgShow", "Common", new
  103. {
  104. msg = "导出成功!",
  105. url = Url.Action("List").AddMenuParameter()
  106. });
  107. }
  108. }
  109. }