TeacherMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. <result column="im_device_id_" property="imDeviceId"/>
  43. <result column="customer_service_" property="customerService"/>
  44. </resultMap>
  45. <resultMap id="HotTeacherVoMap" type="com.yonge.cooleshow.biz.dal.vo.HotTeacherVo">
  46. <result column="user_id_" property="userId"/>
  47. <result column="avatar_" property="avatar"/>
  48. <result column="graduate_school_" property="graduateSchool"/>
  49. <result column="username_" property="username"/>
  50. <result column="isLiving_" property="isLiving"/>
  51. </resultMap>
  52. <!-- 表字段 -->
  53. <sql id="baseColumns">
  54. t.user_id_ as "userId"
  55. , t.education_background_ as "educationBackground"
  56. , t.graduate_school_ as "graduateSchool"
  57. , t.technical_titles_ as "technicalTitles"
  58. , t.work_unit_ as "workUnit"
  59. , t.subject_id_ as "subjectId"
  60. , t.default_subject_ as defaultSubject
  61. , t.introduction_ as "introduction"
  62. , t.subject_ as "subject"
  63. , t.grad_certificate_ as "gradCertificate"
  64. , t.degree_certificate_ as "degreeCertificate"
  65. , t.teacher_certificate_ as "teacherCertificate"
  66. , t.entry_flag_ as "entryFlag"
  67. , t.entry_auth_date_ as "entryAuthDate"
  68. , t.musician_flag_ as "musicianFlag"
  69. , t.musician_date_ as "musicianDate"
  70. , t.live_flag_ as "liveFlag"
  71. , t.music_date_ as "musicDate"
  72. , t.video_date_ as "videoDate"
  73. , t.style_date_ as "styleDate"
  74. , t.degree_date_ as "degreeDate"
  75. , t.teacher_date_ as "teacherDate"
  76. , t.degree_flag_ as "degreeFlag"
  77. , t.teacher_flag_ as "teacherFlag"
  78. , t.member_rank_setting_id_ as "memberRankSettingId"
  79. <!-- , t.membership_start_time_ as "membershipStartTime"-->
  80. <!-- , t.membership_end_time_ as "membershipEndTime"-->
  81. , t.browse_ as "browse"
  82. , t.memo_ as "memo"
  83. , t.tag_ as "tag"
  84. , t.is_settlement_ as "isSettlement"
  85. , t.is_test_user_ as "isTestUser"
  86. , t.create_time_ as "createTime"
  87. , t.update_time_ as "updateTime"
  88. , t.train_time_ as trainTime
  89. , t.evaluate_time_ as evaluateTime
  90. , t.tenant_id_ as tenantId
  91. , t.settlement_from_ as settlementFrom
  92. , t.im_device_id_ as imDeviceId
  93. , t.customer_service_ as customerService
  94. </sql>
  95. <!-- 分页查询 -->
  96. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherVo">
  97. SELECT
  98. <include refid="baseColumns"/>,
  99. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  100. u.username_ as username,
  101. u.phone_ as phone,
  102. u.real_name_ as realName,
  103. u.avatar_ as avatar,
  104. u.birthdate_ as birthdate,
  105. u.gender_ as gender,
  106. <!-- (case when t.membership_end_time_ &gt;= now() then 1 else 0 end) isVip,-->
  107. <!-- t.tag_ tag,-->
  108. u.del_flag_ as delFlag,
  109. ifnull(vcr2.vip_type_ ,'NORMAL') as vipType,
  110. max(if(vcr.vip_type_ = 'VIP', vcr.end_time_, null)) vipEndTime,
  111. max(if(vcr.vip_type_ = 'SVIP' and vcr.type_ = 'PERPETUAL', vcr.end_time_ , null)) perSvipEndTime,
  112. max(if(vcr.vip_type_ = 'SVIP', vcr.end_time_, null)) svipEndTime,
  113. max(vcr.end_time_) currentVipEndTime,
  114. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  115. (case when isnull(b.user_id_) then 0 else 1 end) as isBank,
  116. (case when t.tenant_id_ = -1 then '平台' else ti.name_ end) as tenantName
  117. FROM teacher t
  118. left join sys_user u on t.user_id_ = u.id_
  119. left join (
  120. select distinct user_id_ from user_bank_card where del_flag_ = 0
  121. ) b on t.user_id_ = b.user_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.teacherType and '' != param.teacherType">
  135. and (
  136. 1=0
  137. <if test='param.teacherType.contains("TOURIST")'>
  138. or (t.entry_flag_ = 0 and t.musician_flag_ = 0)
  139. </if>
  140. <if test='param.teacherType.contains("ENTRY")'>
  141. or t.entry_flag_ = 1
  142. </if>
  143. <if test='param.teacherType.contains("MUSICIAN")'>
  144. or t.musician_flag_ = 1
  145. </if>
  146. )
  147. </if>
  148. <if test="param.vipType != null">
  149. <if test="param.vipType.code == 'NORMAL'">
  150. and vcr2.id_ is null
  151. </if>
  152. <if test="param.vipType.code != 'NORMAL'">
  153. and vcr2.vip_type_ = #{param.vipType}
  154. </if>
  155. </if>
  156. <!-- <if test="param.isVip != null">-->
  157. <!-- <if test="param.isVip == 0">-->
  158. <!-- and (t.membership_end_time_ is null or t.membership_end_time_ &lt; now())-->
  159. <!-- </if>-->
  160. <!-- <if test="param.isVip == 1">-->
  161. <!-- and t.membership_end_time_ &gt;= now()-->
  162. <!-- </if>-->
  163. <!-- </if>-->
  164. <if test="param.tag != null">
  165. and find_in_set(#{param.tag},t.tag_)
  166. </if>
  167. <if test="null != param.lockFlag">
  168. and t.lock_flag_ = #{param.lockFlag}
  169. </if>
  170. <if test="null != param.delFlag">
  171. and u.del_flag_ = #{param.delFlag}
  172. </if>
  173. <if test="param.subjectId != null">
  174. and find_in_set(#{param.subjectId},t.subject_id_)
  175. </if>
  176. <if test="param.isSettlement != null">
  177. and t.is_settlement_ = #{param.isSettlement}
  178. </if>
  179. <if test="param.isTestUser != null">
  180. and t.is_test_user_ = #{param.isTestUser}
  181. </if>
  182. <if test="null != param.vipEndTime">
  183. and vcr.end_time_ &lt;= #{param.vipEndTime}
  184. </if>
  185. <if test="null != param.vipStartTime">
  186. and vcr.end_time_ &gt;= #{param.vipStartTime}
  187. </if>
  188. <if test="param.trainFlag != null">
  189. AND t.train_time_ > 0
  190. </if>
  191. <if test="param.evaluateFlag != null">
  192. AND t.evaluate_time_ > 0
  193. </if>
  194. <if test="param.tenantId != null">
  195. AND t.tenant_id_ = #{param.tenantId}
  196. </if>
  197. <if test="param.bindTenant != null and param.bindTenant == 0">
  198. and t.tenant_id_ = -1
  199. </if>
  200. <if test="param.bindTenant != null and param.bindTenant == 1">
  201. and t.tenant_id_ != -1
  202. </if>
  203. <if test="param.settlementFrom != null">
  204. AND t.settlement_from_ = #{param.settlementFrom}
  205. </if>
  206. <if test="param.tenantName != null and param.tenantName.trim() != ''">
  207. and ti.name_ like concat('%',#{param.tenantName},'%')
  208. </if>
  209. <if test="param.customerService != null">
  210. AND t.customer_service_ = #{param.customerService}
  211. </if>
  212. </where>
  213. group by t.user_id_
  214. <if test="param.vipStartTime != null and param.vipEndTime != null">
  215. <!-- having ((vipEndTime >= #{param.vipStartTime} and #{param.vipEndTime}> vipEndTime) or (svipEndTime >= #{param.vipStartTime} and #{param.vipEndTime}> svipEndTime))-->
  216. having currentVipEndTime >= #{param.vipStartTime} and #{param.vipEndTime}> currentVipEndTime
  217. </if>
  218. <choose>
  219. <when test="param.orderBy != null and param.orderBy.trim() != ''">
  220. order by ${param.orderBy}
  221. </when>
  222. <otherwise>
  223. order by t.create_time_ desc
  224. </otherwise>
  225. </choose>
  226. </select>
  227. <resultMap id="BasicUserInfo" type="com.yonge.cooleshow.biz.dal.dto.BasicUserInfo">
  228. <result property="userId" column="user_id_"/>
  229. <result property="username" column="username_"/>
  230. <result property="realName" column="real_name_"/>
  231. <result property="avatar" column="avatar_"/>
  232. <result property="phone" column="phone_"/>
  233. </resultMap>
  234. <select id="getBasicUserInfo" resultMap="BasicUserInfo">
  235. SELECT id_ user_id_, username_, real_name_, avatar_, phone_
  236. FROM sys_user
  237. WHERE del_flag_ = 0
  238. and id_ = #{userId}
  239. LIMIT 1
  240. </select>
  241. <select id="findBasicUserInfo" resultMap="BasicUserInfo">
  242. SELECT id_ user_id_,username_,real_name_,avatar_, phone_ FROM sys_user
  243. WHERE del_flag_ = 0 and id_ IN
  244. <foreach collection="studentIds" open="(" close=")" separator="," item="userId">
  245. #{userId}
  246. </foreach>
  247. </select>
  248. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherVo">
  249. SELECT
  250. <include refid="baseColumns"/>,
  251. if(u.lock_flag_ = 0 and t.lock_flag_ = 0,0,1) as lockFlag,
  252. u.avatar_ as avatar,
  253. u.username_ as username,
  254. u.gender_ as `gender`,
  255. u.birthdate_ as birthdate,
  256. u.phone_ as phone,
  257. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal,
  258. (!isnull(membership_end_time_) and membership_end_time_ > now()) as isVip,
  259. u.real_name_ as realName,
  260. u.id_card_no_ as idCardNo,
  261. if(vcr.type_ = 'PERMANENT',null,vcr.end_time_) as membershipEndTime,
  262. (case when isnull(b.user_id_) then 0 else 1 end) as isBank,
  263. (
  264. SELECT GROUP_CONCAT(name_ ORDER by locate(id_,t.subject_id_)) FROM subject WHERE FIND_IN_SET(id_,t.subject_id_)
  265. ) as subjectName,
  266. u.user_type_ as userType
  267. FROM teacher t
  268. left join sys_user u on t.user_id_ = u.id_
  269. left join (
  270. select distinct user_id_ from user_bank_card where del_flag_ = 0 and user_id_ = #{userId}
  271. ) b on t.user_id_ = b.user_id_
  272. left join vip_card_record vcr on t.user_id_ = vcr.user_id_ and vcr.client_type_ = 'TEACHER'
  273. and vcr.efficient_flag_ = 1 and vcr.end_time_ >= now() and now() > vcr.start_time_ and (vcr.vip_type_ = 'VIP' or vcr.vip_type_ = 'SVIP') and vcr.client_type_ = 'TEACHER'
  274. where u.del_flag_ = 0 and t.user_id_ = #{userId}
  275. </select>
  276. <select id="querySubject" resultMap="com.yonge.cooleshow.biz.dal.dao.SubjectDao.Subject">
  277. SELECT s.*
  278. FROM `subject` s
  279. LEFT JOIN teacher t ON FIND_IN_SET(s.id_, t.subject_id_)
  280. WHERE t.user_id_ = #{userId}
  281. </select>
  282. <update id="setSubject">
  283. update teacher
  284. set subject_id_ = #{subjectIds},
  285. update_time_ = now()
  286. where user_id_ = #{id}
  287. </update>
  288. <update id="addHomeBrowse">
  289. update teacher
  290. set browse_ = browse_ + 1
  291. where user_id_ = #{userId}
  292. </update>
  293. <select id="querySubjectItem" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
  294. select t.* from subject t
  295. join (
  296. select a.subject_id_ from (
  297. <trim prefixOverrides="union all">
  298. <if test="type == null or type =='MUSIC'">
  299. union all
  300. (select music_subject_ as subject_id_ from music_sheet where user_id_ = #{userId} GROUP BY
  301. music_subject_)
  302. </if>
  303. <if test="type == null or type =='VIDEO'">
  304. union all
  305. (select lesson_subject_ as subject_id_ from video_lesson_group where teacher_id_ = #{userId} GROUP BY
  306. lesson_subject_)
  307. </if>
  308. <if test="type == null or type =='PIANO_ROOM'">
  309. union all
  310. (select subject_id_ as subject_id_ from course_group where type_ = 'PIANO_ROOM_CLASS' and teacher_id_ =
  311. #{userId} GROUP BY subject_id_)
  312. </if>
  313. <if test="type == null or type =='PRACTICE'">
  314. union all
  315. (select subject_id_ as subject_id_ from course_group where type_ = 'PRACTICE' and teacher_id_ =
  316. #{userId} GROUP BY subject_id_)
  317. </if>
  318. <if test="type == null or type =='LIVE'">
  319. union all
  320. (select subject_id_ as subject_id_ from course_group where type_ = 'LIVE' and teacher_id_ = #{userId}
  321. GROUP BY subject_id_)
  322. </if>
  323. </trim>
  324. ) a group by a.subject_id_
  325. ) a on t.id_ = a.subject_id_
  326. where t.parent_subject_id_ != 0
  327. and not exists(
  328. select 1 from teacher s where s.user_id_ = #{userId} and find_in_set(t.id_,s.subject_id_)
  329. )
  330. </select>
  331. <select id="queryMyFans" resultType="com.yonge.cooleshow.biz.dal.vo.MyFens">
  332. SELECT
  333. s.student_id_ AS userId,
  334. s.create_time_ AS starTime,
  335. u.avatar_ AS avatar,
  336. u.username_ AS userName,
  337. u.real_name_ AS realName,
  338. u.gender_ AS gender,
  339. u.phone_ AS phone,
  340. u.birthdate_ AS birthdate,
  341. (SELECT group_concat(name_) FROM `subject` WHERE find_in_set(id_,sr.subject_id_)) AS subjectName
  342. <!-- if(sr.membership_start_time_ &lt;= now() and sr.membership_end_time_ &gt;= now(),1,0) AS isVip-->
  343. FROM student_star s
  344. LEFT JOIN sys_user u ON s.student_id_ = u.id_
  345. LEFT JOIN student sr ON s.student_id_ = sr.user_id_
  346. <where>
  347. u.del_flag_ = 0
  348. <if test="record.teacherId != null">
  349. AND s.teacher_id_ =#{record.teacherId}
  350. </if>
  351. <if test="record.nickname != null">
  352. AND u.username_ LIKE '%${record.nickname}%'
  353. </if>
  354. <if test="record.userId != null">
  355. AND u.id_ = #{record.userId}
  356. </if>
  357. <if test="record.phone != null">
  358. AND u.phone_ = #{record.phone}
  359. </if>
  360. <if test="record.startTime != null and record.endTime != null">
  361. AND ( #{record.startTime} &lt;= s.create_time_ AND s.create_time_ &lt;= #{record.endTime})
  362. </if>
  363. </where>
  364. </select>
  365. <select id="queryHotTeacherList" resultMap="HotTeacherVoMap">
  366. select t.user_id_, t.graduate_school_, u.username_, u.avatar_, ifnull(a.speaker_id_, 0) isLiving_
  367. from teacher t
  368. left join sys_user u on t.user_id_ = u.id_
  369. left join teacher_total tt on tt.user_id_ = t.user_id_
  370. left join (SELECT lr.speaker_id_
  371. from live_room lr
  372. WHERE live_state_ = 1 and type_ = 'temp'
  373. group by lr.speaker_id_) a on a.speaker_id_ = t.user_id_
  374. where t.entry_flag_ = 1
  375. and t.is_test_user_ = 0
  376. and find_in_set(#{subjectId}, t.subject_id_)
  377. order by tt.fans_num_ desc
  378. limit 10
  379. </select>
  380. <!--老师学生人数统计-->
  381. <select id="selectTeacherStudentNumberStatInfo"
  382. resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
  383. SELECT t1.teacher_id_ AS id, COUNT(DISTINCT t1.id_) AS total FROM user_binding_teacher t1
  384. <where>
  385. <if test="teacherIds != null">
  386. AND t1.teacher_id_ IN (<foreach collection="teacherIds" separator="," item="item">
  387. #{item}
  388. </foreach>)
  389. </if>
  390. </where>
  391. GROUP BY t1.teacher_id_
  392. </select>
  393. <select id="countTeacherByTenantIds" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper$UserCount">
  394. select tenant_id_ tenantId, count(tenant_id_) count
  395. from teacher
  396. <where>
  397. lock_flag_ = 0
  398. <if test="tenantIdList != null">
  399. AND tenant_id_ in
  400. <foreach collection="tenantIdList" item="item" separator="," open="(" close=")">
  401. #{item}
  402. </foreach>
  403. </if>
  404. </where>
  405. group by tenant_id_
  406. </select>
  407. <select id="queryTeacherCounts" resultType="java.lang.Integer">
  408. select count(tenant_id_)
  409. from teacher
  410. <where>
  411. lock_flag_ = 0
  412. <if test="id != null">
  413. and tenant_id_ = #{id}
  414. </if>
  415. </where>
  416. </select>
  417. <!--老师学生人数统计-->
  418. <select id="getCustomerServiceByFriendLeast" resultMap="BaseResultMap">
  419. select
  420. t.*
  421. from
  422. ( SELECT
  423. te.user_id_,
  424. count(distinct iuf.friend_id_) friends
  425. from teacher te
  426. left join sys_user su on te.user_id_ = su.id_
  427. left join im_user_friend iuf on te.user_id_ = iuf.user_id_
  428. where te.lock_flag_ = 0 and te.customer_service_ = 1 and su.del_flag_ = 0 and su.lock_flag_ = 0
  429. group by te.user_id_
  430. order by friends
  431. limit 1) m
  432. left join teacher t on m.user_id_ = t.user_id_
  433. </select>
  434. <select id="getCustomerServiceFriendNums" resultType="com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherWrapper$TeacherFriend">
  435. SELECT te.user_id_ teacherId,
  436. count(distinct iuf.friend_id_) friendNums
  437. from teacher te
  438. left join sys_user su on te.user_id_ = su.id_
  439. left join im_user_friend iuf on te.user_id_ = iuf.user_id_
  440. where te.lock_flag_ = 0
  441. and te.customer_service_ = 1
  442. and su.del_flag_ = 0
  443. and su.lock_flag_ = 0
  444. group by te.user_id_
  445. </select>
  446. </mapper>