StudentMapper.xml 15 KB

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