StudentChangeServices.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.Students.HighBaseTable;
  6. using EMIS.CommonLogic.SystemServices;
  7. using EMIS.Entities;
  8. namespace EMIS.CommonLogic.Students.HighBaseTable
  9. {
  10. public class StudentChangeServices : BaseServices, IStudentChangeServices
  11. {
  12. public StudentChangeDAL StudentChangeDAL { get; set; }
  13. public Lazy<IWorkflowServices> WorkflowServices { get; set; }
  14. public void GenerateReport(int year)
  15. {
  16. var endStatusID = WorkflowServices.Value.GetCorrectEndStatus(typeof(CF_DifferentDynamic).Name);
  17. //获取上学年初报表在校生数
  18. var lastReportList = StudentChangeDAL.GetLastInschoolStudentCount(year).ToList();
  19. //获取招生数
  20. var recruitStudentList = StudentChangeDAL.GetRecruitStudentCount(year).ToList();
  21. //获取毕业数
  22. var graduationStudentList = StudentChangeDAL.GetGraduationStudentCount(year).ToList();
  23. //获取结业数
  24. var graduationOverStudentList = StudentChangeDAL.GetGraduationOverStudentCount(year).ToList();
  25. //获取本学期报表在校学生数
  26. var currentStudentList = StudentChangeDAL.GetCurrentInschoolStudentCount().ToList();
  27. //获取异动学生数
  28. var studentChangeList = StudentChangeDAL.GetStudentChangeCount(year, endStatusID).ToList();
  29. this.UnitOfWork.Remove<HB_StudentChangeDetail>(x => x.HB_StudentChange.Year == year);
  30. this.UnitOfWork.Remove<HB_StudentChange>(x => x.Year == year);
  31. #region 合并各种主表数据,并生成主表实体
  32. var studentChangeTableList = lastReportList
  33. .Select(x => new
  34. {
  35. x.EducationTypeID,
  36. LastInschoolCount = x.CurrentInschoolCount,
  37. RecruitCount = (int?)0,
  38. GraduationCount = (int?)0,
  39. CompleteCount = (int?)0,
  40. CurrentInschoolCount = (int?)0
  41. }).Concat(recruitStudentList
  42. .Select(x => new
  43. {
  44. x.EducationTypeID,
  45. LastInschoolCount = (int?)0,
  46. RecruitCount = x.StudentCount,
  47. GraduationCount = (int?)0,
  48. CompleteCount = (int?)0,
  49. CurrentInschoolCount = (int?)0
  50. })).Concat(graduationStudentList
  51. .Select(x => new
  52. {
  53. x.EducationTypeID,
  54. LastInschoolCount = (int?)0,
  55. RecruitCount = (int?)0,
  56. GraduationCount = x.StudentCount,
  57. CompleteCount = (int?)0,
  58. CurrentInschoolCount = (int?)0
  59. })).Concat(graduationOverStudentList
  60. .Select(x => new
  61. {
  62. x.EducationTypeID,
  63. LastInschoolCount = (int?)0,
  64. RecruitCount = (int?)0,
  65. GraduationCount = (int?)0,
  66. CompleteCount = x.StudentCount,
  67. CurrentInschoolCount = (int?)0
  68. })).Concat(currentStudentList
  69. .Select(x => new
  70. {
  71. x.EducationTypeID,
  72. LastInschoolCount = (int?)0,
  73. RecruitCount = (int?)0,
  74. GraduationCount = (int?)0,
  75. CompleteCount = (int?)0,
  76. CurrentInschoolCount = x.StudentCount
  77. }))
  78. .GroupBy(x => x.EducationTypeID).Select(x => new HB_StudentChange
  79. {
  80. StudentChangeID = Guid.NewGuid(),
  81. Year = year,
  82. EducationTypeID = x.Key,
  83. LastInschoolCount = x.Sum(w => w.LastInschoolCount),
  84. RecruitCount = x.Sum(w => w.RecruitCount),
  85. GraduationCount = x.Sum(w => w.GraduationCount),
  86. CompleteCount = x.Sum(w => w.CompleteCount),
  87. CurrentInschoolCount = x.Sum(w => w.CurrentInschoolCount)
  88. })
  89. .ToList();
  90. #endregion
  91. studentChangeTableList.ForEach(x =>
  92. {
  93. this.SetNewStatus(x);
  94. var detailList = studentChangeList.Where(w => w.EducationTypeID == x.EducationTypeID)
  95. .Select(w => new HB_StudentChangeDetail
  96. {
  97. StudentChangeDetailID = Guid.NewGuid(),
  98. StudentChangeID = x.StudentChangeID,
  99. DifferentDynamicType = w.DifferentDynamicType ?? 0,
  100. StudentInCount = w.StudentInCount,
  101. StudentOutCount = w.StudentOutCount
  102. }).ToList();
  103. detailList.ForEach(w => this.SetNewStatus(w));
  104. x.HB_StudentChangeDetail = new HashSet<HB_StudentChangeDetail>(detailList);
  105. this.UnitOfWork.Add(x);
  106. });
  107. this.UnitOfWork.Commit();
  108. }
  109. }
  110. }