CourseScheduleMapper.xml 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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
  41. t.user_id_ as userId,
  42. a.expTime,
  43. a.unExpTime,
  44. b.starGrade
  45. from teacher t
  46. left join (
  47. <!-- 统计查询已上课时数,未上课时数 -->
  48. select
  49. a.teacher_id_ as userId,
  50. sum(if(a.end_time_ &lt;= now(),1,0)) as expTime,
  51. sum(if(a.end_time_ &gt; now(),1,0)) as unExpTime
  52. from course_schedule a
  53. where a.lock_ = 0 and a.type_ = 'PRACTICE'
  54. <if test="userId != null and userId != ''">
  55. and a.teacher_id_ = #{userId}
  56. </if>
  57. group by a.teacher_id_
  58. ) a on t.user_id_ = a.userId
  59. left join (
  60. <!-- 统计老师星级评分 -->
  61. select
  62. a.teacher_id_ as userId,
  63. avg (b.score_) as starGrade
  64. from course_schedule a
  65. join course_schedule_replied b on a.id_ = b.course_schedule_id_
  66. where a.lock_ = 0 and a.type_ = 'PRACTICE' and b.score_ is not null
  67. <if test="userId != null and userId != ''">
  68. and a.teacher_id_ = #{userId}
  69. </if>
  70. group by a.teacher_id_
  71. ) b on t.user_id_ = b.userId
  72. <where>
  73. <if test="userId != null and userId != ''">
  74. and t.user_id_ = #{userId}
  75. </if>
  76. </where>
  77. </select>
  78. <select id="queryStudentTotal" resultType="com.yonge.cooleshow.biz.dal.vo.StudentTotalVo">
  79. select
  80. t.user_id_ as userId,
  81. sum(if(b.end_time_ &lt;= now(),1,0)) as finshHours,
  82. sum(if(b.end_time_ &gt; now(),1,0)) as unfinshHours
  83. from student t
  84. left join course_schedule_student_payment a on t.user_id_ = a.user_id_
  85. left join course_schedule b on a.course_id_ = b.id_ and b.lock_ = 0 and b.type_ = 'PRACTICE'
  86. <where>
  87. <if test="userId != null and userId != ''">
  88. and t.user_id_ = #{userId}
  89. </if>
  90. </where>
  91. group by t.user_id_
  92. </select>
  93. <select id="queryStudentCourse" resultMap="BaseResultMap">
  94. select b.id_,
  95. b.course_group_id_,
  96. b.type_,
  97. b.class_num_,
  98. b.teacher_id_,
  99. b.class_date_,
  100. b.start_time_,
  101. b.end_time_,
  102. b.lock_,
  103. b.lock_time_,
  104. b.ex_student_num_,
  105. b.status_,
  106. b.created_by_,
  107. b.created_time_,
  108. b.updated_by_,
  109. b.updated_time_
  110. from course_schedule_student_payment as a
  111. left join course_schedule as b on a.course_id_ = b.id_
  112. <where>
  113. a.user_id_ = #{param.studentId}
  114. <if test="param.greaterDate != null">
  115. AND <![CDATA[ b.start_time_ > #{param.greaterDate} ]]>
  116. </if>
  117. <if test="param.startClassDate != null">
  118. AND <![CDATA[ b.class_date_ >= #{param.startClassDate} ]]>
  119. </if>
  120. <if test="param.endClassDate != null">
  121. AND <![CDATA[ b.class_date_ <= #{param.endClassDate} ]]>
  122. </if>
  123. <if test="param.classDate != null">
  124. AND b.class_date_ = #{param.classDate}
  125. </if>
  126. <if test="param.status != null">
  127. AND b.status_ = #{param.status}
  128. </if>
  129. <if test="param.statusList != null">
  130. AND b.status_ IN
  131. <foreach collection="param.statusList" item="item" open="(" separator="," close=")">
  132. #{item}
  133. </foreach>
  134. </if>
  135. </where>
  136. order by b.start_time_ desc
  137. </select>
  138. <select id="queryLiveTeacherCourse" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherLiveCourseInfoVo">
  139. select
  140. b.id_ as courseGroupId,
  141. b.name_ as courseGroupName,
  142. a.id_ as courseId,
  143. a.class_num_ as classNum,
  144. s.name_ as subjectName,
  145. a.start_time_ as startTime,
  146. a.end_time_ as endTime,
  147. a.status_ as `status`,
  148. b.pre_student_num_ as studentCount,
  149. b.background_pic_ as backgroundPic,
  150. b.im_group_id_ as imGroupId
  151. from course_schedule as a
  152. left join course_group as b on a.course_group_id_ = b.id_
  153. left join subject as s on b.subject_id_ = s.id_
  154. where b.teacher_id_ = #{param.teacherId}
  155. AND a.lock_ = 0
  156. AND a.type_ = #{param.type}
  157. <![CDATA[ AND a.class_date_ >= #{param.startDate} ]]>
  158. <![CDATA[ AND a.class_date_ <= #{param.endDate} ]]>
  159. <if test="param.status !=null and param.status !=''">
  160. AND a.status_ = #{param.status}
  161. </if>
  162. <if test="param.subjectId != null">
  163. AND b.subject_id_ = #{param.subjectId}
  164. </if>
  165. order by start_time_
  166. </select>
  167. <select id="queryTeacherPracticeCourse" resultType="com.yonge.cooleshow.biz.dal.vo.MyCourseVo">
  168. SELECT
  169. u.id_ AS userId,
  170. u.username_ AS userName,
  171. u.real_name_ AS realName,
  172. u.avatar_ AS avatar,
  173. cs.class_date_ AS classDate,
  174. cs.start_time_ AS startTime,
  175. cs.end_time_ AS endTime,
  176. cs.status_ AS `status`,
  177. g.subject_id_ AS subjectId,
  178. sb.name_ AS subjectName,
  179. p.course_id_ AS courseId,
  180. p.course_group_id_ AS courseGoupId,
  181. (r.student_replied_ IS NOT NULL) AS studentReplied,
  182. (r.teacher_replied_ IS NOT NULL) AS teacherReplied
  183. FROM course_schedule_student_payment p
  184. LEFT JOIN sys_user u ON p.user_id_ =u.id_
  185. LEFT JOIN course_schedule cs ON p.course_id_=cs.id_
  186. LEFT JOIN course_group g ON p.course_group_id_ = g.id_
  187. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  188. LEFT JOIN course_schedule_replied r ON cs.id_=r.course_schedule_id_
  189. WHERE p.course_id_ IN
  190. (SELECT s.id_ FROM course_schedule s WHERE s.type_='PRACTICE' AND lock_=0 AND s.teacher_id_=#{param.teacherId})
  191. <if test="param.status !=null and param.status !=''">
  192. AND cs.status_ = #{param.status}
  193. </if>
  194. <if test="param.subjectId !=null">
  195. AND g.subject_id_ = #{param.subjectId}
  196. </if>
  197. <if test="param.classDate !=null and param.classDate !=''">
  198. AND cs.class_date_ = #{param.classDate}
  199. </if>
  200. <if test="param.startDate !=null and param.startDate !=''">
  201. <![CDATA[ AND cs.class_date_ >= #{param.startDate} ]]>
  202. </if>
  203. <if test="param.endDate !=null and param.endDate !=''">
  204. <![CDATA[ AND cs.class_date_ <= #{param.endDate} ]]>
  205. </if>
  206. <if test="param.repliedIds !=null">
  207. AND p.user_id_ IN
  208. <foreach collection="param.repliedIds" item="repliedIds" open="(" close=")" separator=",">
  209. #{repliedIds}
  210. </foreach>
  211. </if>
  212. <if test="param.studentName !=null and param.studentName !=''">
  213. AND u.username_ LIKE CONCAT('%', #{param.studentName}, '%')
  214. </if>
  215. ORDER BY cs.start_time_
  216. </select>
  217. <select id="countTeacherNoDecorateHomework" resultType="java.lang.Integer">
  218. select count(1)
  219. from course_schedule cs
  220. left join course_homework ch on ch.course_schedule_id_ = cs.id_
  221. <where>
  222. <!-- 没有布置作业记录 -->
  223. <if test="param.decorate != null">
  224. <if test="param.decorate.code == 0">
  225. and ch.id_ is null
  226. </if>
  227. <if test="param.decorate.code == 1">
  228. and ch.id_ is not null
  229. </if>
  230. </if>
  231. <if test="param.courseStatus != null">
  232. and cs.type_ = #{param.courseType}
  233. </if>
  234. <if test="param.courseType != null">
  235. and cs.status_ = #{param.courseStatus}
  236. </if>
  237. <if test="param.teacherId != null">
  238. and cs.teacher_id_ = #{param.teacherId}
  239. </if>
  240. <if test="param.courseScheduleId != null ">
  241. and cs.id_ = #{param.courseScheduleId}
  242. </if>
  243. </where>
  244. </select>
  245. <select id="queryCourseSchedule" resultType="java.lang.String"
  246. parameterType="com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch">
  247. SELECT s.class_date_
  248. FROM course_schedule_student_payment p
  249. LEFT JOIN course_schedule s ON p.course_id_ = s.id_
  250. WHERE s.teacher_id_=#{teacherId}
  251. AND s.lock_=0
  252. AND s.status_ IN ('ING','COMPLETE','NOT_START')
  253. <![CDATA[ AND s.class_date_ >= #{startDate} ]]>
  254. <![CDATA[ AND s.class_date_ <= #{endDate} ]]>
  255. </select>
  256. <select id="queryStudentPracticeCourse" resultType="com.yonge.cooleshow.biz.dal.vo.MyCourseVo">
  257. SELECT
  258. s.id_ AS courseId,
  259. s.course_group_id_ AS courseGoupId,
  260. s.class_date_ AS classDate,
  261. s.start_time_ AS startTime,
  262. s.end_time_ AS endTime,
  263. s.status_ AS `status`,
  264. s.teacher_id_ AS teacherId,
  265. u.id_ AS userId,
  266. u.username_ AS userName,
  267. u.real_name_ AS realName,
  268. u.avatar_ AS avatar,
  269. g.subject_id_ AS subjectId,
  270. b.name_ AS subjectName
  271. FROM course_schedule s
  272. LEFT JOIN sys_user u ON s.teacher_id_ = u.id_
  273. LEFT JOIN course_group g ON s.course_group_id_ = g.id_
  274. LEFT JOIN `subject` b ON g.subject_id_ = b.id_
  275. WHERE s.lock_=0
  276. AND s.status_ IN ('ING','NOT_START','COMPLETE')
  277. AND s.id_ IN
  278. (SELECT course_id_ FROM course_schedule_student_payment WHERE user_id_ = #{param.studentId} AND course_type_ = 'PRACTICE')
  279. <if test="param.status !=null and param.status !=''">
  280. AND s.status_ = #{param.status}
  281. </if>
  282. <if test="param.subjectId !=null">
  283. AND g.subject_id_ = #{param.subjectId}
  284. </if>
  285. <if test="param.classDate !=null and param.classDate !=''">
  286. AND s.class_date_ = #{param.classDate}
  287. </if>
  288. <if test="param.startDate !=null and param.startDate !=''">
  289. <![CDATA[ AND s.class_date_ >= #{param.startDate} ]]>
  290. </if>
  291. <if test="param.endDate !=null and param.endDate !=''">
  292. <![CDATA[ AND s.class_date_ <= #{param.endDate} ]]>
  293. </if>
  294. </select>
  295. <select id="queryCourseUser" resultType="com.yonge.cooleshow.biz.dal.vo.CourseStudent">
  296. SELECT
  297. cs.id_ AS courseId,
  298. cs.course_group_id_ AS courseGoupId,
  299. cs.class_date_ AS classDate,
  300. cs.start_time_ AS startTime,
  301. cs.end_time_ AS endTime,
  302. cs.status_ AS `status`,
  303. cs.type_ AS courseType,
  304. NULL AS userId,
  305. CONCAT(g.name_,'-第',cs.class_num_,'课') AS name,
  306. NULL AS realName,
  307. p.payCount AS payCount,
  308. g.background_pic_ AS cover,
  309. g.subject_id_ AS subjectId,
  310. sb.name_ AS subjectName,
  311. (r.student_replied_ IS NOT NULL) AS studentReplied,
  312. (r.teacher_replied_ IS NOT NULL) AS teacherReplied
  313. FROM course_schedule cs
  314. LEFT JOIN course_group g ON cs.course_group_id_ = g.id_
  315. 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
  316. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  317. LEFT JOIN course_schedule_replied r ON cs.id_ = r.course_schedule_id_
  318. WHERE cs.lock_=0
  319. AND cs.status_ IN ('ING','COMPLETE','NOT_START')
  320. AND cs.type_ IN ('LIVE','PIANO_ROOM_CLASS')
  321. AND cs.teacher_id_=#{param.teacherId}
  322. AND cs.class_date_=#{param.classDate}
  323. AND cs.id_ IN(
  324. SELECT c.id_
  325. FROM course_schedule_student_payment p,course_schedule c
  326. WHERE p.course_id_=c.id_
  327. AND p.course_group_id_ = c.course_group_id_
  328. AND c.teacher_id_=#{param.teacherId}
  329. AND c.class_date_=#{param.classDate}
  330. AND c.type_ IN ('LIVE','PIANO_ROOM_CLASS')
  331. )
  332. UNION
  333. SELECT
  334. p.course_id_ AS courseId,
  335. p.course_group_id_ AS courseGoupId,
  336. cs.class_date_ AS classDate,
  337. cs.start_time_ AS startTime,
  338. cs.end_time_ AS endTime,
  339. cs.status_ AS `status`,
  340. cs.type_ AS courseType,
  341. u.id_ AS userId,
  342. u.username_ AS name,
  343. u.real_name_ AS realName,
  344. NULL AS payCount,
  345. u.avatar_ AS cover,
  346. g.subject_id_ AS subjectId,
  347. sb.name_ AS subjectName,
  348. (r.student_replied_ IS NOT NULL) AS studentReplied,
  349. (r.teacher_replied_ IS NOT NULL) AS teacherReplied
  350. FROM course_schedule_student_payment p
  351. LEFT JOIN sys_user u ON p.user_id_ =u.id_
  352. LEFT JOIN course_schedule cs ON p.course_id_=cs.id_
  353. LEFT JOIN course_group g ON p.course_group_id_ = g.id_
  354. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  355. LEFT JOIN course_schedule_replied r ON cs.id_ = r.course_schedule_id_
  356. WHERE cs.lock_=0
  357. AND cs.status_ IN ('ING','COMPLETE','NOT_START')
  358. AND p.course_id_ IN (SELECT s.id_ FROM course_schedule s WHERE s.type_='PRACTICE' AND s.teacher_id_=#{param.teacherId})
  359. AND cs.class_date_=#{param.classDate}
  360. ORDER BY startTime
  361. </select>
  362. <select id="queryCourseScheduleStudent" resultType="java.lang.String"
  363. parameterType="com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch">
  364. SELECT class_date_ FROM course_schedule
  365. WHERE lock_=0
  366. AND status_ IN ('ING','NOT_START','COMPLETE')
  367. AND id_ IN (SELECT course_id_ FROM course_schedule_student_payment WHERE user_id_ = #{studentId})
  368. <![CDATA[ AND class_date_ >= #{startDate} ]]>
  369. <![CDATA[ AND class_date_ <= #{endDate} ]]>
  370. </select>
  371. <select id="teacherList" resultType="com.yonge.cooleshow.biz.dal.vo.PracticeTeacherVo">
  372. SELECT
  373. t.user_id_ AS teacherId,
  374. u.username_ AS userName,
  375. u.real_name_ AS realName,
  376. u.avatar_ AS avatar,
  377. tt.star_grade_ AS starGrade,
  378. tt.exp_time_ AS expTime,
  379. t.graduate_school_ AS school,
  380. t.subject_ AS schoolSubject,
  381. (SELECT group_concat(p.subject_name_) FROM teacher_subject_price p WHERE find_in_set(t.user_id_,p.teacher_id_)) AS configSubject,
  382. sp.subjectId AS subjectId,
  383. sp.subjectName AS subjectName,
  384. sp.subjectPrice AS subjectPrice,
  385. sp.courseMinutes AS courseMinutes
  386. FROM teacher t
  387. LEFT JOIN sys_user u ON t.user_id_ = u.id_
  388. LEFT JOIN teacher_total tt ON t.user_id_=tt.user_id_
  389. LEFT JOIN (SELECT
  390. f.teacher_id_ AS teacherId,
  391. p.subject_id_ AS subjectId,
  392. p.subject_name_ AS subjectName,
  393. p.subject_price_ AS subjectPrice,
  394. p.course_minutes_ AS courseMinutes
  395. FROM teacher_free_time f
  396. LEFT JOIN teacher_subject_price p ON f.id_=p.teacher_free_time_id
  397. WHERE f.default_flag_=1
  398. AND p.subject_id_=#{param.subjectId}) sp ON t.user_id_=sp.teacherId
  399. <where>
  400. <if test="param.teacherIdList != null and param.teacherIdList.size>0">
  401. AND t.user_id_ IN
  402. <foreach collection="param.teacherIdList" item="item" open="(" separator="," close=")">
  403. #{item}
  404. </foreach>
  405. </if>
  406. <if test="param.subjectId !=null">
  407. AND sp.subjectId=#{param.subjectId}
  408. </if>
  409. <if test="param.search !=null and param.search !=''">
  410. AND u.username_ LIKE CONCAT('%', #{param.search}, '%')
  411. </if>
  412. <choose>
  413. <when test="param.sort !=null and param.sort !=''">
  414. ORDER BY ${param.sort}
  415. </when>
  416. </choose>
  417. </where>
  418. </select>
  419. <select id="queryCourseTeacher" resultType="com.yonge.cooleshow.biz.dal.vo.CourseStudent"
  420. parameterType="com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch">
  421. SELECT
  422. s.id_ AS courseId,
  423. s.course_group_id_ AS courseGoupId,
  424. s.class_date_ AS classDate,
  425. s.start_time_ AS startTime,
  426. s.end_time_ AS endTime,
  427. s.type_ AS courseType,
  428. s.status_ AS `status`,
  429. u.id_ AS userId,
  430. u.username_ AS name,
  431. u.real_name_ AS realName,
  432. u.avatar_ AS cover,
  433. g.subject_id_ AS subjectId,
  434. b.name_ AS subjectName,
  435. (r.student_replied_ IS NOT NULL) AS studentReplied,
  436. (r.teacher_replied_ IS NOT NULL) AS teacherReplied
  437. FROM course_schedule s
  438. LEFT JOIN sys_user u ON s.teacher_id_ = u.id_
  439. LEFT JOIN course_group g ON s.course_group_id_ = g.id_
  440. LEFT JOIN `subject` b ON g.subject_id_ = b.id_
  441. LEFT JOIN course_schedule_replied r ON s.id_ = r.course_schedule_id_
  442. WHERE s.lock_=0
  443. AND s.status_ IN ('ING','NOT_START','COMPLETE')
  444. AND s.id_ IN
  445. (SELECT course_id_ FROM course_schedule_student_payment WHERE user_id_ = #{param.studentId} AND course_type_ = 'PRACTICE')
  446. AND s.class_date_ = #{param.classDate}
  447. UNION
  448. SELECT
  449. s.id_ AS courseId,
  450. s.course_group_id_ AS courseGoupId,
  451. s.class_date_ AS classDate,
  452. s.start_time_ AS startTime,
  453. s.end_time_ AS endTime,
  454. s.type_ AS courseType,
  455. s.status_ AS `status`,
  456. NULL AS userId,
  457. CONCAT(g.name_,'-第',s.class_num_,'课') AS name,
  458. NULL AS realName,
  459. g.background_pic_ AS cover,
  460. g.subject_id_ AS subjectId,
  461. sb.name_ AS subjectName,
  462. (r.student_replied_ IS NOT NULL) AS studentReplied,
  463. (r.teacher_replied_ IS NOT NULL) AS teacherReplied
  464. FROM course_schedule s
  465. LEFT JOIN course_group g ON s.course_group_id_ = g.id_
  466. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  467. LEFT JOIN course_schedule_replied r ON s.id_ = r.course_schedule_id_
  468. WHERE s.lock_=0
  469. AND s.status_ IN ('ING','NOT_START','COMPLETE')
  470. AND s.id_ IN
  471. (SELECT course_id_ FROM course_schedule_student_payment WHERE user_id_ = #{param.studentId} AND course_type_ IN ('LIVE','PIANO_ROOM_CLASS'))
  472. AND s.class_date_ = #{param.classDate}
  473. ORDER BY startTime
  474. </select>
  475. <select id="queryStudentLiveCourse" parameterType="map" resultType="com.yonge.cooleshow.biz.dal.vo.CourseStudent">
  476. SELECT distinct
  477. cs.id_ AS courseId,
  478. cs.course_group_id_ AS courseGoupId,
  479. cs.class_date_ AS classDate,
  480. cs.start_time_ AS startTime,
  481. cs.end_time_ AS endTime,
  482. cs.status_ AS `status`,
  483. cs.type_ AS courseType,
  484. su.username_ AS userId,
  485. CONCAT(g.name_,'-第',cs.class_num_,'课') AS name,
  486. IFNULL(g.pre_student_num_, 0) AS payCount,
  487. g.background_pic_ AS cover,
  488. g.subject_id_ AS subjectId,
  489. sb.name_ AS subjectName,
  490. su.avatar_ AS avatar,
  491. g.im_group_id_ as imGroupId
  492. FROM
  493. course_schedule_student_payment as a
  494. LEFT JOIN course_schedule cs on a.course_id_ = cs.id_
  495. LEFT JOIN course_group g ON cs.course_group_id_ = g.id_
  496. LEFT JOIN `subject` sb ON g.subject_id_=sb.id_
  497. LEFT JOIN sys_user su on g.teacher_id_ = su.id_
  498. LEFT JOIN user_order o on a.order_no_ = o.order_no_
  499. WHERE cs.type_=#{param.type}
  500. AND a.user_id_ = #{param.studentId}
  501. <![CDATA[ AND class_date_ >= #{param.startDate} ]]>
  502. <![CDATA[ AND class_date_ <= #{param.endDate} ]]>
  503. <if test="param.orderState != null">
  504. AND o.status_ = #{param.orderState}
  505. </if>
  506. <if test="param.subjectId != null">
  507. AND g.subject_id_ = #{param.subjectId}
  508. </if>
  509. <if test="param.courseState != null">
  510. and cs.status_ = #{param.courseState}
  511. </if>
  512. </select>
  513. <insert id="addCourseGroup" parameterType="com.yonge.cooleshow.biz.dal.dto.PracticeScheduleDto" useGeneratedKeys="true" keyProperty="groupId">
  514. Insert INTO course_group(teacher_id_,type_,name_,subject_id_,single_course_minutes_,course_num_,course_introduce_,
  515. course_price_,status_,created_by_,mix_student_num_,course_start_time_,pre_student_num_)
  516. VALUES (#{teacherId},#{type},#{courseGroupName},#{subjectId},#{singleCourseMinutes},#{courseNum},#{courseIntroduce},
  517. #{coursePrice},#{status},#{studentId},#{mixStudentNum},#{courseStartTime},1)
  518. </insert>
  519. <update id="updateLock" parameterType="java.util.List">
  520. UPDATE course_schedule SET lock_ = 0 WHERE id_ IN
  521. <foreach collection="list" item="item" open="(" separator="," close=")">
  522. #{item}
  523. </foreach>
  524. </update>
  525. <update id="courseAdjust" parameterType="com.yonge.cooleshow.biz.dal.vo.CourseAdjustVo">
  526. UPDATE course_schedule
  527. SET class_date_=#{classDate},start_time_=#{startTime},end_time_=#{endTime}
  528. WHERE id_ = #{courseId}
  529. </update>
  530. <select id="selectLive" resultType="com.yonge.cooleshow.biz.dal.vo.StudentHomePage$Live">
  531. SELECT
  532. u.id_ AS teacherId,
  533. u.username_ AS teacherName,
  534. u.real_name_ AS realName,
  535. u.avatar_ AS avatar,
  536. g.id_ AS courseGroupId,
  537. g.name_ AS courseGroupName,
  538. g.course_price_ AS courseGroupPrice,
  539. g.course_start_time_ AS courseStartTime,
  540. g.background_pic_ AS backgroundPic,
  541. g.course_num_ AS courseNum,
  542. g.pre_student_num_ AS buyCount,
  543. g.subject_id_ AS subjectId,
  544. s.name_ AS subjectName
  545. FROM course_group g
  546. LEFT JOIN sys_user u ON g.teacher_id_=u.id_
  547. LEFT JOIN subject s ON g.subject_id_=s.id_
  548. WHERE type_='LIVE' and g.status_ = 'APPLY' and #{appAuditVersion} = g.audit_version_
  549. ORDER BY courseStartTime DESC LIMIT 4
  550. </select>
  551. <select id="selectVideo" resultType="com.yonge.cooleshow.biz.dal.vo.StudentHomePage$Video">
  552. SELECT
  553. u.id_ AS teacherId,
  554. u.username_ AS teacherName,
  555. u.real_name_ AS realName,
  556. u.avatar_ AS avatar,
  557. g.id_ AS videoGroupId,
  558. g.lesson_name_ AS videoGroupName,
  559. g.lesson_price_ AS lessonPrice,
  560. g.create_time_ AS createTime,
  561. g.lesson_cover_url_ AS lessonCoverUrl,
  562. g.lesson_count_ AS lessonCount,
  563. g.lesson_subject_ AS subjectId,
  564. s.name_ AS subjectName,
  565. IFNULL(r.count_,0) AS buyCount
  566. FROM video_lesson_group g
  567. LEFT JOIN sys_user u ON g.teacher_id_=u.id_
  568. LEFT JOIN `subject` s ON g.lesson_subject_=s.id_
  569. LEFT JOIN (SELECT video_lesson_group_id_ ,COUNT(1) AS count_ FROM video_lesson_purchase_record WHERE order_status_='PAID' GROUP BY video_lesson_group_id_) r ON g.id_= r.video_lesson_group_id_
  570. WHERE g.audit_status_='PASS' and #{appAuditVersion} = g.audit_version_
  571. ORDER BY g.create_time_ DESC LIMIT 4
  572. </select>
  573. <select id="selectRecentCourses" resultType="com.yonge.cooleshow.biz.dal.vo.StudentHomePage$RecentCourses">
  574. SELECT
  575. u.id_ AS teacherId,
  576. u.username_ AS teacherName,
  577. u.real_name_ AS realName,
  578. u.avatar_ AS avatar,
  579. p.course_group_id_ AS courseGroupId,
  580. p.course_id_ AS courseId,
  581. g.name_ AS courseGroupName,
  582. p.course_type_ AS courseType,
  583. s.status_ AS `status`,
  584. s.start_time_ AS courseStartTime
  585. FROM course_schedule_student_payment p
  586. LEFT JOIN course_schedule s ON p.course_id_=s.id_
  587. LEFT JOIN sys_user u ON s.teacher_id_=u.id_
  588. LEFT JOIN course_group g ON p.course_group_id_=g.id_
  589. WHERE p.user_id_=#{studentId}
  590. AND s.status_ = 'ING'
  591. ORDER BY ABS(NOW() - s.start_time_) ASC
  592. limit 1
  593. </select>
  594. <select id="selectRecentCoursesPractice" resultType="com.yonge.cooleshow.biz.dal.vo.StudentHomePage$RecentCourses">
  595. SELECT
  596. p.user_id_ AS studentId,
  597. u.id_ AS teacherId,
  598. u.username_ AS teacherName,
  599. u.real_name_ AS realName,
  600. u.avatar_ AS avatar,
  601. s.course_group_id_ AS courseGroupId,
  602. s.id_ AS courseId,
  603. g.name_ AS courseGroupName,
  604. s.type_ AS courseType,
  605. s.status_ AS `status`,
  606. s.start_time_ AS courseStartTime
  607. FROM course_schedule s
  608. LEFT JOIN sys_user u ON s.teacher_id_=u.id_
  609. LEFT JOIN course_group g ON s.course_group_id_=g.id_
  610. LEFT JOIN course_schedule_student_payment p ON s.id_=p.course_id_
  611. WHERE s.teacher_id_=#{teacherId}
  612. AND s.type_='PRACTICE'
  613. AND s.status_ = 'ING'
  614. ORDER BY ABS(NOW() - s.start_time_) ASC
  615. limit 1
  616. </select>
  617. <select id="selectRecentCoursesLive" resultType="com.yonge.cooleshow.biz.dal.vo.StudentHomePage$RecentCourses"
  618. parameterType="java.lang.Long">
  619. SELECT
  620. u.id_ AS teacherId,
  621. u.username_ AS teacherName,
  622. u.real_name_ AS realName,
  623. u.avatar_ AS avatar,
  624. s.course_group_id_ AS courseGroupId,
  625. s.id_ AS courseId,
  626. g.name_ AS courseGroupName,
  627. s.type_ AS courseType,
  628. s.status_ AS `status`,
  629. s.start_time_ AS courseStartTime
  630. FROM course_schedule s
  631. LEFT JOIN sys_user u ON s.teacher_id_=u.id_
  632. LEFT JOIN course_group g ON s.course_group_id_=g.id_
  633. WHERE s.teacher_id_=#{teacherId}
  634. AND s.type_ IN ('LIVE','PIANO_ROOM_CLASS')
  635. AND s.status_ ='ING'
  636. ORDER BY ABS(NOW() - s.start_time_) ASC
  637. limit 1
  638. </select>
  639. <select id="selectWeekNotStartCourseSchedule" resultType="java.lang.Integer">
  640. select count(1)
  641. from course_schedule cs
  642. left join course_group cg on cs.course_group_id_ = cg.id_
  643. where cs.teacher_id_ = #{userId} and cs.status_ = 'NOT_START' and cg.status_ = 'ING'
  644. and YEARWEEK(date_format(cs.class_date_,'%Y-%m-%d'),7) = YEARWEEK(now(),7)
  645. </select>
  646. <select id="selectHomeworkNotDecorate" resultType="java.lang.Integer">
  647. select count(1)
  648. from course_schedule cs
  649. left join course_homework ch on cs.id_ = ch.course_schedule_id_
  650. where cs.teacher_id_ = #{userId} and cs.status_ = 'COMPLETE' and cs.type_ in( 'PRACTICE','PIANO_ROOM_CLASS')
  651. and YEARWEEK(date_format(cs.class_date_,'%Y-%m-%d'),7) = YEARWEEK(now(),7)
  652. and ch.id_ is null
  653. </select>
  654. <select id="selectNotRepliedCourseSchedule" resultType="java.lang.Integer">
  655. select count(1)
  656. from course_schedule cs
  657. left join course_schedule_replied csr on cs.id_ = csr.course_schedule_id_
  658. where cs.teacher_id_ = #{userId} and cs.status_ = 'COMPLETE' and cs.type_ = 'PRACTICE'
  659. and csr.teacher_replied_ is null
  660. </select>
  661. <select id="selectWeekStudentRepliedCourseSchedule" resultType="java.lang.Integer">
  662. select count(1)
  663. from course_schedule cs
  664. left join course_schedule_replied csr on cs.id_ = csr.course_schedule_id_
  665. where cs.teacher_id_ = #{userId} and cs.status_ = 'COMPLETE' and cs.type_ = 'PRACTICE'
  666. and csr.student_replied_ is not null
  667. and YEARWEEK(date_format(csr.create_time_,'%Y-%m-%d'),7) = YEARWEEK(now(),7)
  668. </select>
  669. <select id="selectStartTime" resultType="java.lang.String" parameterType="java.lang.String">
  670. SELECT s.start_time_
  671. FROM course_schedule_student_payment p
  672. LEFT JOIN course_schedule s ON p.course_id_=s.id_
  673. WHERE p.order_no_=#{orderNo}
  674. </select>
  675. <select id="selectTeacher" resultType="com.yonge.cooleshow.auth.api.entity.SysUser"
  676. parameterType="java.lang.String">
  677. SELECT s.teacher_id_ AS id,u.phone_ AS phone
  678. FROM course_schedule s
  679. LEFT JOIN sys_user u ON s.teacher_id_=u.id_
  680. WHERE class_date_=#{tomorrow} AND lock_=0
  681. GROUP BY s.teacher_id_
  682. </select>
  683. <select id="selectTypeCount" resultType="com.yonge.cooleshow.biz.dal.vo.CountVo">
  684. SELECT type_ AS type, COUNT(1) AS count
  685. FROM course_schedule
  686. WHERE class_date_=#{tomorrow}
  687. AND teacher_id_=#{teacherId} AND lock_=0
  688. GROUP BY type_
  689. </select>
  690. <select id="selectTodayNotRepliedAndNotDecorateHomework"
  691. resultType="com.yonge.cooleshow.biz.dal.vo.TodayNotRepliedAndNotDecorateHomeworkVo">
  692. select sum(if(ch.id_ is null,1,0)) as decorateNum,
  693. sum(if(csr.teacher_replied_ is null,1,0)) as repliedNum,
  694. su.id_ as teacherId,
  695. su.phone_ as phone
  696. from course_schedule cs
  697. left join course_schedule_replied csr on cs.id_ = csr.course_schedule_id_
  698. left join course_homework ch on cs.id_ = ch.course_schedule_id_
  699. left join sys_user su on cs.teacher_id_ = su.id_
  700. where cs.status_ = 'COMPLETE' and date_format(cs.class_date_,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
  701. and cs.type_ = 'PRACTICE'
  702. group by su.id_,su.phone_
  703. </select>
  704. <select id="countAllReplie" resultType="com.yonge.cooleshow.biz.dal.vo.RepliedCountVo"
  705. parameterType="java.lang.String">
  706. SELECT
  707. p.user_id_ AS userId,
  708. u.phone_ AS phone,
  709. COUNT(1) AS count
  710. FROM course_schedule_student_payment p
  711. LEFT JOIN sys_user u ON p.user_id_=u.id_
  712. WHERE p.course_id_ IN (SELECT id_ FROM course_schedule WHERE class_date_=#{today} AND lock_=0 AND type_='PRACTICE')
  713. GROUP BY p.user_id_;
  714. </select>
  715. <select id="countReplies" resultType="java.lang.Integer" parameterType="java.lang.Integer">
  716. SELECT COUNT(1)
  717. FROM course_schedule_replied
  718. WHERE student_id_=#{studentId}
  719. </select>
  720. <select id="queryCourseHomeOfYear" parameterType="map"
  721. resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeVo$CourseHomeInfoVo">
  722. select `date`,
  723. sum(a.not_start_count) as undoneCount,
  724. sum(a.complete_count) as doneCount
  725. from (select date_format(class_date_, '%Y-%m-01') as `date`,
  726. ifnull(case when status_ in ('NOT_START', 'ING') then count(1) end, 0) as not_start_count,
  727. ifnull(case when status_ = 'COMPLETE' then count(1) end, 0) as complete_count
  728. from course_schedule
  729. where type_ = #{param.type}
  730. and status_ in ('NOT_START', 'ING', 'COMPLETE')
  731. <![CDATA[ AND class_date_ >= #{param.startDate} ]]>
  732. <![CDATA[ AND class_date_ <= #{param.endDate} ]]>
  733. group by class_date_) as a
  734. group by date
  735. </select>
  736. <select id="queryCourseHomeOfMonth" parameterType="map"
  737. resultType="com.yonge.cooleshow.biz.dal.vo.CourseHomeVo$CourseHomeInfoVo">
  738. select class_date_ as `date`,
  739. ifnull(case when status_ in ('NOT_START', 'ING') then count(1) end, 0) as undoneCount,
  740. ifnull(case when status_ = 'COMPLETE' then count(1) end, 0) as doneCount
  741. from course_schedule
  742. where type_ = #{param.type}
  743. and status_ in ('NOT_START', 'ING', 'COMPLETE')
  744. <![CDATA[ AND class_date_ >= #{param.startDate} ]]>
  745. <![CDATA[ AND class_date_ <= #{param.endDate} ]]>
  746. group by class_date_
  747. </select>
  748. <select id="selectPrice" resultType="java.math.BigDecimal">
  749. SELECT p.subject_price_
  750. FROM teacher_free_time t
  751. LEFT JOIN teacher_subject_price p ON t.id_=p.teacher_free_time_id
  752. WHERE t.teacher_id_=#{teacherId}
  753. AND p.subject_id_=#{subjectId}
  754. AND t.default_flag_=1
  755. </select>
  756. <select id="selectSchedule" resultType="com.yonge.cooleshow.biz.dal.entity.CourseSchedule"
  757. parameterType="java.lang.Integer">
  758. SELECT * FROM course_schedule
  759. WHERE id_ IN (
  760. SELECT course_id_ FROM course_schedule_student_payment
  761. WHERE user_id_=(SELECT user_id_ FROM course_schedule_student_payment WHERE course_id_=#{courseId} AND course_type_='PRACTICE')
  762. )
  763. </select>
  764. <select id="teacherIdList" resultType="java.lang.Long">
  765. SELECT teacher_id_ FROM teacher_free_time GROUP BY teacher_id_
  766. </select>
  767. <select id="selectIdList" resultType="java.lang.Long">
  768. SELECT id_ FROM course_schedule WHERE lock_=0 AND class_date_ &lt;= #{day}
  769. </select>
  770. <select id="selectComplete" resultType="com.yonge.cooleshow.biz.dal.vo.CourseCompleteVo">
  771. SELECT course_group_id_ AS courseGroupId ,COUNT(1) AS courseCount FROM course_schedule WHERE lock_=0 AND status_='COMPLETE' GROUP BY course_group_id_
  772. </select>
  773. <update id="updateStartTime">
  774. UPDATE course_schedule SET status_='ING' WHERE id_ IN(
  775. <foreach collection="list" item="item" index="index" open="" close="" separator=",">
  776. #{item.id}
  777. </foreach>)
  778. </update>
  779. <update id="updateEndTime">
  780. UPDATE course_schedule SET status_='COMPLETE' WHERE id_ IN(
  781. <foreach collection="list" item="item" index="index" open="" close="" separator=",">
  782. #{item.courseId}
  783. </foreach>)
  784. </update>
  785. <update id="updateTeacherSalary" parameterType="java.util.List">
  786. UPDATE course_schedule_teacher_salary
  787. SET status_='COMPLETE',settlement_time_=NOW()
  788. WHERE course_schedule_id_ IN
  789. <foreach collection="list" item="item" open="(" separator="," close=")">
  790. #{item}
  791. </foreach>
  792. </update>
  793. </mapper>