StudentMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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.StudentDao">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.Student">
  5. <result column="user_id_" property="userId"/>
  6. <result column="subject_id_" property="subjectId"/>
  7. <result column="member_rank_setting_id_" property="memberRankSettingId"/>
  8. <result column="membership_start_time_" property="membershipStartTime"/>
  9. <result column="membership_end_time_" property="membershipEndTime"/>
  10. <result column="cloud_study_sequence_days_" property="cloudStudySequenceDays"/>
  11. <result column="cloud_study_use_last_day_" property="cloudStudyUseLastDay"/>
  12. <result column="lock_flag_" property="lockFlag" />
  13. <result column="create_time_" property="createTime"/>
  14. <result column="update_time_" property="updateTime"/>
  15. </resultMap>
  16. <!-- 表字段 -->
  17. <sql id="baseColumns">
  18. t.user_id_ as "userId"
  19. , t.subject_id_ as "subjectId"
  20. , t.current_grade_num_ as "currentGradeNum"
  21. , t.member_rank_setting_id_ as "memberRankSettingId"
  22. , t.membership_start_time_ as "membershipStartTime"
  23. , t.membership_end_time_ as "membershipEndTime"
  24. , t.cloud_study_sequence_days_ as "cloudStudySequenceDays"
  25. , t.cloud_study_use_last_day_ as "cloudStudyUseLastDay"
  26. , t.train_time_ as trainTime
  27. , t.evaluate_time_ as evaluateTime
  28. , t.create_time_ as "createTime"
  29. , t.update_time_ as "updateTime"
  30. </sql>
  31. <update id="setSubject">
  32. update student set subject_id_ = #{subjectIds},update_time_ = now() where user_id_ = #{id}
  33. </update>
  34. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.StudentVo">
  35. SELECT
  36. <include refid="baseColumns"/>,
  37. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  38. u.avatar_ as avatar,
  39. u.real_name_ as realName,
  40. u.id_card_no_ as idCardNo,
  41. u.username_ as username,
  42. u.gender_ as gender,
  43. u.birthdate_ as birthdate,
  44. TIMESTAMPDIFF(YEAR, u.birthdate_, CURDATE()) as age,
  45. u.phone_ as phone,
  46. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  47. (!isnull(membership_end_time_) and membership_end_time_ > now()) as isVip,
  48. (
  49. SELECT GROUP_CONCAT(name_ ORDER by locate(id_,t.subject_id_)) FROM subject WHERE FIND_IN_SET(id_,t.subject_id_)
  50. ) as subjectName,
  51. u.user_type_ as userType
  52. FROM student t
  53. left join sys_user u on t.user_id_ = u.id_
  54. where u.del_flag_ = 0 and t.user_id_ = #{userId}
  55. </select>
  56. <select id="detailByPhone" resultType="com.yonge.cooleshow.biz.dal.vo.StudentVo">
  57. SELECT
  58. <include refid="baseColumns"/>,
  59. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  60. u.avatar_ as avatar,
  61. u.real_name_ as realName,
  62. u.id_card_no_ as idCardNo,
  63. u.username_ as username,
  64. u.gender_ as gender,
  65. u.birthdate_ as birthdate,
  66. TIMESTAMPDIFF(YEAR, u.birthdate_, CURDATE()) as age,
  67. u.phone_ as phone,
  68. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  69. (!isnull(membership_end_time_) and membership_end_time_ > now()) as isVip,
  70. (
  71. SELECT GROUP_CONCAT(name_ ORDER by locate(id_,t.subject_id_)) FROM subject WHERE FIND_IN_SET(id_,t.subject_id_)
  72. ) as subjectName,
  73. u.user_type_ as userType
  74. FROM student t
  75. left join sys_user u on t.user_id_ = u.id_
  76. where u.del_flag_ = 0 and u.phone_ = #{phone}
  77. </select>
  78. <!-- 分页查询 -->
  79. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.StudentVo">
  80. SELECT
  81. <include refid="baseColumns"/>,
  82. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  83. u.username_ as username,
  84. u.gender_ as gender,
  85. u.birthdate_ as birthdate,
  86. u.del_flag_ as delFlag,
  87. TIMESTAMPDIFF(YEAR, u.birthdate_, CURDATE()) as age,
  88. u.phone_ as phone,
  89. !isnull(birthdate_) as isReal,
  90. u.real_name_ as realName,
  91. (!isnull(membership_end_time_) and membership_end_time_ > now()) as isVip,
  92. (
  93. SELECT GROUP_CONCAT(name_ ORDER by locate(id_,t.subject_id_)) FROM subject WHERE FIND_IN_SET(id_,t.subject_id_)
  94. ) as subjectName
  95. FROM student t
  96. left join sys_user u on t.user_id_ = u.id_
  97. <where>
  98. <if test="null != param.search and '' != param.search">
  99. AND (
  100. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  101. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  102. u.real_name_ LIKE CONCAT('%', #{param.search}, '%') or
  103. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  104. )
  105. </if>
  106. <if test="null != param.gender">
  107. and u.gender_ = #{param.gender}
  108. </if>
  109. <if test="null != param.subjectId and '' != param.subjectId">
  110. and INTE_ARRAY(t.subject_id_,#{param.subjectId})
  111. </if>
  112. <if test="null != param.isVip">
  113. <if test="1 == param.isVip.code">
  114. and t.membership_end_time_ &gt; now()
  115. </if>
  116. <if test="0 == param.isVip.code">
  117. and (t.membership_end_time_ is null or t.membership_end_time_ &lt;= now())
  118. </if>
  119. </if>
  120. <if test="param.startTime !=null">
  121. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  122. </if>
  123. <if test="param.endTime !=null">
  124. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  125. </if>
  126. <if test="null != param.lockFlag">
  127. and t.lock_flag_ = #{param.lockFlag}
  128. </if>
  129. <if test="null != param.delFlag">
  130. and u.del_flag_ = #{param.delFlag}
  131. </if>
  132. <if test="null != param.vipEndTime">
  133. and t.membership_end_time_ &lt;= #{param.vipEndTime}
  134. </if>
  135. <if test="null != param.vipStartTime">
  136. and t.membership_end_time_ &gt;= #{param.vipStartTime}
  137. </if>
  138. <if test="param.trainFlag != null">
  139. AND t.train_time_ > 0
  140. </if>
  141. <if test="param.evaluateFlag != null">
  142. AND t.evaluate_time_ > 0
  143. </if>
  144. </where>
  145. order by t.create_time_ desc
  146. </select>
  147. <select id="querySubject" resultMap="com.yonge.cooleshow.biz.dal.dao.SubjectDao.Subject">
  148. SELECT s.* FROM `subject` s
  149. LEFT JOIN student t ON FIND_IN_SET(s.id_,t.subject_id_)
  150. WHERE t.user_id_ = #{userId}
  151. </select>
  152. <select id="querySubjectItem" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  153. select t.* from subject t
  154. join (
  155. select a.subject_id_ from (
  156. <trim prefixOverrides="union all">
  157. <if test="type == null or type =='MUSIC'">
  158. union all
  159. (
  160. select
  161. a.music_subject_ as subject_id_
  162. from music_sheet a
  163. join music_sheet_purchase_record a1 on a.id_ = a1.music_sheet_id_
  164. where a1.student_id_ = #{userId} and a1.order_status_ = 'PAID'
  165. GROUP BY a.music_subject_
  166. )
  167. </if>
  168. <if test="type == null or type =='VIDEO'">
  169. union all
  170. (
  171. select
  172. a.lesson_subject_ as subject_id_
  173. from video_lesson_group a
  174. join video_lesson_purchase_record a1 on a.id_ = a1.video_lesson_group_id_
  175. where a1.student_id_ = #{userId}
  176. GROUP BY a.lesson_subject_
  177. )
  178. </if>
  179. <if test="type == null or type =='PINAO_ROOM'">
  180. union all
  181. (
  182. select
  183. a.subject_id_ as subject_id_
  184. from course_group a
  185. join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
  186. where a.type_ = 'PIANO_ROOM_CLASS' and a1.user_id_ = #{userId}
  187. GROUP BY a.subject_id_
  188. )
  189. </if>
  190. <if test="type == null or type =='PRACTICE'">
  191. union all
  192. (
  193. select
  194. a.subject_id_ as subject_id_
  195. from course_group a
  196. join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
  197. where a.type_ = 'PRACTICE' and a1.user_id_ = #{userId}
  198. GROUP BY a.subject_id_
  199. )
  200. </if>
  201. <if test="type == null or type =='LIVE'">
  202. union all
  203. (
  204. select
  205. a.subject_id_ as subject_id_
  206. from course_group a
  207. join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
  208. where a.type_ = 'LIVE' and a1.user_id_ = #{userId}
  209. GROUP BY a.subject_id_
  210. )
  211. </if>
  212. </trim>
  213. ) a group by a.subject_id_
  214. ) a on t.id_ = a.subject_id_
  215. where t.parent_subject_id_ != 0
  216. and not exists(
  217. select 1 from student s where s.user_id_ = #{userId} and find_in_set(t.id_,s.subject_id_)
  218. )
  219. </select>
  220. <resultMap id="queryMyFollowResult" type="com.yonge.cooleshow.biz.dal.vo.MyFollow">
  221. <id column="userId" property="userId" />
  222. <result column="avatar" property="avatar" />
  223. <result column="userName" property="userName" />
  224. <result column="realName" property="realName" />
  225. <result column="gender" property="gender" />
  226. <result column="starGrade" property="starGrade" />
  227. <result column="fansNum" property="fansNum" />
  228. <result column="liveFlag" property="liveFlag" />
  229. <result column="subjectName" property="subjectName" />
  230. <result column="roomUid" property="roomUid" />
  231. <association property="teacher" javaType="com.yonge.cooleshow.biz.dal.entity.Teacher" resultMap="com.yonge.cooleshow.biz.dal.dao.TeacherDao.BaseResultMap"/>
  232. </resultMap>
  233. <select id="queryMyFollow" resultMap="queryMyFollowResult">
  234. SELECT
  235. s.teacher_id_ as userId,
  236. u.avatar_ as avatar,
  237. u.username_ as userName,
  238. u.real_name_ as realName,
  239. u.gender_ as gender,
  240. t.star_grade_ as starGrade,
  241. t.fans_num_ as fansNum,
  242. t.live_flag_ as liveFlag,
  243. t.exp_time_ as expTime,
  244. (SELECT group_concat( name_ ) FROM `subject` WHERE find_in_set( id_, tr.subject_id_ )) AS subjectName,
  245. r.room_uid_ as roomUid,
  246. tr.entry_flag_ as entryFlag,
  247. tr.musician_flag_ as musicianFlag,
  248. tr.*
  249. FROM student_star s
  250. LEFT JOIN sys_user u ON s.teacher_id_ = u.id_
  251. LEFT JOIN teacher_total t ON s.teacher_id_ = t.user_id_
  252. LEFT JOIN teacher tr ON s.teacher_id_ = tr.user_id_
  253. LEFT JOIN (SELECT room_uid_,speaker_id_ FROM live_room WHERE live_state_=1 and room_state_ = 0 and type_ = 'TEMP') r ON t.user_id_= r.speaker_id_
  254. WHERE s.student_id_ = #{param.userId}
  255. <if test="param.username != null and param.username != ''">
  256. and u.username_ LIKE CONCAT('%', #{param.username}, '%')
  257. </if>
  258. </select>
  259. </mapper>