CourseScheduleMapper.xml 34 KB

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