CourseHomeworkMapper.xml 18 KB

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