ClassmajorDAL.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.ViewModel.Specialtyclass;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. using EMIS.ViewModel.Students;
  11. namespace EMIS.DataLogic.Common.Specialtyclass
  12. {
  13. public class ClassmajorDAL
  14. {
  15. public ClassmajorRepository ClassmajorRepository { get; set; }
  16. public SocialClassmajorRepository SocialClassmajorRepository { get; set; }
  17. public FacultymajorRepository FacultymajorRepository { get; set; }
  18. public GrademajorRepository GrademajorRepository { get; set; }
  19. public StudentRepository StudentRepository { get; set; }
  20. public UserRepository UserRepository { get; set; }
  21. /// <summary>
  22. /// 查询对应的班级信息View
  23. /// </summary>
  24. /// <param name="expClassmajor"></param>
  25. /// <returns></returns>
  26. public IQueryable<ClassmajorView> GetClassmajorViewQueryable(Expression<Func<CF_Classmajor, bool>> expClassmajor)
  27. {
  28. var query = from cl in ClassmajorRepository.GetList(expClassmajor)
  29. join c in UserRepository.Entities
  30. on cl.UserID equals c.UserID into gu
  31. from guser in gu.DefaultIfEmpty()
  32. join d in UserRepository.Entities
  33. on cl.AssistantUserID equals d.UserID into ga
  34. from gassis in ga.DefaultIfEmpty()
  35. select new ClassmajorView
  36. {
  37. ClassmajorID = cl.ClassmajorID,
  38. No = cl.No,
  39. Name = cl.Name,
  40. Abbreviation = cl.Abbreviation,
  41. EnglishName = cl.EnglishName,
  42. ClassNum = cl.ClassNum,
  43. FacultymajorID = cl.CF_Grademajor.CF_Facultymajor.FacultymajorID,
  44. FacultymajorCode = cl.CF_Grademajor.CF_Facultymajor.Code,
  45. FacultymajorName = cl.CF_Grademajor.CF_Facultymajor.Name,
  46. GrademajorID = cl.GrademajorID,
  47. GrademajorCode = cl.CF_Grademajor.Code,
  48. GrademajorName = cl.CF_Grademajor.Name,
  49. CampusID = cl.CF_Grademajor.CF_Facultymajor.CF_College.CampusID,
  50. CampusNo = cl.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.No,
  51. CampusName = cl.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.Name,
  52. SchoolAreaID = cl.CF_Grademajor.SchoolAreaID,
  53. CollegeID = cl.CF_Grademajor.CF_Facultymajor.CollegeID,
  54. CollegeCode = cl.CF_Grademajor.CF_Facultymajor.CF_College.No,
  55. CollegeName = cl.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  56. SchoolyearID = cl.CF_Grademajor.SchoolyearID,
  57. SchoolcodeID = cl.CF_Grademajor.SchoolcodeID,
  58. StandardID = cl.CF_Grademajor.CF_Facultymajor.StandardID,
  59. EducationID = cl.CF_Grademajor.CF_Facultymajor.EducationID,
  60. LearningformID = cl.CF_Grademajor.CF_Facultymajor.LearningformID,
  61. LearnSystem = cl.CF_Grademajor.CF_Facultymajor.LearnSystem,
  62. GraduatingSemesterID = cl.CF_Grademajor.GraduatingSemesterID,
  63. Value = cl.CF_Grademajor.CF_Schoolyear.Value,
  64. GraduatingSemesterCode = cl.CF_Grademajor.CF_Schoolyear.Code,
  65. UserID = cl.UserID,
  66. UserName = guser.Name,
  67. AssistantUserID = cl.AssistantUserID,
  68. AssistantUserName = gassis.Name,
  69. Fixedclassroom = cl.Fixedclassroom,
  70. Remark = cl.Remark,
  71. RecordStatus = cl.RecordStatus,
  72. CreateUserID = cl.CreateUserID,
  73. CreateTime = cl.CreateTime,
  74. ModifyUserID = cl.ModifyUserID,
  75. ModifyTime = cl.ModifyTime
  76. };
  77. return query;
  78. }
  79. /// <summary>
  80. /// 查询对应的班级信息View(统计对应的学生人数)
  81. /// </summary>
  82. /// <param name="expClassmajor"></param>
  83. /// <param name="expStudent"></param>
  84. /// <returns></returns>
  85. public IQueryable<ClassmajorView> GetClassmajorViewQueryable(Expression<Func<CF_Classmajor, bool>> expClassmajor,
  86. Expression<Func<CF_Student, bool>> expStudent)
  87. {
  88. var query = from cl in ClassmajorRepository.GetList(expClassmajor)
  89. join sc in
  90. (
  91. from sc in StudentRepository.GetList(expStudent)
  92. group sc by sc.CF_Classmajor.ClassmajorID into g
  93. select new
  94. {
  95. ClassmajorID = g.Key,
  96. StudentCount = g.Count()
  97. })
  98. on cl.ClassmajorID equals sc.ClassmajorID into dsc
  99. from esc in dsc.DefaultIfEmpty()
  100. join c in UserRepository.Entities
  101. on cl.UserID equals c.UserID into gu
  102. from guser in gu.DefaultIfEmpty()
  103. join d in UserRepository.Entities
  104. on cl.AssistantUserID equals d.UserID into ga
  105. from gassis in ga.DefaultIfEmpty()
  106. select new ClassmajorView
  107. {
  108. ClassmajorID = cl.ClassmajorID,
  109. No = cl.No,
  110. Name = cl.Name,
  111. Abbreviation = cl.Abbreviation,
  112. EnglishName = cl.EnglishName,
  113. ClassNum = cl.ClassNum,
  114. FacultymajorID = cl.CF_Grademajor.CF_Facultymajor.FacultymajorID,
  115. FacultymajorCode = cl.CF_Grademajor.CF_Facultymajor.Code,
  116. FacultymajorName = cl.CF_Grademajor.CF_Facultymajor.Name,
  117. GrademajorID = cl.GrademajorID,
  118. GrademajorCode = cl.CF_Grademajor.Code,
  119. GrademajorName = cl.CF_Grademajor.Name,
  120. CampusID = cl.CF_Grademajor.CF_Facultymajor.CF_College.CampusID,
  121. CampusNo = cl.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.No,
  122. CampusName = cl.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.Name,
  123. SchoolAreaID = cl.CF_Grademajor.SchoolAreaID,
  124. CollegeID = cl.CF_Grademajor.CF_Facultymajor.CollegeID,
  125. CollegeCode = cl.CF_Grademajor.CF_Facultymajor.CF_College.No,
  126. CollegeName = cl.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  127. SchoolyearID = cl.CF_Grademajor.SchoolyearID,
  128. SchoolcodeID = cl.CF_Grademajor.SchoolcodeID,
  129. StandardID = cl.CF_Grademajor.CF_Facultymajor.StandardID,
  130. EducationID = cl.CF_Grademajor.CF_Facultymajor.EducationID,
  131. LearningformID = cl.CF_Grademajor.CF_Facultymajor.LearningformID,
  132. LearnSystem = cl.CF_Grademajor.CF_Facultymajor.LearnSystem,
  133. GraduatingSemesterID = cl.CF_Grademajor.GraduatingSemesterID,
  134. Value = cl.CF_Grademajor.CF_Schoolyear.Value,
  135. GraduatingSemesterCode = cl.CF_Grademajor.CF_Schoolyear.Code,
  136. UserID = cl.UserID,
  137. UserName = guser.Name,
  138. AssistantUserID = cl.AssistantUserID,
  139. AssistantUserName = gassis.Name,
  140. Fixedclassroom = cl.Fixedclassroom,
  141. StudentCount = esc.StudentCount == null ? 0 : esc.StudentCount,
  142. Remark = cl.Remark,
  143. RecordStatus = cl.RecordStatus,
  144. CreateUserID = cl.CreateUserID,
  145. CreateTime = cl.CreateTime,
  146. ModifyUserID = cl.ModifyUserID,
  147. ModifyTime = cl.ModifyTime
  148. };
  149. return query;
  150. }
  151. /// <summary>
  152. /// 查询班级信息对应的学生信息BaseStudentView
  153. /// </summary>
  154. /// <param name="expClassmajor"></param>
  155. /// <param name="expStudent"></param>
  156. /// <returns></returns>
  157. public IQueryable<BaseStudentView> GetBaseStudentViewQueryable(Expression<Func<CF_Classmajor, bool>> expClassmajor,
  158. Expression<Func<CF_Student, bool>> expStudent)
  159. {
  160. var query = from cl in ClassmajorRepository.GetList(expClassmajor)
  161. join stu in StudentRepository.GetList(expStudent)
  162. on cl.ClassmajorID equals stu.ClassmajorID
  163. join gr in GrademajorRepository.Entities
  164. on cl.GrademajorID equals gr.GrademajorID
  165. join fa in FacultymajorRepository.Entities
  166. on gr.FacultymajorID equals fa.FacultymajorID
  167. join us in UserRepository.Entities
  168. on stu.UserID equals us.UserID
  169. select new BaseStudentView
  170. {
  171. UserID = stu.UserID,
  172. LoginID = us.LoginID,
  173. StudentNo = stu.StudentCardNo,
  174. UserName = us.Name,
  175. Sex = stu.Sex,
  176. IDNumber = stu.IDNumber,
  177. StudentStatus = stu.StudentStatus,
  178. InSchoolStatusID = stu.InSchoolStatusID,
  179. ClassmajorID = stu.ClassmajorID,
  180. ClassmajorCode = cl.No,
  181. ClassmajorName = cl.Name,
  182. ClassNum = cl.ClassNum == null ? 1 : cl.ClassNum,
  183. SchoolyearID = gr.SchoolyearID,
  184. GrademajorID = cl.GrademajorID,
  185. GrademajorCode = gr.Code,
  186. GrademajorName = gr.Name,
  187. FacultymajorID = gr.FacultymajorID,
  188. FacultymajorCode = fa.Code,
  189. FacultymajorName = fa.Name
  190. };
  191. return query;
  192. }
  193. public IQueryable<ClassmajorView> GetSocialClassmajor(Expression<Func<CF_SocialClassmajor, bool>> exp)
  194. {
  195. var socialClassmajorIDList = this.SocialClassmajorRepository.GetList(exp).Select(x => x.ClassmajorID).ToList();
  196. return this.GetClassmajorViewQueryable(x => socialClassmajorIDList.Contains(x.ClassmajorID));
  197. }
  198. }
  199. }