CourseScheduleMapper.xml 37 KB

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