TeacherselfSchedulingView.sql 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. SELECT distinct ct.CoursesTimeID
  2. ,ct.StartTimes
  3. ,ct.Times
  4. ,ct.TimeDesc
  5. ,w.Weekday
  6. ,w.WeekdayDesc
  7. ,s.SchoolyearID
  8. ,s.Code
  9. ,es.ClassroomID
  10. ,es.EducationSchedulingClassID
  11. ,es.TaskGroupName
  12. ,es.StudentCount
  13. ,es.EducationMissionClassID
  14. ,es.OrderNo
  15. ,es.Name
  16. ,es.TeachingModeID
  17. ,es.EducationMissionID
  18. ,u.CollegeID
  19. ,u.CollegeName
  20. ,u.DepartmentID
  21. ,u.DepartmentName
  22. ,es.CourseCode
  23. ,es.CourseName
  24. ,es.StartWeeklyNum
  25. ,es.EndWeeklyNum
  26. ,es.ClassroomName
  27. ,u.UserID
  28. ,u.StaffName
  29. ,es.TeacherName
  30. ,es.WeekNums
  31. ,es.MinWeekNum
  32. ,es.StopWeekNumStr
  33. FROM (select ct.CoursesTimeID,ct.StartTimes,convert(varchar(10),ct.StartTimes)+'-'+CONVERT(varchar(10),ct.EndTimes) as Times,
  34. REPLICATE('0',2-len(convert(varchar(10),ct.StartHour)))+convert(varchar(10),ct.StartHour)
  35. +':'+REPLICATE('0',2-len(convert(varchar(10),ct.StartMinutes)))+convert(varchar(10),ct.StartMinutes)
  36. +'-'+REPLICATE('0',2-len(convert(varchar(10),ct.EndHour)))+convert(varchar(10),ct.EndHour)
  37. +':'+REPLICATE('0',2-len(convert(varchar(10),ct.EndMinutes)))+convert(varchar(10),ct.EndMinutes) as TimeDesc
  38. from EM_CoursesTime ct
  39. where ct.RecordStatus>0
  40. ) ct
  41. full join (
  42. select 1 as Weekday,'星期一' as WeekdayDesc
  43. union all
  44. select 2 as Weekday,'星期二' as WeekdayDesc
  45. union all
  46. select 3 as Weekday,'星期三' as WeekdayDesc
  47. union all
  48. select 4 as Weekday,'星期四' as WeekdayDesc
  49. union all
  50. select 5 as Weekday,'星期五' as WeekdayDesc
  51. union all
  52. select 6 as Weekday,'星期六' as WeekdayDesc
  53. union all
  54. select 0 as Weekday,'星期日' as WeekdayDesc
  55. ) w on 1 =1
  56. inner join CF_Schoolyear s on 1=1
  57. inner join (
  58. select es.SchoolyearID,c.CollegeID,c.Name as CollegeName,d.DepartmentID,d.Name as DepartmentName,u.UserID,u.Name as StaffName
  59. from Sys_User u
  60. left join CF_Staff s on u.UserID=s.UserID
  61. left join CF_Department d on s.DepartmentID=d.DepartmentID
  62. left join CF_College c on s.CollegeID=c.CollegeID
  63. inner join (
  64. select em.SchoolyearID,escc.UserID
  65. from ES_EducationScheduling es
  66. inner join EM_CoursesTime ct on es.CoursesTimeID=ct.CoursesTimeID and ct.RecordStatus>0
  67. inner join EM_EducationSchedulingClass esc on es.EducationSchedulingClassID=esc.EducationSchedulingClassID
  68. inner join EM_EducationMissionClass emc on esc.EducationMissionClassID=emc.EducationMissionClassID
  69. inner join EM_EducationMission em on emc.EducationMissionID=em.EducationMissionID
  70. inner join ES_EducationSchedulingTeacher escc on es.EducationSchedulingID=escc.EducationSchedulingID
  71. group by em.SchoolyearID,escc.UserID
  72. ) es on u.UserID=es.UserID
  73. ) u on s.SchoolyearID = u.SchoolyearID
  74. left join (
  75. select distinct *
  76. from (
  77. SELECT
  78. ES_EducationScheduling.Weekday
  79. ,ES_EducationScheduling.CoursesTimeID
  80. ,ES_EducationScheduling.ClassroomID
  81. ,EM_EducationSchedulingClass.EducationSchedulingClassID
  82. ,EM_EducationSchedulingClass.TaskGroupName
  83. ,ISNULL(esccs.StudentCount,0) AS StudentCount
  84. ,EM_EducationMissionClass.EducationMissionClassID
  85. ,EM_EducationMissionClass.OrderNo
  86. ,EM_EducationMissionClass.Name
  87. ,EM_EducationMissionClass.TeachingModeID
  88. ,EM_EducationMission.EducationMissionID
  89. ,EM_EducationMission.CollegeID
  90. ,EM_EducationMission.SchoolyearID
  91. ,EM_Coursematerial.CourseCode
  92. ,EM_Coursematerial.CourseName
  93. ,EM_EducationMissionClassTeachingSetting.StartWeeklyNum
  94. ,EM_EducationMissionClassTeachingSetting.EndWeeklyNum
  95. ,CF_Classroom.Name AS ClassroomName
  96. ,CF_Classmajor.ClassmajorID
  97. ,CF_Classmajor.Name AS ClassMajorName
  98. ,ES_EducationSchedulingTeacher.UserID
  99. ,mct.TeacherName
  100. ,emcs.WeekNums
  101. ,emcs.MinWeekNum
  102. ,ess.StopWeekNumStr
  103. FROM
  104. ES_EducationScheduling
  105. INNER JOIN EM_EducationSchedulingClass
  106. ON EM_EducationSchedulingClass.EducationSchedulingClassID = ES_EducationScheduling.EducationSchedulingClassID
  107. LEFT JOIN (
  108. SELECT EducationSchedulingClassID,COUNT(1) AS StudentCount
  109. FROM EM_EducationSchedulingClass_CF_Student
  110. GROUP BY EducationSchedulingClassID
  111. ) esccs ON EM_EducationSchedulingClass.EducationSchedulingClassID=esccs.EducationSchedulingClassID
  112. INNER JOIN EM_EducationMissionClass
  113. ON EM_EducationSchedulingClass.EducationMissionClassID = EM_EducationMissionClass.EducationMissionClassID
  114. INNER JOIN EM_EducationMission
  115. ON EM_EducationMissionClass.EducationMissionID = EM_EducationMission.EducationMissionID
  116. LEFT JOIN ES_CollegeScheduleStatus
  117. ON EM_EducationMission.CollegeID=ES_CollegeScheduleStatus.CollegeID AND EM_EducationMission.SchoolyearID=ES_CollegeScheduleStatus.SchoolyearID AND ES_CollegeScheduleStatus.RecordStatus=2
  118. INNER JOIN EM_EducationMissionClassTeachingSetting
  119. ON EM_EducationMissionClass.EducationMissionClassID = EM_EducationMissionClassTeachingSetting.EducationMissionClassID
  120. INNER JOIN EM_Coursematerial
  121. ON EM_EducationMissionClass.CoursematerialID = EM_Coursematerial.CoursematerialID
  122. INNER JOIN CF_Classroom
  123. ON ES_EducationScheduling.ClassroomID = CF_Classroom.ClassroomID
  124. LEFT JOIN EM_EducationMissionClass_CF_Classmajor
  125. ON EM_EducationMissionClass.EducationMissionClassID = EM_EducationMissionClass_CF_Classmajor.EducationMissionClassID
  126. LEFT JOIN CF_Classmajor
  127. ON EM_EducationMissionClass_CF_Classmajor.ClassmajorID = CF_Classmajor.ClassmajorID
  128. INNER JOIN ES_EducationSchedulingTeacher
  129. ON ES_EducationScheduling.EducationSchedulingID = ES_EducationSchedulingTeacher.EducationSchedulingID
  130. LEFT JOIN (select es.EducationSchedulingID, STUFF((select ','+tu.Name
  131. from ES_EducationSchedulingTeacher tescs
  132. inner join ES_EducationScheduling tes on tescs.EducationSchedulingID=tes.EducationSchedulingID
  133. inner join EM_EducationSchedulingClass tesc on tes.EducationSchedulingClassID=tesc.EducationSchedulingClassID
  134. inner join Sys_User tu on tescs.UserID=tu.UserID
  135. where tescs.EducationSchedulingID=es.EducationSchedulingID
  136. order by ISNULL(tescs.TeachingMethod,0),tu.Name
  137. for xml path('')), 1, 1, '') as TeacherName
  138. from ES_EducationSchedulingTeacher escs
  139. inner join ES_EducationScheduling es on escs.EducationSchedulingID=es.EducationSchedulingID
  140. inner join EM_EducationSchedulingClass esc on es.EducationSchedulingClassID=esc.EducationSchedulingClassID
  141. inner join Sys_User u on escs.UserID=u.UserID
  142. group by es.EducationSchedulingID
  143. ) mct ON ES_EducationScheduling.EducationSchedulingID = mct.EducationSchedulingID
  144. left join (
  145. select x.EducationSchedulingID,x.MinWeekNum,case when right(x.WeekNums,1)=',' then substring(x.WeekNums,0,LEN(x.WeekNums)) else x.WeekNums end as WeekNums
  146. from (
  147. select emcs.EducationSchedulingID,MIN(emcs.WeekNum) as MinWeekNum,WeekNums=stuff
  148. (
  149. (select emcst.WeekNum+','
  150. from (
  151. select distinct EducationSchedulingID,convert(varchar(10),WeekNum) as WeekNum
  152. from ES_EducationSchedulingWeekNum
  153. ) emcst
  154. where emcst.EducationSchedulingID=emcs.EducationSchedulingID
  155. order by convert(int,WeekNum)
  156. for xml path('')),1,0,''
  157. )
  158. from ES_EducationSchedulingWeekNum emcs
  159. group by emcs.EducationSchedulingID
  160. ) x ) emcs on ES_EducationScheduling.EducationSchedulingID=emcs.EducationSchedulingID
  161. LEFT JOIN (
  162. select es.EducationSchedulingID,STUFF((select ','+Convert(varchar(10),ISNULL(tess.WeekNum,0))
  163. from ES_EducationSchedulingStop tess
  164. inner join ES_EducationSchedulingStopTeacher tesst on tess.EducationSchedulingStopID=tesst.EducationSchedulingStopID
  165. inner join Sys_DictionaryItem ttm on ttm.DictionaryCode='EM_TeachingMethod' and ttm.Code='Lecturer' and tesst.TeachingMethod=ttm.Value
  166. inner join EM_EducationMissionClass temc on tess.EducationMissionClassID=temc.EducationMissionClassID
  167. inner join EM_EducationSchedulingClass tesc on temc.EducationMissionClassID=tesc.EducationMissionClassID
  168. inner join ES_EducationScheduling tes on tesc.EducationSchedulingClassID=tes.EducationSchedulingClassID
  169. and tes.Weekday=tess.Weekday and tes.CoursesTimeID=tess.CoursesTimeID and tes.ClassroomID=tess.ClassroomID
  170. where tes.EducationSchedulingID=es.EducationSchedulingID
  171. and tess.RecordStatus=3
  172. order by ISNULL(tess.WeekNum,0)
  173. for xml path('')), 1, 1, '') as StopWeekNumStr
  174. from ES_EducationSchedulingStop ess
  175. inner join ES_EducationSchedulingStopTeacher esst on ess.EducationSchedulingStopID=esst.EducationSchedulingStopID
  176. inner join Sys_DictionaryItem tm on tm.DictionaryCode='EM_TeachingMethod' and tm.Code='Lecturer' and esst.TeachingMethod=tm.Value
  177. inner join EM_EducationMissionClass emc on ess.EducationMissionClassID=emc.EducationMissionClassID
  178. inner join EM_EducationSchedulingClass esc on emc.EducationMissionClassID=esc.EducationMissionClassID
  179. inner join ES_EducationScheduling es on esc.EducationSchedulingClassID=es.EducationSchedulingClassID
  180. and es.Weekday=ess.Weekday and es.CoursesTimeID=ess.CoursesTimeID and es.ClassroomID=ess.ClassroomID
  181. inner join ES_EducationSchedulingWeekNum esw on es.EducationSchedulingID=esw.EducationSchedulingID and ess.WeekNum=esw.WeekNum
  182. where ess.RecordStatus=3
  183. group by es.EducationSchedulingID
  184. ) ess on ES_EducationScheduling.EducationSchedulingID=ess.EducationSchedulingID
  185. WHERE (ES_CollegeScheduleStatus.CollegeScheduleStatusID IS NOT NULL OR EM_EducationMissionClass.OptionalCourseTypeID=3)
  186. ) x
  187. ) es
  188. on ct.CoursesTimeID=es.CoursesTimeID
  189. and w.Weekday=es.Weekday
  190. and s.SchoolyearID=es.SchoolyearID
  191. and u.UserID=es.UserID
  192. where s.SchoolyearID=@SchoolyearID
  193. and (u.UserID=@UserID or @UserID is null)