RetakeConditionDAL.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.RetakeManage;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.RetakeManage
  11. {
  12. public class RetakeConditionDAL
  13. {
  14. public RetakeConditionRepository RetakConditionRepository { get; set; }
  15. public RetakeConditionParameterRepository RetakeConditionParameterRepository { get; set; }
  16. public StudentRepository StudentRepository { get; set; }
  17. public InSchoolSettingRepository InSchoolSettingRepository { get; set; }
  18. public ParameterRepository ParameterRepository { get; set; }
  19. public RetakePlanStudentRepository RetakePlanStudentRepository { get; set; }
  20. public RetakeExamsCatagoryRepository RetakeExamsCatagoryRepository { get; set; }
  21. public CoursematerialRepository CoursematerialRepository { get; set; }
  22. public FinallyScoreRepository FinallyScoreRepository { get; set; }
  23. /// <summary>
  24. /// 查询重修条件限定信息View
  25. /// </summary>
  26. /// <param name="exp"></param>
  27. /// <returns></returns>
  28. public IQueryable<RetakeConditionView> GetRetakeConditionView(Expression<Func<ER_RetakeCondition, bool>> exp)
  29. {
  30. var q = (from condition in RetakConditionRepository.GetList(exp)
  31. select new RetakeConditionView
  32. {
  33. RetakeConditionID = condition.RetakeConditionID,
  34. RetakeConditionTypeID = condition.RetakeConditionTypeID,
  35. Title = condition.Title,
  36. MethodFullName = condition.MethodFullName,
  37. RecordStatus = condition.RecordStatus
  38. });
  39. return q;
  40. }
  41. /// <summary>
  42. /// 查询对应的重修条件参数
  43. /// </summary>
  44. /// <param name="parameterType"></param>
  45. /// <returns></returns>
  46. private string GetParameterValue(ER_RetakeParameterType parameterType)
  47. {
  48. return RetakeConditionParameterRepository.GetList(x => x.RetakeParameterTypeID == (int)parameterType
  49. && x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  50. .Select(x => x.Value).FirstOrDefault();
  51. }
  52. /// <summary>
  53. /// 重修条件限定查询(大于等于最小不及格门数且小于等于最大不及格门数)
  54. /// </summary>
  55. /// <param name="sourceView"></param>
  56. /// <returns></returns>
  57. public IQueryable<RetakeStudentListView> NoPassCondition(IQueryable<RetakeStudentListView> sourceView)
  58. {
  59. var minNoPassCount = Convert.ToInt32(GetParameterValue(ER_RetakeParameterType.MinNoPassCount) ?? "1");
  60. var maxNoPassCount = Convert.ToInt32(GetParameterValue(ER_RetakeParameterType.MaxNoPassCount) ?? "100");
  61. var query = (from retake in sourceView
  62. group retake by retake.UserID
  63. into g
  64. where g.Count() >= minNoPassCount && g.Count() <= maxNoPassCount
  65. select g).SelectMany(x => x.Select(w => w));
  66. return query;
  67. }
  68. public IQueryable<RetakeStudentView> GetRetakeStudentView()
  69. {
  70. var schoolyearIDStr = ParameterRepository.GetList(x => x.ParameterTypeID == (int)CF_ParameterType.RetakeSchoolyearID)
  71. .Select(x => x.Value).FirstOrDefault();
  72. Guid? schoolyearID = null;
  73. if (schoolyearIDStr != null)
  74. {
  75. schoolyearID = new Guid(schoolyearIDStr);
  76. }
  77. else
  78. {
  79. throw new Exception("未设置重修学年学期,请设置。");
  80. }
  81. var query = (from score in FinallyScoreRepository.GetList(x => x.TotalScore < 60 && x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  82. join type in RetakeExamsCatagoryRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  83. on score.ExamsCategoryID equals type.ExamsCategoryID
  84. join student in StudentRepository.Entities
  85. on score.UserID equals student.UserID
  86. join inschool in InSchoolSettingRepository.GetList(x => x.IsSelected == true)
  87. on student.InSchoolStatusID equals inschool.InSchoolStatusID
  88. join course in CoursematerialRepository.Entities
  89. on score.CoursematerialID equals course.CoursematerialID
  90. join retake in RetakePlanStudentRepository.GetList(x => x.ER_RetakePlan.SchoolyearID == schoolyearID)
  91. on
  92. new { score.CoursematerialID, score.CourseTypeID, score.Credit, score.UserID }
  93. equals
  94. new { retake.ER_RetakePlan.CoursematerialID, retake.ER_RetakePlan.CourseTypeID, retake.ER_RetakePlan.Credit, UserID = (Guid?)retake.UserID }
  95. into dretake
  96. from eretake in dretake.DefaultIfEmpty()
  97. where eretake.RetakePlanStudentID == null
  98. select new RetakeStudentView
  99. {
  100. CoursematerialID = score.CoursematerialID,
  101. Abbreviation = course.Abbreviation,
  102. CourseCode = course.CourseCode,
  103. CourseName = course.CourseName,
  104. CourseTypeID = score.CourseTypeID,
  105. UserID = score.UserID,
  106. Credit = score.Credit,
  107. SchoolyearNumID = score.SchoolyearNumID,
  108. StarttermID = score.StarttermID
  109. });
  110. return query;
  111. }
  112. }
  113. }