CourseScheduleMapper.xml 35 KB

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