TeacherMapper.xml 19 KB

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