CourseHomeworkMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.yonge.cooleshow.biz.dal.dao.CourseHomeworkDao">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.CourseHomework">
  5. <result column="id_" property="id" />
  6. <result column="course_group_id_" property="courseGroupId" />
  7. <result column="course_group_type_" property="courseGroupType" />
  8. <result column="course_schedule_id_" property="courseScheduleId" />
  9. <result column="title_" property="title" />
  10. <result column="content_" property="content" />
  11. <result column="attachments_" property="attachments" />
  12. <result column="expect_num_" property="expectNum" />
  13. <result column="completed_num_" property="completedNum" />
  14. <result column="create_time_" property="createTime" />
  15. <result column="update_time_" property="updateTime" />
  16. </resultMap>
  17. <!-- 表字段 -->
  18. <sql id="baseColumns">
  19. t.id_
  20. , t.course_group_id_
  21. , t.course_group_type_
  22. , t.course_schedule_id_
  23. , t.title_
  24. , t.content_
  25. , t.attachments_
  26. , t.expect_num_
  27. , t.completed_num_
  28. , t.create_time_
  29. , t.update_time_
  30. </sql>
  31. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  32. SELECT
  33. <include refid="baseColumns"/>
  34. FROM course_homework t
  35. where t.id_ = #{id}
  36. </select>
  37. <select id="selectAdminPage" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  38. select
  39. cs.id_ AS courseId,
  40. cs.course_group_id_ AS courseGroupId,
  41. cs.class_date_ AS classDate,
  42. cs.type_ as type,
  43. cs.start_time_ AS startTime,
  44. cs.end_time_ AS endTime,
  45. ch.create_time_ as decorateTime,
  46. su2.id_ as studentId,
  47. su2.username_ as studentName,
  48. su2.avatar_ as studentAvatar,
  49. su.username_ as teacherName,
  50. su.avatar_ as teacherAvatar,
  51. sch.submit_time_ as submitTime,
  52. su.id_ as teacherId,
  53. ch.create_time_ as decorateTime
  54. from course_homework ch
  55. left join course_schedule cs on ch.course_schedule_id_ = cs.id_
  56. left join course_schedule_student_payment cssp on cssp.course_id_ = cs.id_
  57. left join sys_user su on cs.teacher_id_ = su.id_
  58. left join sys_user su2 on cssp.user_id_ = su2.id_
  59. left join student_course_homework sch on sch.student_id_ = cssp.user_id_ and sch.course_schedule_id_ = cssp.course_id_
  60. <where>
  61. <if test="param.courseStatus != null">
  62. and cs.status_ = #{param.courseStatus}
  63. </if>
  64. <if test="param.courseType != null and param.courseType.size() != 0">
  65. and cs.type_ in
  66. <foreach collection="param.courseType" item="item" open="(" close=")" separator=",">
  67. #{item}
  68. </foreach>
  69. </if>
  70. <if test="param.startTime != null">
  71. and #{param.startTime} &lt; ch.create_time_
  72. </if>
  73. <if test="param.endTime != null">
  74. and #{param.endTime} &gt; ch.create_time_
  75. </if>
  76. <if test="param.studentSearch != null and param.studentSearch != ''">
  77. and ( su2.id_ like concat('%',#{param.studentSearch},'%')
  78. or su2.username_ like concat('%',#{param.studentSearch},'%')
  79. or su2.phone_ like concat('%',#{param.studentSearch},'%') )
  80. </if>
  81. <if test="param.teacherSearch != null and param.teacherSearch != ''">
  82. and ( su.id_ like concat('%',#{param.teacherSearch},'%')
  83. or su.username_ like concat('%',#{param.teacherSearch},'%')
  84. or su.phone_ like concat('%',#{param.teacherSearch},'%') )
  85. </if>
  86. </where>
  87. order by cs.start_time_ desc
  88. </select>
  89. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  90. select distinct cs.id_ AS courseId,
  91. cs.course_group_id_ AS courseGroupId,
  92. cs.class_date_ AS classDate,
  93. cs.class_num_ as classNum,
  94. cs.start_time_ AS startTime,
  95. cs.end_time_ AS endTime,
  96. cs.type_ as type,
  97. ch.create_time_ as decorateTime,
  98. (case when a.commitNum &gt; a.repliedNum then 'NOTREVIEW'
  99. when a.studentNum &gt; a.commitNum then 'NOTCOMMIT'
  100. else 'REVIEWED' end ) as homeworkStatus
  101. from course_schedule cs
  102. left join course_homework ch on ch.course_schedule_id_ = cs.id_
  103. left join student_course_homework sch on ch.id_ = sch.course_homework_id_
  104. left join course_schedule_student_payment cssp on cssp.course_id_ = cs.id_
  105. left join (select cssp.course_id_,
  106. count(cssp.id_) as studentNum,
  107. sum(if(sch.attachments_ is null or sch.attachments_ = '',0,1)) as commitNum,
  108. sum(if(sch.teacher_replied_ is null or sch.teacher_replied_ = '',0,1)) as repliedNum
  109. from course_schedule_student_payment cssp
  110. left join student_course_homework sch on sch.student_id_ = cssp.user_id_ and
  111. sch.course_schedule_id_ = cssp.course_id_
  112. group by cssp.course_id_) a on a.course_id_ = cs.id_
  113. <where>
  114. <if test="param.decorate != null">
  115. <if test="param.decorate.code == 0">
  116. and ch.id_ is null
  117. </if>
  118. <if test="param.decorate.code == 1">
  119. and ch.id_ is not null
  120. </if>
  121. </if>
  122. <if test="param.submit != null">
  123. <if test="param.submit.code == 0">
  124. and sch.id_ is null
  125. </if>
  126. <if test="param.submit.code == 1">
  127. and sch.id_ is not null
  128. </if>
  129. </if>
  130. <if test="param.courseStatus != null">
  131. and cs.status_ = #{param.courseStatus}
  132. </if>
  133. <if test="param.courseType != null and param.courseType.size() != 0">
  134. and cs.type_ in
  135. <foreach collection="param.courseType" separator="," close=")" open="(" item="item" >
  136. #{item}
  137. </foreach>
  138. </if>
  139. <if test="param.teacherId != null">
  140. and cs.teacher_id_ = #{param.teacherId}
  141. </if>
  142. <if test="param.studentId != null">
  143. and cssp.user_id_ = #{param.studentId}
  144. </if>
  145. <if test="param.courseScheduleId != null ">
  146. and cs.id_ = #{param.courseScheduleId}
  147. </if>
  148. <if test="param.date != null and param.date != ''">
  149. and date_format(cs.class_date_,'%Y-%m') = #{param.date}
  150. </if>
  151. <if test="param.startTime != null">
  152. and #{param.startTime} &lt; ch.create_time_
  153. </if>
  154. <if test="param.endTime != null">
  155. and #{param.endTime} &gt; ch.create_time_
  156. </if>
  157. <if test="param.homeworkStatus != null">
  158. <choose>
  159. <when test="param.homeworkStatus.code == 'NOTREVIEW'">
  160. and a.commitNum &gt; a.repliedNum
  161. </when>
  162. <when test="param.homeworkStatus.code == 'NOTCOMMIT'">
  163. and a.studentNum &gt; a.commitNum
  164. </when>
  165. <otherwise>
  166. and a.commitNum = a.repliedNum and a.studentNum = a.commitNum
  167. </otherwise>
  168. </choose>
  169. </if>
  170. </where>
  171. order by cs.start_time_
  172. <if test="param.date == null or param.date == ''">
  173. desc
  174. </if>
  175. </select>
  176. <select id="selectCourseHomeworkDetailByCourseId"
  177. resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkDetailVo">
  178. select ch.id_ as id
  179. ,cs.id_ as courseScheduleId
  180. ,ch.title_ as title
  181. ,ch.content_ as content
  182. ,ch.attachments_ as attachments
  183. ,ch.create_time_ as decorateTime
  184. ,sch.attachments_ as studentAttachments
  185. ,sch.teacher_replied_ as teacherReplied
  186. ,sch.submit_time_ as submitTime
  187. ,sch.id_ as studentHomeworkId
  188. ,sch.student_id_ as studentId
  189. ,cs.teacher_id_ as teacherId
  190. ,cs.type_ as courseType
  191. ,cs.class_date_ as classDate
  192. ,cs.start_time_ as startTime
  193. ,cs.end_time_ as endTime
  194. ,cs.status_ as courseStatus
  195. ,cs.course_group_id_ as courseGroupId
  196. ,if(ch.id_ is null,0,1) as decorateHomework
  197. ,if(sch.attachments_ is null or sch.attachments_ = '',0,1) as submitHomework
  198. ,if(sch.teacher_replied_ is null or sch.teacher_replied_ = '',0,1) as reviewHomework
  199. from course_schedule cs
  200. left join course_homework ch on ch.course_schedule_id_ = cs.id_
  201. left join student_course_homework sch on ch.id_ = sch.course_homework_id_
  202. left join course_schedule_student_payment cssp on cs.id_ = cssp.course_id_
  203. <where>
  204. <if test="courseId != null">
  205. and cs.id_ = #{courseId}
  206. </if>
  207. <if test="studentId != null">
  208. and cssp.user_id_ = #{studentId}
  209. </if>
  210. </where>
  211. limit 1
  212. </select>
  213. <select id="selectPaymentStudentInfo" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkDetailVo">
  214. select su.username_ as studentName
  215. ,su.avatar_ as studentAvatar
  216. ,cssp.user_id_ as studentId
  217. from course_schedule cs
  218. left join course_schedule_student_payment cssp on cs.id_ = cssp.course_id_
  219. left join sys_user su on su.id_ = cssp.user_id_
  220. <where>
  221. <if test="courseScheduleId != null">
  222. and cs.id_ = #{courseScheduleId}
  223. </if>
  224. <if test="studentId != null">
  225. and cssp.user_id_ = #{studentId}
  226. </if>
  227. </where>
  228. </select>
  229. <select id="selectSubjectAndTeacherInfo" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkDetailVo">
  230. select s.name_ as subjectName
  231. ,su.username_ as teacherName
  232. ,su.avatar_ as teacherAvatar
  233. ,su.id_ as teacherId
  234. from course_group cg
  235. left join subject s on cg.subject_id_ = s.id_
  236. left join sys_user su on cg.teacher_id_ = su.id_
  237. <where>
  238. <if test="courseGroupId != null">
  239. and cg.id_ = #{courseGroupId}
  240. </if>
  241. </where>
  242. </select>
  243. <select id="selectStudentInfo" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  244. select
  245. cs.id_ as courseId,
  246. cssp.user_id_ as studentId
  247. ,su.username_ as studentName
  248. ,su.avatar_ as studentAvatar
  249. from course_schedule cs
  250. left join course_schedule_student_payment cssp on cssp.course_id_ = cs.id_
  251. left join sys_user su on cssp.user_id_ = su.id_
  252. <where>
  253. <if test="records != null and records.size() != 0">
  254. and cs.id_ in
  255. <foreach collection="records" separator="," close=")" open="(" item="item" >
  256. #{item}
  257. </foreach>
  258. </if>
  259. </where>
  260. </select>
  261. <select id="selectSubjectAndGroupInfoList" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  262. select
  263. cs.id_ as courseId,
  264. s.name_ as subjectName
  265. ,cg.name_ as courseGroupName
  266. ,cg.background_pic_ as backgroundPic
  267. ,cs.class_num_ as classNum
  268. from course_schedule cs
  269. left join course_group cg on cs.course_group_id_ = cg.id_
  270. left join subject s on s.id_ = cg.subject_id_
  271. <where>
  272. <if test="records != null and records.size() != 0">
  273. and cs.id_ in
  274. <foreach collection="records" separator="," close=")" open="(" item="item" >
  275. #{item}
  276. </foreach>
  277. </if>
  278. </where>
  279. </select>
  280. <select id="selectTeacherInfo" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  281. select
  282. cs.id_ as courseId,
  283. cs.teacher_id_ as teacherId
  284. ,su.username_ as teacherName
  285. ,su.avatar_ as teacherAvatar
  286. from course_schedule cs
  287. left join sys_user su on cs.teacher_id_ = su.id_
  288. <where>
  289. <if test="records != null and records.size() != 0">
  290. and cs.id_ in
  291. <foreach collection="records" separator="," close=")" open="(" item="item" >
  292. #{item}
  293. </foreach>
  294. </if>
  295. </where>
  296. </select>
  297. <select id="selectCourseHomeworkByCourseId" resultType="com.yonge.cooleshow.biz.dal.vo.CourseScheduleHomeworkVo">
  298. select
  299. cs.id_ as courseId,
  300. cg.id_ as courseGroupId,
  301. cg.name_ as courseGroupName,
  302. cs.type_ as type,
  303. cs.class_num_ as classNum,
  304. cs.class_date_ as classDate,
  305. cs.start_time_ as startTime,
  306. cs.end_time_ as endTime,
  307. s.name_ as subjectName,
  308. ch.title_ as title,
  309. ch.content_ as content,
  310. ch.attachments_ as attachments,
  311. if(ch.id_ is null,0,1) as decorateHomework,
  312. ch.create_time_ as decorateTime,
  313. cs.status_ as courseStatus,
  314. cg.background_pic_ as backgroundPic
  315. from course_schedule cs
  316. left join course_group cg on cs.course_group_id_ = cg.id_
  317. left join course_homework ch on cs.id_ = ch.course_schedule_id_
  318. left join subject s on cg.subject_id_ = s.id_
  319. where cs.id_ = #{courseId}
  320. </select>
  321. <select id="selectStudentHomeworkByCourseId" resultType="com.yonge.cooleshow.biz.dal.vo.StudentHomeworkVo">
  322. select
  323. s.id_ as studentId,
  324. s.username_ as studentName,
  325. s.phone_ as studentAvatar,
  326. if(sch.id_ is not null,1,0) as submitHomework,
  327. (case when sch.id_ is null then 'NOTCOMMIT'
  328. when sch.teacher_replied_ is not null or sch.teacher_replied_ != '' then 'NOTREVIEW'
  329. else 'REVIEWED' end ) as homeworkStatus,
  330. (select group_concat(s2.name_) from subject s2
  331. where find_in_set(s2.id_,st.subject_id_) and s2.del_flag_ = 0 ) as subjectName
  332. from course_schedule_student_payment cssp
  333. left join sys_user s on cssp.user_id_ = s.id_
  334. left join student st on st.user_id_ = s.id_
  335. left join student_course_homework sch on cssp.user_id_ = sch.student_id_ and sch.course_schedule_id_ = cssp.course_id_
  336. <where>
  337. <if test="courseId != null">
  338. and cssp.course_id_ = #{courseId}
  339. </if>
  340. </where>
  341. </select>
  342. <select id="selectAbsenteeism" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  343. select
  344. cs.id_ as courseId
  345. ,if(sa.id_ is null,1,0) as absenteeism
  346. from course_schedule cs
  347. left join student_attendance sa on sa.course_schedule_id_ = cs.id_
  348. <where>
  349. sa.student_id_ = #{studentId}
  350. <if test="practiceRecord != null and practiceRecord.size() != 0">
  351. and cs.id_ in
  352. <foreach collection="practiceRecord" separator="," close=")" open="(" item="item" >
  353. #{item}
  354. </foreach>
  355. </if>
  356. </where>
  357. </select>
  358. </mapper>