StudentMapper.xml 13 KB

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