StudentEvaluationCountDAL.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using System.Linq.Expressions;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel.EvaluationManage;
  9. using EMIS.DataLogic.SystemDAL;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.EducationManage;
  12. using EMIS.ViewModel.EvaluationManage.EvaluationEnter;
  13. using EMIS.Utility;
  14. using EMIS.DataLogic.Common.Students;
  15. using Bowin.Common.Linq;
  16. namespace EMIS.DataLogic.Common.EvaluationManage
  17. {
  18. public class StudentEvaluationCountDAL
  19. {
  20. public StudentRepository StudentRepository { get; set; }
  21. public EvaluationSettingRepository EvaluationSettingRepository { get; set; }
  22. public UserRepository UserRepository { get; set; }
  23. //public StudentEvaluationRepository StudentEvaluationRepository { get; set; }
  24. public EducationMissionRepository EducationMissionRepository { get; set; }
  25. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  26. public EM_EvaluationSetting EvaluationSetting { get; set; }
  27. public SchoolyearRepository SchoolyearRepository { get; set; }
  28. public EvaluationEnterRepository EvaluationEnterRepository { get; set; }
  29. public IQueryable<StudentEvaluationCountView> GetStudentView(Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> exp
  30. )
  31. // Expression<Func<EM_EducationMissionClass, bool>> exp =null
  32. {
  33. //var query = from esr in EvaluationSettingRepository.Entities
  34. // join em in EducationMissionClassRepository.Entities on esr.EducationMissionClassID equals em.EducationMissionClassID into emcr
  35. // from sr in emcr.DefaultIfEmpty()
  36. // from s in esr.CF_Student
  37. // select new StudentEvaluationCountView
  38. // {
  39. // CollegeID = s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  40. // //StartSchoolyearValue = (s.CF_Classmajor.CF_Grademajor.SchoolyearID.Value * 2) - 1 + (s.CF_Classmajor.CF_Grademajor.SchoolcodeID.Value - 1),
  41. // //EndSchoolyearValue = s.CF_Classmajor.CF_Grademajor.CF_Schoolyear.Value,
  42. // SchoolyearNumID = //esr.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolcodeID,
  43. // (int?)Math.Ceiling((decimal)(((s.CF_Classmajor.CF_Grademajor.SchoolyearID.Value * 2) - 1 + (s.CF_Classmajor.CF_Grademajor.SchoolcodeID.Value - 1)) - (s.CF_Classmajor.CF_Grademajor.CF_Schoolyear.Value) + 1) / 2),
  44. // StandardID = s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID,
  45. // StudentNo = s.Sys_User.LoginID,
  46. // Name = s.Sys_User.Name,
  47. // ClassmajorID = s.ClassmajorID,
  48. // ClassmajorName = s.CF_Classmajor.Name,
  49. // SchoolyearID = esr.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolyearID,//sr.EM_EducationMission.CF_Schoolyear.SchoolyearID,
  50. // SchoolyearCode = esr.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.Code,
  51. // CompleteCount = s.EM_EvaluationSetting.Where(x => x.EM_EducationMissionClass.EM_EvaluationEnter.Any(z => z.CF_Student == s)).Count(),
  52. // NeedEvaluationCount = s.EM_EvaluationSetting.Where(x => x.OpenStatus == 0).Count(),
  53. // UncompletedCount = s.EM_EvaluationSetting.Where(x => x.OpenStatus == 0).Count() - s.EM_EvaluationSetting.Where(x => x.EM_EducationMissionClass.EM_EvaluationEnter.Any(z => z.CF_Student == s)).Count(),
  54. // };
  55. //return query.Distinct();
  56. //var query = from s in StudentRepository.Entities
  57. // from sc in s.EM_EducationSchedulingClass
  58. // join ms in EducationMissionClassRepository.Entities on sc.EducationMissionClassID equals ms.EducationMissionClassID
  59. // from set in s.EM_EvaluationSetting.Where(x => x.EducationMissionClassID == sc.EM_EducationMissionClass.EducationMissionClassID)
  60. // //group s by new
  61. // //{
  62. // // s.Sys_User.LoginID,
  63. // // s.Sys_User.UserID
  64. // //}
  65. // select new StudentEvaluationCountView
  66. // {
  67. // CollegeID = s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  68. // SchoolyearNumID = s.CF_Classmajor.CF_Grademajor.SchoolyearID,
  69. // StandardID = s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID,
  70. // StudentNo = s.Sys_User.LoginID,
  71. // Name = s.Sys_User.Name,
  72. // ClassmajorID = s.ClassmajorID,
  73. // ClassmajorName = s.CF_Classmajor.Name,
  74. // SchoolyearID = sc.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.SchoolyearID,
  75. // SchoolyearCode = sc.EM_EducationMissionClass.EM_EducationMission.CF_Schoolyear.Code,
  76. // CompleteCount = s.EM_EvaluationSetting.Where(x => x.EM_EducationMissionClass.EM_EvaluationEnter.Any(z => z.CF_Student == s)).Count(),
  77. // NeedEvaluationCount = s.EM_EvaluationSetting.Where(x => x.OpenStatus == 0).Count(),
  78. // UncompletedCount = s.EM_EvaluationSetting.Where(x => x.OpenStatus == 0).Count() - s.EM_EvaluationSetting.Where(x => x.EM_EducationMissionClass.EM_EvaluationEnter.Any(z => z.CF_Student == s)).Count(),
  79. // };
  80. //return query;//.GroupBy(x => x.StudentNo).Select(y => y.FirstOrDefault());
  81. //var query1 = from stu in StudentRepository.Entities
  82. // from es in stu.EM_EvaluationSetting
  83. // group stu by stu.UserID into ns
  84. // select new
  85. // {
  86. // NeedEvaluationCount = ns.Count()
  87. // };
  88. //var query2 = from stu in StudentRepository.Entities
  89. // from est in stu.EM_EvaluationSetting
  90. // join et in EvaluationEnterRepository.Entities on new { est.EducationMissionClassID, UserID=(Guid?)stu.UserID } equals new { et.EducationMissionClassID, UserID=et.StudentUserID } into es_et
  91. // group stu by stu.UserID into nst
  92. // select new
  93. // {
  94. // CompleteCount = nst.Count()
  95. // };
  96. var query3 = from s in StudentRepository.Entities
  97. join nses in
  98. (from stu in StudentRepository.Entities
  99. from es in stu.EM_EvaluationSetting.Where(x => x.OpenStatus == 1)
  100. join em in EducationMissionClassRepository.Entities on es.EducationMissionClassID equals em.EducationMissionClassID
  101. join emc in EducationMissionRepository.Entities on em.EducationMissionID equals emc.EducationMissionID
  102. join sy in SchoolyearRepository.GetList(exp) on emc.SchoolyearID equals sy.SchoolyearID
  103. group stu by new { stu.UserID, sy.SchoolyearID, sy.Code } into ns
  104. //from sy in SchoolyearRepository.Entities
  105. //from stu in StudentRepository.Entities
  106. select new
  107. {
  108. SchoolCode = ns.Key.Code,
  109. SchoolyearID = ns.Key.SchoolyearID,
  110. UserID = ns.Key.UserID,
  111. NeedEvaluationCount = ns.Count()
  112. }) on s.UserID equals nses.UserID
  113. join set in
  114. (from stu in StudentRepository.Entities
  115. from est in stu.EM_EvaluationSetting.Where(x => x.OpenStatus == 1)
  116. join em in EducationMissionClassRepository.Entities on est.EducationMissionClassID equals em.EducationMissionClassID
  117. join emc in EducationMissionRepository.Entities on em.EducationMissionID equals emc.EducationMissionID
  118. join sy in SchoolyearRepository.GetList(exp) on emc.SchoolyearID equals sy.SchoolyearID
  119. //join ee in EvaluationEnterRepository.Entities on est.EducationMissionClassID equals ee.EducationMissionClassID
  120. //where ee.StudentUserID == stu.UserID
  121. where (from et in EvaluationEnterRepository.Entities.Where(x => x.StudentUserID == stu.UserID) select et.EducationMissionClassID).Contains(est.EducationMissionClassID)
  122. //join et in EvaluationEnterRepository.Entities.DefaultIfEmpty() on new { est.EducationMissionClassID, UserID = (Guid?)stu.UserID } equals new { et.EducationMissionClassID, UserID = et.StudentUserID } into es_et
  123. group stu by new { stu.UserID, sy.SchoolyearID, sy.Code } into nst
  124. //from nt in nst.Distinct()
  125. //from stu in StudentRepository.Entities
  126. select new
  127. {
  128. SchoolCode = nst.Key.Code,
  129. SchoolyearID = nst.Key.SchoolyearID,
  130. UserID = nst.Key.UserID,
  131. CompleteCount = nst.Count(),
  132. }) on s.UserID equals set.UserID
  133. into g
  134. from n_set in g.DefaultIfEmpty()
  135. select new StudentEvaluationCountView
  136. {
  137. CollegeID = s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  138. SchoolyearNumID = s.CF_Classmajor.CF_Grademajor.GradeID,
  139. StandardID = s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID,
  140. StudentNo = s.Sys_User.LoginID,
  141. Name = s.Sys_User.Name,
  142. ClassmajorID = s.ClassmajorID,
  143. ClassmajorName = s.CF_Classmajor.Name,
  144. SchoolyearID = n_set.SchoolyearID,//s.CF_Classmajor.CF_Grademajor.CF_Schoolyear.SchoolyearID,
  145. SchoolyearCode = nses.SchoolCode,//s.CF_Classmajor.CF_Grademajor.CF_Schoolyear.Code,
  146. CompleteCount = n_set.CompleteCount == null ? 0 : n_set.CompleteCount,
  147. NeedEvaluationCount = nses.NeedEvaluationCount,
  148. UncompletedCount = nses.NeedEvaluationCount - (n_set.CompleteCount == null ? 0 : n_set.CompleteCount),
  149. };
  150. return query3;
  151. }
  152. }
  153. }