CourseScheduleMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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.CourseScheduleDao">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.CourseSchedule">
  5. <id column="id_" jdbcType="INTEGER" property="id"/>
  6. <result column="course_group_id_" jdbcType="INTEGER" property="courseGroupId"/>
  7. <result column="type_" jdbcType="VARCHAR" property="type"/>
  8. <result column="status_" jdbcType="VARCHAR" property="status"/>
  9. <result column="class_num_" jdbcType="INTEGER" property="classNum"/>
  10. <result column="teacher_id_" jdbcType="INTEGER" property="teacherId"/>
  11. <result column="class_date_" jdbcType="TIMESTAMP" property="classDate"/>
  12. <result column="start_time_" jdbcType="TIMESTAMP" property="startTime"/>
  13. <result column="end_time_" jdbcType="TIMESTAMP" property="endTime"/>
  14. <result column="lock_" jdbcType="INTEGER" property="lock"/>
  15. <result column="lock_time_" jdbcType="TIMESTAMP" property="lockTime"/>
  16. <result column="ex_student_num_" jdbcType="INTEGER" property="exStudentNum"/>
  17. <result column="created_by_" jdbcType="INTEGER" property="createdBy"/>
  18. <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
  19. <result column="updated_by_" jdbcType="INTEGER" property="updatedBy"/>
  20. <result column="updated_time_" jdbcType="TIMESTAMP" property="updatedTime"/>
  21. </resultMap>
  22. <sql id="Base_Column_List">
  23. id_
  24. , course_group_id_, type_, status_,class_num_, teacher_id_, class_date_, start_time_, end_time_, lock_, lock_time_, ex_student_num_, created_by_, created_time_, updated_by_, updated_time_
  25. </sql>
  26. <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
  27. parameterType="com.yonge.cooleshow.biz.dal.entity.CourseSchedule">
  28. insert into course_schedule(course_group_id_, type_, status_,class_num_, teacher_id_, class_date_, start_time_,
  29. end_time_, lock_, lock_time_, ex_student_num_, created_by_, created_time_, updated_by_,
  30. updated_time_)
  31. values
  32. <foreach collection="entities" item="entity" separator=",">
  33. (#{entity.courseGroupId}, #{entity.type}, #{entity.status},#{entity.classNum}, #{entity.teacherId}, #{entity.classDate},
  34. #{entity.startTime}, #{entity.endTime}, #{entity.lock}, #{entity.lockTime},
  35. #{entity.exStudentNum}, #{entity.createdBy}, #{entity.createdTime}, #{entity.updatedBy},
  36. #{entity.updatedTime})
  37. </foreach>
  38. </insert>
  39. <select id="queryTeacherTotal" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherTotalVo">
  40. select a.*,b.starGrade from (
  41. <!-- 统计查询已上课时数,未上课时数 -->
  42. select
  43. a.teacher_id_ as userId,
  44. sum(if(a.end_time_ &lt;= now(),1,0)) as expTime,
  45. sum(if(a.end_time_ &gt; now(),1,0)) as unExpTime
  46. from course_schedule a
  47. where a.lock_ = 0 and a.type_ = 'PRACTICE'
  48. group by a.teacher_id_
  49. ) a
  50. left join (
  51. <!-- 统计老师星级评分 -->
  52. select
  53. a.teacher_id_ as userId,
  54. avg (b.score_) as starGrade
  55. from course_schedule a
  56. join course_schedule_replied b on a.id_ = b.course_schedule_id_
  57. where a.lock_ = 0 and type_ = 'PRACTICE' and b.score_ is not null
  58. group by a.teacher_id_
  59. ) b on a.userId = b.userId
  60. </select>
  61. <select id="queryStudentTotal" resultType="com.yonge.cooleshow.biz.dal.vo.StudentTotalVo">
  62. select
  63. b.user_id_ as userId,
  64. sum(if(a.end_time_ &lt;= now(),1,0)) as finshHours,
  65. sum(if(a.end_time_ &gt; now(),1,0)) as unfinshHours
  66. from course_schedule a
  67. join course_schedule_student_payment b on a.id_ = b.course_id_
  68. where a.lock_ = 0 and a.type_ = 'PRACTICE'
  69. group by b.user_id_
  70. </select>
  71. <select id="queryStudentCourse" resultMap="BaseResultMap">
  72. select b.id_,
  73. b.course_group_id_,
  74. b.type_,
  75. b.class_num_,
  76. b.teacher_id_,
  77. b.class_date_,
  78. b.start_time_,
  79. b.end_time_,
  80. b.lock_,
  81. b.lock_time_,
  82. b.ex_student_num_,
  83. b.status_,
  84. b.created_by_,
  85. b.created_time_,
  86. b.updated_by_,
  87. b.updated_time_
  88. from course_schedule_student_payment as a
  89. left join course_schedule as b on a.course_id_ = b.id_
  90. <where>
  91. a.user_id_ = #{param.studentId}
  92. <if test="param.greaterDate != null">
  93. AND <![CDATA[ b.start_time_ > #{param.greaterDate} ]]>
  94. </if>
  95. <if test="param.startClassDate != null">
  96. AND <![CDATA[ b.class_date_ >= #{param.startClassDate} ]]>
  97. </if>
  98. <if test="param.endClassDate != null">
  99. AND <![CDATA[ b.class_date_ <= #{param.endClassDate} ]]>
  100. </if>
  101. <if test="param.classDate != null">
  102. AND b.class_date_ = #{param.classDate}
  103. </if>
  104. <if test="param.status != null">
  105. AND b.status_ = #{param.status}
  106. </if>
  107. </where>
  108. order by b.start_time_ desc
  109. </select>
  110. <select id="queryLiveTeacherCourse" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherLiveCourseInfoVo">
  111. select
  112. b.id_ as courseGroupId,
  113. b.name_ as courseGroupName,
  114. s.name_ as subjectName,
  115. a.start_time_ as startTime,
  116. a.end_time_ as endTime,
  117. a.status_ as `status`,
  118. b.pre_student_num_ as studentCount,
  119. b.background_pic_ as backgroundPic
  120. from course_schedule as a
  121. left join course_group as b on a.course_group_id_ = b.id_
  122. left join subject as s on b.subject_id_ = s.id_
  123. where b.teacher_id_ = #{param.teacherId}
  124. AND a.lock_ = 0
  125. AND a.type_ = #{param.type}
  126. <![CDATA[ AND a.class_date_ >= #{param.startDate} ]]>
  127. <![CDATA[ AND a.class_date_ <= #{param.endDate} ]]>
  128. <if test="param.status !=null and param.status !=''">
  129. AND a.status_ = #{param.status}
  130. </if>
  131. <if test="param.subjectId != null">
  132. AND b.subject_id_ = #{param.subjectId}
  133. </if>
  134. </select>
  135. <select id="queryTeacherPracticeCourse" resultType="com.yonge.cooleshow.biz.dal.vo.MyCourseVo">
  136. SELECT
  137. u.id_ AS userId,
  138. u.username_ AS userName,
  139. u.avatar_ AS avatar,
  140. cs.class_date_ AS classDate,
  141. cs.start_time_ AS startTime,
  142. cs.end_time_ AS endTime,
  143. cs.status_ AS `status`,
  144. g.subject_id_ AS subjectId,
  145. sb.name_ AS subjectName,
  146. p.course_id_ AS courseId,
  147. p.course_group_id_ AS courseGoupId
  148. FROM course_schedule_student_payment p
  149. LEFT JOIN sys_user u ON p.user_id_ =u.id_
  150. LEFT JOIN course_schedule cs ON p.course_id_=cs.id_
  151. LEFT JOIN course_group g ON p.course_group_id_ = g.id_
  152. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  153. WHERE p.course_id_ IN
  154. (SELECT s.id_ FROM course_schedule s WHERE s.type_='PRACTICE' AND s.teacher_id_=#{param.teacherId})
  155. <if test="param.status !=null and param.status !=''">
  156. AND cs.status_ = #{param.status}
  157. </if>
  158. <if test="param.subjectId !=null">
  159. AND g.subject_id_ = #{param.subjectId}
  160. </if>
  161. <if test="param.classDate !=null and param.classDate !=''">
  162. AND cs.class_date_ = #{param.classDate}
  163. </if>
  164. <if test="param.startDate !=null and param.startDate !=''">
  165. <![CDATA[ AND cs.class_date_ >= #{param.startDate} ]]>
  166. </if>
  167. <if test="param.endDate !=null and param.endDate !=''">
  168. <![CDATA[ AND cs.class_date_ <= #{param.endDate} ]]>
  169. </if>
  170. <if test="param.repliedIds !=null">
  171. AND p.user_id_ IN
  172. <foreach collection="param.repliedIds" item="repliedIds" open="(" close=")" separator=",">
  173. #{repliedIds}
  174. </foreach>
  175. </if>
  176. <if test="param.studentName !=null and param.studentName !=''">
  177. AND u.username_ LIKE CONCAT('%', #{param.studentName}, '%')
  178. </if>
  179. </select>
  180. <select id="countTeacherNoDecorateHomework" resultType="java.lang.Integer">
  181. select count(1)
  182. from course_schedule cs
  183. left join course_homework ch on ch.course_schedule_id_ = cs.id_
  184. <where>
  185. <!-- 没有布置作业记录 -->
  186. <if test="param.decorate != null">
  187. <if test="param.decorate.code == 0">
  188. and ch.id_ is null
  189. </if>
  190. <if test="param.decorate.code == 1">
  191. and ch.id_ is not null
  192. </if>
  193. </if>
  194. <if test="param.courseStatus != null">
  195. and cs.type_ = #{param.courseType}
  196. </if>
  197. <if test="param.courseType != null">
  198. and cs.status_ = #{param.courseStatus}
  199. </if>
  200. <if test="param.teacherId != null">
  201. and cs.teacher_id_ = #{param.teacherId}
  202. </if>
  203. <if test="param.courseScheduleId != null ">
  204. and cs.id_ = #{param.courseScheduleId}
  205. </if>
  206. </where>
  207. </select>
  208. <select id="queryCourseSchedule" resultType="java.lang.String"
  209. parameterType="com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch">
  210. SELECT s.class_date_
  211. FROM course_schedule_student_payment p
  212. LEFT JOIN course_schedule s ON p.course_id_ = s.id_
  213. WHERE s.teacher_id_=#{teacherId}
  214. <![CDATA[ AND s.class_date_ >= #{startDate} ]]>
  215. <![CDATA[ AND s.class_date_ <= #{endDate} ]]>
  216. </select>
  217. <select id="queryStudentPracticeCourse" resultType="com.yonge.cooleshow.biz.dal.vo.MyCourseVo">
  218. SELECT
  219. s.id_ AS courseId,
  220. s.course_group_id_ AS courseGoupId,
  221. s.class_date_ AS classDate,
  222. s.start_time_ AS startTime,
  223. s.end_time_ AS endTime,
  224. s.status_ AS `status`,
  225. s.teacher_id_ AS teacherId,
  226. u.id_ AS userId,
  227. u.username_ AS userName,
  228. u.avatar_ AS avatar,
  229. g.subject_id_ AS subjectId,
  230. b.name_ AS subjectName
  231. FROM course_schedule s
  232. LEFT JOIN sys_user u ON s.teacher_id_ = u.id_
  233. LEFT JOIN course_group g ON s.course_group_id_ = g.id_
  234. LEFT JOIN `subject` b ON g.subject_id_ = b.id_
  235. WHERE s.id_ IN
  236. (SELECT course_id_ FROM course_schedule_student_payment WHERE user_id_ = #{param.studentId} AND course_type_ = 'PRACTICE')
  237. <if test="param.status !=null and param.status !=''">
  238. AND s.status_ = #{param.status}
  239. </if>
  240. <if test="param.subjectId !=null">
  241. AND g.subject_id_ = #{param.subjectId}
  242. </if>
  243. <if test="param.classDate !=null and param.classDate !=''">
  244. AND s.class_date_ = #{param.classDate}
  245. </if>
  246. <if test="param.startDate !=null and param.startDate !=''">
  247. <![CDATA[ AND s.class_date_ >= #{param.startDate} ]]>
  248. </if>
  249. <if test="param.endDate !=null and param.endDate !=''">
  250. <![CDATA[ AND s.class_date_ <= #{param.endDate} ]]>
  251. </if>
  252. </select>
  253. <select id="queryCourseUser" resultType="com.yonge.cooleshow.biz.dal.vo.CourseStudent">
  254. SELECT
  255. cs.id_ AS courseId,
  256. cs.course_group_id_ AS courseGoupId,
  257. cs.class_date_ AS classDate,
  258. cs.start_time_ AS startTime,
  259. cs.end_time_ AS endTime,
  260. cs.status_ AS `status`,
  261. cs.type_ AS courseType,
  262. NULL AS userId,
  263. CONCAT(g.name_,'-第',cs.class_num_,'课') AS name,
  264. p.payCount AS payCount,
  265. g.background_pic_ AS cover,
  266. g.subject_id_ AS subjectId,
  267. sb.name_ AS subjectName
  268. FROM course_schedule cs
  269. LEFT JOIN course_group g ON cs.course_group_id_ = g.id_
  270. LEFT JOIN (SELECT course_id_ AS pid,count(*) AS payCount FROM course_schedule_student_payment GROUP BY course_id_ ) p ON cs.id_=p.pid
  271. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  272. WHERE cs.type_='LIVE'
  273. AND cs.teacher_id_=#{param.teacherId}
  274. AND cs.class_date_=#{param.classDate}
  275. AND cs.id_ IN(
  276. SELECT c.id_
  277. FROM course_schedule_student_payment p,course_schedule c
  278. WHERE p.course_id_=c.id_
  279. AND p.course_group_id_ = c.course_group_id_
  280. AND c.teacher_id_=#{param.teacherId}
  281. AND c.class_date_=#{param.classDate}
  282. AND c.type_='LIVE')
  283. UNION
  284. SELECT
  285. p.course_id_ AS courseId,
  286. p.course_group_id_ AS courseGoupId,
  287. cs.class_date_ AS classDate,
  288. cs.start_time_ AS startTime,
  289. cs.end_time_ AS endTime,
  290. cs.status_ AS `status`,
  291. cs.type_ AS courseType,
  292. u.id_ AS userId,
  293. u.username_ AS name,
  294. NULL AS payCount,
  295. u.avatar_ AS cover,
  296. g.subject_id_ AS subjectId,
  297. sb.name_ AS subjectName
  298. FROM course_schedule_student_payment p
  299. LEFT JOIN sys_user u ON p.user_id_ =u.id_
  300. LEFT JOIN course_schedule cs ON p.course_id_=cs.id_
  301. LEFT JOIN course_group g ON p.course_group_id_ = g.id_
  302. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  303. WHERE p.course_id_ IN (SELECT s.id_ FROM course_schedule s WHERE s.type_='PRACTICE' AND s.teacher_id_=#{param.teacherId})
  304. AND cs.class_date_=#{param.classDate}
  305. ORDER BY startTime
  306. </select>
  307. <select id="queryCourseScheduleStudent" resultType="java.lang.String"
  308. parameterType="com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch">
  309. SELECT class_date_ FROM course_schedule
  310. WHERE id_ IN (SELECT course_id_ FROM course_schedule_student_payment WHERE user_id_ = #{studentId} AND course_type_ = 'PRACTICE')
  311. <![CDATA[ AND class_date_ >= #{startDate} ]]>
  312. <![CDATA[ AND class_date_ <= #{endDate} ]]>
  313. </select>
  314. <select id="teacherList" resultType="com.yonge.cooleshow.biz.dal.vo.PracticeTeacherVo">
  315. SELECT
  316. cs.teacher_id_ AS teacherId,
  317. u.username_ AS userName,
  318. u.avatar_ AS avatar,
  319. tt.star_grade_ AS starGrade,
  320. tt.exp_time_ AS expTime,
  321. t.graduate_school_ AS school,
  322. t.subject_ AS schoolSubject,
  323. (SELECT group_concat(p.subject_name_) FROM teacher_subject_price p WHERE find_in_set(cs.teacher_id_,p.teacher_id_)) AS configSubject,
  324. sp.subject_id_ AS subjectId,
  325. sp.subject_name_ AS subjectName,
  326. sp.subject_price_ AS subjectPrice,
  327. sp.course_minutes_ AS courseMinutes
  328. FROM course_schedule cs
  329. LEFT JOIN sys_user u ON cs.teacher_id_ = u.id_
  330. LEFT JOIN teacher_total tt ON cs.teacher_id_=tt.user_id_
  331. LEFT JOIN teacher t ON cs.teacher_id_=t.user_id_
  332. LEFT JOIN teacher_subject_price sp ON cs.teacher_id_=sp.teacher_id_
  333. WHERE cs.type_='PRACTICE'
  334. <if test="param.subjectId !=null">
  335. AND sp.subject_id_=#{param.subjectId}
  336. </if>
  337. <if test="param.search !=null and param.search !=''">
  338. AND u.username_ LIKE CONCAT('%', #{param.search}, '%')
  339. </if>
  340. <choose>
  341. <when test="param.sort !=null and param.sort !=''">
  342. ORDER BY ${param.sort}
  343. </when>
  344. </choose>
  345. </select>
  346. <select id="queryCourseTeacher" resultType="com.yonge.cooleshow.biz.dal.vo.CourseStudent"
  347. parameterType="com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch">
  348. SELECT
  349. s.id_ AS courseId,
  350. s.course_group_id_ AS courseGoupId,
  351. s.class_date_ AS classDate,
  352. s.start_time_ AS startTime,
  353. s.end_time_ AS endTime,
  354. s.type_ AS courseType,
  355. s.status_ AS `status`,
  356. u.id_ AS userId,
  357. u.username_ AS name,
  358. u.avatar_ AS cover,
  359. g.subject_id_ AS subjectId,
  360. b.name_ AS subjectName
  361. FROM course_schedule s
  362. LEFT JOIN sys_user u ON s.teacher_id_ = u.id_
  363. LEFT JOIN course_group g ON s.course_group_id_ = g.id_
  364. LEFT JOIN `subject` b ON g.subject_id_ = b.id_
  365. WHERE s.id_ IN
  366. (SELECT course_id_ FROM course_schedule_student_payment WHERE user_id_ = #{param.studentId} AND course_type_ = 'PRACTICE')
  367. AND s.class_date_ = #{param.classDate}
  368. UNION
  369. SELECT
  370. s.id_ AS courseId,
  371. s.course_group_id_ AS courseGoupId,
  372. s.class_date_ AS classDate,
  373. s.start_time_ AS startTime,
  374. s.end_time_ AS endTime,
  375. s.type_ AS courseType,
  376. s.status_ AS `status`,
  377. NULL AS userId,
  378. CONCAT(g.name_,'-第',s.class_num_,'课') AS name,
  379. g.background_pic_ AS cover,
  380. g.subject_id_ AS subjectId,
  381. sb.name_ AS subjectName
  382. FROM course_schedule s
  383. LEFT JOIN course_group g ON s.course_group_id_ = g.id_
  384. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  385. WHERE s.id_ IN
  386. (SELECT course_id_ FROM course_schedule_student_payment WHERE user_id_ = #{param.studentId} AND course_type_ = 'LIVE')
  387. AND s.class_date_ = #{param.classDate}
  388. ORDER BY startTime
  389. </select>
  390. <select id="queryStudentLiveCourse" parameterType="map" resultType="com.yonge.cooleshow.biz.dal.vo.CourseStudent">
  391. SELECT
  392. cs.id_ AS courseId,
  393. cs.course_group_id_ AS courseGoupId,
  394. cs.class_date_ AS classDate,
  395. cs.start_time_ AS startTime,
  396. cs.end_time_ AS endTime,
  397. cs.status_ AS `status`,
  398. cs.type_ AS courseType,
  399. su.real_name_ AS userId,
  400. CONCAT(g.name_,'-第',cs.class_num_,'课') AS name,
  401. IFNULL(g.pre_student_num_, 0) AS payCount,
  402. g.background_pic_ AS cover,
  403. g.subject_id_ AS subjectId,
  404. sb.name_ AS subjectName,
  405. su.avatar_ AS avatar
  406. FROM
  407. course_schedule_student_payment as a
  408. LEFT JOIN course_schedule cs on a.course_id_ = cs.id_
  409. LEFT JOIN course_group g ON cs.course_group_id_ = g.id_
  410. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  411. LEFT JOIN sys_user su on g.teacher_id_ = su.id_
  412. WHERE cs.type_=#{param.type}
  413. AND a.user_id_ = #{param.studentId}
  414. <![CDATA[ AND class_date_ >= #{param.startDate} ]]>
  415. <![CDATA[ AND class_date_ <= #{param.endDate} ]]>
  416. <if test="param.subjectId != null">
  417. AND g.subject_id_ = #{param.subjectId}
  418. </if>
  419. <if test="param.courseState != null">
  420. and cs.status_ = #{param.courseState}
  421. </if>
  422. </select>
  423. <insert id="addCourseGroup" parameterType="com.yonge.cooleshow.biz.dal.dto.PracticeScheduleDto" useGeneratedKeys="true" keyProperty="groupId">
  424. Insert INTO course_group(teacher_id_,type_,name_,subject_id_,single_course_minutes_,course_num_,course_introduce_,
  425. course_price_,status_,created_by_,mix_student_num_,course_start_time_,pre_student_num_)
  426. VALUES (#{teacherId},#{type},#{courseGroupName},#{subjectId},#{singleCourseMinutes},#{courseNum},#{courseIntroduce},
  427. #{coursePrice},#{status},#{studentId},#{mixStudentNum},#{courseStartTime},1)
  428. </insert>
  429. <update id="updateLock" parameterType="java.util.List">
  430. UPDATE course_schedule SET lock_ = 0 WHERE id_ IN
  431. <foreach collection="list" item="item" open="(" separator="," close=")">
  432. #{item}
  433. </foreach>
  434. </update>
  435. <update id="courseAdjust" parameterType="com.yonge.cooleshow.biz.dal.vo.CourseAdjustVo">
  436. UPDATE course_schedule
  437. SET class_date_=#{classDate},start_time_=#{startTime},end_time_=#{endTime}
  438. WHERE id_ = #{courseId}
  439. </update>
  440. </mapper>