StudentMapper.xml 17 KB

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