TeacherMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.TeacherDao">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.Teacher">
  5. <result column="user_id_" property="userId" />
  6. <result column="education_background_" property="educationBackground" />
  7. <result column="graduate_school_" property="graduateSchool" />
  8. <result column="technical_titles_" property="technicalTitles" />
  9. <result column="work_unit_" property="workUnit" />
  10. <result column="subject_id_" property="subjectId" />
  11. <result column="introduction_" property="introduction" />
  12. <result column="subject_" property="subject" />
  13. <result column="grad_certificate_" property="gradCertificate" />
  14. <result column="degree_certificate_" property="degreeCertificate" />
  15. <result column="teacher_certificate_" property="teacherCertificate" />
  16. <result column="entry_flag_" property="entryFlag" />
  17. <result column="entry_auth_date_" property="entryAuthDate" />
  18. <result column="musician_flag_" property="musicianFlag" />
  19. <result column="musician_date_" property="musicianDate" />
  20. <result column="member_rank_setting_id_" property="memberRankSettingId"/>
  21. <result column="membership_start_time_" property="membershipStartTime"/>
  22. <result column="membership_end_time_" property="membershipEndTime"/>
  23. <result column="live_flag_" property="liveFlag" />
  24. <result column="live_date_" property="liveDate" />
  25. <result column="music_date_" property="musicDate" />
  26. <result column="video_date_" property="videoDate" />
  27. <result column="style_date_" property="styleDate" />
  28. <result column="browse_" property="browse" />
  29. <result column="memo_" property="memo" />
  30. <result column="lock_flag_" property="lockFlag" />
  31. <result column="create_time_" property="createTime" />
  32. <result column="update_time_" property="updateTime" />
  33. </resultMap>
  34. <!-- 表字段 -->
  35. <sql id="baseColumns">
  36. t.user_id_ as "userId"
  37. , t.education_background_ as "educationBackground"
  38. , t.graduate_school_ as "graduateSchool"
  39. , t.technical_titles_ as "technicalTitles"
  40. , t.work_unit_ as "workUnit"
  41. , t.subject_id_ as "subjectId"
  42. , t.introduction_ as "introduction"
  43. , t.subject_ as "subject"
  44. , t.grad_certificate_ as "gradCertificate"
  45. , t.degree_certificate_ as "degreeCertificate"
  46. , t.teacher_certificate_ as "teacherCertificate"
  47. , t.entry_flag_ as "entryFlag"
  48. , t.entry_auth_date_ as "entryAuthDate"
  49. , t.musician_flag_ as "musicianFlag"
  50. , t.musician_date_ as "musicianDate"
  51. , t.live_flag_ as "liveFlag"
  52. , t.music_date_ as "musicDate"
  53. , t.video_date_ as "videoDate"
  54. , t.style_date_ as "styleDate"
  55. , t.member_rank_setting_id_ as "memberRankSettingId"
  56. , t.membership_start_time_ as "membershipStartTime"
  57. , t.membership_end_time_ as "membershipEndTime"
  58. , t.browse_ as "browse"
  59. , t.memo_ as "memo"
  60. , t.tag_ as "tag"
  61. , t.create_time_ as "createTime"
  62. , t.update_time_ as "updateTime"
  63. </sql>
  64. <!-- 分页查询 -->
  65. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherVo" >
  66. SELECT
  67. <include refid="baseColumns"/>,
  68. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  69. u.username_ as username,
  70. u.phone_ as phone,
  71. u.real_name_ as realName,
  72. (case when t.membership_end_time_ &gt;= now() then 1 else 0 end) isVip,
  73. <!-- t.tag_ tag,-->
  74. u.del_flag_ as delFlag,
  75. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  76. (case when isnull(b.user_id_) then 0 else 1 end) as isBank
  77. FROM teacher t
  78. left join sys_user u on t.user_id_ = u.id_
  79. left join (
  80. select distinct user_id_ from user_bank_card where del_flag_ = 0
  81. ) b on t.user_id_ = b.user_id_
  82. <where>
  83. <if test="null != param.search and '' != param.search">
  84. AND (
  85. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  86. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  87. u.real_name_ LIKE CONCAT('%', #{param.search}, '%') or
  88. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  89. )
  90. </if>
  91. <if test="null != param.teacherType and '' != param.teacherType">
  92. and (
  93. 1=0
  94. <if test='param.teacherType.contains("TOURIST")'>
  95. or (t.entry_flag_ = 0 and t.musician_flag_ = 0)
  96. </if>
  97. <if test='param.teacherType.contains("ENTRY")'>
  98. or t.entry_flag_ = 1
  99. </if>
  100. <if test='param.teacherType.contains("MUSICIAN")'>
  101. or t.musician_flag_ = 1
  102. </if>
  103. )
  104. </if>
  105. <if test="param.isVip != null">
  106. <if test="param.isVip == 0">
  107. and (t.membership_end_time_ is null or t.membership_end_time_ &lt; now())
  108. </if>
  109. <if test="param.isVip == 1">
  110. and t.membership_end_time_ &gt;= now()
  111. </if>
  112. </if>
  113. <if test="param.tag != null">
  114. and find_in_set(#{param.tag},t.tag_)
  115. </if>
  116. <if test="null != param.lockFlag">
  117. and (u.lock_flag_ = #{param.lockFlag} or t.lock_flag_ = #{param.lockFlag})
  118. </if>
  119. </where>
  120. </select>
  121. <resultMap id="BasicUserInfo" type="com.yonge.cooleshow.biz.dal.dto.BasicUserInfo">
  122. <result property="userId" column="user_id_"/>
  123. <result property="username" column="username_"/>
  124. <result property="realName" column="real_name_"/>
  125. <result property="avatar" column="avatar_"/>
  126. </resultMap>
  127. <select id="getBasicUserInfo" resultMap="BasicUserInfo">
  128. SELECT id_ user_id_,username_,real_name_,avatar_ FROM sys_user
  129. WHERE del_flag_ = 0 and id_ = #{userId} LIMIT 1
  130. </select>
  131. <select id="findBasicUserInfo" resultMap="BasicUserInfo">
  132. SELECT id_ user_id_,username_,real_name_,avatar_ FROM sys_user
  133. WHERE del_flag_ = 0 and id_ IN
  134. <foreach collection="studentIds" open="(" close=")" separator="," item="userId">
  135. #{userId}
  136. </foreach>
  137. </select>
  138. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherVo">
  139. SELECT
  140. <include refid="baseColumns"/>,
  141. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  142. u.avatar_ as avatar,
  143. u.username_ as username,
  144. u.gender_ as `gender`,
  145. u.birthdate_ as birthdate,
  146. u.phone_ as phone,
  147. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  148. (!isnull(membership_end_time_) and membership_end_time_ > now()) as isVip,
  149. u.real_name_ as realName,
  150. u.id_card_no_ as idCardNo,
  151. (case when isnull(b.user_id_) then 0 else 1 end) as isBank,
  152. (
  153. SELECT GROUP_CONCAT(name_ ORDER by locate(id_,t.subject_id_)) FROM subject WHERE FIND_IN_SET(id_,t.subject_id_)
  154. ) as subjectName,
  155. u.user_type_ as userType
  156. FROM teacher t
  157. left join sys_user u on t.user_id_ = u.id_
  158. left join (
  159. select distinct user_id_ from user_bank_card where del_flag_ = 0 and user_id_ = #{userId}
  160. ) b on t.user_id_ = b.user_id_
  161. where u.del_flag_ = 0 and t.user_id_ = #{userId}
  162. </select>
  163. <select id="querySubject" resultMap="com.yonge.cooleshow.biz.dal.dao.SubjectDao.Subject">
  164. SELECT s.* FROM `subject` s
  165. LEFT JOIN teacher t ON FIND_IN_SET(s.id_,t.subject_id_)
  166. WHERE t.user_id_ = #{userId}
  167. </select>
  168. <update id="setSubject">
  169. update teacher set subject_id_ = #{subjectIds},update_time_ = now() where user_id_ = #{id}
  170. </update>
  171. <update id="addHomeBrowse">
  172. update teacher set browse_ = browse_ + 1 where user_id_ = #{userId}
  173. </update>
  174. <select id="querySubjectItem" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  175. select t.* from subject t
  176. join (
  177. select a.subject_id_ from (
  178. <trim prefixOverrides="union all">
  179. <if test="type == null or type =='MUSIC'">union all
  180. (select music_subject_ as subject_id_ from music_sheet where user_id_ = #{userId} GROUP BY
  181. music_subject_)
  182. </if>
  183. <if test="type == null or type =='VIDEO'">
  184. union all
  185. (select lesson_subject_ as subject_id_ from video_lesson_group where teacher_id_ = #{userId} GROUP BY lesson_subject_)
  186. </if>
  187. <if test="type == null or type =='PINAO_ROOM'">
  188. union all
  189. (select subject_id_ as subject_id_ from course_group where type_ = 'PIANO_ROOM_CLASS' and teacher_id_ = #{userId} GROUP BY subject_id_)
  190. </if>
  191. <if test="type == null or type =='PRACTICE'">
  192. union all
  193. (select subject_id_ as subject_id_ from course_group where type_ = 'PRACTICE' and teacher_id_ = #{userId} GROUP BY subject_id_)
  194. </if>
  195. <if test="type == null or type =='LIVE'">
  196. union all
  197. (select subject_id_ as subject_id_ from course_group where type_ = 'LIVE' and teacher_id_ = #{userId} GROUP BY subject_id_)
  198. </if>
  199. </trim>
  200. ) a group by a.subject_id_
  201. ) a on t.id_ = a.subject_id_
  202. where t.parent_subject_id_ != 0
  203. and not exists(
  204. select 1 from teacher s where s.user_id_ = #{userId} and find_in_set(t.id_,s.subject_id_)
  205. )
  206. </select>
  207. <select id="queryMyFans" resultType="com.yonge.cooleshow.biz.dal.vo.MyFens">
  208. SELECT
  209. s.student_id_ AS userId,
  210. u.avatar_ AS avatar,
  211. u.username_ AS userName,
  212. u.real_name_ AS realName,
  213. u.gender_ AS gender,
  214. (SELECT group_concat(name_) FROM `subject` WHERE find_in_set(id_,sr.subject_id_)) AS subjectName,
  215. if(sr.membership_start_time_ &lt;= now() and sr.membership_end_time_ &gt;= now(),1,0) AS isVip
  216. FROM student_star s
  217. LEFT JOIN sys_user u ON s.student_id_ = u.id_
  218. LEFT JOIN student sr ON s.student_id_ = sr.user_id_
  219. WHERE u.del_flag_ = 0 and s.teacher_id_ =#{teacherId}
  220. </select>
  221. </mapper>