TeacherScheduleSettingDAL.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.SchedulingManage.SchedulingSettings;
  7. using EMIS.Entities;
  8. using System.Linq.Expressions;
  9. using EMIS.ViewModel.CalendarManage;
  10. using EMIS.ViewModel;
  11. namespace EMIS.DataLogic.SchedulingManage.SchedulingSettings
  12. {
  13. public class TeacherScheduleSettingDAL
  14. {
  15. public TeacherScheduleSettingRepository teacherScheduleSettingRepository { get; set; }
  16. public StaffRepository staffRepository { get; set; }
  17. public DictionaryItemRepository dictionaryItemRepository { get; set; }
  18. public CoursesTimeRepository coursesTimeRepository { get; set; }
  19. /// <summary>
  20. /// 获取已经教师可排时间设置
  21. /// </summary>
  22. /// <param name="exp"></param>
  23. /// <returns></returns>
  24. public IQueryable<TeacherScheduleSettingView> GetTeacherScheduleSettingViewQueryable(Expression<Func<CF_Staff, bool>> exp)
  25. {
  26. var query = from a in staffRepository.GetList(exp)
  27. join c in dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_TeacherType).Name)
  28. on a.TeacherTypeID equals c.Value into gtt
  29. from gTeacherType in gtt.DefaultIfEmpty()
  30. join d in dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_IncumbencyState).Name)
  31. on a.IncumbencyState equals d.Value into gis
  32. from gIncumbencyState in gis.DefaultIfEmpty()
  33. join e in dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_Title).Name)
  34. on a.TitleID equals e.Value into gt
  35. from gTitle in gt.DefaultIfEmpty()
  36. select new TeacherScheduleSettingView
  37. {
  38. UserID = a.UserID,
  39. StaffCode = a.Sys_User.LoginID,
  40. StaffName = a.Sys_User.Name,
  41. TeacherTypeName = gTeacherType.Name,
  42. IncumbencyStateName = gIncumbencyState.Name,
  43. TitleName = gTitle.Name,
  44. CollegeName = a.CF_College.Name,
  45. CreateUserID = a.CreateUserID,
  46. CreateTime = a.CreateTime
  47. };
  48. return query;
  49. }
  50. /// <summary>
  51. /// 获取教师可排时间设置
  52. /// </summary>
  53. /// <param name="userID"></param>
  54. /// <returns></returns>
  55. public IQueryable<ArrangementView> GetArrangementViewQueryable(Guid? userID)
  56. {
  57. var query = from a in coursesTimeRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  58. join b in
  59. teacherScheduleSettingRepository.GetList(x => x.UserID == userID)
  60. on a.CoursesTimeID equals b.CoursesTimeID
  61. group a by new
  62. {
  63. CoursesTimeID = a.CoursesTimeID,
  64. StartTimes = a.StartTimes,
  65. EndTimes = a.EndTimes,
  66. TimesSegment = a.TimesSegment,
  67. StartHour = a.StartHour,
  68. StartMinutes = a.StartMinutes,
  69. EndHour = a.EndHour,
  70. EndMinutes = a.EndMinutes,
  71. CreateTime = a.CreateTime,
  72. CreateUserID = a.CreateUserID,
  73. MondayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Monday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
  74. TuesdayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Tuesday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
  75. WednesdayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Wednesday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
  76. ThursdayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Thursday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
  77. FridayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Friday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
  78. SaturdayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Saturday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
  79. SundayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Sunday && x.UserID == b.UserID).FirstOrDefault().IsOnWork
  80. }into g
  81. select new ArrangementView
  82. {
  83. CoursesTimeID = g.Key.CoursesTimeID,
  84. StartTimes = g.Key.StartTimes,
  85. EndTimes = g.Key.EndTimes,
  86. TimesSegment = g.Key.TimesSegment,
  87. StartHour = g.Key.StartHour,
  88. StartMinutes = g.Key.StartMinutes,
  89. EndHour = g.Key.EndHour,
  90. EndMinutes = g.Key.EndMinutes,
  91. CreateTime = g.Key.CreateTime,
  92. CreateUserID = g.Key.CreateUserID,
  93. MondayIsOnWork = g.Key.MondayIsOnWork,
  94. TuesdayIsOnWork = g.Key.TuesdayIsOnWork,
  95. WednesdayIsOnWork = g.Key.WednesdayIsOnWork,
  96. ThursdayIsOnWork = g.Key.ThursdayIsOnWork,
  97. FridayIsOnWork = g.Key.FridayIsOnWork,
  98. SaturdayIsOnWork = g.Key.SaturdayIsOnWork,
  99. SundayIsOnWork = g.Key.SundayIsOnWork,
  100. };
  101. return query;
  102. }
  103. }
  104. }