FacultymajorStudentCountDAL.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel.Students.HighBaseTable;
  6. using EMIS.DataLogic.Repositories;
  7. using EMIS.ViewModel;
  8. namespace EMIS.DataLogic.Common.Students.HighBaseTable
  9. {
  10. public class FacultymajorStudentCountDAL
  11. {
  12. public ClassmajorRepository ClassmajorRepository { get; set; }
  13. public GrademajorRepository GrademajorRepository { get; set; }
  14. public FacultymajorRepository FacultymajorRepository { get; set; }
  15. public StudentRepository StudentRepository { get; set; }
  16. public RecruitstudentsRepository RecruitstudentsRepository { get; set; }
  17. public InSchoolSettingRepository InSchoolSettingRepository { get; set; }
  18. public EducationTypeSettingRepository EducationTypeSettingRepository { get; set; }
  19. public SchoolyearRepository SchoolyearRepository { get; set; }
  20. public ExamineeTypeSettingRepository ExamineeTypeSettingRepository { get; set; }
  21. public IQueryable<FacultymajorStudentCountView> GetFacultymajorStudentCountViewQueryable(int year)
  22. {
  23. var dataSql = (from faculty in FacultymajorRepository.Entities
  24. join graGrade in GrademajorRepository.Entities
  25. on new { FacultymajorID = (Guid?)faculty.FacultymajorID, Gradeyear = Math.Floor((double)year - (double)faculty.LearnSystem) }
  26. equals new { graGrade.FacultymajorID, Gradeyear = (double)graGrade.GradeID }
  27. join classmajor in ClassmajorRepository.Entities on graGrade.GrademajorID equals classmajor.ClassmajorID
  28. join student in StudentRepository.Entities.Where(x => x.StudentStatus == (int)CF_StudentStatus.Graduation)
  29. on classmajor.ClassmajorID equals student.ClassmajorID
  30. group faculty by new { faculty.FacultymajorID, student.SexID } into g
  31. select new
  32. {
  33. FacultymajorID = g.Key.FacultymajorID,
  34. SexID = g.Key.SexID,
  35. LastGraduateCount = g.Count(),
  36. RecruitstudentsCount = 0,
  37. FreshGraduateCount = 0,
  38. GradeOneCount = 0,
  39. GradeTwoCount = 0,
  40. GradeThreeCount = 0,
  41. AfterGradeFourCount = 0,
  42. PlanGraduateCount = 0
  43. }).Concat(
  44. from student in StudentRepository.Entities
  45. join inschool in InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true)
  46. on student.InSchoolStatusID equals inschool.InSchoolStatusID
  47. join recruit in RecruitstudentsRepository.Entities on student.UserID equals recruit.UserID
  48. join schoolyear in SchoolyearRepository.Entities.Where(x => x.Years == year)
  49. on recruit.EnteringSchoolYearID equals schoolyear.SchoolyearID
  50. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  51. join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID
  52. join faculty in FacultymajorRepository.Entities on grade.FacultymajorID equals faculty.FacultymajorID
  53. join examineeType in ExamineeTypeSettingRepository.Entities on recruit.ExamineeType equals examineeType.ExamineeTypeID into dexamineeType
  54. from examineeType in dexamineeType.DefaultIfEmpty()
  55. group examineeType by new { faculty.FacultymajorID, student.SexID } into g
  56. select new
  57. {
  58. FacultymajorID = g.Key.FacultymajorID,
  59. SexID = g.Key.SexID,
  60. LastGraduateCount = 0,
  61. RecruitstudentsCount = g.Count(),
  62. FreshGraduateCount = g.Sum(x => x.IsFreshGraduate == true ? 1 : 0),
  63. GradeOneCount = 0,
  64. GradeTwoCount = 0,
  65. GradeThreeCount = 0,
  66. AfterGradeFourCount = 0,
  67. PlanGraduateCount = 0
  68. }).Concat(
  69. from student in StudentRepository.Entities
  70. join inschool in InSchoolSettingRepository.Entities.Where(x => x.IsSelected == true)
  71. on student.InSchoolStatusID equals inschool.InSchoolStatusID
  72. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  73. join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID
  74. join faculty in FacultymajorRepository.Entities on grade.FacultymajorID equals faculty.FacultymajorID
  75. join graSchoolyear in SchoolyearRepository.Entities on grade.GraduateSchoolyearID equals graSchoolyear.SchoolyearID into dgraSchoolyear
  76. from graSchoolyear in dgraSchoolyear.DefaultIfEmpty()
  77. group new { grade.GradeID, GraduateYear = graSchoolyear.Years } by new { faculty.FacultymajorID, student.SexID } into g
  78. select new
  79. {
  80. FacultymajorID = g.Key.FacultymajorID,
  81. SexID = g.Key.SexID,
  82. LastGraduateCount = 0,
  83. RecruitstudentsCount = 0,
  84. FreshGraduateCount = 0,
  85. GradeOneCount = g.Sum(x => (year - x.GradeID) == 0 ? 1 : 0),
  86. GradeTwoCount = g.Sum(x => (year - x.GradeID) == 1 ? 1 : 0),
  87. GradeThreeCount = g.Sum(x => (year - x.GradeID) == 2 ? 1 : 0),
  88. AfterGradeFourCount = g.Sum(x => (year - x.GradeID) > 2 ? 1 : 0),
  89. PlanGraduateCount = g.Sum(x => x.GraduateYear == year ? 1 : 0)
  90. });
  91. var sql = (from faculty in FacultymajorRepository.Entities
  92. join educationType in EducationTypeSettingRepository.Entities.Where(x => x.EducationTypeID == (int)CF_EducationType.Special)
  93. on faculty.EducationID equals educationType.EducationID
  94. join data in dataSql on faculty.FacultymajorID equals data.FacultymajorID
  95. group data by new { faculty.FacultymajorID, faculty.StandardID, educationType.EducationTypeID, data.SexID } into g
  96. select new FacultymajorStudentCountView
  97. {
  98. Year = year,
  99. EducationTypeID = g.Key.EducationTypeID,
  100. StandardID = g.Key.StandardID,
  101. FacultymajorID = g.Key.FacultymajorID,
  102. SexID = g.Key.SexID,
  103. LastGraduateCount = g.Sum(x => x.LastGraduateCount),
  104. RecruitstudentsCount = g.Sum(x => x.RecruitstudentsCount),
  105. FreshGraduateCount = g.Sum(x => x.FreshGraduateCount),
  106. GradeOneCount = g.Sum(x => x.GradeOneCount),
  107. GradeTwoCount = g.Sum(x => x.GradeTwoCount),
  108. GradeThreeCount = g.Sum(x => x.GradeThreeCount),
  109. AfterGradeFourCount = g.Sum(x => x.AfterGradeFourCount),
  110. PlanGraduateCount = g.Sum(x => x.PlanGraduateCount)
  111. });
  112. return sql;
  113. }
  114. }
  115. }