StudentMapper.xml 19 KB

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