SatisfyRateDAL.cs 7.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.EvaluationManage;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. namespace EMIS.DataLogic.Common.EvaluationManage
  10. {
  11. public class SatisfyRateDAL
  12. {
  13. public StaffRepository StaffRepository { get; set; }
  14. public CollegeRepository CollegeRepository { get; set; }
  15. public SchoolyearRepository SchoolyearRepository { get; set; }
  16. public EvaluationEnterRepository EvaluationEnterRepository { get; set; }
  17. public EvaluationEnter_EM_EvaluationProjectRepository EvaluationEnter_EM_EvaluationProjectRepository { get; set; }
  18. public EvaluationProjectRepository EvaluationProjectRepository { get; set; }
  19. public EvaluationTargetRepository EvaluationTargetRepository { get; set; }
  20. public EvaluationTableRepository EvaluationTableRepository { get; set; }
  21. public EvaluationTypeRepository EvaluationTypeRepository { get; set; }
  22. public EvaluationNormRepository EvaluationNormRepository { get; set; }
  23. public EducationMissionRepository EducationMissionRepository { get; set; }
  24. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  25. public UserRepository UserRepository { get; set; }
  26. public IQueryable<SatisfyRateView> GetUserSatisfyRateView(Expression<Func<CF_Staff, bool>> exp, Expression<Func<EM_EvaluationType, bool>> typeExp)
  27. {
  28. var query = (from staff in StaffRepository.GetList(exp)
  29. join college in CollegeRepository.Entities on staff.CollegeID equals college.CollegeID
  30. join user in UserRepository.Entities on staff.UserID equals user.UserID
  31. from missionClassTeacher in staff.EM_MissionClassTeacher
  32. join missionClass in EducationMissionClassRepository.Entities on missionClassTeacher.MissionClassID equals missionClass.EducationMissionClassID
  33. join mission in EducationMissionRepository.Entities on missionClass.EducationMissionID equals mission.EducationMissionID
  34. join score in EvaluationEnterRepository.Entities on missionClassTeacher.MissionClassID equals score.EducationMissionClassID
  35. join scoreDetail in EvaluationEnter_EM_EvaluationProjectRepository.Entities on score.EvaluationEnterID equals scoreDetail.EvaluationEnterID
  36. join project in EvaluationProjectRepository.Entities on scoreDetail.ProjectID equals project.EvaluationProjectID
  37. join target in EvaluationTargetRepository.Entities on project.EvaluationTargetID equals target.EvaluationTargetID
  38. join table in EvaluationTableRepository.Entities on target.EvaluationTableID equals table.EvaluationTableID
  39. join type in EvaluationTypeRepository.GetList(typeExp) on table.EvaluationTypeID equals type.EvaluationTypeID
  40. join norm in EvaluationNormRepository.Entities on target.EvaluationNormID equals norm.EvaluationNormID
  41. join schoolyear in SchoolyearRepository.GetList(x => x.IsCurrent == true) on mission.SchoolyearID equals schoolyear.SchoolyearID
  42. where score.StudentUserID != null
  43. group new { score, scoreDetail, norm } by new { user.UserID, user.LoginID, user.Name, staff.TeacherTypeID,
  44. college.CollegeID, CollegeName = college.Name, TypeID = type.EvaluationTypeID, TypeName = type.Name } into g
  45. select new SatisfyRateView
  46. {
  47. UserID = g.Key.UserID,
  48. LoginID = g.Key.LoginID,
  49. Name = g.Key.Name,
  50. TeacherType = g.Key.TeacherTypeID,
  51. CollegeID = g.Key.CollegeID,
  52. CollegeName = g.Key.Name,
  53. EvaluationTypeID = g.Key.TypeID,
  54. EvaluationTypeName = g.Key.TypeName,
  55. SatisfyRate = ((decimal?)g.Sum(x => (x.scoreDetail.EvaluationScore >= x.norm.SatisfyWeight) ? 1 : 0) / g.Sum(x => 1) * 100)
  56. }).Concat(
  57. (from staff in StaffRepository.GetList(exp)
  58. join college in CollegeRepository.Entities on staff.CollegeID equals college.CollegeID
  59. join user in UserRepository.Entities on staff.UserID equals user.UserID
  60. from missionClassTeacher in staff.EM_MissionClassTeacher
  61. join missionClass in EducationMissionClassRepository.Entities on missionClassTeacher.MissionClassID equals missionClass.EducationMissionClassID
  62. join mission in EducationMissionRepository.Entities on missionClass.EducationMissionID equals mission.EducationMissionID
  63. join score in EvaluationEnterRepository.Entities on missionClassTeacher.MissionClassID equals score.EducationMissionClassID
  64. join scoreDetail in EvaluationEnter_EM_EvaluationProjectRepository.Entities on score.EvaluationEnterID equals scoreDetail.EvaluationEnterID
  65. join project in EvaluationProjectRepository.Entities on scoreDetail.ProjectID equals project.EvaluationProjectID
  66. join target in EvaluationTargetRepository.Entities on project.EvaluationTargetID equals target.EvaluationTargetID
  67. join table in EvaluationTableRepository.Entities on target.EvaluationTableID equals table.EvaluationTableID
  68. join type in EvaluationTypeRepository.GetList(typeExp) on table.EvaluationTypeID equals type.EvaluationTypeID
  69. join norm in EvaluationNormRepository.Entities on target.EvaluationNormID equals norm.EvaluationNormID
  70. join schoolyear in SchoolyearRepository.GetList(x => x.IsCurrent == true) on mission.SchoolyearID equals schoolyear.SchoolyearID
  71. where score.StaffUserID != null
  72. group new { score, scoreDetail, norm } by new { user.UserID, user.LoginID, user.Name, staff.TeacherTypeID,
  73. college.CollegeID,
  74. CollegeName = college.Name,
  75. TypeID = type.EvaluationTypeID,
  76. TypeName = type.Name
  77. } into g
  78. select new SatisfyRateView
  79. {
  80. UserID = g.Key.UserID,
  81. LoginID = g.Key.LoginID,
  82. Name = g.Key.Name,
  83. TeacherType = g.Key.TeacherTypeID,
  84. CollegeID = g.Key.CollegeID,
  85. CollegeName = g.Key.Name,
  86. EvaluationTypeID = g.Key.TypeID,
  87. EvaluationTypeName = g.Key.TypeName,
  88. SatisfyRate = ((decimal?)g.Sum(x => (x.scoreDetail.EvaluationScore >= x.norm.SatisfyWeight) ? 1 : 0) / g.Sum(x => 1) * 100)
  89. })
  90. );
  91. return query;
  92. }
  93. }
  94. }