EducationMissionClassSchedulingASdultDAL.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel.EducationSchedule;
  6. using System.Linq.Expressions;
  7. using EMIS.Entities;
  8. using EMIS.DataLogic.Repositories;
  9. using EMIS.ViewModel.EducationManagement;
  10. using EMIS.ViewModel.EducationManage;
  11. using EMIS.Utility;
  12. namespace EMIS.DataLogic.EducationSchedule
  13. {
  14. public class EducationMissionClassSchedulingASdultDAL
  15. {
  16. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  17. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  18. public EducationMissionClassSettingsRepository EducationMissionClassSettingsRepository { get; set; }
  19. public EducationMissionClassTeachingSettingRepository EducationMissionClassTeachingSettingRepository { get; set; }
  20. public EducationMissionRepository EducationMissionRepository { get; set; }
  21. public MissionClassTeacherRepository MissionClassTeacherRepository { get; set; }
  22. public EducationSchedulingClassRepository EducationSchedulingClassRepository { get; set; }
  23. public StudentRepository StudentRepository { get; set; }
  24. public UserRepository UserRepository { get; set; }
  25. public ClassmajorRepository ClassmajorRepository { get; set; }
  26. public CourseProcessRepository CourseProcessRepository { get; set; }
  27. public EducationMissionRepository educationMissionRepository { get; set; }
  28. public ClassroomRepository ClassroomRepository { get; set; }
  29. public CourseTimeHoursRepository CourseTimeHoursRepository { get; set; }
  30. public CoursematerialRepository CoursematerialRepository { get; set; }
  31. public GrademajorRepository GrademajorRepository { get; set; }
  32. public FacultymajorRepository FacultymajorRepository { get; set; }
  33. public CollegeRepository CollegeRepository { get; set; }
  34. public DepartmentRepository DepartmentRepository { get; set; }
  35. public SchoolyearRepository SchoolyearRepository { get; set; }
  36. public EducationMissionExamTimeRepository EducationMissionExamTimeRepository { get; set; }
  37. public EducationMissionExamWeekNumRepository EducationMissionExamWeekNumRepository { get; set; }
  38. public EducationSchedulingWeekNumRepository EducationSchedulingWeekNumRepository { get; set; }
  39. public AdultEducationScheduleRepository AdultEducationScheduleRepository{get;set;}
  40. public AdultEducationScheduleTeacherRepository AdultEducationScheduleTeacherRepository{get;set;}
  41. public EducationSchedulingRepository EducationSchedulingRepository { get; set; }
  42. /// <summary>
  43. /// 查询教学任务班数据
  44. /// </summary>
  45. /// <param name="exp"></param>
  46. /// <returns></returns>
  47. public IQueryable<EducationMissionImportClassView> GetEducationMissionClassViewQuery(Expression<Func<EM_EducationMissionClass, bool>> missionClassExp,
  48. Expression<Func<EM_ExecutablePlan, bool>> executablePlanExp, Expression<Func<EM_ExecutableOptionalCourse, bool>> executableOptionalCourseExp,
  49. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> executableFreeSelectionCourseCourseExp)
  50. {
  51. TimeSpan s = new TimeSpan();
  52. DateTime d = new DateTime();
  53. var query = from missionClass in EducationMissionClassRepository.GetList(missionClassExp)
  54. join mission in EducationMissionRepository.Entities on missionClass.EducationMissionID equals mission.EducationMissionID
  55. join teachSetting in EducationMissionClassTeachingSettingRepository.Entities on missionClass.EducationMissionClassID equals teachSetting.EducationMissionClassID
  56. join classmajor in ClassmajorRepository.Entities on missionClass.MainScheduleClassID equals classmajor.ClassmajorID into dclassmajor
  57. from classmajor in dclassmajor.DefaultIfEmpty()
  58. join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID into dgrade
  59. from grade in dgrade.DefaultIfEmpty()
  60. join faculty in FacultymajorRepository.Entities on grade.FacultymajorID equals faculty.FacultymajorID into dfaculty
  61. from faculty in dfaculty.DefaultIfEmpty()
  62. join college in CollegeRepository.Entities on mission.CollegeID equals college.CollegeID
  63. join department in DepartmentRepository.Entities on mission.DepartmentID equals department.DepartmentID
  64. join schoolyear in SchoolyearRepository.Entities on mission.SchoolyearID equals schoolyear.SchoolyearID
  65. join course in CoursematerialRepository.Entities on missionClass.CoursematerialID equals course.CoursematerialID
  66. join schedulingClass in
  67. (
  68. from sc in EducationSchedulingClassRepository.Entities
  69. group sc by sc.EducationMissionClassID into g
  70. select new
  71. {
  72. EducationMissionClassID = g.Key,
  73. ClassNum = g.Sum(x => x.CF_Student.Count())
  74. }
  75. ) on missionClass.EducationMissionClassID equals schedulingClass.EducationMissionClassID into dschedulingClass
  76. from schedulingClass in dschedulingClass.DefaultIfEmpty()
  77. join courseProcess in
  78. (from cp in CourseProcessRepository.Entities
  79. group cp by cp.EducationMissionClassID into g
  80. select new
  81. {
  82. EducationMissionClassID = g.Key,
  83. CourseProcessTimes = g.Sum(x => x.Times)
  84. }) on missionClass.EducationMissionClassID equals courseProcess.EducationMissionClassID into dcourseProcess
  85. from courseProcess in dcourseProcess.DefaultIfEmpty()
  86. join week in
  87. (from schedule in AdultEducationScheduleRepository.Entities
  88. group schedule by schedule.EM_EducationSchedulingClass.EducationMissionClassID into g
  89. select new
  90. {
  91. EducationMissionClassID = g.Key,
  92. ScheduledTimes = g.Select(x => x.ScheduleDate).ToList(),
  93. ClassroomName = g.Select(x => x.CF_Classroom.Name).FirstOrDefault()
  94. }) on missionClass.EducationMissionClassID equals week.EducationMissionClassID into dweek
  95. from week in dweek.DefaultIfEmpty()
  96. join assistant in UserRepository.Entities on classmajor.UserID equals assistant.UserID into dassistant
  97. from assistant in dassistant.DefaultIfEmpty()
  98. join examtime in EducationMissionExamTimeRepository.Entities on missionClass.EducationMissionID equals examtime.EducationMissionID into dexamtime
  99. from examtime in dexamtime.DefaultIfEmpty()
  100. join examweek in
  101. (from ew in EducationMissionExamWeekNumRepository.Entities
  102. group ew by ew.EducationMissionID into g
  103. select new
  104. {
  105. EducationMissionID = g.Key,
  106. WeeklyNum = g.Select(x => x.WeeklyNum).ToList()
  107. })
  108. on missionClass.EducationMissionID equals examweek.EducationMissionID into dexamweek
  109. from examweek in dexamweek.DefaultIfEmpty()
  110. from courseTime in missionClass.EM_CoursesTime.DefaultIfEmpty()
  111. join hours in CourseTimeHoursRepository.Entities
  112. on new { CoursesTimeID = (Guid?)courseTime.CoursesTimeID, GradeYearID = grade.GradeID } equals new { CoursesTimeID = hours.CoursesTimeID, GradeYearID = hours.Years }
  113. into dhours
  114. from hours in dhours.DefaultIfEmpty()
  115. join classroom in ClassroomRepository.Entities on missionClass.ClassroomID equals classroom.ClassroomID into dclassroom
  116. from classroom in dclassroom.DefaultIfEmpty()
  117. select new EducationMissionImportClassView
  118. {
  119. TimeID = courseTime.TimesSegment,
  120. StartHour = courseTime.StartHour,
  121. StartMinutes = courseTime.StartMinutes,
  122. EndHour = courseTime.EndHour,
  123. EndMinutes = courseTime.EndMinutes,
  124. scheduleClassroomName = week.ClassroomName,
  125. EducationID = faculty.EducationID,
  126. LearningformID = faculty.LearningformID,
  127. Assistant = assistant.Name,
  128. StandardName = grade.Name,
  129. TDate = week.ScheduledTimes,
  130. ExaWeek = examweek.WeeklyNum,
  131. EndTime = examtime.EndTime ?? s,
  132. StarTime = examtime.StartTime ?? s,
  133. ExamDate = examtime.ExamDate ?? d,
  134. EducationMissionID = missionClass.EducationMissionID,
  135. EducationMissionClassID = missionClass.EducationMissionClassID,
  136. MainScheduleClassID = missionClass.MainScheduleClassID,
  137. TeachingModeID = missionClass.TeachingModeID ?? 1,
  138. SchoolyearID = mission.SchoolyearID,
  139. SchoolyearCode = schoolyear.Code,
  140. Name = classmajor.Name,
  141. CoursematerialID = missionClass.CoursematerialID,
  142. CourseCode = course.CourseCode,
  143. CourseName = course.CourseName,
  144. CampusID = college.CampusID,
  145. CollegeID = college.CollegeID,
  146. CollegeNo = college.No,
  147. CollegeName = college.Name,
  148. DepartmentID = mission.DepartmentID,
  149. DepartmentName = department.Name,
  150. GrademajorID = grade.GrademajorID,
  151. StandardID = faculty.StandardID,
  152. GradeYearID = grade.GradeID,
  153. ClassroomID = missionClass.ClassroomID,
  154. ClassroomName = classroom.Name,
  155. ClassroomTypeID = missionClass.ClassroomTypeID,
  156. CourseStructureID = missionClass.CourseStructureID,
  157. CourseCategoryID = missionClass.CourseCategoryID,
  158. CourseTypeID = missionClass.CourseTypeID,
  159. CourseQualityID = missionClass.CourseQualityID,
  160. ExaminationModeID = missionClass.ExaminationModeID,
  161. TeachinglanguageID = missionClass.TeachinglanguageID,
  162. HandleModeID = missionClass.HandleModeID,
  163. IsNeedMaterial = missionClass.IsNeedMaterial ?? false,
  164. OrderNo = missionClass.OrderNo ?? 0,
  165. SchedulingClassNum = missionClass.EM_EducationSchedulingClass.Count,
  166. ClassNum = (schedulingClass.EducationMissionClassID == null ? 0 : schedulingClass.ClassNum),
  167. MainScheduleClassGrademajorID = classmajor.GrademajorID,
  168. MainScheduleClassCollegeID = classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  169. SchedulingClass = mission.ClassName,
  170. StartWeeklyNum = teachSetting.StartWeeklyNum,
  171. EndWeeklyNum = teachSetting.EndWeeklyNum,
  172. StartWeeklyNumReserved = missionClass.EM_EducationMissionClassSettings.Min(w => w.WeeklyNum).Value,
  173. EndWeeklyNumReserved = missionClass.EM_EducationMissionClassSettings.Max(w => w.WeeklyNum).Value,
  174. Credit = teachSetting.Credit,
  175. TheoryCourse = teachSetting.TheoryCourse,
  176. Practicehours = teachSetting.Practicehours,
  177. Trialhours = teachSetting.Trialhours,
  178. TeachingDay = week.ScheduledTimes.Count().ToString(),
  179. Hours = hours.Hours,
  180. TeachingHours = (week.ScheduledTimes.Count() * (hours.Hours == null ? (courseTime.EndTimes - courseTime.StartTimes + 1) : hours.Hours)).ToString(),
  181. TheoryWeeklyNum = teachSetting.TheoryWeeklyNum,
  182. PracticeWeeklyNum = teachSetting.PracticeWeeklyNum,
  183. //ScheduledTimes = wgcp.ScheduledTimes == null ? 0 : wgcp.ScheduledTimes,
  184. TrialWeeklyNum = teachSetting.TrialWeeklyNum,
  185. WeeklyNum = teachSetting.WeeklyNum,
  186. WeeklyHours = teachSetting.WeeklyHours,
  187. ApprovalStatus = missionClass.RecordStatus,
  188. CourseProcessTimes = courseProcess.CourseProcessTimes,
  189. CreateTime = missionClass.CreateTime,
  190. CreateUserID = missionClass.CreateUserID,
  191. Remark = missionClass.Remark
  192. };
  193. return query;
  194. }
  195. //导出用
  196. /// <summary>
  197. /// 查询教学任务班数据
  198. /// </summary>
  199. /// <param name="exp"></param>
  200. /// <returns></returns>
  201. public IQueryable<EducationMissionImportClassView> GetEducationMissionClassViewQueryblExcel(Expression<Func<EM_EducationMissionClass, bool>> missionClassExp,
  202. Expression<Func<EM_ExecutablePlan, bool>> executablePlanExp, Expression<Func<EM_ExecutableOptionalCourse, bool>> executableOptionalCourseExp,
  203. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> executableFreeSelectionCourseCourseExp)
  204. {
  205. TimeSpan s = new TimeSpan();
  206. DateTime d = new DateTime();
  207. var query = (from missionClass in EducationMissionClassRepository.GetList(missionClassExp)
  208. join mission in EducationMissionRepository.Entities on missionClass.EducationMissionID equals mission.EducationMissionID
  209. join teachSetting in EducationMissionClassTeachingSettingRepository.Entities on missionClass.EducationMissionClassID equals teachSetting.EducationMissionClassID
  210. join classmajor in ClassmajorRepository.Entities on missionClass.MainScheduleClassID equals classmajor.ClassmajorID into dclassmajor
  211. from classmajor in dclassmajor.DefaultIfEmpty()
  212. join grade in GrademajorRepository.Entities on classmajor.GrademajorID equals grade.GrademajorID into dgrade
  213. from grade in dgrade.DefaultIfEmpty()
  214. join faculty in FacultymajorRepository.Entities on grade.FacultymajorID equals faculty.FacultymajorID into dfaculty
  215. from faculty in dfaculty.DefaultIfEmpty()
  216. join college in CollegeRepository.Entities on mission.CollegeID equals college.CollegeID
  217. join department in DepartmentRepository.Entities on mission.DepartmentID equals department.DepartmentID
  218. join schoolyear in SchoolyearRepository.Entities on mission.SchoolyearID equals schoolyear.SchoolyearID
  219. join course in CoursematerialRepository.Entities on missionClass.CoursematerialID equals course.CoursematerialID
  220. join schedulingClass in
  221. (
  222. from sc in EducationSchedulingClassRepository.Entities
  223. group sc by sc.EducationMissionClassID into g
  224. select new
  225. {
  226. EducationMissionClassID = g.Key,
  227. ClassNum = g.Sum(x => x.CF_Student.Count())
  228. }
  229. ) on missionClass.EducationMissionClassID equals schedulingClass.EducationMissionClassID into dschedulingClass
  230. from schedulingClass in dschedulingClass.DefaultIfEmpty()
  231. join courseProcess in
  232. (from cp in CourseProcessRepository.Entities
  233. group cp by cp.EducationMissionClassID into g
  234. select new
  235. {
  236. EducationMissionClassID = g.Key,
  237. CourseProcessTimes = g.Sum(x => x.Times)
  238. }) on missionClass.EducationMissionClassID equals courseProcess.EducationMissionClassID into dcourseProcess
  239. from courseProcess in dcourseProcess.DefaultIfEmpty()
  240. join week in
  241. (from es in AdultEducationScheduleRepository.Entities
  242. group es by new { es.EM_EducationSchedulingClass.EducationMissionClassID,es.ClassroomID }
  243. into g
  244. select new
  245. {
  246. EducationMissionClassID = g.Key.EducationMissionClassID,
  247. ScheduledTimes = g.Select(x => x.ScheduleDate).ToList(),
  248. ClassroomName = g.Select(x => x.CF_Classroom.Name).FirstOrDefault()
  249. }) on missionClass.EducationMissionClassID equals week.EducationMissionClassID into dweek
  250. from week in dweek.DefaultIfEmpty()
  251. join assistant in UserRepository.Entities on classmajor.UserID equals assistant.UserID into dassistant
  252. from assistant in dassistant.DefaultIfEmpty()
  253. join examtime in EducationMissionExamTimeRepository.Entities on missionClass.EducationMissionID equals examtime.EducationMissionID into dexamtime
  254. from examtime in dexamtime.DefaultIfEmpty()
  255. join examweek in
  256. (from ew in EducationMissionExamWeekNumRepository.Entities
  257. group ew by ew.EducationMissionID into g
  258. select new
  259. {
  260. EducationMissionID = g.Key,
  261. WeeklyNum = g.Select(x => x.WeeklyNum).ToList()
  262. })
  263. on missionClass.EducationMissionID equals examweek.EducationMissionID into dexamweek
  264. from examweek in dexamweek.DefaultIfEmpty()
  265. from courseTime in missionClass.EM_CoursesTime.DefaultIfEmpty()
  266. join hours in CourseTimeHoursRepository.Entities
  267. on new { CoursesTimeID = (Guid?)courseTime.CoursesTimeID, GradeYearID = grade.GradeID } equals new { CoursesTimeID = hours.CoursesTimeID, GradeYearID = hours.Years }
  268. //on cou.CoursesTimeID equals h.CoursesTimeID
  269. into dhours
  270. from hours in dhours.DefaultIfEmpty()
  271. join classroom in ClassroomRepository.Entities on missionClass.ClassroomID equals classroom.ClassroomID into dclassroom
  272. from classroom in dclassroom.DefaultIfEmpty()
  273. select new EducationMissionImportClassView
  274. {
  275. TimeID = courseTime.TimesSegment,
  276. StartHour = courseTime.StartHour,
  277. StartMinutes = courseTime.StartMinutes,
  278. EndHour = courseTime.EndHour,
  279. EndMinutes = courseTime.EndMinutes,
  280. scheduleClassroomName = week.ClassroomName,
  281. EducationID = faculty.EducationID,
  282. LearningformID = faculty.LearningformID,
  283. Assistant = assistant.Name,
  284. StandardName = grade.Name,
  285. TDate = week.ScheduledTimes,
  286. ExaWeek = examweek.WeeklyNum,
  287. EndTime = examtime.EndTime ?? s,
  288. StarTime = examtime.StartTime ?? s,
  289. ExamDate = examtime.ExamDate ?? d,
  290. EducationMissionID = missionClass.EducationMissionID,
  291. EducationMissionClassID = missionClass.EducationMissionClassID,
  292. MainScheduleClassID = missionClass.MainScheduleClassID,
  293. TeachingModeID = missionClass.TeachingModeID ?? 1,
  294. SchoolyearID = mission.SchoolyearID,
  295. SchoolyearCode = schoolyear.Code,
  296. Name = missionClass.Name,
  297. CoursematerialID = missionClass.CoursematerialID,
  298. CourseCode = course.CourseCode,
  299. CourseName = course.CourseName,
  300. CampusID = college.CampusID,
  301. CollegeID = mission.CollegeID,
  302. CollegeNo = college.No,
  303. CollegeName = college.Name,
  304. DepartmentID = mission.DepartmentID,
  305. DepartmentName = department.Name,
  306. GrademajorID = grade.GrademajorID,
  307. StandardID = faculty.StandardID,
  308. GradeYearID = grade.GradeID,
  309. ClassroomID = missionClass.ClassroomID,
  310. ClassroomName = classroom.Name,
  311. ClassroomTypeID = missionClass.ClassroomTypeID,
  312. CourseStructureID = missionClass.CourseStructureID,
  313. CourseCategoryID = missionClass.CourseCategoryID,
  314. CourseTypeID = missionClass.CourseTypeID,
  315. CourseQualityID = missionClass.CourseQualityID,
  316. ExaminationModeID = missionClass.ExaminationModeID,
  317. TeachinglanguageID = missionClass.TeachinglanguageID,
  318. HandleModeID = missionClass.HandleModeID,
  319. IsNeedMaterial = missionClass.IsNeedMaterial ?? false,
  320. OrderNo = missionClass.OrderNo ?? 0,
  321. SchedulingClassNum = missionClass.EM_EducationSchedulingClass.Count,
  322. ClassNum = (schedulingClass.EducationMissionClassID == null ? 0 : schedulingClass.ClassNum),
  323. MainScheduleClassGrademajorID = classmajor.GrademajorID,
  324. MainScheduleClassCollegeID = faculty.CollegeID,
  325. SchedulingClass = mission.ClassName,
  326. StartWeeklyNum = teachSetting.StartWeeklyNum,
  327. EndWeeklyNum = teachSetting.EndWeeklyNum,
  328. StartWeeklyNumReserved = missionClass.EM_EducationMissionClassSettings.Min(w => w.WeeklyNum).Value,
  329. EndWeeklyNumReserved = missionClass.EM_EducationMissionClassSettings.Max(w => w.WeeklyNum).Value,
  330. Credit = teachSetting.Credit,
  331. TheoryCourse = teachSetting.TheoryCourse,
  332. Practicehours = teachSetting.Practicehours,
  333. Trialhours = teachSetting.Trialhours,
  334. TeachingDay = week.ScheduledTimes.Count().ToString(),
  335. Hours = hours.Hours,
  336. TeachingHours = (week.ScheduledTimes.Count() * (hours.Hours == null ? (courseTime.EndTimes - courseTime.StartTimes + 1) : hours.Hours)).ToString(),
  337. TheoryWeeklyNum = teachSetting.TheoryWeeklyNum,
  338. PracticeWeeklyNum = teachSetting.PracticeWeeklyNum,
  339. TrialWeeklyNum = teachSetting.TrialWeeklyNum,
  340. WeeklyNum = teachSetting.WeeklyNum,
  341. WeeklyHours = teachSetting.WeeklyHours,
  342. ApprovalStatus = missionClass.RecordStatus,
  343. CourseProcessTimes = courseProcess.CourseProcessTimes,
  344. CreateTime = missionClass.CreateTime,
  345. CreateUserID = missionClass.CreateUserID,
  346. Remark = missionClass.Remark
  347. });
  348. return query;
  349. }
  350. //检查教师是否不能排课
  351. public IQueryable<TeacherIsOnWorkResultView> CheckTeacherIsOnWork(Expression<Func<ES_AdultEducationSchedule, bool>> schedulingExp,
  352. Expression<Func<ES_AdultEducationScheduleTeacher, bool>> staffExp)
  353. {
  354. var query=from es in AdultEducationScheduleRepository.GetList(schedulingExp)
  355. join et in AdultEducationScheduleTeacherRepository.GetList(staffExp) on es.AdultEducationScheduleID equals et.AdultEducationScheduleID into ed
  356. from eset in ed.DefaultIfEmpty()
  357. select new TeacherIsOnWorkResultView{
  358. AdultUserId = eset.UserID
  359. };
  360. return query;
  361. }
  362. }
  363. }