CourseHomeworkMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. <update id="updateSubmitNum">
  32. update course_homework set completed_num_ =
  33. (select COUNT(1) from student_course_homework where course_homework_id_ = #{homeworkId}) WHERE id_ = #{homeworkId}
  34. </update>
  35. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  36. SELECT
  37. <include refid="baseColumns"/>
  38. FROM course_homework t
  39. where t.id_ = #{id}
  40. </select>
  41. <select id="selectAdminPage" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  42. select
  43. cs.id_ AS courseId,
  44. cs.course_group_id_ AS courseGroupId,
  45. cs.class_date_ AS classDate,
  46. cs.type_ as type,
  47. cs.start_time_ AS startTime,
  48. cs.end_time_ AS endTime,
  49. ch.create_time_ as decorateTime,
  50. su2.id_ as studentId,
  51. su2.username_ as studentName,
  52. su2.avatar_ as studentAvatar,
  53. su.username_ as teacherName,
  54. su.avatar_ as teacherAvatar,
  55. sch.submit_time_ as submitTime,
  56. su.id_ as teacherId,
  57. ch.create_time_ as decorateTime
  58. from course_homework ch
  59. left join course_schedule cs on ch.course_schedule_id_ = cs.id_
  60. left join course_schedule_student_payment cssp on cssp.course_id_ = ch.course_schedule_id_
  61. left join student_course_homework sch on sch.course_schedule_id_ = cssp.course_id_ and sch.student_id_ = cssp.user_id_
  62. left join sys_user su on cs.teacher_id_ = su.id_
  63. left join sys_user su2 on cssp.user_id_ = su2.id_
  64. <where>
  65. <if test="param.courseStatus != null">
  66. and cs.status_ = #{param.courseStatus}
  67. </if>
  68. <if test="param.courseType != null and param.courseType.size() != 0">
  69. and cs.type_ in
  70. <foreach collection="param.courseType" item="item" open="(" close=")" separator=",">
  71. #{item}
  72. </foreach>
  73. </if>
  74. <if test="param.startTime != null">
  75. and #{param.startTime} &lt; ch.create_time_
  76. </if>
  77. <if test="param.endTime != null">
  78. and #{param.endTime} &gt; ch.create_time_
  79. </if>
  80. <if test="param.studentSearch != null and param.studentSearch != ''">
  81. and ( su2.id_ like concat('%',#{param.studentSearch},'%')
  82. or su2.username_ like concat('%',#{param.studentSearch},'%')
  83. or su2.phone_ like concat('%',#{param.studentSearch},'%') )
  84. </if>
  85. <if test="param.teacherSearch != null and param.teacherSearch != ''">
  86. and ( su.id_ like concat('%',#{param.teacherSearch},'%')
  87. or su.username_ like concat('%',#{param.teacherSearch},'%')
  88. or su.phone_ like concat('%',#{param.teacherSearch},'%') )
  89. </if>
  90. </where>
  91. order by cs.start_time_ desc
  92. </select>
  93. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  94. select distinct cs.id_ AS courseId,
  95. cs.course_group_id_ AS courseGroupId,
  96. cs.class_date_ AS classDate,
  97. cs.class_num_ as classNum,
  98. cs.start_time_ AS startTime,
  99. cs.end_time_ AS endTime,
  100. cs.type_ as type,
  101. ch.create_time_ as decorateTime,
  102. (case when a.commitNum &gt; a.repliedNum then 'NOTREVIEW'
  103. when a.studentNum &gt; a.commitNum then 'NOTCOMMIT'
  104. else 'REVIEWED' end ) as homeworkStatus
  105. from course_schedule cs
  106. left join course_homework ch on ch.course_schedule_id_ = cs.id_
  107. left join course_schedule_student_payment cssp on cssp.course_id_ = cs.id_
  108. left join student_course_homework sch on sch.course_schedule_id_ = cssp.course_id_ and sch.student_id_ = cssp.user_id_
  109. <if test="param.search != null and param.search != ''">
  110. <if test="param.clientType == 'STUDENT'">
  111. left join sys_user su on su.id_ = cs.teacher_id_
  112. </if>
  113. <if test="param.clientType == 'TEACHER'">
  114. left join sys_user su on su.id_ = cssp.user_id_
  115. </if>
  116. </if>
  117. left join (select cssp.course_id_,
  118. count(cssp.id_) as studentNum,
  119. sum(if(sch.attachments_ is null or sch.attachments_ = '',0,1)) as commitNum,
  120. sum(if(sch.teacher_replied_ is null or sch.teacher_replied_ = '',0,1)) as repliedNum
  121. from course_schedule_student_payment cssp
  122. left join student_course_homework sch on sch.student_id_ = cssp.user_id_ and
  123. sch.course_schedule_id_ = cssp.course_id_
  124. <where>
  125. <if test="param.studentId != null">
  126. and cssp.user_id_ = #{param.studentId}
  127. </if>
  128. </where>
  129. group by cssp.course_id_) a on a.course_id_ = cs.id_
  130. <where>
  131. <if test="param.decorate != null">
  132. <if test="param.decorate.code == 0">
  133. and ch.id_ is null
  134. </if>
  135. <if test="param.decorate.code == 1">
  136. and ch.id_ is not null
  137. </if>
  138. </if>
  139. <if test="param.search != null and param.search != ''">
  140. and su.username_ like concat('%',#{param.search},'%')
  141. </if>
  142. <if test="param.submit != null">
  143. <if test="param.submit.code == 0">
  144. and sch.id_ is null
  145. </if>
  146. <if test="param.submit.code == 1">
  147. and sch.id_ is not null
  148. </if>
  149. </if>
  150. <if test="param.courseStatus != null">
  151. and cs.status_ = #{param.courseStatus}
  152. </if>
  153. <if test="param.courseType != null and param.courseType.size() != 0">
  154. and cs.type_ in
  155. <foreach collection="param.courseType" separator="," close=")" open="(" item="item" >
  156. #{item}
  157. </foreach>
  158. </if>
  159. <if test="param.teacherId != null">
  160. and cs.teacher_id_ = #{param.teacherId}
  161. </if>
  162. <if test="param.studentId != null">
  163. and cssp.user_id_ = #{param.studentId}
  164. </if>
  165. <if test="param.courseScheduleId != null ">
  166. and cs.id_ = #{param.courseScheduleId}
  167. </if>
  168. <if test="param.date != null and param.date != ''">
  169. and date_format(cs.class_date_,'%Y-%m') = #{param.date}
  170. </if>
  171. <if test="param.startTime != null">
  172. and #{param.startTime} &lt; ch.create_time_
  173. </if>
  174. <if test="param.endTime != null">
  175. and #{param.endTime} &gt; ch.create_time_
  176. </if>
  177. <if test="param.homeworkStatus != null">
  178. <choose>
  179. <when test="param.homeworkStatus.code == 'NOTREVIEW'">
  180. and a.commitNum &gt; a.repliedNum
  181. </when>
  182. <when test="param.homeworkStatus.code == 'NOTCOMMIT'">
  183. and a.studentNum &gt; a.commitNum
  184. </when>
  185. <otherwise>
  186. and a.commitNum = a.repliedNum and a.studentNum = a.commitNum
  187. </otherwise>
  188. </choose>
  189. </if>
  190. </where>
  191. order by cs.start_time_
  192. <if test="param.date == null or param.date == ''">
  193. desc
  194. </if>
  195. </select>
  196. <select id="selectCourseHomeworkDetailByCourseId"
  197. resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkDetailVo">
  198. select ch.id_ as id
  199. ,cs.id_ as courseScheduleId
  200. ,ch.title_ as title
  201. ,ch.content_ as content
  202. ,ch.attachments_ as attachments
  203. ,ch.create_time_ as decorateTime
  204. ,sch.attachments_ as studentAttachments
  205. ,sch.teacher_replied_ as teacherReplied
  206. ,cg.id_ as courseGroupId
  207. ,concat(cg.name_,'-第',cs.class_num_,'课') as courseGroupName
  208. ,cs.class_num_ as classNum
  209. ,sch.submit_time_ as submitTime
  210. ,sch.id_ as studentHomeworkId
  211. ,sch.student_id_ as studentId
  212. ,cs.teacher_id_ as teacherId
  213. ,cs.type_ as courseType
  214. ,cs.class_date_ as classDate
  215. ,cs.start_time_ as startTime
  216. ,cs.end_time_ as endTime
  217. ,cs.status_ as courseStatus
  218. ,cs.course_group_id_ as courseGroupId
  219. ,if(ch.id_ is null,0,1) as decorateHomework
  220. ,if(sch.attachments_ is null or sch.attachments_ = '',0,1) as submitHomework
  221. ,if(sch.teacher_replied_ is null or sch.teacher_replied_ = '',0,1) as reviewHomework
  222. ,if(sch.id_ is not null and date_add(sch.submit_time_,INTERVAL #{homeworkExpireTime} DAY) &lt; now(),1,0) as homeworkExpire
  223. from course_schedule cs
  224. left join course_group cg on cs.course_group_id_ = cg.id_
  225. left join course_homework ch on ch.course_schedule_id_ = cs.id_
  226. left join course_schedule_student_payment cssp on cs.id_ = cssp.course_id_
  227. left join student_course_homework sch on sch.course_schedule_id_ = cssp.course_id_ and sch.student_id_ = cssp.user_id_
  228. <where>
  229. <if test="courseId != null">
  230. and cs.id_ = #{courseId}
  231. </if>
  232. <if test="studentId != null">
  233. and cssp.user_id_ = #{studentId}
  234. </if>
  235. </where>
  236. limit 1
  237. </select>
  238. <select id="selectPaymentStudentInfo" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkDetailVo">
  239. select su.username_ as studentName
  240. ,su.avatar_ as studentAvatar
  241. ,cssp.user_id_ as studentId
  242. from course_schedule cs
  243. left join course_schedule_student_payment cssp on cs.id_ = cssp.course_id_
  244. left join sys_user su on su.id_ = cssp.user_id_
  245. <where>
  246. <if test="courseScheduleId != null">
  247. and cs.id_ = #{courseScheduleId}
  248. </if>
  249. <if test="studentId != null">
  250. and cssp.user_id_ = #{studentId}
  251. </if>
  252. </where>
  253. </select>
  254. <select id="selectSubjectAndTeacherInfo" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkDetailVo">
  255. select s.name_ as subjectName
  256. ,su.username_ as teacherName
  257. ,su.avatar_ as teacherAvatar
  258. ,su.id_ as teacherId
  259. from course_group cg
  260. left join subject s on cg.subject_id_ = s.id_
  261. left join sys_user su on cg.teacher_id_ = su.id_
  262. <where>
  263. <if test="courseGroupId != null">
  264. and cg.id_ = #{courseGroupId}
  265. </if>
  266. </where>
  267. </select>
  268. <select id="selectStudentInfo" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  269. select
  270. cs.id_ as courseId,
  271. cssp.user_id_ as studentId
  272. ,su.username_ as studentName
  273. ,su.avatar_ as studentAvatar
  274. ,su.del_flag_ as delFlag
  275. from course_schedule cs
  276. left join course_schedule_student_payment cssp on cssp.course_id_ = cs.id_
  277. left join sys_user su on cssp.user_id_ = su.id_
  278. <where>
  279. <if test="records != null and records.size() != 0">
  280. and cs.id_ in
  281. <foreach collection="records" separator="," close=")" open="(" item="item" >
  282. #{item}
  283. </foreach>
  284. </if>
  285. </where>
  286. </select>
  287. <select id="selectSubjectAndGroupInfoList" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  288. select
  289. cs.id_ as courseId,
  290. s.name_ as subjectName
  291. ,concat(cg.name_,'-第',cs.class_num_,'课') as courseGroupName
  292. ,cg.background_pic_ as backgroundPic
  293. ,cs.class_num_ as classNum
  294. ,ig.id_ as imGroupId
  295. from course_schedule cs
  296. left join course_group cg on cs.course_group_id_ = cg.id_
  297. left join subject s on s.id_ = cg.subject_id_
  298. left join im_group ig on cs.course_group_id_ = ig.course_group_id_
  299. <where>
  300. <if test="records != null and records.size() != 0">
  301. and cs.id_ in
  302. <foreach collection="records" separator="," close=")" open="(" item="item" >
  303. #{item}
  304. </foreach>
  305. </if>
  306. </where>
  307. </select>
  308. <select id="selectTeacherInfo" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  309. select
  310. cs.id_ as courseId,
  311. cs.teacher_id_ as teacherId
  312. ,su.username_ as teacherName
  313. ,su.avatar_ as teacherAvatar
  314. from course_schedule cs
  315. left join sys_user su on cs.teacher_id_ = su.id_
  316. <where>
  317. <if test="records != null and records.size() != 0">
  318. and cs.id_ in
  319. <foreach collection="records" separator="," close=")" open="(" item="item" >
  320. #{item}
  321. </foreach>
  322. </if>
  323. </where>
  324. </select>
  325. <select id="selectCourseHomeworkByCourseId" resultType="com.yonge.cooleshow.biz.dal.vo.CourseScheduleHomeworkVo">
  326. select
  327. cs.id_ as courseId,
  328. cg.id_ as courseGroupId,
  329. cg.name_ as courseGroupName,
  330. cs.type_ as type,
  331. cs.class_num_ as classNum,
  332. cs.class_date_ as classDate,
  333. cs.start_time_ as startTime,
  334. cs.end_time_ as endTime,
  335. s.name_ as subjectName,
  336. ch.title_ as title,
  337. ch.content_ as content,
  338. ch.attachments_ as attachments,
  339. if(ch.id_ is null,0,1) as decorateHomework,
  340. ch.create_time_ as decorateTime,
  341. cs.status_ as courseStatus,
  342. cg.background_pic_ as backgroundPic
  343. from course_schedule cs
  344. left join course_group cg on cs.course_group_id_ = cg.id_
  345. left join course_homework ch on cs.id_ = ch.course_schedule_id_
  346. left join subject s on cg.subject_id_ = s.id_
  347. where cs.id_ = #{courseId}
  348. </select>
  349. <select id="selectStudentHomeworkByCourseId" resultType="com.yonge.cooleshow.biz.dal.vo.StudentHomeworkVo">
  350. select
  351. s.id_ as studentId,
  352. s.username_ as studentName,
  353. s.avatar_ as studentAvatar,
  354. s.del_flag_ as delFlag,
  355. if(sch.id_ is not null,1,0) as submitHomework,
  356. (case when sch.id_ is null then 'NOTCOMMIT'
  357. when sch.teacher_replied_ is null or sch.teacher_replied_ = '' then 'NOTREVIEW'
  358. else 'REVIEWED' end ) as homeworkStatus,
  359. (select group_concat(s2.name_) from subject s2
  360. where find_in_set(s2.id_,st.subject_id_) and s2.del_flag_ = 0 ) as subjectName
  361. from course_schedule_student_payment cssp
  362. left join sys_user s on cssp.user_id_ = s.id_
  363. left join student st on st.user_id_ = s.id_
  364. left join student_course_homework sch on cssp.user_id_ = sch.student_id_ and sch.course_schedule_id_ = cssp.course_id_
  365. <where>
  366. <if test="courseId != null">
  367. and cssp.course_id_ = #{courseId}
  368. </if>
  369. </where>
  370. ORDER BY cssp.id_ DESC
  371. </select>
  372. <select id="selectAbsenteeism" resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo">
  373. select
  374. cs.id_ as courseId
  375. ,if(sa.id_ is null,1,0) as absenteeism
  376. from course_schedule cs
  377. left join student_attendance sa on sa.course_schedule_id_ = cs.id_
  378. <where>
  379. sa.student_id_ = #{studentId}
  380. <if test="practiceRecord != null and practiceRecord.size() != 0">
  381. and cs.id_ in
  382. <foreach collection="practiceRecord" separator="," close=")" open="(" item="item" >
  383. #{item}
  384. </foreach>
  385. </if>
  386. </where>
  387. </select>
  388. <select id="selectGroupHomeworkList"
  389. resultType="com.yonge.cooleshow.biz.dal.wrapper.HomeworkWrapper$GroupHomework">
  390. select ch.id_ homeworkId,ch.course_schedule_id_ courseId,cs.class_num_ classNum,ch.content_ content,
  391. ch.completed_num_ completedNum,cg.pre_student_num_ studentNum,
  392. COUNT(CASE WHEN sch.id_ IS NULL OR sch.teacher_replied_ IS NULL OR sch.teacher_replied_ = '' THEN NULL ELSE 1 END) repliedNum
  393. from course_homework ch
  394. left join course_schedule cs ON cs.id_ = ch.course_schedule_id_
  395. left join student_course_homework sch ON sch.course_homework_id_ = ch.id_
  396. left join course_group cg ON cg.id_ = ch.course_group_id_
  397. WHERE ch.course_group_id_ = #{param.courseGroupId}
  398. <if test="param.search != null and param.search != ''">
  399. AND (ch.course_schedule_id_ = #{param.search} OR ch.content_ LIKE CONCAT('%',#{param.search},'%'))
  400. </if>
  401. GROUP BY ch.id_ ORDER BY cs.class_num_
  402. </select>
  403. </mapper>