PaymentDAL.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using EMIS.ViewModel.PaymentManage;
  7. using EMIS.Entities;
  8. using EMIS.DataLogic.Repositories;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.PaymentManage
  11. {
  12. public class PaymentDAL
  13. {
  14. public StaffRepository StaffRepository { get; set; }
  15. public StaffProfileRepository StaffProfileRepository { get; set; }
  16. public UserRepository UserRepository { get; set; }
  17. public SchoolyearRepository SchoolyearRepository { get; set; }
  18. public GrademajorRepository GrademajorRepository { get; set; }
  19. public CollegeRepository CollegeRepository { get; set; }
  20. public CourseTimeHoursRepository CourseTimeHoursRepository { get; set; }
  21. public CoursematerialRepository CoursematerialRepository { get; set; }
  22. public FacultymajorRepository FacultymajorRepository { get; set; }
  23. public EducationMissionRepository EducationMissionRepository { get; set; }
  24. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  25. public EducationMissionClassTeachingSettingRepository EducationMissionClassTeachingSettingRepository { get; set; }
  26. public ExaminationExemptionRepository ExaminationExemptionRepository { get; set; }
  27. public PaymentStandardRepository PaymentStandardRepository { get; set; }
  28. public LearningformRateRepository LearningformRateRepository { get; set; }
  29. public StudentCountRateRepository StudentCountRateRepository { get; set; }
  30. public PracticeRateRepository PracticeRateRepository { get; set; }
  31. public IQueryable<PaymentDetailView> GetPaymentDetailViewQueryable(Expression<Func<CF_Staff, bool>> staffExp,
  32. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp,
  33. Expression<Func<EM_EducationMission, bool>> missionExp,
  34. Expression<Func<EM_Coursematerial, bool>> coursematerialExp)
  35. {
  36. var query = (from staff in StaffRepository.GetList(staffExp)
  37. join profile in StaffProfileRepository.Entities on staff.UserID equals profile.UserID
  38. join user in UserRepository.Entities on staff.UserID equals user.UserID
  39. from teacher in staff.EM_MissionClassTeacher.GroupBy(x => x.MissionClassID).Select(x => x.FirstOrDefault())
  40. join missionClass in EducationMissionClassRepository.GetList(x => x.RecordStatus == (int)EM_EducationMissionClassStatus.Scheduled)
  41. on teacher.MissionClassID equals missionClass.EducationMissionClassID
  42. join teachSetting in EducationMissionClassTeachingSettingRepository.Entities on missionClass.EducationMissionClassID equals teachSetting.EducationMissionClassID
  43. join mission in EducationMissionRepository.GetList(missionExp) on missionClass.EducationMissionID equals mission.EducationMissionID
  44. join college in CollegeRepository.Entities on mission.CollegeID equals college.CollegeID
  45. join schoolyear in SchoolyearRepository.GetList(schoolyearExp) on mission.SchoolyearID equals schoolyear.SchoolyearID
  46. join course in CoursematerialRepository.GetList(coursematerialExp) on missionClass.CoursematerialID equals course.CoursematerialID
  47. join faculty in
  48. (
  49. from missionClass in EducationMissionClassRepository.Entities
  50. from studentClass in missionClass.CF_Classmajor
  51. join grade in GrademajorRepository.Entities on studentClass.GrademajorID equals grade.GrademajorID
  52. join faculty in FacultymajorRepository.Entities on grade.FacultymajorID equals faculty.FacultymajorID
  53. group faculty by new { missionClass.EducationMissionClassID, faculty.EducationID, faculty.LearningformID } into g
  54. select new { g.Key.EducationMissionClassID, g.Key.EducationID, g.Key.LearningformID }
  55. ) on missionClass.EducationMissionClassID equals faculty.EducationMissionClassID
  56. join timeSegment in
  57. (
  58. from missionClass in EducationMissionClassRepository.Entities
  59. from courseTime in missionClass.EM_CoursesTime
  60. join courseTimeHours in CourseTimeHoursRepository.Entities
  61. on new { CoursesTimeID = (Guid?)courseTime.CoursesTimeID, Years = (int?)missionClass.CF_Classmajor.Max(x => x.CF_Grademajor.GradeID) } equals new { courseTimeHours.CoursesTimeID, courseTimeHours.Years }
  62. into dcourseTimeHours
  63. from courseTimeHours in dcourseTimeHours.DefaultIfEmpty()
  64. group new { courseTime, courseTimeHours } by new { missionClass.EducationMissionClassID, courseTime.TimesSegment } into g
  65. select new { g.Key.EducationMissionClassID, g.Key.TimesSegment, Hours = g.Sum(x => x.courseTimeHours.Hours ?? (x.courseTime.EndTimes - x.courseTime.StartTimes + 1)) }
  66. ) on missionClass.EducationMissionClassID equals timeSegment.EducationMissionClassID
  67. join exemption in
  68. (
  69. from exemption in ExaminationExemptionRepository.Entities
  70. from schedulingClass in exemption.CF_Student.EM_EducationSchedulingClass.Where(x => x.EM_EducationMissionClass.CoursematerialID == exemption.CoursematerialID
  71. && exemption.SchoolyearID == x.EM_EducationMissionClass.EM_EducationMission.SchoolyearID)
  72. where exemption.ExamsCategoryID == (int)CF_ExamsCategory.FinalExam
  73. group exemption by new { schedulingClass.EducationMissionClassID } into g
  74. select new { g.Key.EducationMissionClassID, StudentCount = (int?)g.Count() }
  75. ) on missionClass.EducationMissionClassID equals exemption.EducationMissionClassID into dexemption
  76. from eexemption in dexemption.DefaultIfEmpty()
  77. join paymentStandard in PaymentStandardRepository.Entities on new { staff.TitleID, staff.TeacherTypeID } equals new { TitleID = paymentStandard.Title, TeacherTypeID = paymentStandard.TeacherType }
  78. join learnformRate in LearningformRateRepository.Entities on new { faculty.EducationID, faculty.LearningformID } equals new { learnformRate.EducationID, learnformRate.LearningformID }
  79. join studentCountRate in StudentCountRateRepository.GetList(x => x.Title.HasValue) on staff.TitleID equals studentCountRate.Title into dstudentCountRate
  80. from estudentCountRate in dstudentCountRate.DefaultIfEmpty()
  81. join defaultStudentCountRate in StudentCountRateRepository.GetList(x => !x.Title.HasValue) on true equals true into ddefaultStudentCountRate
  82. from edefaultStudentCountRate in ddefaultStudentCountRate.DefaultIfEmpty()
  83. join practiceRate in PracticeRateRepository.Entities on missionClass.CourseTypeID equals practiceRate.CourseTypeID
  84. select new PaymentDetailView
  85. {
  86. UserID = staff.UserID,
  87. LoginID = user.LoginID,
  88. UserName = user.Name,
  89. TeacherTypeID = staff.TeacherTypeID,
  90. TitleID = staff.TitleID,
  91. Account = profile.Account,
  92. SchoolyearID = schoolyear.SchoolyearID,
  93. SchoolyearCode = schoolyear.Code,
  94. CollegeID = mission.CollegeID,
  95. CollegeNo = college.No,
  96. CollegeName = college.Name,
  97. EducationID = faculty.EducationID,
  98. LearningformID = faculty.LearningformID,
  99. StudentCount = missionClass.EM_EducationSchedulingClass.SelectMany(x => x.CF_Student).Count(),
  100. ExaminationModeID = missionClass.ExaminationModeID,
  101. RetakeStudentCount = mission.ER_RetakePlanStudent.Count(),
  102. PracticeHours = teachSetting.Practicehours,
  103. CF_Classmajor = missionClass.CF_Classmajor,
  104. CoursematerialID = missionClass.CoursematerialID,
  105. CoursematerialName = course.CourseName,
  106. PlanTotalHours = teachSetting.TheoryCourse + teachSetting.Practicehours,
  107. TimeSegmentID = timeSegment.TimesSegment,
  108. ScheduleDayCount = missionClass.EM_EducationSchedulingClass
  109. .SelectMany(x => x.ES_AdultEducationSchedule
  110. .Where(w => w.ES_AdultEducationScheduleTeacher.Any(y => y.UserID == staff.UserID))
  111. ).Count(),
  112. CourseTimeHours = timeSegment.Hours,
  113. ExemptionCount = eexemption.StudentCount ?? 0,
  114. PaymentStandard = paymentStandard.Amount,
  115. LearningformRate = learnformRate.Rate,
  116. BaseStudentCount = estudentCountRate.BaseStudentCount ?? edefaultStudentCountRate.BaseStudentCount,
  117. StudentCountRateLimit = estudentCountRate.Limit ?? edefaultStudentCountRate.Limit,
  118. PracticeRate = practiceRate.Rate
  119. });
  120. return query;
  121. }
  122. }
  123. }