StudentScoreDAL.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 Bowin.Common.Linq;
  9. using System.Linq.Expressions;
  10. using System.Data.Entity;
  11. using EMIS.ViewModel;
  12. using EMIS.DataLogic.Common.Cultureplan;
  13. using EMIS.ViewModel.Cultureplan;
  14. namespace EMIS.DataLogic.ScoreManage
  15. {
  16. public class StudentScoreDAL
  17. {
  18. public SubmitedScoreRepository submitedScoreRepository { get; set; }
  19. public SubmitedScoreDetailRepository SubmitedScoreDetailRepository { get; set; }
  20. public ExaminationExemptionRepository ExaminationExemptionRepository { get; set; }
  21. public MisconductRepository MisconductRepository { get; set; }
  22. public FinallyScoreRepository FinallyScoreRepository { get; set; }
  23. public FinallyScoreDetailRepository FinallyScoreDetailRepository { get; set; }
  24. public ClassmajorRepository classmajorRepository { get; set; }
  25. public StudentRepository studentRepository { get; set; }
  26. public UserRepository userRepository { get; set; }
  27. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  28. public ResultTypeDetailRepository ResultTypeDetailRepository { get; set; }
  29. public ExamsStateSettingRepository examsStateSettingRepository { get; set; }
  30. public StaffRepository staffRepository { get; set; }
  31. public GrademajorRepository GrademajorRepository { get; set; }
  32. public FacultymajorRepository FacultymajorRepository { get; set; }
  33. public CollegeRepository CollegeRepository { get; set; }
  34. public DepartmentRepository DepartmentRepository { get; set; }
  35. public SchoolyearRepository SchoolyearRepository { get; set; }
  36. public CoursematerialRepository CoursematerialRepository { get; set; }
  37. public Lazy<CoursematerialDAL> CoursematerialDAL { get; set; }
  38. /// <summary>
  39. /// 已提交成绩
  40. /// </summary>
  41. /// <param name="exp"></param>
  42. /// <returns></returns>
  43. public virtual IQueryable<StudentScoreView> GetStudentScoreViewQueryable(Expression<Func<ER_SubmitedScore, bool>> exp)
  44. {
  45. List<int?> examsStateList = examsStateSettingRepository.GetList(x => x.IsNormal == true).Select(x => x.ExamsStateID).ToList();
  46. var query = from x in submitedScoreRepository.GetList(exp)
  47. join u in userRepository.Entities on x.CreatorUserID equals u.UserID
  48. into user from a in user.DefaultIfEmpty()
  49. join ed in DictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_ExamsState") on x.ExamsStateID equals ed.Value
  50. into ged from f in ged.DefaultIfEmpty()
  51. join d in DictionaryItemRepository.GetList(x => x.DictionaryCode == "CF_ResultType") on x.ResultTypeID equals d.Value
  52. join rd in ResultTypeDetailRepository.GetList(x => true) on d.Value equals rd.ResultTypeID
  53. into ResultTypeDetail from Result in ResultTypeDetail.DefaultIfEmpty()
  54. where (Result.ResultTypeDetailID != null &&
  55. ((x.TotalScore <= Result.MaxScore && Result.MinScore <= x.TotalScore && (Result.MaxScoreOperator == "<=" && Result.MinScoreOperator == "<="))
  56. || (x.TotalScore <= Result.MaxScore && Result.MinScore < x.TotalScore && (Result.MaxScoreOperator == "<=" && Result.MinScoreOperator == "<"))
  57. || (x.TotalScore < Result.MaxScore && Result.MinScore < x.TotalScore && (Result.MaxScoreOperator == "<" && Result.MinScoreOperator == "<"))
  58. || (x.TotalScore < Result.MaxScore && Result.MinScore <= x.TotalScore && (Result.MaxScoreOperator == "<" && Result.MinScoreOperator == "<="))
  59. ))
  60. || (Result.ResultTypeDetailID == null)
  61. select new StudentScoreView
  62. {
  63. SubmitedScoreID = x.SubmitedScoreID,
  64. SchoolyearID = x.SchoolyearID,
  65. SchoolyearCode = x.CF_Schoolyear.Code,
  66. SchoolyearNumID = x.SchoolyearNumID,
  67. ClassName = x.ClassName,
  68. GrademajorID = x.CF_Student.CF_Classmajor.CF_Grademajor.GrademajorID,
  69. GrademajorCode = x.CF_Student.CF_Classmajor.CF_Grademajor.Code,
  70. GrademajorName = x.CF_Student.CF_Classmajor.CF_Grademajor.Name,
  71. ClassmajorID = x.CF_Student.CF_Classmajor.ClassmajorID,
  72. ClassmajorCode = x.CF_Student.CF_Classmajor.No,
  73. ClassmajorName = x.CF_Student.CF_Classmajor.Name,
  74. CollegeID = x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  75. CollegeName = x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  76. DepartmentID = x.DepartmentID,
  77. DepartmentName = x.CF_Department.Name,
  78. CoursematerialID = x.EM_Coursematerial.CoursematerialID,
  79. CourseCode = x.EM_Coursematerial.CourseCode,
  80. CourseName = x.EM_Coursematerial.CourseName,
  81. CourseTypeID = x.CourseTypeID,
  82. ExamsCategoryID = x.ExamsCategoryID,
  83. ExaminationModeID = x.ExaminationModeID,
  84. Credit = x.Credit ?? 0,
  85. ExamsDatetime = x.ExamsDatetime,
  86. ResultTypeID = x.ResultTypeID,
  87. CreatorUserID = x.CreatorUserID,
  88. CreatorUserCode = a.LoginID,
  89. CreatorUserName = a.Name,
  90. EntryDeadlineTime = x.EntryDeadlineTime,
  91. ExaminationType = x.ExaminationType,
  92. StarttermID = x.StarttermID,
  93. UserID = x.UserID,
  94. LoginID = x.CF_Student.Sys_User.LoginID,
  95. UserName = x.CF_Student.Sys_User.Name,
  96. ExamsStateID = x.ExamsStateID,
  97. TotalScore = x.TotalScore,
  98. //暂时按此种逻辑处理。。后续优化(廖兵良)
  99. //已经优化--20180517李晓林
  100. TotalScoreStr = examsStateList.Any(w => w.Value == x.ExamsStateID) ? (Result.Name ?? ((double)Math.Round(x.TotalScore.Value, 1)).ToString()) : f.Name,
  101. ScoreCredit = x.ScoreCredit ?? 0,
  102. GradePoint = x.GradePoint,
  103. Remarks = x.Remark,
  104. StudentScoreRemark = x.Remark,
  105. CreateTime = x.CreateTime,
  106. CreateUserID = x.CreateUserID,
  107. TotalHours = x.TotalHours,
  108. Pingshi = x.ER_SubmitedScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Peacetime).FirstOrDefault().Score == null ? (decimal?)null : Math.Round(x.ER_SubmitedScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Peacetime).FirstOrDefault().Score ?? 0, 0),
  109. Jishu = x.ER_SubmitedScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Technique).FirstOrDefault().Score == null ? (decimal?)null : Math.Round(x.ER_SubmitedScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Technique).FirstOrDefault().Score ?? 0, 0),
  110. Lilun = x.ER_SubmitedScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Theoretical).FirstOrDefault().Score == null ? (decimal?)null : Math.Round(x.ER_SubmitedScoreDetail.Where(q => q.ScoreTypeID == (int)EMIS.ViewModel.CF_ScoreType.Theoretical).FirstOrDefault().Score ?? 0, 0),
  111. HandleModeID = x.HandleModeID,
  112. };
  113. return query;
  114. }
  115. public virtual IQueryable<ER_SubmitedScore> GetLastSubmittedScore(Expression<Func<ER_SubmitedScore, bool>> exp)
  116. {
  117. var maxSubmitedScoreList = (
  118. from ss in submitedScoreRepository.Entities
  119. join mss in
  120. (
  121. from ss in submitedScoreRepository.Entities
  122. join mss in
  123. (
  124. from nss in submitedScoreRepository.GetList(exp)
  125. join ssl in submitedScoreRepository.Entities
  126. on new { nss.CoursematerialID, nss.UserID, nss.StarttermID }
  127. equals new { ssl.CoursematerialID, ssl.UserID, ssl.StarttermID }
  128. group ssl by new { ssl.UserID, ssl.CoursematerialID, ssl.StarttermID }
  129. into g
  130. select new { g.Key.UserID, g.Key.CoursematerialID, g.Key.StarttermID, MaxTotalScore = g.Max(x => x.TotalScore) })
  131. on new { ss.UserID, ss.CoursematerialID, ss.StarttermID, ss.TotalScore }
  132. equals new { mss.UserID, mss.CoursematerialID, mss.StarttermID, TotalScore = mss.MaxTotalScore }
  133. group ss by new { ss.UserID, ss.CoursematerialID, ss.StarttermID, ss.TotalScore } into g
  134. select new { g.Key.UserID, g.Key.CoursematerialID, g.Key.StarttermID, g.Key.TotalScore, CreateTime = g.Max(x => x.CreateTime) }
  135. )
  136. on new { ss.UserID, ss.CoursematerialID, ss.StarttermID, ss.TotalScore, ss.CreateTime }
  137. equals new { mss.UserID, mss.CoursematerialID, mss.StarttermID, TotalScore = mss.TotalScore, mss.CreateTime }
  138. group ss by new { ss.UserID, ss.CoursematerialID, ss.StarttermID } into g
  139. select new { g.Key.UserID, g.Key.CoursematerialID, g.Key.StarttermID, SubmitedScoreID = g.Max(x => x.SubmitedScoreID.ToString()) }
  140. );
  141. var lastSubmittedScoreList = (from ssl in submitedScoreRepository.Entities
  142. join mss in maxSubmitedScoreList
  143. on ssl.SubmitedScoreID.ToString() equals mss.SubmitedScoreID
  144. select ssl);
  145. return lastSubmittedScoreList;
  146. }
  147. public virtual IQueryable<ER_SubmitedScore> GetLastSubmittedScoreBeforDelete(Expression<Func<ER_SubmitedScore, bool>> exp)
  148. {
  149. var maxSubmitedScoreList = (
  150. from ss in submitedScoreRepository.Entities
  151. join nss in submitedScoreRepository.GetList(exp)
  152. on new { ss.UserID, ss.CoursematerialID, ss.StarttermID }
  153. equals new { nss.UserID, nss.CoursematerialID, nss.StarttermID }
  154. join mss in
  155. (from ss in submitedScoreRepository.Entities
  156. join nss in submitedScoreRepository.GetList(exp)
  157. on new { ss.UserID, ss.CoursematerialID, ss.StarttermID }
  158. equals new { nss.UserID, nss.CoursematerialID, nss.StarttermID }
  159. join mss in
  160. (from ssl in submitedScoreRepository.Entities
  161. join nss in submitedScoreRepository.GetList(exp)
  162. on new { ssl.UserID, ssl.CoursematerialID, ssl.StarttermID }
  163. equals new { nss.UserID, nss.CoursematerialID, nss.StarttermID }
  164. where ssl.SubmitedScoreID != nss.SubmitedScoreID
  165. group ssl by new { ssl.UserID, ssl.CoursematerialID, ssl.StarttermID }
  166. into g
  167. select new { g.Key.UserID, g.Key.CoursematerialID, g.Key.StarttermID, MaxTotalScore = g.Max(x => x.TotalScore) })
  168. on new { ss.UserID, ss.CoursematerialID, ss.StarttermID, ss.TotalScore }
  169. equals new { mss.UserID, mss.CoursematerialID, mss.StarttermID, TotalScore = mss.MaxTotalScore }
  170. where ss.SubmitedScoreID != nss.SubmitedScoreID
  171. group ss by new { ss.UserID, ss.CoursematerialID, ss.StarttermID, ss.TotalScore } into g
  172. select new { g.Key.UserID, g.Key.CoursematerialID, g.Key.StarttermID, g.Key.TotalScore, CreateTime = g.Max(x => x.CreateTime) })
  173. on new { ss.UserID, ss.CoursematerialID, ss.StarttermID, ss.TotalScore, ss.CreateTime }
  174. equals new { mss.UserID, mss.CoursematerialID, mss.StarttermID, mss.TotalScore, mss.CreateTime }
  175. where ss.SubmitedScoreID != nss.SubmitedScoreID
  176. group ss by new { ss.UserID, ss.CoursematerialID, ss.StarttermID, ss.TotalScore } into g
  177. select g.Max(x => x.SubmitedScoreID.ToString())
  178. );
  179. var lastSubmittedScoreList = (from ssl in submitedScoreRepository.Entities
  180. join mss in maxSubmitedScoreList
  181. on ssl.SubmitedScoreID.ToString() equals mss
  182. select ssl);
  183. return lastSubmittedScoreList;
  184. }
  185. public IQueryable<ER_FinallyScore> GetFinallyScoreBySubmittedScore(Expression<Func<ER_SubmitedScore, bool>> exp)
  186. {
  187. var lastFinallyScoreList = (from ssl in submitedScoreRepository.GetList(exp)
  188. .Select(x => new { x.UserID, x.CoursematerialID, x.StarttermID }).Distinct()
  189. join fs in FinallyScoreRepository.Entities
  190. on new { ssl.UserID, ssl.CoursematerialID, ssl.StarttermID }
  191. equals new { fs.UserID, fs.CoursematerialID, fs.StarttermID }
  192. select fs).Include(x => x.ER_FinallyScoreDetail);
  193. return lastFinallyScoreList;
  194. }
  195. public IQueryable<ER_SubmitedScore> GetSubmitedScoreByExaminationExemption(Expression<Func<ER_ExaminationExemption, bool>> examinationExemptsionExp)
  196. {
  197. var query = (from exemption in ExaminationExemptionRepository.GetList(examinationExemptsionExp)
  198. join score in submitedScoreRepository.Entities
  199. on new { exemption.SchoolyearID, exemption.CoursematerialID, exemption.ExamsCategoryID, exemption.UserID }
  200. equals new { score.SchoolyearID, score.CoursematerialID, score.ExamsCategoryID, score.UserID }
  201. select score);
  202. return query;
  203. }
  204. public IQueryable<ER_SubmitedScore> GetSubmitedScoreByMisconduct(Expression<Func<ER_Misconduct, bool>> misconductExp)
  205. {
  206. var query = (from exemption in MisconductRepository.GetList(misconductExp)
  207. join score in submitedScoreRepository.Entities
  208. on new { exemption.SchoolyearID, exemption.CoursematerialID, exemption.ExamsCategoryID, exemption.UserID }
  209. equals new { score.SchoolyearID, score.CoursematerialID, score.ExamsCategoryID, score.UserID }
  210. select score);
  211. return query;
  212. }
  213. public IQueryable<FinallyScoreView> GetFinallyScoreViewQueryable(Expression<Func<ER_FinallyScore, bool>> exp)
  214. {
  215. var query = (from score in FinallyScoreRepository.GetList(exp)
  216. from student in studentRepository.Entities.Where(x => x.UserID == score.UserID)
  217. from classmajor in classmajorRepository.Entities.Where(x => x.ClassmajorID == student.ClassmajorID)
  218. from grade in GrademajorRepository.Entities.Where(x => x.GrademajorID == classmajor.GrademajorID)
  219. from faculty in FacultymajorRepository.Entities.Where(x => x.FacultymajorID == grade.FacultymajorID)
  220. from college in CollegeRepository.Entities.Where(x => x.CollegeID == faculty.CollegeID)
  221. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == score.SchoolyearID)
  222. from department in DepartmentRepository.Entities.Where(x => x.DepartmentID == score.DepartmentID)
  223. from sourcecourse in CoursematerialRepository.Entities.Where(x => x.CoursematerialID == score.CoursematerialID)
  224. from user in userRepository.Entities.Where(x => x.UserID == score.UserID)
  225. from creatoruser in userRepository.Entities.Where(x => x.UserID == score.CreatorUserID).DefaultIfEmpty()
  226. from createuser in userRepository.Entities.Where(x => x.UserID == score.CreateUserID).DefaultIfEmpty()
  227. where score.TotalScore >= 60
  228. select new FinallyScoreView
  229. {
  230. FinallyScoreID = score.FinallyScoreID,
  231. SchoolyearID = score.SchoolyearID,
  232. SchoolyearCode = schoolyear.Code,
  233. SchoolyearNumID = score.SchoolyearNumID,
  234. ClassName = classmajor.Name,
  235. CollegeID = faculty.CollegeID,
  236. CollegeName = college.Name,
  237. DepartmentID = score.DepartmentID,
  238. DepartmentName = department.Name,
  239. CoursematerialID = score.CoursematerialID,
  240. CourseCode = sourcecourse.CourseCode,
  241. CourseName = sourcecourse.CourseName,
  242. CourseTypeID = score.CourseTypeID,
  243. ExamsCategoryID = score.ExamsCategoryID,
  244. ExaminationModeID = score.ExaminationModeID,
  245. Credit = score.Credit,
  246. TotalHours = score.TotalHours,
  247. ExamsDatetime = score.ExamsDatetime,
  248. ResultTypeID = score.ResultTypeID,
  249. CreatorUserID = score.CreatorUserID,
  250. CreatorUserName = creatoruser.Name,
  251. EntryDeadlineTime = score.EntryDeadlineTime,
  252. ExaminationType = score.ExaminationType,
  253. StarttermID = score.StarttermID,
  254. UserID = score.UserID,
  255. LoginID = user.LoginID,
  256. UserName = user.Name,
  257. ExamsStateID = score.ExamsStateID,
  258. TotalScore = score.TotalScore,
  259. ScoreCredit = score.ScoreCredit,
  260. GradePoint = score.GradePoint,
  261. Remarks = score.Remark,
  262. CreateTime = score.CreateTime,
  263. CreateUserID = score.CreateUserID
  264. });
  265. return query;
  266. }
  267. public IQueryable<CoursematerialView> GetCoursematerialViewQueryableByFinallyScore(Expression<Func<ER_FinallyScore, bool>> exp)
  268. {
  269. var coursematerialQueryable = this.CoursematerialDAL.Value.GetCoursematerialViewQueryable(x => true);
  270. var query = (from score in FinallyScoreRepository.GetList(exp)
  271. from course in coursematerialQueryable.Where(x => x.CoursematerialID == score.CoursematerialID)
  272. where score.TotalScore >= 60
  273. select course).Distinct();
  274. return query;
  275. }
  276. }
  277. }