TeacherMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. if (t.avatar_ = '' OR t.avatar_ IS NULL, u.avatar_, t.avatar_) as avatar,
  100. u.birthdate_ as birthdate,
  101. u.gender_ as gender,
  102. (case when t.membership_end_time_ &gt;= now() then 1 else 0 end) isVip,
  103. <!-- t.tag_ tag,-->
  104. u.del_flag_ as delFlag,
  105. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  106. (case when isnull(b.user_id_) then 0 else 1 end) as isBank,
  107. (case when t.tenant_id_ = -1 then '平台' else ti.name_ end) as tenantName
  108. FROM teacher t
  109. left join sys_user u on t.user_id_ = u.id_
  110. left join (
  111. select distinct user_id_ from user_bank_card where del_flag_ = 0
  112. ) b on t.user_id_ = b.user_id_
  113. left join tenant_info ti on t.tenant_id_ = ti.id_
  114. <where>
  115. <if test="null != param.search and '' != param.search">
  116. AND (
  117. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  118. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  119. u.real_name_ LIKE CONCAT('%', #{param.search}, '%') or
  120. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  121. )
  122. </if>
  123. <if test="null != param.teacherType and '' != param.teacherType">
  124. and (
  125. 1=0
  126. <if test='param.teacherType.contains("TOURIST")'>
  127. or (t.entry_flag_ = 0 and t.musician_flag_ = 0)
  128. </if>
  129. <if test='param.teacherType.contains("ENTRY")'>
  130. or t.entry_flag_ = 1
  131. </if>
  132. <if test='param.teacherType.contains("MUSICIAN")'>
  133. or t.musician_flag_ = 1
  134. </if>
  135. )
  136. </if>
  137. <if test="param.isVip != null">
  138. <if test="param.isVip == 0">
  139. and (t.membership_end_time_ is null or t.membership_end_time_ &lt; now())
  140. </if>
  141. <if test="param.isVip == 1">
  142. and t.membership_end_time_ &gt;= now()
  143. </if>
  144. </if>
  145. <if test="param.tag != null">
  146. and find_in_set(#{param.tag},t.tag_)
  147. </if>
  148. <if test="null != param.lockFlag">
  149. and t.lock_flag_ = #{param.lockFlag}
  150. </if>
  151. <if test="null != param.delFlag">
  152. and u.del_flag_ = #{param.delFlag}
  153. </if>
  154. <if test="param.subjectId != null">
  155. and find_in_set(#{param.subjectId},t.subject_id_)
  156. </if>
  157. <if test="param.isSettlement != null">
  158. and t.is_settlement_ = #{param.isSettlement}
  159. </if>
  160. <if test="param.isTestUser != null">
  161. and t.is_test_user_ = #{param.isTestUser}
  162. </if>
  163. <if test="null != param.vipEndTime">
  164. and t.membership_end_time_ &lt;= #{param.vipEndTime}
  165. </if>
  166. <if test="null != param.vipStartTime">
  167. and t.membership_end_time_ &gt;= #{param.vipStartTime}
  168. </if>
  169. <if test="param.trainFlag != null">
  170. AND t.train_time_ > 0
  171. </if>
  172. <if test="param.evaluateFlag != null">
  173. AND t.evaluate_time_ > 0
  174. </if>
  175. <if test="param.tenantId != null">
  176. AND t.tenant_id_ = #{param.tenantId}
  177. </if>
  178. <if test="param.bindTenant != null and param.bindTenant == 0">
  179. and t.tenant_id_ = -1
  180. </if>
  181. <if test="param.bindTenant != null and param.bindTenant == 1">
  182. and t.tenant_id_ != -1
  183. </if>
  184. <if test="param.settlementFrom != null">
  185. AND t.settlement_from_ = #{param.settlementFrom}
  186. </if>
  187. <if test="param.tenantName != null and param.tenantName.trim() != ''">
  188. and ti.name_ like concat('%',#{param.tenantName},'%')
  189. </if>
  190. </where>
  191. <choose>
  192. <when test="param.orderBy != null and param.orderBy.trim() != ''">
  193. order by ${param.orderBy}
  194. </when>
  195. <otherwise>
  196. order by t.create_time_ desc
  197. </otherwise>
  198. </choose>
  199. </select>
  200. <resultMap id="BasicUserInfo" type="com.yonge.cooleshow.biz.dal.dto.BasicUserInfo">
  201. <result property="userId" column="user_id_"/>
  202. <result property="username" column="username_"/>
  203. <result property="realName" column="real_name_"/>
  204. <result property="avatar" column="avatar_"/>
  205. </resultMap>
  206. <select id="getBasicUserInfo" resultMap="BasicUserInfo">
  207. SELECT id_ user_id_, username_, real_name_, avatar_
  208. FROM sys_user
  209. WHERE del_flag_ = 0
  210. and id_ = #{userId}
  211. LIMIT 1
  212. </select>
  213. <select id="findBasicUserInfo" resultMap="BasicUserInfo">
  214. SELECT id_ user_id_,username_,real_name_,avatar_ FROM sys_user
  215. WHERE del_flag_ = 0 and id_ IN
  216. <foreach collection="studentIds" open="(" close=")" separator="," item="userId">
  217. #{userId}
  218. </foreach>
  219. </select>
  220. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherVo">
  221. SELECT
  222. <include refid="baseColumns"/>,
  223. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  224. u.avatar_ as avatar,
  225. u.username_ as username,
  226. u.gender_ as `gender`,
  227. u.birthdate_ as birthdate,
  228. u.phone_ as phone,
  229. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  230. (!isnull(membership_end_time_) and membership_end_time_ > now()) as isVip,
  231. u.real_name_ as realName,
  232. u.id_card_no_ as idCardNo,
  233. (case when isnull(b.user_id_) then 0 else 1 end) as isBank,
  234. (
  235. SELECT GROUP_CONCAT(name_ ORDER by locate(id_,t.subject_id_)) FROM subject WHERE FIND_IN_SET(id_,t.subject_id_)
  236. ) as subjectName,
  237. u.user_type_ as userType
  238. FROM teacher t
  239. left join sys_user u on t.user_id_ = u.id_
  240. left join (
  241. select distinct user_id_ from user_bank_card where del_flag_ = 0 and user_id_ = #{userId}
  242. ) b on t.user_id_ = b.user_id_
  243. where u.del_flag_ = 0 and t.user_id_ = #{userId}
  244. </select>
  245. <select id="querySubject" resultMap="com.yonge.cooleshow.biz.dal.dao.SubjectDao.Subject">
  246. SELECT s.*
  247. FROM `subject` s
  248. LEFT JOIN teacher t ON FIND_IN_SET(s.id_, t.subject_id_)
  249. WHERE t.user_id_ = #{userId}
  250. </select>
  251. <update id="setSubject">
  252. update teacher
  253. set subject_id_ = #{subjectIds},
  254. update_time_ = now()
  255. where user_id_ = #{id}
  256. </update>
  257. <update id="addHomeBrowse">
  258. update teacher
  259. set browse_ = browse_ + 1
  260. where user_id_ = #{userId}
  261. </update>
  262. <select id="querySubjectItem" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  263. select t.* from subject t
  264. join (
  265. select a.subject_id_ from (
  266. <trim prefixOverrides="union all">
  267. <if test="type == null or type =='MUSIC'">
  268. union all
  269. (select music_subject_ as subject_id_ from music_sheet where user_id_ = #{userId} GROUP BY
  270. music_subject_)
  271. </if>
  272. <if test="type == null or type =='VIDEO'">
  273. union all
  274. (select lesson_subject_ as subject_id_ from video_lesson_group where teacher_id_ = #{userId} GROUP BY
  275. lesson_subject_)
  276. </if>
  277. <if test="type == null or type =='PIANO_ROOM'">
  278. union all
  279. (select subject_id_ as subject_id_ from course_group where type_ = 'PIANO_ROOM_CLASS' and teacher_id_ =
  280. #{userId} GROUP BY subject_id_)
  281. </if>
  282. <if test="type == null or type =='PRACTICE'">
  283. union all
  284. (select subject_id_ as subject_id_ from course_group where type_ = 'PRACTICE' and teacher_id_ =
  285. #{userId} GROUP BY subject_id_)
  286. </if>
  287. <if test="type == null or type =='LIVE'">
  288. union all
  289. (select subject_id_ as subject_id_ from course_group where type_ = 'LIVE' and teacher_id_ = #{userId}
  290. GROUP BY subject_id_)
  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 teacher s where s.user_id_ = #{userId} and find_in_set(t.id_,s.subject_id_)
  298. )
  299. </select>
  300. <select id="queryMyFans" resultType="com.yonge.cooleshow.biz.dal.vo.MyFens">
  301. SELECT
  302. s.student_id_ AS userId,
  303. s.create_time_ AS starTime,
  304. u.avatar_ AS avatar,
  305. u.username_ AS userName,
  306. u.real_name_ AS realName,
  307. u.gender_ AS gender,
  308. u.phone_ AS phone,
  309. u.birthdate_ AS birthdate,
  310. (SELECT group_concat(name_) FROM `subject` WHERE find_in_set(id_,sr.subject_id_)) AS subjectName,
  311. if(sr.membership_start_time_ &lt;= now() and sr.membership_end_time_ &gt;= now(),1,0) AS isVip
  312. FROM student_star s
  313. LEFT JOIN sys_user u ON s.student_id_ = u.id_
  314. LEFT JOIN student sr ON s.student_id_ = sr.user_id_
  315. <where>
  316. u.del_flag_ = 0
  317. <if test="record.teacherId != null">
  318. AND s.teacher_id_ =#{record.teacherId}
  319. </if>
  320. <if test="record.nickname != null">
  321. AND u.username_ LIKE '%${record.nickname}%'
  322. </if>
  323. <if test="record.userId != null">
  324. AND u.id_ = #{record.userId}
  325. </if>
  326. <if test="record.phone != null">
  327. AND u.phone_ = #{record.phone}
  328. </if>
  329. <if test="record.startTime != null and record.endTime != null">
  330. AND ( #{record.startTime} &lt;= s.create_time_ AND s.create_time_ &lt;= #{record.endTime})
  331. </if>
  332. </where>
  333. </select>
  334. <select id="queryHotTeacherList" resultMap="HotTeacherVoMap">
  335. select t.user_id_, t.graduate_school_, u.username_, u.avatar_, ifnull(a.speaker_id_, 0) isLiving_
  336. from teacher t
  337. left join sys_user u on t.user_id_ = u.id_
  338. left join teacher_total tt on tt.user_id_ = t.user_id_
  339. left join (SELECT lr.speaker_id_
  340. from live_room lr
  341. WHERE live_state_ = 1 and type_ = 'temp'
  342. group by lr.speaker_id_) a on a.speaker_id_ = t.user_id_
  343. where t.entry_flag_ = 1
  344. and t.is_test_user_ = 0
  345. and find_in_set(#{subjectId}, t.subject_id_)
  346. order by tt.fans_num_ desc
  347. limit 10
  348. </select>
  349. <!--老师学生人数统计-->
  350. <select id="selectTeacherStudentNumberStatInfo"
  351. resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
  352. SELECT t1.teacher_id_ AS id, COUNT(DISTINCT t1.id_) AS total FROM user_binding_teacher t1
  353. <where>
  354. <if test="teacherIds != null">
  355. AND t1.teacher_id_ IN (<foreach collection="teacherIds" separator="," item="item">
  356. #{item}
  357. </foreach>)
  358. </if>
  359. </where>
  360. GROUP BY t1.teacher_id_
  361. </select>
  362. <select id="countTeacherByTenantIds" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper$UserCount">
  363. select tenant_id_ tenantId, count(tenant_id_) count
  364. from teacher
  365. <where>
  366. lock_flag_ = 0
  367. <if test="tenantIdList != null">
  368. AND tenant_id_ in
  369. <foreach collection="tenantIdList" item="item" separator="," open="(" close=")">
  370. #{item}
  371. </foreach>
  372. </if>
  373. </where>
  374. group by tenant_id_
  375. </select>
  376. <select id="queryTeacherCounts" resultType="java.lang.Integer">
  377. select count(tenant_id_)
  378. from teacher
  379. <where>
  380. lock_flag_ = 0
  381. <if test="id != null">
  382. and tenant_id_ = #{id}
  383. </if>
  384. </where>
  385. </select>
  386. <!--老师学生人数统计-->
  387. </mapper>