StudentMapper.xml 17 KB

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