StudentScoreDAL.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.Entity;
  6. using System.Linq.Expressions;
  7. using EMIS.Entities;
  8. using EMIS.DataLogic.Repositories;
  9. namespace EMIS.ExtensionLogic.DataLogic.ScoreManage
  10. {
  11. public class StudentScoreDAL : EMIS.DataLogic.ScoreManage.StudentScoreDAL
  12. {
  13. public CourseTypeSelectCourseTypeRepository CourseTypeSelectCourseTypeRepository { get; set; }
  14. public override IQueryable<ER_SubmitedScore> GetLastSubmittedScoreBeforDelete(Expression<Func<ER_SubmitedScore, bool>> exp)
  15. {
  16. var maxSubmitedScoreList = (
  17. from ss in submitedScoreRepository.Entities
  18. join nss in submitedScoreRepository.GetList(exp)
  19. on new { ss.UserID, ss.CoursematerialID }
  20. equals new { nss.UserID, nss.CoursematerialID }
  21. join ctsc in CourseTypeSelectCourseTypeRepository.Entities
  22. on ss.CourseTypeID equals ctsc.CourseTypeID into dctsc
  23. from ctsc in dctsc.DefaultIfEmpty()
  24. join mss in
  25. (from ssl in submitedScoreRepository.Entities
  26. join nss in submitedScoreRepository.GetList(exp)
  27. on new { ssl.UserID, ssl.CoursematerialID }
  28. equals new { nss.UserID, nss.CoursematerialID }
  29. join ctsc1 in CourseTypeSelectCourseTypeRepository.Entities
  30. on ssl.CourseTypeID equals ctsc1.CourseTypeID into dctsc1
  31. from ctsc1 in dctsc1.DefaultIfEmpty()
  32. where ssl.SubmitedScoreID != nss.SubmitedScoreID
  33. group new { Score = ssl, SelectCourseType = ctsc1 } by new { ssl.UserID, ssl.CoursematerialID }
  34. into g
  35. select new
  36. {
  37. g.Key.UserID,
  38. g.Key.CoursematerialID,
  39. IsRequired = g.Max(x => (x.SelectCourseType.IsRequired == true) ? 1 : 0) == 1,
  40. MaxCreateTime = g.Max(x => (x.SelectCourseType.IsRequired == true) ? 1 : 0) == 1 ? g.Max(x => (x.SelectCourseType.IsRequired == true) ? x.Score.CreateTime : null) : g.Max(x => x.Score.CreateTime)
  41. })
  42. on new { ss.UserID, ss.CoursematerialID, IsRequired = ctsc.IsRequired.Value, ss.CreateTime }
  43. equals new { mss.UserID, mss.CoursematerialID, IsRequired = mss.IsRequired, CreateTime = mss.MaxCreateTime }
  44. where ss.SubmitedScoreID != nss.SubmitedScoreID
  45. group ss by new { ss.UserID, ss.CoursematerialID, ss.CreateTime } into g
  46. select (g.Max(x => x.SubmitedScoreID.ToString()))
  47. );
  48. //这个算法,需要找条重录完后还有成绩的学生来试试
  49. var lastSubmittedScoreList = (from mss in maxSubmitedScoreList
  50. join ssl in submitedScoreRepository.Entities
  51. on mss equals ssl.SubmitedScoreID.ToString()
  52. select ssl);
  53. return lastSubmittedScoreList;
  54. }
  55. public override IQueryable<ER_SubmitedScore> GetLastSubmittedScore(Expression<Func<ER_SubmitedScore, bool>> exp)
  56. {
  57. var maxSubmitedScoreList = (
  58. from ss in submitedScoreRepository.Entities
  59. join ctsc in CourseTypeSelectCourseTypeRepository.Entities
  60. on ss.CourseTypeID equals ctsc.CourseTypeID into dctsc
  61. from ctsc in dctsc.DefaultIfEmpty()
  62. join mss in
  63. (
  64. from ssl in submitedScoreRepository.GetList(exp)
  65. join ssm in submitedScoreRepository.Entities on new
  66. {
  67. ssl.UserID,
  68. ssl.CoursematerialID
  69. } equals new { ssm.UserID, ssm.CoursematerialID }
  70. join ctsc1 in CourseTypeSelectCourseTypeRepository.Entities
  71. on ssm.CourseTypeID equals ctsc1.CourseTypeID into dctsc1
  72. from ctsc1 in dctsc1.DefaultIfEmpty()
  73. group new { Score = ssm, SelectCourseType = ctsc1 }
  74. by new { ssm.UserID, ssm.CoursematerialID }
  75. into g
  76. select new
  77. {
  78. g.Key.UserID,
  79. g.Key.CoursematerialID,
  80. IsRequired = g.Max(x => x.SelectCourseType.IsRequired.Value ? 1 : 0) == 1,
  81. MaxCreateTime = (g.Max(x => x.SelectCourseType.IsRequired.Value ? 1 : 0) == 1) ? g.Max(x => (x.SelectCourseType.IsRequired.Value) ? x.Score.CreateTime : null) : g.Max(x => x.Score.CreateTime)
  82. }
  83. )
  84. on
  85. new { ss.UserID, ss.CoursematerialID, IsRequired = ctsc.IsRequired.Value, ss.CreateTime }
  86. equals
  87. new { mss.UserID, mss.CoursematerialID, IsRequired = mss.IsRequired, CreateTime = mss.MaxCreateTime }
  88. group ss by new { ss.UserID, ss.CoursematerialID, ss.CreateTime }
  89. into g
  90. select g.Max(x => x.SubmitedScoreID.ToString())
  91. );
  92. var lastSubmittedScoreList = (from ssl in submitedScoreRepository.Entities
  93. join mss in maxSubmitedScoreList
  94. on ssl.SubmitedScoreID.ToString() equals mss
  95. select ssl);
  96. return lastSubmittedScoreList;
  97. }
  98. }
  99. }