ChangeTotalController.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using System.Dynamic;
  7. using System.Data;
  8. using Bowin.Common.Mvc;
  9. using Bowin.Common.Utility;
  10. using Bowin.Common.Data;
  11. using Bowin.Web.Controls.Mvc;
  12. using EMIS.Utility;
  13. using EMIS.Web.Controls;
  14. using EMIS.ViewModel;
  15. using EMIS.ViewModel.StudentManage.StudentChange;
  16. using EMIS.CommonLogic.StudentManage.StudentChange;
  17. namespace EMIS.Web.Controllers.StudentManage.StudentChange
  18. {
  19. [Authorization]
  20. public class ChangeTotalController : JsonNetController
  21. {
  22. public Lazy<IChangeTotalServices> ChangeTotalServices { get; set; }
  23. /// <summary>
  24. /// 异动统计页面
  25. /// </summary>
  26. /// <returns></returns>
  27. public ActionResult List()
  28. {
  29. var changeTypeDisPlayList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType).Where(x => x.RecordStatus >= 1).ToList();
  30. ViewBag.ChangeTypeList = changeTypeDisPlayList;
  31. return View();
  32. }
  33. /// <summary>
  34. /// 异动统计列表查询
  35. /// </summary>
  36. /// <param name="pararms"></param>
  37. /// <returns></returns>
  38. [HttpPost]
  39. public ActionResult List(QueryParamsModel pararms)
  40. {
  41. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  42. var schoolyearID = pararms.getExtraGuid("SchoolyearDropdown");
  43. var campusID = pararms.getExtraGuid("CampusDropdown");
  44. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  45. var changeTotalViewList = ChangeTotalServices.Value.GetChangeTotalViewList(configuretView, schoolyearID, campusID, collegeID);
  46. var camColList = changeTotalViewList.Select(x => new
  47. {
  48. x.CampusID,
  49. x.CampusCode,
  50. x.CampusName,
  51. x.CollegeID,
  52. x.CollegeNo,
  53. x.CollegeName
  54. }).OrderBy(x => x.CollegeNo).Distinct().ToList();
  55. var changeTypeDisPlayList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType).Where(x => x.RecordStatus >= 1).ToList();
  56. var dblist = new List<ExpandoObject>();
  57. foreach (var camCol in camColList)
  58. {
  59. dynamic item = new ExpandoObject();
  60. ((IDictionary<string, object>)item).Add("CampusID", camCol.CampusID);
  61. ((IDictionary<string, object>)item).Add("CampusCode", camCol.CampusCode);
  62. ((IDictionary<string, object>)item).Add("CampusName", camCol.CampusName);
  63. ((IDictionary<string, object>)item).Add("CollegeID", camCol.CollegeID);
  64. ((IDictionary<string, object>)item).Add("CollegeNo", camCol.CollegeNo);
  65. ((IDictionary<string, object>)item).Add("CollegeName", camCol.CollegeName);
  66. var changeTypeTotal = 0;
  67. foreach (var changeTypeDisPlay in changeTypeDisPlayList)
  68. {
  69. var changeTotalView = changeTotalViewList.Where(x => x.CollegeID == camCol.CollegeID && x.ChangeTypeID == changeTypeDisPlay.Value).SingleOrDefault();
  70. changeTypeTotal += (changeTotalView == null ? 0 : changeTotalView.ChangeTypeCount.Value);
  71. ((IDictionary<string, object>)item).Add("ChangeType_" + changeTypeDisPlay.Value, (changeTotalView == null ? 0 : changeTotalView.ChangeTypeCount).ToString());
  72. }
  73. ((IDictionary<string, object>)item).Add("ChangeTypeTotal", changeTypeTotal.ToString());
  74. dblist.Add(item);
  75. }
  76. return Json(new { total = dblist.Count, rows = dblist });
  77. }
  78. /// <summary>
  79. /// Excel导出
  80. /// </summary>
  81. /// <returns></returns>
  82. [HttpPost]
  83. public ActionResult Excel()
  84. {
  85. NpoiExcelHelper neh = new NpoiExcelHelper();
  86. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  87. var schoolyearID = Request.Form["SchoolyearDropdown"] == DropdownList.SELECT_ALL.ToString() ? null : Request.Form["SchoolyearDropdown"].ParseStrTo<Guid>();
  88. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  89. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  90. var changeTotalViewList = ChangeTotalServices.Value.GetChangeTotalViewList(configuretView, schoolyearID, campusID, collegeID);
  91. var camColList = changeTotalViewList.Select(x => new
  92. {
  93. x.CampusID,
  94. x.CampusCode,
  95. x.CampusName,
  96. x.CollegeID,
  97. x.CollegeNo,
  98. x.CollegeName
  99. }).OrderBy(x => x.CollegeNo).Distinct().ToList();
  100. var changeTypeDisPlayList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ChangeType).Where(x => x.RecordStatus >= 1).ToList();
  101. var dt = new DataTable();
  102. dt.Columns.Add("CampusCode", typeof(string));
  103. dt.Columns.Add("CampusName", typeof(string));
  104. dt.Columns.Add("CollegeNo", typeof(string));
  105. dt.Columns.Add("CollegeName", typeof(string));
  106. foreach (var changeTypeDisPlay in changeTypeDisPlayList)
  107. {
  108. dt.Columns.Add("Change_" + changeTypeDisPlay.Value, typeof(string));
  109. }
  110. dt.Columns.Add("ChangeTypeTotal", typeof(string));
  111. foreach (var camCol in camColList)
  112. {
  113. DataRow dr = dt.NewRow();
  114. dr["CampusCode"] = camCol.CampusCode;
  115. dr["CampusName"] = camCol.CampusName;
  116. dr["CollegeNo"] = camCol.CollegeNo;
  117. dr["CollegeName"] = camCol.CollegeName;
  118. var changeTypeTotal = 0;
  119. foreach (var changeTypeDisPlay in changeTypeDisPlayList)
  120. {
  121. var changeTotalView = changeTotalViewList.Where(x => x.CollegeID == camCol.CollegeID && x.ChangeTypeID == changeTypeDisPlay.Value).SingleOrDefault();
  122. changeTypeTotal += (changeTotalView == null ? 0 : changeTotalView.ChangeTypeCount.Value);
  123. dr["Change_" + changeTypeDisPlay.Value] = (changeTotalView == null ? 0 : changeTotalView.ChangeTypeCount).ToString();
  124. }
  125. dr["ChangeTypeTotal"] = changeTypeTotal.ToString();
  126. dt.Rows.Add(dr);
  127. }
  128. var liststring = new List<string> { RSL.Get("CampusCode"), RSL.Get("Campus"), RSL.Get("CollegeCode"), RSL.Get("College") };
  129. foreach (var changeTypeDisPlay in changeTypeDisPlayList)
  130. {
  131. liststring.Add(changeTypeDisPlay.Name);
  132. }
  133. liststring.Add("总数");
  134. neh.Export(dt, liststring.ToArray(), "异动统计信息" + DateTime.Now.ToString("yyyyMMdd"));
  135. return Json(new ReturnMessage()
  136. {
  137. IsSuccess = true,
  138. Message = "导出成功。"
  139. });
  140. }
  141. }
  142. }