TeacherMapper.xml 25 KB

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