TeacherMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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="default_subject_" property="defaultSubject" />
  12. <result column="introduction_" property="introduction" />
  13. <result column="subject_" property="subject" />
  14. <result column="grad_certificate_" property="gradCertificate" />
  15. <result column="degree_certificate_" property="degreeCertificate" />
  16. <result column="teacher_certificate_" property="teacherCertificate" />
  17. <result column="entry_flag_" property="entryFlag" />
  18. <result column="entry_auth_date_" property="entryAuthDate" />
  19. <result column="musician_flag_" property="musicianFlag" />
  20. <result column="musician_date_" property="musicianDate" />
  21. <result column="member_rank_setting_id_" property="memberRankSettingId"/>
  22. <result column="membership_start_time_" property="membershipStartTime"/>
  23. <result column="membership_end_time_" property="membershipEndTime"/>
  24. <result column="live_flag_" property="liveFlag" />
  25. <result column="live_date_" property="liveDate" />
  26. <result column="music_date_" property="musicDate" />
  27. <result column="video_date_" property="videoDate" />
  28. <result column="style_date_" property="styleDate" />
  29. <result column="degree_date_" property="degreeDate" />
  30. <result column="teacher_date_" property="teacherDate" />
  31. <result column="degree_flag_" property="degreeFlag" />
  32. <result column="teacher_flag_" property="teacherFlag" />
  33. <result column="browse_" property="browse" />
  34. <result column="memo_" property="memo" />
  35. <result column="lock_flag_" property="lockFlag" />
  36. <result column="is_settlement_" property="isSettlement" />
  37. <result column="is_test_user_" property="isTestUser" />
  38. <result column="tenant_id_" property="tenantId" />
  39. <result column="settlement_from_" property="settlementFrom" />
  40. <result column="create_time_" property="createTime" />
  41. <result column="update_time_" property="updateTime" />
  42. </resultMap>
  43. <resultMap id="HotTeacherVoMap" type="com.yonge.cooleshow.biz.dal.vo.HotTeacherVo">
  44. <result column="user_id_" property="userId" />
  45. <result column="avatar_" property="avatar" />
  46. <result column="graduate_school_" property="graduateSchool" />
  47. <result column="username_" property="username" />
  48. <result column="isLiving_" property="isLiving" />
  49. </resultMap>
  50. <!-- 表字段 -->
  51. <sql id="baseColumns">
  52. t.user_id_ as "userId"
  53. , t.education_background_ as "educationBackground"
  54. , t.graduate_school_ as "graduateSchool"
  55. , t.technical_titles_ as "technicalTitles"
  56. , t.work_unit_ as "workUnit"
  57. , t.subject_id_ as "subjectId"
  58. , t.default_subject_ as defaultSubject
  59. , t.introduction_ as "introduction"
  60. , t.subject_ as "subject"
  61. , t.grad_certificate_ as "gradCertificate"
  62. , t.degree_certificate_ as "degreeCertificate"
  63. , t.teacher_certificate_ as "teacherCertificate"
  64. , t.entry_flag_ as "entryFlag"
  65. , t.entry_auth_date_ as "entryAuthDate"
  66. , t.musician_flag_ as "musicianFlag"
  67. , t.musician_date_ as "musicianDate"
  68. , t.live_flag_ as "liveFlag"
  69. , t.music_date_ as "musicDate"
  70. , t.video_date_ as "videoDate"
  71. , t.style_date_ as "styleDate"
  72. , t.degree_date_ as "degreeDate"
  73. , t.teacher_date_ as "teacherDate"
  74. , t.degree_flag_ as "degreeFlag"
  75. , t.teacher_flag_ as "teacherFlag"
  76. , t.member_rank_setting_id_ as "memberRankSettingId"
  77. , t.membership_start_time_ as "membershipStartTime"
  78. , t.membership_end_time_ as "membershipEndTime"
  79. , t.browse_ as "browse"
  80. , t.memo_ as "memo"
  81. , t.tag_ as "tag"
  82. , t.is_settlement_ as "isSettlement"
  83. , t.is_test_user_ as "isTestUser"
  84. , t.create_time_ as "createTime"
  85. , t.update_time_ as "updateTime"
  86. , t.train_time_ as trainTime
  87. , t.evaluate_time_ as evaluateTime
  88. , t.tenant_id_ as tenantId
  89. , t.settlement_from_ as settlementFrom
  90. </sql>
  91. <!-- 分页查询 -->
  92. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherVo" >
  93. SELECT
  94. <include refid="baseColumns"/>,
  95. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  96. u.username_ as username,
  97. u.phone_ as phone,
  98. u.real_name_ as realName,
  99. (case when t.membership_end_time_ &gt;= now() then 1 else 0 end) isVip,
  100. <!-- t.tag_ tag,-->
  101. u.del_flag_ as delFlag,
  102. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  103. (case when isnull(b.user_id_) then 0 else 1 end) as isBank,
  104. (case when t.tenant_id_ = -1 then '平台老师' else ti.name_ end) as tenantName
  105. FROM teacher t
  106. left join sys_user u on t.user_id_ = u.id_
  107. left join (
  108. select distinct user_id_ from user_bank_card where del_flag_ = 0
  109. ) b on t.user_id_ = b.user_id_
  110. left join tenant_info ti on t.tenant_id_ = ti.id_
  111. <where>
  112. <if test="null != param.search and '' != param.search">
  113. AND (
  114. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  115. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  116. u.real_name_ LIKE CONCAT('%', #{param.search}, '%') or
  117. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  118. )
  119. </if>
  120. <if test="null != param.teacherType and '' != param.teacherType">
  121. and (
  122. 1=0
  123. <if test='param.teacherType.contains("TOURIST")'>
  124. or (t.entry_flag_ = 0 and t.musician_flag_ = 0)
  125. </if>
  126. <if test='param.teacherType.contains("ENTRY")'>
  127. or t.entry_flag_ = 1
  128. </if>
  129. <if test='param.teacherType.contains("MUSICIAN")'>
  130. or t.musician_flag_ = 1
  131. </if>
  132. )
  133. </if>
  134. <if test="param.isVip != null">
  135. <if test="param.isVip == 0">
  136. and (t.membership_end_time_ is null or t.membership_end_time_ &lt; now())
  137. </if>
  138. <if test="param.isVip == 1">
  139. and t.membership_end_time_ &gt;= now()
  140. </if>
  141. </if>
  142. <if test="param.tag != null">
  143. and find_in_set(#{param.tag},t.tag_)
  144. </if>
  145. <if test="null != param.lockFlag">
  146. and t.lock_flag_ = #{param.lockFlag}
  147. </if>
  148. <if test="null != param.delFlag">
  149. and u.del_flag_ = #{param.delFlag}
  150. </if>
  151. <if test="param.subjectId != null">
  152. and find_in_set(#{param.subjectId},t.subject_id_)
  153. </if>
  154. <if test="param.isSettlement != null">
  155. and t.is_settlement_ = #{param.isSettlement}
  156. </if>
  157. <if test="param.isTestUser != null">
  158. and t.is_test_user_ = #{param.isTestUser}
  159. </if>
  160. <if test="null != param.vipEndTime">
  161. and t.membership_end_time_ &lt;= #{param.vipEndTime}
  162. </if>
  163. <if test="null != param.vipStartTime">
  164. and t.membership_end_time_ &gt;= #{param.vipStartTime}
  165. </if>
  166. <if test="param.trainFlag != null">
  167. AND t.train_time_ > 0
  168. </if>
  169. <if test="param.evaluateFlag != null">
  170. AND t.evaluate_time_ > 0
  171. </if>
  172. <if test="param.tenantId ! =null">
  173. AND t.tenantId_ = #{param.tenantId}
  174. </if>
  175. <if test="param.settlementFrom ! =null and param.settlementFrom.trim() != ''">
  176. AND t.settlement_from_ = #{param.settlementFrom}
  177. </if>
  178. <if test="param.tenantName != null and param.tenantName.trim() != ''">
  179. and te.name_ like concat('%',#{param.tenantName},'%')
  180. </if>
  181. </where>
  182. order by t.create_time_ desc
  183. </select>
  184. <resultMap id="BasicUserInfo" type="com.yonge.cooleshow.biz.dal.dto.BasicUserInfo">
  185. <result property="userId" column="user_id_"/>
  186. <result property="username" column="username_"/>
  187. <result property="realName" column="real_name_"/>
  188. <result property="avatar" column="avatar_"/>
  189. </resultMap>
  190. <select id="getBasicUserInfo" resultMap="BasicUserInfo">
  191. SELECT id_ user_id_,username_,real_name_,avatar_ FROM sys_user
  192. WHERE del_flag_ = 0 and id_ = #{userId} LIMIT 1
  193. </select>
  194. <select id="findBasicUserInfo" resultMap="BasicUserInfo">
  195. SELECT id_ user_id_,username_,real_name_,avatar_ FROM sys_user
  196. WHERE del_flag_ = 0 and id_ IN
  197. <foreach collection="studentIds" open="(" close=")" separator="," item="userId">
  198. #{userId}
  199. </foreach>
  200. </select>
  201. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherVo">
  202. SELECT
  203. <include refid="baseColumns"/>,
  204. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  205. u.avatar_ as avatar,
  206. u.username_ as username,
  207. u.gender_ as `gender`,
  208. u.birthdate_ as birthdate,
  209. u.phone_ as phone,
  210. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  211. (!isnull(membership_end_time_) and membership_end_time_ > now()) as isVip,
  212. u.real_name_ as realName,
  213. u.id_card_no_ as idCardNo,
  214. (case when isnull(b.user_id_) then 0 else 1 end) as isBank,
  215. (
  216. SELECT GROUP_CONCAT(name_ ORDER by locate(id_,t.subject_id_)) FROM subject WHERE FIND_IN_SET(id_,t.subject_id_)
  217. ) as subjectName,
  218. u.user_type_ as userType
  219. FROM teacher t
  220. left join sys_user u on t.user_id_ = u.id_
  221. left join (
  222. select distinct user_id_ from user_bank_card where del_flag_ = 0 and user_id_ = #{userId}
  223. ) b on t.user_id_ = b.user_id_
  224. where u.del_flag_ = 0 and t.user_id_ = #{userId}
  225. </select>
  226. <select id="querySubject" resultMap="com.yonge.cooleshow.biz.dal.dao.SubjectDao.Subject">
  227. SELECT s.* FROM `subject` s
  228. LEFT JOIN teacher t ON FIND_IN_SET(s.id_,t.subject_id_)
  229. WHERE t.user_id_ = #{userId}
  230. </select>
  231. <update id="setSubject">
  232. update teacher set subject_id_ = #{subjectIds},update_time_ = now() where user_id_ = #{id}
  233. </update>
  234. <update id="addHomeBrowse">
  235. update teacher set browse_ = browse_ + 1 where user_id_ = #{userId}
  236. </update>
  237. <select id="querySubjectItem" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  238. select t.* from subject t
  239. join (
  240. select a.subject_id_ from (
  241. <trim prefixOverrides="union all">
  242. <if test="type == null or type =='MUSIC'">union all
  243. (select music_subject_ as subject_id_ from music_sheet where user_id_ = #{userId} GROUP BY
  244. music_subject_)
  245. </if>
  246. <if test="type == null or type =='VIDEO'">
  247. union all
  248. (select lesson_subject_ as subject_id_ from video_lesson_group where teacher_id_ = #{userId} GROUP BY lesson_subject_)
  249. </if>
  250. <if test="type == null or type =='PIANO_ROOM'">
  251. union all
  252. (select subject_id_ as subject_id_ from course_group where type_ = 'PIANO_ROOM_CLASS' and teacher_id_ = #{userId} GROUP BY subject_id_)
  253. </if>
  254. <if test="type == null or type =='PRACTICE'">
  255. union all
  256. (select subject_id_ as subject_id_ from course_group where type_ = 'PRACTICE' and teacher_id_ = #{userId} GROUP BY subject_id_)
  257. </if>
  258. <if test="type == null or type =='LIVE'">
  259. union all
  260. (select subject_id_ as subject_id_ from course_group where type_ = 'LIVE' and teacher_id_ = #{userId} GROUP BY subject_id_)
  261. </if>
  262. </trim>
  263. ) a group by a.subject_id_
  264. ) a on t.id_ = a.subject_id_
  265. where t.parent_subject_id_ != 0
  266. and not exists(
  267. select 1 from teacher s where s.user_id_ = #{userId} and find_in_set(t.id_,s.subject_id_)
  268. )
  269. </select>
  270. <select id="queryMyFans" resultType="com.yonge.cooleshow.biz.dal.vo.MyFens">
  271. SELECT
  272. s.student_id_ AS userId,
  273. s.create_time_ AS starTime,
  274. u.avatar_ AS avatar,
  275. u.username_ AS userName,
  276. u.real_name_ AS realName,
  277. u.gender_ AS gender,
  278. u.phone_ AS phone,
  279. u.birthdate_ AS birthdate,
  280. (SELECT group_concat(name_) FROM `subject` WHERE find_in_set(id_,sr.subject_id_)) AS subjectName,
  281. if(sr.membership_start_time_ &lt;= now() and sr.membership_end_time_ &gt;= now(),1,0) AS isVip
  282. FROM student_star s
  283. LEFT JOIN sys_user u ON s.student_id_ = u.id_
  284. LEFT JOIN student sr ON s.student_id_ = sr.user_id_
  285. <where>
  286. u.del_flag_ = 0
  287. <if test="record.teacherId != null">
  288. AND s.teacher_id_ =#{record.teacherId}
  289. </if>
  290. <if test="record.nickname != null">
  291. AND u.username_ LIKE '%${record.nickname}%'
  292. </if>
  293. <if test="record.userId != null">
  294. AND u.id_ = #{record.userId}
  295. </if>
  296. <if test="record.phone != null">
  297. AND u.phone_ = #{record.phone}
  298. </if>
  299. <if test="record.startTime != null and record.endTime != null">
  300. AND ( #{record.startTime} &lt;= s.create_time_ AND s.create_time_ &lt;= #{record.endTime})
  301. </if>
  302. </where>
  303. </select>
  304. <select id="queryHotTeacherList" resultMap="HotTeacherVoMap">
  305. select t.user_id_,t.graduate_school_,u.username_,u.avatar_,ifnull(a.speaker_id_,0) isLiving_
  306. from teacher t
  307. left join sys_user u on t.user_id_ = u.id_
  308. left join teacher_total tt on tt.user_id_ = t.user_id_
  309. left join (SELECT lr.speaker_id_ from live_room lr WHERE live_state_ = 1 and type_ = 'temp' group by lr.speaker_id_) a on a.speaker_id_ = t.user_id_
  310. where t.entry_flag_ = 1 and t.is_test_user_ = 0 and find_in_set(#{subjectId},t.subject_id_)
  311. order by tt.fans_num_ desc limit 10
  312. </select>
  313. <!--老师学生人数统计-->
  314. <select id="selectTeacherStudentNumberStatInfo"
  315. resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
  316. SELECT t1.teacher_id_ AS id, COUNT(DISTINCT t1.id_) AS total FROM user_binding_teacher t1
  317. <where>
  318. <if test="teacherIds != null">
  319. AND t1.teacher_id_ IN (<foreach collection="teacherIds" separator="," item="item">#{item}</foreach>)
  320. </if>
  321. </where>
  322. GROUP BY t1.teacher_id_
  323. </select>
  324. <!--老师学生人数统计-->
  325. </mapper>