SpecialityScoreSumDAL.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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.ScoreManage;
  7. using EMIS.Entities;
  8. using System.Linq.Expressions;
  9. using Bowin.Common.Linq;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.Students;
  12. using EMIS.DataLogic.Common.Students;
  13. namespace EMIS.DataLogic.ScoreManage
  14. {
  15. public class SpecialityScoreSumDAL
  16. {
  17. public SchoolyearRepository SchoolyearRepository { get; set; }
  18. public CollegeRepository CollegeRepository { get; set; }
  19. public CoursematerialRepository CoursematerialRepository { get; set; }
  20. public ClassmajorRepository ClassmajorRepository { get; set; }
  21. public GrademajorRepository GrademajorRepository { get; set; }
  22. public FacultymajorRepository FacultymajorRepository { get; set; }
  23. public ExecutablePlanRepository ExecutablePlanRepository { get; set; }
  24. public ExecutableOptionalCourseRepository ExecutableOptionalCourseRepository { get; set; }
  25. public ExecutableFreeSelectionCouseRepository ExecutableFreeSelectionCouseRepository { get; set; }
  26. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  27. public EducationMissionRepository EducationMissionRepository { get; set; }
  28. public FinallyScoreRepository finallyScoreRepository { get; set; }
  29. public GraduationCourseTypeSettingRepository graduationCourseTypeSettingRepository { get; set; }
  30. public CourseTypeSelectCourseTypeRepository courseTypeSelectCourseTypeRepository { get; set; }
  31. public ClubCourseRepository clubCourseRepository { get; set; }
  32. public DictionaryItemRepository dictionaryItemRepository { get; set; }
  33. public DepartmentRepository departmentRepository { get; set; }
  34. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  35. public ResultTypeDetailRepository ResultTypeDetailRepository { get; set; }
  36. public StudentRepository StudentRepository { get; set; }
  37. public UserRepository UserRepository { get; set; }
  38. public ExamsStateSettingRepository examsStateSettingRepository { get; set; }
  39. public IQueryable<CoursematerialPlanView> GetCoursematerialPlanViewQueryable(Expression<Func<CF_Classmajor, bool>> classmajorExp,
  40. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp)
  41. {
  42. //获取课程
  43. var queryCourse = (from c in ClassmajorRepository.GetList(classmajorExp)
  44. join g in GrademajorRepository.Entities on c.GrademajorID equals g.GrademajorID
  45. join f in FacultymajorRepository.Entities on g.FacultymajorID equals f.FacultymajorID
  46. join college in CollegeRepository.Entities on f.CollegeID equals college.CollegeID
  47. from temc in c.EM_EducationMissionClass
  48. join emc in EducationMissionClassRepository.GetList(missionClassExp) on temc.EducationMissionClassID equals emc.EducationMissionClassID
  49. join em in EducationMissionRepository.Entities on emc.EducationMissionID equals em.EducationMissionID
  50. join sy in SchoolyearRepository.Entities on em.SchoolyearID equals sy.SchoolyearID
  51. join cm in CoursematerialRepository.Entities on emc.CoursematerialID equals cm.CoursematerialID
  52. select new CoursematerialPlanView
  53. {
  54. SchoolyearID = sy.SchoolyearID,
  55. SchoolyearCode = sy.Code,
  56. CollegeID = college.CollegeID,
  57. CollegeName = college.Name,
  58. SchoolyearNumID = (sy.Value - (((g.GradeID * 2 - 1) + (g.SemesterID - 1))) + 1 - (sy.SchoolcodeID == g.SemesterID ? 0 : 1)) / 2 + 1,
  59. SchoolcodeID = sy.SchoolcodeID,
  60. StartTermID = ((sy.Value - ((g.GradeID * 2 - 1) + (g.SemesterID - 1))) + 1),
  61. CoursematerialID = cm.CoursematerialID,
  62. CourseCode = cm.CourseCode,
  63. CourseName = cm.CourseName,
  64. TypePlan = 1
  65. } into s
  66. group s by new { s.StartTermID, s.CoursematerialID, s.TypePlan } into g
  67. select g.FirstOrDefault()
  68. );
  69. return queryCourse;
  70. }
  71. public IQueryable<ER_FinallyScore> GetFinallyScoreQueryable(Guid? collegeID, int? years, int? schoolyearNumID, int? schoolcodeID, Guid? classmajorID)
  72. {
  73. Expression<Func<ER_FinallyScore, bool>> exp = (x => true);
  74. if (collegeID.HasValue)
  75. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  76. if (years.HasValue)
  77. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == years);
  78. if (schoolyearNumID.HasValue)
  79. exp = exp.And(x => x.SchoolyearNumID == schoolyearNumID);
  80. if (schoolcodeID.HasValue)
  81. exp = exp.And(x => (x.CF_Student.CF_Classmajor.CF_Grademajor.SemesterID + (x.StarttermID - 1)) % 2 == schoolcodeID % 2);
  82. if (classmajorID.HasValue)
  83. exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID);
  84. var query = finallyScoreRepository.GetList(exp, (x => x.CF_Student), (x => x.CF_Student.Sys_User), (x => x.CF_Schoolyear), (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor), (x => x.CF_Student.CF_Classmajor));
  85. return query.OrderByDescending(x => x.CF_Schoolyear.Code);
  86. }
  87. public virtual IQueryable<StudentScoreView> GetStudentScoreViewQueryable(Guid? collegeID, int? years, int? schoolyearNumID, int? schoolcodeID, Guid? classmajorID)
  88. {
  89. List<int?> examsStateList = examsStateSettingRepository.GetList(x => x.IsNormal == true).Select(x => x.ExamsStateID).ToList();
  90. Expression<Func<ER_FinallyScore, bool>> exp = (x => true);
  91. if (collegeID.HasValue)
  92. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID);
  93. if (years.HasValue)
  94. exp = exp.And(x => x.CF_Student.CF_Classmajor.CF_Grademajor.GradeID == years);
  95. if (schoolyearNumID.HasValue)
  96. exp = exp.And(x => x.SchoolyearNumID == schoolyearNumID);
  97. if (schoolcodeID.HasValue)
  98. exp = exp.And(x => (x.CF_Student.CF_Classmajor.CF_Grademajor.SemesterID + (x.StarttermID - 1)) % 2 == schoolcodeID % 2);
  99. if (classmajorID.HasValue)
  100. exp = exp.And(x => x.CF_Student.ClassmajorID == classmajorID);
  101. var query = from x in finallyScoreRepository.GetList(exp, (x => x.CF_Student), (x => x.CF_Student.Sys_User), (x => x.CF_Schoolyear), (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor), (x => x.CF_Student.CF_Classmajor))
  102. join ed in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(CF_ExamsState).Name) on x.ExamsStateID equals ed.Value
  103. into ged
  104. from f in ged.DefaultIfEmpty()
  105. join d in DictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_ResultType") on x.ResultTypeID equals d.Value
  106. join rd in ResultTypeDetailRepository.GetList(x => true) on d.Value equals rd.ResultTypeID
  107. into ResultTypeDetail
  108. from Result in ResultTypeDetail.DefaultIfEmpty()
  109. where (Result.ResultTypeDetailID != null &&
  110. (( x.TotalScore <= Result.MaxScore && Result.MinScore <= x.TotalScore && (Result.MaxScoreOperator == "<=" && Result.MinScoreOperator == "<="))
  111. || (x.TotalScore <= Result.MaxScore && Result.MinScore < x.TotalScore && (Result.MaxScoreOperator == "<=" && Result.MinScoreOperator == "<"))
  112. || (x.TotalScore < Result.MaxScore && Result.MinScore < x.TotalScore && (Result.MaxScoreOperator == "<" && Result.MinScoreOperator == "<"))
  113. || (x.TotalScore < Result.MaxScore && Result.MinScore <= x.TotalScore && (Result.MaxScoreOperator == "<" && Result.MinScoreOperator == "<="))
  114. ))
  115. || (Result.ResultTypeDetailID == null)
  116. select new StudentScoreView
  117. {
  118. SchoolyearID = x.SchoolyearID,
  119. SchoolyearCode = x.CF_Schoolyear.Code,
  120. SchoolyearNumID = x.SchoolyearNumID,
  121. ClassName = x.ClassName,
  122. GrademajorID = x.CF_Student.CF_Classmajor.CF_Grademajor.GrademajorID,
  123. GrademajorCode = x.CF_Student.CF_Classmajor.CF_Grademajor.Code,
  124. GrademajorName = x.CF_Student.CF_Classmajor.CF_Grademajor.Name,
  125. ClassmajorID = x.CF_Student.CF_Classmajor.ClassmajorID,
  126. ClassmajorCode = x.CF_Student.CF_Classmajor.No,
  127. ClassmajorName = x.CF_Student.CF_Classmajor.Name,
  128. CollegeID = x.CF_Department.CollegeID,
  129. CollegeName = x.CF_Department.CF_College.Name,
  130. DepartmentID = x.DepartmentID,
  131. DepartmentName = x.CF_Department.Name,
  132. CoursematerialID = x.EM_Coursematerial.CoursematerialID,
  133. CourseCode = x.EM_Coursematerial.CourseCode,
  134. CourseName = x.EM_Coursematerial.CourseName,
  135. CourseTypeID = x.CourseTypeID,
  136. ExamsCategoryID = x.ExamsCategoryID,
  137. ExaminationModeID = x.ExaminationModeID,
  138. Credit = x.Credit ?? 0,
  139. ExamsDatetime = x.ExamsDatetime,
  140. ResultTypeID = x.ResultTypeID,
  141. CreatorUserID = x.CreatorUserID,
  142. EntryDeadlineTime = x.EntryDeadlineTime,
  143. ExaminationType = x.ExaminationType,
  144. StarttermID = x.StarttermID,
  145. UserID = x.UserID,
  146. LoginID = x.CF_Student.Sys_User.LoginID,
  147. UserName = x.CF_Student.Sys_User.Name,
  148. ExamsStateID = x.ExamsStateID,
  149. TotalScore = x.TotalScore,
  150. TotalScoreStr = examsStateList.Any(w => w.Value == x.ExamsStateID) ? (Result.Name ?? ((double)x.TotalScore).ToString()) : f.Name,
  151. ScoreCredit = x.ScoreCredit ?? 0,
  152. GradePoint = x.GradePoint,
  153. Remarks = x.Remark,
  154. StudentScoreRemark = x.Remark,
  155. CreateTime = x.CreateTime,
  156. CreateUserID = x.CreateUserID,
  157. Pingshi = Math.Round(x.ER_FinallyScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Peacetime).FirstOrDefault().Score ?? 0, 0),
  158. Jishu = Math.Round(x.ER_FinallyScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Technique).FirstOrDefault().Score ?? 0, 0),
  159. Lilun = Math.Round(x.ER_FinallyScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Theoretical).FirstOrDefault().Score ?? 0, 0)
  160. };
  161. return query.OrderByDescending(x => x.SchoolyearCode);
  162. }
  163. public IQueryable<StudentScoreView> GetFinalScoreQueryable(Expression<Func<ER_FinallyScore, bool>> scoreExp, Expression<Func<CF_Student, bool>> studentExp,
  164. Expression<Func<CF_Grademajor, bool>> gradeExp, Expression<Func<CF_Facultymajor, bool>> facultyExp, Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp)
  165. {
  166. List<int?> examsStateList = examsStateSettingRepository.GetList(x => x.IsNormal == true).Select(x => x.ExamsStateID).ToList();
  167. var query = from x in finallyScoreRepository.GetList(scoreExp)
  168. join student in StudentRepository.Entities.Where(studentExp) on x.UserID equals student.UserID
  169. join user in UserRepository.Entities on student.UserID equals user.UserID
  170. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  171. join grade in GrademajorRepository.Entities.Where(gradeExp) on classmajor.GrademajorID equals grade.GrademajorID
  172. join faculty in FacultymajorRepository.Entities.Where(facultyExp) on grade.FacultymajorID equals faculty.FacultymajorID
  173. join schoolyear in SchoolyearRepository.Entities.Where(schoolyearExp) on x.SchoolyearID equals schoolyear.SchoolyearID
  174. join ed in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(CF_ExamsState).Name) on x.ExamsStateID equals ed.Value
  175. into ged
  176. from f in ged.DefaultIfEmpty()
  177. join d in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(CF_ResultType).Name) on x.ResultTypeID equals d.Value
  178. join rd in ResultTypeDetailRepository.GetList(x => true) on d.Value equals rd.ResultTypeID
  179. into ResultTypeDetail
  180. from Result in ResultTypeDetail.DefaultIfEmpty()
  181. where (Result.ResultTypeDetailID != null &&
  182. ((x.TotalScore <= Result.MaxScore && Result.MinScore <= x.TotalScore && (Result.MaxScoreOperator == "<=" && Result.MinScoreOperator == "<="))
  183. || (x.TotalScore <= Result.MaxScore && Result.MinScore < x.TotalScore && (Result.MaxScoreOperator == "<=" && Result.MinScoreOperator == "<"))
  184. || (x.TotalScore < Result.MaxScore && Result.MinScore < x.TotalScore && (Result.MaxScoreOperator == "<" && Result.MinScoreOperator == "<"))
  185. || (x.TotalScore < Result.MaxScore && Result.MinScore <= x.TotalScore && (Result.MaxScoreOperator == "<" && Result.MinScoreOperator == "<="))
  186. ))
  187. || (Result.ResultTypeDetailID == null)
  188. select new StudentScoreView
  189. {
  190. SchoolyearID = x.SchoolyearID,
  191. SchoolyearCode = schoolyear.Code,
  192. SchoolyearNumID = x.SchoolyearNumID,
  193. ClassName = x.ClassName,
  194. GrademajorID = grade.GrademajorID,
  195. GrademajorCode = grade.Code,
  196. GrademajorName = grade.Name,
  197. ClassmajorID = classmajor.ClassmajorID,
  198. ClassmajorCode = classmajor.No,
  199. ClassmajorName = classmajor.Name,
  200. CollegeID = x.CF_Department.CollegeID,
  201. CollegeName = x.CF_Department.CF_College.Name,
  202. DepartmentID = x.DepartmentID,
  203. DepartmentName = x.CF_Department.Name,
  204. CoursematerialID = x.EM_Coursematerial.CoursematerialID,
  205. CourseCode = x.EM_Coursematerial.CourseCode,
  206. CourseName = x.EM_Coursematerial.CourseName,
  207. CourseTypeID = x.CourseTypeID,
  208. ExamsCategoryID = x.ExamsCategoryID,
  209. ExaminationModeID = x.ExaminationModeID,
  210. Credit = x.Credit ?? 0,
  211. ExamsDatetime = x.ExamsDatetime,
  212. ResultTypeID = x.ResultTypeID,
  213. CreatorUserID = x.CreatorUserID,
  214. EntryDeadlineTime = x.EntryDeadlineTime,
  215. ExaminationType = x.ExaminationType,
  216. StarttermID = x.StarttermID,
  217. UserID = x.UserID,
  218. LoginID = x.CF_Student.Sys_User.LoginID,
  219. UserName = x.CF_Student.Sys_User.Name,
  220. ExamsStateID = x.ExamsStateID,
  221. TotalScore = x.TotalScore,
  222. TotalScoreStr = examsStateList.Any(w => w.Value == x.ExamsStateID) ? (Result.Name ?? ((double)x.TotalScore).ToString()) : f.Name,
  223. ScoreCredit = x.ScoreCredit ?? 0,
  224. GradePoint = x.GradePoint,
  225. Remarks = x.Remark,
  226. StudentScoreRemark = x.Remark,
  227. CreateTime = x.CreateTime,
  228. CreateUserID = x.CreateUserID,
  229. Pingshi = Math.Round(x.ER_FinallyScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Peacetime).FirstOrDefault().Score ?? 0, 0),
  230. Jishu = Math.Round(x.ER_FinallyScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Technique).FirstOrDefault().Score ?? 0, 0),
  231. Lilun = Math.Round(x.ER_FinallyScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Theoretical).FirstOrDefault().Score ?? 0, 0)
  232. };
  233. return query.OrderByDescending(x => x.SchoolyearCode);
  234. }
  235. //获取总学分
  236. public IQueryable<SpecialityCreditView> GetCreditQueryable(Expression<Func<ER_FinallyScore, bool>> scoreExp, Expression<Func<CF_Student, bool>> studentExp,
  237. Expression<Func<CF_Grademajor, bool>> gradeExp, Expression<Func<CF_Facultymajor, bool>> facultyExp, Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp)
  238. {
  239. var finallyScoreQuery = (from score in finallyScoreRepository.GetList(scoreExp)
  240. join student in StudentRepository.Entities.Where(studentExp) on score.UserID equals student.UserID
  241. join user in UserRepository.Entities on student.UserID equals user.UserID
  242. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  243. join grade in GrademajorRepository.Entities.Where(gradeExp) on classmajor.GrademajorID equals grade.GrademajorID
  244. join faculty in FacultymajorRepository.Entities.Where(facultyExp) on grade.FacultymajorID equals faculty.FacultymajorID
  245. join schoolyear in SchoolyearRepository.Entities.Where(schoolyearExp) on score.SchoolyearID equals schoolyear.SchoolyearID
  246. select score);
  247. //总学分(必修、限选、任选学分)
  248. var TotalCredit = from q in finallyScoreQuery
  249. join a in courseTypeSelectCourseTypeRepository.Entities
  250. on q.CourseTypeID equals a.CourseTypeID
  251. group new { score = q, courseType = a } by q.UserID
  252. into g
  253. select new SpecialityCreditView
  254. {
  255. UserID = g.Key,
  256. RequiredCredit = g.Sum(x => (x.courseType.IsRequired == true) ? (x.score.ScoreCredit ?? 0) : 0),
  257. OptionalCourseCredit = g.Sum(x => (x.courseType.IsOptionalCourse == true) ? (x.score.ScoreCredit ?? 0) : 0),
  258. FreeSelectionCourseCredit = g.Sum(x => (x.courseType.IsFreeSelectionCourse == true) ? (x.score.ScoreCredit ?? 0) : 0),
  259. GeneralEducationCredit = 0,
  260. ElectiveCredit = 0,
  261. ElectivePublicCredit = 0,
  262. SchoolbasedWithClub = 0,
  263. SchoolbasedNotCredit = 0,
  264. SchoolbasedCredit = 0,
  265. SchoolbasedRealCredit = 0,
  266. PractiseWithClub = 0,
  267. PractiseNotCredit = 0,
  268. PractiseCredit = 0,
  269. PractiseRealCredit = 0,
  270. AvgScore = 0,
  271. TotalCredit = g.Sum(x => x.score.ScoreCredit ?? 0),//总学分 = 必修 + 限选 + 任选
  272. };
  273. //通识教育、方向选修、公共选修、校本课(不包含俱乐部)、校本课(包含俱乐部)、校本课(包含俱乐部,大于等于4只取4学分)、实践环节(不包含俱乐部)、实践环节(包含俱乐部)、实践环节(包含俱乐部,大于等于4只取4学分)
  274. var GraduationCourseTypeCredit = from final in finallyScoreQuery
  275. join gcts in graduationCourseTypeSettingRepository.Entities
  276. on final.CourseTypeID equals gcts.CourseTypeID
  277. join cc in clubCourseRepository.Entities
  278. on final.CoursematerialID equals cc.CoursematerialID
  279. into b
  280. from k in b.DefaultIfEmpty()
  281. group new { score = final, setting = gcts, club = k } by final.UserID
  282. into g
  283. select new SpecialityCreditView
  284. {
  285. UserID = g.Key,
  286. RequiredCredit = 0,
  287. OptionalCourseCredit = 0,
  288. FreeSelectionCourseCredit = 0,
  289. GeneralEducationCredit = g.Sum(x => (x.setting.IsGeneralEducation == true) ? (x.score.ScoreCredit ?? 0) : 0),
  290. ElectiveCredit = g.Sum(x => (x.setting.IsElective == true) ? (x.score.ScoreCredit ?? 0) : 0),
  291. ElectivePublicCredit = g.Sum(x => (x.setting.IsElectivePublic == true) ? (x.score.ScoreCredit ?? 0) : 0),
  292. SchoolbasedWithClub = g.Sum(x => (x.setting.IsSchoolbasedCurriculum == true && x.club.ClubCourseID != null) ? (x.score.ScoreCredit ?? 0) : 0),
  293. SchoolbasedNotCredit = g.Sum(x => (x.setting.IsSchoolbasedCurriculum == true && x.club.ClubCourseID == null) ? (x.score.ScoreCredit ?? 0) : 0),
  294. SchoolbasedCredit = g.Sum(x => (x.setting.IsSchoolbasedCurriculum == true) ? (x.score.ScoreCredit ?? 0) : 0),
  295. SchoolbasedRealCredit = (g.Sum(x => (x.setting.IsSchoolbasedCurriculum == true) ? (x.score.ScoreCredit ?? 0) : 0) > 4) ? 4 : g.Sum(x => (x.setting.IsSchoolbasedCurriculum == true) ? (x.score.ScoreCredit ?? 0) : 0),
  296. PractiseWithClub = g.Sum(x => (x.setting.IsPractise == true && x.club.ClubCourseID != null) ? (x.score.ScoreCredit ?? 0) : 0),
  297. PractiseNotCredit = g.Sum(x => (x.setting.IsPractise == true && x.club.ClubCourseID == null) ? (x.score.ScoreCredit ?? 0) : 0),
  298. PractiseCredit = g.Sum(x => (x.setting.IsPractise == true) ? (x.score.ScoreCredit ?? 0) : 0),
  299. PractiseRealCredit = (g.Sum(x => (x.setting.IsPractise == true) ? (x.score.ScoreCredit ?? 0) : 0) > 4) ? 4 : g.Sum(x => (x.setting.IsPractise == true) ? (x.score.ScoreCredit ?? 0) : 0),
  300. AvgScore = 0,
  301. TotalCredit = 0
  302. };
  303. //平均分
  304. var AvgScore = from final in finallyScoreQuery
  305. group final by final.UserID
  306. into a
  307. select new SpecialityCreditView
  308. {
  309. UserID = a.Key,
  310. RequiredCredit = 0,
  311. OptionalCourseCredit = 0,
  312. FreeSelectionCourseCredit = 0,
  313. GeneralEducationCredit = 0,
  314. ElectiveCredit = 0,
  315. ElectivePublicCredit = 0,
  316. SchoolbasedWithClub = 0,
  317. SchoolbasedNotCredit = 0,
  318. SchoolbasedCredit = 0,
  319. SchoolbasedRealCredit = 0,
  320. PractiseWithClub = 0,
  321. PractiseNotCredit = 0,
  322. PractiseCredit = 0,
  323. PractiseRealCredit = 0,
  324. AvgScore = a.Average(x => x.TotalScore ?? 0),
  325. TotalCredit = 0
  326. };
  327. var queryall = from score in TotalCredit.Concat(GraduationCourseTypeCredit).Concat(AvgScore)
  328. group score by score.UserID into g
  329. select new SpecialityCreditView
  330. {
  331. UserID = g.Key,
  332. RequiredCredit = g.Sum(x => x.RequiredCredit),
  333. OptionalCourseCredit = g.Sum(x => x.OptionalCourseCredit),
  334. FreeSelectionCourseCredit = g.Sum(x => x.FreeSelectionCourseCredit),
  335. GeneralEducationCredit = g.Sum(x => x.GeneralEducationCredit),
  336. ElectiveCredit = g.Sum(x => x.ElectiveCredit),
  337. ElectivePublicCredit = g.Sum(x => x.ElectivePublicCredit),
  338. SchoolbasedWithClub = g.Sum(x => x.SchoolbasedWithClub),
  339. SchoolbasedNotCredit = g.Sum(x => x.SchoolbasedNotCredit),
  340. SchoolbasedCredit = g.Sum(x => x.SchoolbasedCredit),
  341. SchoolbasedRealCredit = g.Sum(x => x.SchoolbasedRealCredit),
  342. PractiseWithClub = g.Sum(x => x.PractiseWithClub),
  343. PractiseNotCredit = g.Sum(x => x.PractiseNotCredit),
  344. PractiseCredit = g.Sum(x => x.PractiseCredit),
  345. PractiseRealCredit = g.Sum(x => x.PractiseRealCredit),
  346. AvgScore = g.Sum(x => x.AvgScore),
  347. TotalCredit = g.Sum(x => x.TotalCredit)
  348. };
  349. return queryall;
  350. }
  351. //根据最终成绩获取课程
  352. public IQueryable<CoursematerialPlanView> GetCoursematerialViewQueryable(Expression<Func<ER_FinallyScore, bool>> scoreExp,
  353. Expression<Func<CF_Student, bool>> studentExp,
  354. Expression<Func<CF_Grademajor, bool>> grademajorExp,
  355. Expression<Func<CF_Facultymajor, bool>> facultyExp,
  356. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp)
  357. {
  358. var queryCourse = (from score in finallyScoreRepository.GetList(scoreExp)
  359. join cm in CoursematerialRepository.Entities on score.CoursematerialID equals cm.CoursematerialID
  360. join student in StudentRepository.GetList(studentExp) on score.UserID equals student.UserID
  361. join classmajor in ClassmajorRepository.Entities on student.ClassmajorID equals classmajor.ClassmajorID
  362. join grade in GrademajorRepository.GetList(grademajorExp) on classmajor.GrademajorID equals grade.GrademajorID
  363. join facult in FacultymajorRepository.GetList(facultyExp) on grade.FacultymajorID equals facult.FacultymajorID
  364. join de in departmentRepository.Entities on score.DepartmentID equals de.DepartmentID
  365. join college in CollegeRepository.Entities on de.CollegeID equals college.CollegeID
  366. join sy in SchoolyearRepository.GetList(schoolyearExp) on score.SchoolyearID equals sy.SchoolyearID
  367. select new CoursematerialPlanView
  368. {
  369. SchoolyearID = sy.SchoolyearID,
  370. SchoolyearCode = sy.Code,
  371. CollegeID = college.CollegeID,
  372. CollegeName = college.Name,
  373. Credit = score.Credit,
  374. CourseTypeID = score.CourseTypeID,
  375. SchoolyearNumID = score.SchoolyearNumID,
  376. SchoolcodeID = sy.SchoolcodeID,
  377. StartTermID = score.StarttermID,
  378. //StartTermID = ((sy.Value - ((g.SchoolyearID * 2 - 1) + (g.SchoolcodeID - 1))) + 1),
  379. CoursematerialID = cm.CoursematerialID,
  380. CourseCode = cm.CourseCode,
  381. CourseName = cm.CourseName,
  382. //TypePlan = 1
  383. } into s
  384. group s by new { s.StartTermID, s.CoursematerialID } into g
  385. select g.FirstOrDefault()
  386. );
  387. return queryCourse;
  388. }
  389. public List<int> GetCourseTypeQueryble()
  390. {
  391. var query = from b in dictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_CourseType")
  392. join c in courseTypeSelectCourseTypeRepository.Entities
  393. on b.Value equals c.CourseTypeID
  394. where c.IsRequired == true
  395. select b.Value.Value;
  396. return query.ToList();
  397. }
  398. public string GetIsByCourseTypeID(int courseTypeID)
  399. {
  400. var query = from b in courseTypeSelectCourseTypeRepository.Entities
  401. where b.CourseTypeID == courseTypeID
  402. select new
  403. {
  404. IsRequired = b.IsRequired,
  405. IsOptionalCourse = b.IsOptionalCourse,
  406. IsFreeSelectionCourse = b.IsFreeSelectionCourse,
  407. };
  408. var a = query.FirstOrDefault();
  409. if ((bool)a.IsRequired)
  410. {
  411. return "必";
  412. }
  413. if ((bool)a.IsOptionalCourse)
  414. {
  415. return "限";
  416. }
  417. if ((bool)a.IsFreeSelectionCourse)
  418. {
  419. return "任";
  420. }
  421. return "";
  422. }
  423. }
  424. }