StudentMapper.xml 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.StudentDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.Student" id="Student">
  9. <result column="user_id_" property="userId"/>
  10. <result column="subject_id_list_" property="subjectIdList"/>
  11. <result column="service_tag_" property="serviceTag"/>
  12. <result column="operating_tag_" property="operatingTag"/>
  13. <result column="operating_temp_tag_" property="operatingTempTag"/>
  14. <result column="teacher_id_" property="teacherId"/>
  15. <result column="teacher_name_" property="teacherName"/>
  16. <result column="is_new_user_" property="isNewUser"/>
  17. <result column="create_time_" property="createTime"/>
  18. <result column="update_time_" property="updateTime"/>
  19. <result column="care_package_" property="carePackage"/>
  20. <result column="come_on_package_" property="comeOnPackage"/>
  21. <result column="current_grade_num_" property="currentGradeNum"/>
  22. <result column="current_class_" property="currentClass"/>
  23. <result column="cooperation_organ_id_" property="cooperationOrganId"/>
  24. <result column="member_rank_setting_id_" property="memberRankSettingId"/>
  25. <result column="membership_start_time_" property="membershipStartTime"/>
  26. <result column="membership_end_time_" property="membershipEndTime"/>
  27. <result column="experience_member_rank_setting_id_" property="experienceMemberRankSettingId"/>
  28. <result column="experience_membership_start_time_" property="experienceMembershipStartTime"/>
  29. <result column="experience_membership_end_time_" property="experienceMembershipEndTime"/>
  30. <result column="activity_course_detail_" property="activityCourseDetail"/>
  31. <result column="organ_name_" property="organName"/>
  32. <result column="phone_" property="phone"/>
  33. <result column="username_" property="username"/>
  34. </resultMap>
  35. <!-- 根据主键查询一条记录 -->
  36. <select id="get" resultMap="Student">
  37. SELECT *
  38. FROM student
  39. WHERE user_id_ = #{id}
  40. </select>
  41. <select id="getLocked" resultMap="Student">
  42. SELECT *
  43. FROM student
  44. WHERE user_id_ = #{id} for update
  45. </select>
  46. <!-- 全查询 -->
  47. <select id="findAll" resultMap="Student">
  48. SELECT *
  49. FROM student
  50. </select>
  51. <select id="lockUser" resultType="int" useCache="false" flushCache="true">
  52. SELECT id_
  53. FROM sys_user
  54. WHERE id_ = #{userId} FOR
  55. UPDATE
  56. </select>
  57. <select id="lockUserReturnInfo" resultMap="com.ym.mec.biz.dal.dao.TeacherDao.SysUser">
  58. SELECT *
  59. FROM sys_user
  60. WHERE id_ = #{userId} FOR UPDATE
  61. </select>
  62. <select id="getUser" resultMap="com.ym.mec.biz.dal.dao.TeacherDao.SysUser">
  63. SELECT *
  64. FROM sys_user
  65. WHERE id_ = #{userId}
  66. </select>
  67. <!-- 向数据库增加一条记录 -->
  68. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Student" useGeneratedKeys="true" keyColumn="id"
  69. keyProperty="id">
  70. INSERT INTO student (user_id_,subject_id_list_,
  71. <if test="serviceTag != null">
  72. service_tag_,
  73. </if>
  74. <if test="operatingTag != null">
  75. operating_tag_,
  76. </if>
  77. teacher_id_,create_time_,update_time_,service_tag_update_time_,cooperation_organ_id_,
  78. care_package_,come_on_package_,member_rank_setting_id_,membership_start_time_,membership_end_time_)
  79. VALUES
  80. (#{userId},#{subjectIdList},
  81. <if test="serviceTag != null">
  82. #{serviceTag},
  83. </if>
  84. <if test="operatingTag != null">
  85. #{operatingTag},
  86. </if>
  87. #{teacherId},NOW(),NOW(),NOW(),#{cooperationOrganId},
  88. #{carePackage},#{comeOnPackage},#{memberRankSettingId},#{membershipStartTime},#{membershipEndTime})
  89. </insert>
  90. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Student">
  91. UPDATE student
  92. <set>
  93. <if test="subjectIdList != null">
  94. subject_id_list_ = #{subjectIdList},
  95. </if>
  96. <if test="serviceTag != null">
  97. service_tag_update_time_=IF(service_tag_ = #{serviceTag}, service_tag_update_time_, NOW()),
  98. service_tag_ = #{serviceTag},
  99. </if>
  100. <if test="operatingTag != null">
  101. operating_tag_ = #{operatingTag},
  102. </if>
  103. <if test="operatingTempTag != null">
  104. operating_temp_tag_ = #{operatingTempTag},
  105. </if>
  106. <if test="teacherId != null">
  107. teacher_id_=#{teacherId},
  108. </if>
  109. <if test="isNewUser != null">
  110. is_new_user_=#{isNewUser},
  111. </if>
  112. <if test="carePackage != null">
  113. care_package_=#{carePackage},
  114. </if>
  115. <if test="comeOnPackage != null">
  116. come_on_package_=#{comeOnPackage},
  117. </if>
  118. <if test="currentGradeNum != null">
  119. current_grade_num_=#{currentGradeNum},
  120. </if>
  121. <if test="currentClass != null">
  122. current_class_=#{currentClass},
  123. </if>
  124. <if test="memberRankSettingId != null">
  125. member_rank_setting_id_=#{memberRankSettingId},
  126. </if>
  127. <if test="membershipStartTime != null">
  128. membership_start_time_=#{membershipStartTime},
  129. </if>
  130. <if test="membershipEndTime != null">
  131. membership_end_time_=#{membershipEndTime},
  132. </if>
  133. <if test="experienceMemberRankSettingId != null">
  134. experience_member_rank_setting_id_=#{experienceMemberRankSettingId},
  135. </if>
  136. <if test="experienceMembershipStartTime != null">
  137. experience_membership_start_time_=#{experienceMembershipStartTime},
  138. </if>
  139. <if test="experienceMembershipEndTime != null">
  140. experience_membership_end_time_=#{experienceMembershipEndTime},
  141. </if>
  142. <if test="activityCourseDetail != null">
  143. activity_course_detail_=#{activityCourseDetail},
  144. </if>
  145. cooperation_organ_id_=#{cooperationOrganId},
  146. update_time_ = NOW()
  147. </set>
  148. WHERE user_id_ = #{userId}
  149. </update>
  150. <!-- 分页查询 -->
  151. <select id="queryPage" resultMap="Student" parameterType="map">
  152. SELECT s.*,su.username_,su.phone_,o.name_ organ_name_ FROM student s
  153. LEFT JOIN sys_user su ON su.id_ = s.user_id_
  154. LEFT JOIN organization o ON o.id_ = su.organ_id_
  155. <include refid="queryPageSql"/>
  156. ORDER BY s.activity_course_detail_ DESC
  157. <include refid="global.limit"/>
  158. </select>
  159. <!-- 查询当前表的总记录数 -->
  160. <select id="queryCount" resultType="int">
  161. SELECT COUNT(s.user_id_) FROM student s
  162. LEFT JOIN sys_user su ON su.id_ = s.user_id_
  163. <include refid="queryPageSql"/>
  164. </select>
  165. <sql id="queryPageSql">
  166. <where>
  167. <if test="organId != null and organId != ''">
  168. AND FIND_IN_SET(su.organ_id_,#{organId})
  169. </if>
  170. <if test="search != null and search != ''">
  171. AND (s.user_id_ = #{search} OR su.username_ LIKE CONCAT('%', #{search}, '%') OR su.phone_ LIKE CONCAT('%', #{search}, '%'))
  172. </if>
  173. </where>
  174. </sql>
  175. <select id="findStudents" resultMap="com.ym.mec.biz.dal.dao.TeacherDao.SysUser">
  176. SELECT id_, username_, phone_,avatar_ FROM sys_user
  177. <include refid="studentQueryCondition"/>
  178. ORDER BY id_
  179. <include refid="global.limit"/>
  180. </select>
  181. <select id="countStudents" resultType="int">
  182. SELECT COUNT(id_) FROM sys_user
  183. <include refid="studentQueryCondition"/>
  184. </select>
  185. <sql id="studentQueryCondition">
  186. <where>
  187. <if test="organIdList!=null">
  188. organ_id_ IN
  189. <foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
  190. #{organId}
  191. </foreach>
  192. </if>
  193. <if test="search!=null">
  194. AND (username_ LIKE CONCAT('%', #{search}, '%') OR phone_ LIKE CONCAT('%', #{search}, '%'))
  195. </if>
  196. AND FIND_IN_SET("STUDENT", user_type_)
  197. </where>
  198. </sql>
  199. <select id="queryByOperatingTempTag" resultMap="Student">
  200. SELECT *
  201. FROM student
  202. WHERE operating_temp_tag_ = #{operatingTempTag}
  203. </select>
  204. <update id="batchUpdate" parameterType="java.util.List">
  205. <foreach collection="studentList" item="item" index="index" open="" close="" separator=";">
  206. UPDATE student
  207. <set>
  208. <if test="item.subjectIdList != null">
  209. subject_id_list_ = #{item.subjectIdList},
  210. </if>
  211. <if test="item.currentGradeNum != null">
  212. current_grade_num_=#{item.currentGradeNum},
  213. </if>
  214. <if test="item.serviceTag != null">
  215. service_tag_ = #{item.serviceTag},
  216. </if>
  217. <if test="item.operatingTag != null">
  218. operating_tag_ = #{item.operatingTag},
  219. </if>
  220. <if test="item.operatingTempTag != null">
  221. operating_temp_tag_ = #{item.operatingTempTag},
  222. </if>
  223. <if test="item.teacherId != null">
  224. teacher_id_=#{item.teacherId},
  225. </if>
  226. <if test="item.updateTime != null">
  227. update_time_ = #{item.updateTime},
  228. </if>
  229. <if test="item.carePackage != null">
  230. care_package_=#{item.carePackage},
  231. </if>
  232. <if test="item.comeOnPackage != null">
  233. come_on_package_=#{item.comeOnPackage},
  234. </if>
  235. <if test="item.cooperationOrganId != null">
  236. cooperation_organ_id_=#{item.cooperationOrganId},
  237. </if>
  238. <if test="item.activityCourseDetail != null">
  239. activity_course_detail_=#{item.activityCourseDetail},
  240. </if>
  241. <if test="item.memberRankSettingId != null">
  242. member_rank_setting_id_=#{item.memberRankSettingId},
  243. </if>
  244. <if test="item.membershipStartTime != null">
  245. membership_start_time_=#{item.membershipStartTime},
  246. </if>
  247. <if test="item.membershipEndTime != null">
  248. membership_end_time_=#{item.membershipEndTime},
  249. </if>
  250. update_time_ = NOW()
  251. </set>
  252. WHERE user_id_ = #{item.userId}
  253. </foreach>
  254. </update>
  255. <update id="updateStudentServiceOrOperatingTag">
  256. UPDATE student
  257. <set>
  258. <if test="serviceTag != null">
  259. service_tag_ = #{serviceTag},
  260. </if>
  261. <if test="operatingTag != null">
  262. operating_tag_ = #{operatingTag},
  263. </if>
  264. update_time_ = NOW()
  265. </set>
  266. WHERE
  267. <if test="studentId!=null">
  268. user_id_ = #{studentId}
  269. </if>
  270. <if test="studentIds!=null and studentIds.size()>0">
  271. user_id_ IN
  272. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  273. #{studentId}
  274. </foreach>
  275. </if>
  276. </update>
  277. <update id="updateStudentServiceTag">
  278. UPDATE student
  279. <set>
  280. <if test="serviceTag != null">
  281. service_tag_update_time_ = IF(service_tag_=#{serviceTag}, service_tag_update_time_, NOW()),
  282. service_tag_ = #{serviceTag},
  283. </if>
  284. update_time_ = NOW()
  285. </set>
  286. WHERE
  287. service_tag_=0
  288. <if test="studentId!=null">
  289. AND user_id_ = #{studentId}
  290. </if>
  291. <if test="studentIds!=null and studentIds.size()>0">
  292. AND user_id_ IN
  293. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  294. #{studentId}
  295. </foreach>
  296. </if>
  297. </update>
  298. <update id="batchUpdateAdviser">
  299. UPDATE student s SET s.teacher_id_ = #{teacherId},s.update_time_ = NOW() WHERE FIND_IN_SET(s.user_id_,#{studentIds})
  300. </update>
  301. <update id="updateServiceTag">
  302. UPDATE student SET service_tag_ = #{serviceTag},update_time_ = NOW() WHERE user_id_ IN
  303. <foreach collection="studentIds" item="item" open="(" separator="," close=")">
  304. #{item}
  305. </foreach>
  306. </update>
  307. <resultMap id="student4operating" type="com.ym.mec.biz.dal.dto.Student4operating">
  308. <result column="organ_name_" property="organName"/>
  309. <result column="organ_id_" property="organId"/>
  310. <result column="student_name_" property="studentName"/>
  311. <result column="student_id_" property="studentId"/>
  312. <result column="teacher_id_" property="teacherId"/>
  313. <result column="teacher_name_" property="teacherName"/>
  314. <result column="operating_tag_" property="operatingTag"/>
  315. <result column="vip_times_" property="vipTimes"/>
  316. <result column="free_practice_times_" property="freePracticeTimes"/>
  317. <result column="buy_practice_times_" property="buyPracticeTimes"/>
  318. <result column="music_netWork_times_" property="musicNetWorkTimes"/>
  319. <result column="student_num_" property="studentNum"/>
  320. </resultMap>
  321. <select id="getOperatingStudents" resultMap="student4operating">
  322. SELECT su.organ_id_,
  323. o.name_ organ_name_,
  324. su.username_ student_name_,
  325. s.user_id_ student_id_,
  326. tsu.id_ teacher_id_,
  327. tsu.real_name_ teacher_name_,
  328. s.operating_tag_,
  329. a.vip_times_,
  330. a.buy_practice_times_,
  331. a.music_netWork_times_,
  332. p.free_practice_times_
  333. FROM student s
  334. LEFT JOIN sys_user su ON s.user_id_ = su.id_
  335. LEFT JOIN sys_user tsu ON tsu.id_ = s.teacher_id_
  336. LEFT JOIN organization o ON o.id_ = su.organ_id_
  337. LEFT JOIN (
  338. SELECT cssp.user_id_,
  339. SUM(case when (cs.group_type_ = 'VIP' AND cs.teach_mode_='ONLINE') then 1 ELSE 0 END) vip_times_,
  340. SUM(case when (pg.type_='CHARGE') then 1 ELSE 0 END) buy_practice_times_,
  341. SUM(case when (cs.type_='MUSIC_NETWORK' OR cs.type_='HIGH_ONLINE') then 1 ELSE 0 END) music_netWork_times_
  342. FROM course_schedule_student_payment cssp
  343. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  344. LEFT JOIN practice_group pg ON pg.`id_` = cs.`music_group_id_` AND cs.`group_type_` = 'PRACTICE'
  345. WHERE cs.status_ IN ('NOT_START','UNDERWAY') AND (cs.is_lock_ IS NULL OR cs.is_lock_=0) AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
  346. GROUP BY cssp.user_id_
  347. ) a on a.user_id_ = s.user_id_
  348. LEFT JOIN (
  349. SELECT student_id_, count(id_) free_practice_times_
  350. FROM practice_group
  351. WHERE type_='FREE' AND group_status_ IN ('NORMAL', 'FINISH')
  352. GROUP BY student_id_
  353. ) p ON p.student_id_ = s.user_id_
  354. <include refid="student4OperatingQueryCondition"/>
  355. ORDER BY s.user_id_
  356. <include refid="global.limit"/>
  357. </select>
  358. <select id="countOperatingStudents" resultType="int">
  359. SELECT COUNT(s.user_id_) FROM student s
  360. LEFT JOIN sys_user su ON s.user_id_ = su.id_
  361. LEFT JOIN sys_user tsu ON tsu.id_ = s.teacher_id_
  362. LEFT JOIN (
  363. SELECT cssp.user_id_,
  364. SUM(case when (cs.group_type_ = 'VIP' AND cs.teach_mode_='ONLINE') then 1 ELSE 0 END) vip_times_,
  365. SUM(case when (pg.type_='CHARGE') then 1 ELSE 0 END) buy_practice_times_,
  366. SUM(case when (cs.type_='MUSIC_NETWORK' OR cs.type_='HIGH_ONLINE') then 1 ELSE 0 END) music_netWork_times_
  367. FROM course_schedule_student_payment cssp
  368. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  369. LEFT JOIN practice_group pg ON pg.`id_` = cs.`music_group_id_` AND cs.`group_type_` = 'PRACTICE'
  370. WHERE cs.status_ IN ('NOT_START','UNDERWAY') AND (cs.is_lock_ IS NULL OR cs.is_lock_=0) AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
  371. GROUP BY cssp.user_id_
  372. ) a on a.user_id_ = s.user_id_
  373. LEFT JOIN (
  374. SELECT student_id_, count(id_) free_practice_times_
  375. FROM practice_group
  376. WHERE type_='FREE' AND group_status_ IN ('NORMAL', 'FINISH')
  377. GROUP BY student_id_
  378. ) p ON p.student_id_ = s.user_id_
  379. <include refid="student4OperatingQueryCondition"/>
  380. </select>
  381. <sql id="student4OperatingQueryCondition">
  382. <where>
  383. su.user_type_ LIKE '%STUDENT%'
  384. <if test="search != null and search != ''">
  385. AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_
  386. LIKE CONCAT('%',#{search},'%'))
  387. </if>
  388. <if test="organId != null and organId != ''">
  389. AND FIND_IN_SET(su.organ_id_,#{organId})
  390. </if>
  391. <if test="teacherId!=null">
  392. AND s.teacher_id_ = #{teacherId}
  393. </if>
  394. <if test="operatingTag !=null">
  395. AND s.operating_tag_ = #{operatingTag}
  396. </if>
  397. <if test='hasVip != null and hasVip=="1"'>
  398. AND a.vip_times_ >=1
  399. </if>
  400. <if test='hasVip != null and hasVip=="0"'>
  401. AND (a.vip_times_ =0 OR a.vip_times_ IS NULL)
  402. </if>
  403. <if test='hasFreePractice != null and hasFreePractice=="1"'>
  404. AND p.free_practice_times_ >=1
  405. </if>
  406. <if test='hasFreePractice != null and hasFreePractice=="0"'>
  407. AND (p.free_practice_times_ =0 OR p.free_practice_times_ IS NULL)
  408. </if>
  409. <if test='hasBuyPractice != null and hasBuyPractice=="1"'>
  410. AND a.buy_practice_times_ >=1
  411. </if>
  412. <if test='hasBuyPractice != null and hasBuyPractice=="0"'>
  413. AND (a.buy_practice_times_ =0 OR a.buy_practice_times_ IS NULL)
  414. </if>
  415. <if test='hasMusicNetWork != null and hasMusicNetWork=="1"'>
  416. AND a.music_netWork_times_ >=1
  417. </if>
  418. <if test='hasMusicNetWork != null and hasMusicNetWork=="0"'>
  419. AND (a.music_netWork_times_ =0 OR a.music_netWork_times_ IS NULL)
  420. </if>
  421. </where>
  422. </sql>
  423. <select id="getTeacherOperatingStudentsNum" resultType="java.util.Map">
  424. select teacher_id_ 'key', count(*) 'value'
  425. FROM student
  426. WHERE FIND_IN_SET(teacher_id_, #{teacherIds})
  427. AND operating_tag_ = 1
  428. GROUP BY teacher_id_
  429. </select>
  430. <select id="getBuyNums" resultType="java.util.Map">
  431. SELECT s.teacher_id_ 'key', COUNT(DISTINCT cssp.user_id_) 'value'
  432. FROM course_schedule_student_payment cssp
  433. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_ AND cs.teach_mode_ = 'ONLINE'
  434. LEFT JOIN student s ON s.user_id_ = cssp.user_id_
  435. <if test="groupType != null and groupType==@com.ym.mec.biz.dal.enums.GroupType@PRACTICE">
  436. LEFT JOIN practice_group pg ON cssp.music_group_id_ = pg.id_ AND cssp.group_type_ = 'PRACTICE'
  437. </if>
  438. WHERE s.teacher_id_ = #{teacherId}
  439. AND cs.status_ IN ('NOT_START', 'UNDERWAY')
  440. AND (cs.is_lock_ IS NULL OR cs.is_lock_ = 0)
  441. <if test="groupType != null">
  442. AND cs.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  443. </if>
  444. <if test="groupType != null and groupType==@com.ym.mec.biz.dal.enums.GroupType@PRACTICE">
  445. AND pg.group_status_ IN ('NORMAL', 'FINISH')
  446. AND pg.buy_months_ >= 1
  447. </if>
  448. GROUP BY s.teacher_id_
  449. </select>
  450. <select id="getPracticeAndVipNums" resultType="java.util.Map">
  451. SELECT s.teacher_id_ 'key', COUNT(DISTINCT pg.student_id_) 'value'
  452. FROM practice_group pg
  453. LEFT JOIN student s on s.user_id_ = pg.student_id_
  454. LEFT JOIN course_schedule_student_payment vcssp
  455. ON vcssp.user_id_ = pg.student_id_ AND vcssp.group_type_ = 'VIP'
  456. LEFT JOIN course_schedule_student_payment pcssp
  457. ON pcssp.user_id_ = pg.student_id_ AND pcssp.group_type_ = 'PRACTICE'
  458. LEFT JOIN course_schedule vcs ON vcs.id_ = vcssp.course_schedule_id_ AND vcs.teach_mode_ = 'ONLINE'
  459. LEFT JOIN course_schedule pcs ON pcs.id_ = pcssp.course_schedule_id_
  460. WHERE FIND_IN_SET(s.teacher_id_, #{teacherIds})
  461. AND pg.group_status_ IN ('NORMAL', 'FINISH')
  462. AND vcs.status_ IN ('NOT_START', 'UNDERWAY')
  463. AND pcs.status_ IN ('NOT_START', 'UNDERWAY')
  464. AND (vcs.is_lock_ IS NULL OR vcs.is_lock_ = 0)
  465. AND (pcs.is_lock_ IS NULL OR pcs.is_lock_ = 0)
  466. AND pg.buy_months_ >= 1
  467. GROUP BY s.teacher_id_
  468. </select>
  469. <select id="getServiceStudents" resultMap="Student">
  470. SELECT su.id_ user_id_,s.teacher_id_ FROM sys_user su
  471. LEFT JOIN student s ON s.user_id_=su.id_
  472. WHERE s.service_tag_=1 AND FIND_IN_SET('STUDENT', su.user_type_)
  473. </select>
  474. <resultMap id="StudentServeDto" type="com.ym.mec.biz.dal.dto.StudentServeDto" extends="Student">
  475. <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  476. <result column="teach_mode_" property="teachMode" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  477. <result property="courseStartTime" column="course_start_time_"/>
  478. </resultMap>
  479. <select id="getBeServiceStudents" resultMap="StudentServeDto">
  480. SELECT
  481. s.user_id_,
  482. s.teacher_id_,
  483. cs.group_type_,
  484. cs.teach_mode_,
  485. IF(CONCAT( cs.class_date_, ' ', cs.end_class_time_ )&lt;#{courseExpireDate} AND (sa.status_ != 'NORMAL' OR sa.status_ IS NULL), NULL, cs.class_date_) course_start_time_
  486. FROM
  487. student s
  488. LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = s.user_id_
  489. LEFT JOIN student_attendance sa ON cssp.course_schedule_id_=sa.course_schedule_id_ AND sa.user_id_=cssp.user_id_
  490. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  491. AND cs.group_type_ IN ('VIP', 'PRACTICE')
  492. AND CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) > #{monday}
  493. WHERE
  494. s.service_tag_ = 1
  495. </select>
  496. <select id="getBeServiceStudentsInfoWithStudents" resultMap="StudentServeDto">
  497. SELECT
  498. s.user_id_,
  499. s.teacher_id_,
  500. cs.group_type_,
  501. cs.teach_mode_,
  502. IF(CONCAT( cs.class_date_, ' ', cs.end_class_time_ )&lt;#{courseExpireDate} AND (sa.status_ != 'NORMAL' OR sa.status_ IS NULL), NULL, cs.class_date_) course_start_time_
  503. FROM
  504. student s
  505. LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = s.user_id_
  506. LEFT JOIN student_attendance sa ON cssp.course_schedule_id_=sa.course_schedule_id_ AND sa.user_id_=cssp.user_id_
  507. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  508. AND cs.group_type_ IN ('VIP', 'PRACTICE')
  509. AND CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) > #{monday}
  510. WHERE
  511. s.service_tag_ = 1 AND s.user_id_ IN
  512. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  513. #{studentId}
  514. </foreach>
  515. </select>
  516. <select id="getBeServiceStudentsInfoWithStudentsForHistory" resultMap="StudentServeDto">
  517. SELECT
  518. s.student_id_ user_id_,
  519. s.teacher_id_,
  520. cs.group_type_,
  521. cs.teach_mode_,
  522. IF(CONCAT( cs.class_date_, ' ', cs.end_class_time_ )&lt;#{courseExpireDate} AND (sa.status_ != 'NORMAL' OR sa.status_ IS NULL), NULL, cs.class_date_) course_start_time_
  523. FROM
  524. student_extracurricular_exercises_situation_ s
  525. LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = s.student_id_
  526. LEFT JOIN student_attendance sa ON cssp.course_schedule_id_=sa.course_schedule_id_ AND sa.user_id_=cssp.user_id_
  527. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  528. AND cs.group_type_ IN ('VIP', 'PRACTICE')
  529. AND CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) > #{monday}
  530. WHERE
  531. s.monday_ = #{monday} AND s.student_id_ IN
  532. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  533. #{studentId}
  534. </foreach>
  535. </select>
  536. <select id="getServeStudentIds" resultType="int">
  537. SELECT user_id_
  538. FROM student stu
  539. LEFT JOIN sys_user su ON stu.user_id_=su.id_
  540. WHERE service_tag_=1 AND su.del_flag_=0
  541. </select>
  542. <select id="getServeStudentCourseStartTimes" resultType="com.ym.mec.biz.dal.dto.StudentServeCourseDto">
  543. SELECT
  544. cssp.user_id_ studentId,
  545. stu.service_tag_update_time_ serviceTagUpdateTime,
  546. CONCAT(cs.class_date_, ' ', cs.start_class_time_) courseStartTime
  547. FROM course_schedule_student_payment cssp
  548. LEFT JOIN course_schedule cs ON cs.id_=cssp.course_schedule_id_
  549. LEFT JOIN student stu ON cssp.user_id_ = stu.user_id_
  550. WHERE stu.service_tag_=1 AND class_date_&gt;=#{monday}
  551. </select>
  552. <resultMap id="StudentServeCourseDto" type="com.ym.mec.biz.dal.dto.StudentServeCourseDto">
  553. <result column="student_id_" property="studentId"/>
  554. <result column="lead_teacher_id_" property="leadTeacherId"/>
  555. <result column="course_schedule_id_" property="courseScheduleId"/>
  556. <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  557. <result column="music_group_id_" property="musicGroupId"/>
  558. <result column="class_group_id_" property="classGroupId"/>
  559. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  560. <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  561. <result column="actual_teacher_id_" property="actualTeacherId"/>
  562. <result column="course_start_time_" property="courseStartTime"/>
  563. <result column="teach_mode_" property="teachMode"/>
  564. </resultMap>
  565. <select id="getStudentFutureCourseInfo" resultMap="StudentServeCourseDto">
  566. SELECT
  567. cssp.user_id_ student_id_,
  568. stu.teacher_id_ lead_teacher_id_,
  569. cs.id_ course_schedule_id_,
  570. cs.group_type_,
  571. cs.music_group_id_,
  572. cs.class_group_id_,
  573. cs.status_,
  574. CASE cs.type_ WHEN 'TRAINING_SINGLE' THEN 'SINGLE' WHEN 'TRAINING_MIX' THEN 'MIX' ELSE cs.type_ END type_,
  575. cs.actual_teacher_id_,
  576. CONCAT(cs.class_date_, ' ', cs.start_class_time_) course_start_time_,
  577. cs.teach_mode_
  578. FROM course_schedule_student_payment cssp
  579. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
  580. LEFT JOIN student stu ON cssp.user_id_ = stu.user_id_
  581. WHERE stu.service_tag_=1
  582. AND (stu.service_tag_update_time_ IS NULL OR stu.service_tag_update_time_&lt;#{nextMonday})
  583. AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
  584. AND (cs.new_course_id_ IS NULL OR cs.new_course_id_=cs.id_)
  585. AND cs.class_date_&gt;=#{monday}
  586. AND cs.type_ IN ('SINGLE', 'TRAINING_SINGLE', 'VIP', 'MIX', 'TRAINING_MIX', 'PRACTICE')
  587. AND cssp.create_time_&lt;#{nextMonday}
  588. <if test="studentIds!=null and studentIds.size()>0">
  589. AND cssp.user_id_ IN
  590. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  591. #{studentId}
  592. </foreach>
  593. </if>
  594. ORDER BY cssp.user_id_,course_start_time_
  595. </select>
  596. <select id="getNoCourseBeServeStudentInfo" resultMap="StudentServeCourseDto">
  597. SELECT
  598. sr.user_id_ student_id_,
  599. stu.teacher_id_ lead_teacher_id_,
  600. 'MUSIC' group_type_,
  601. sr.music_group_id_
  602. FROM
  603. student_registration sr
  604. LEFT JOIN student stu ON sr.user_id_ = stu.user_id_
  605. LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
  606. WHERE
  607. mg.del_flag_ = 0
  608. AND mg.organ_id_ IS NOT NULL
  609. AND mg.status_ = 'PROGRESS'
  610. AND sr.music_group_status_ = 'NORMAL'
  611. <if test="noCourseStudentIds!=null and noCourseStudentIds.size()>0">
  612. AND sr.user_id_ IN
  613. <foreach collection="noCourseStudentIds" item="noCourseStudentId" open="(" close=")" separator=",">
  614. #{noCourseStudentId}
  615. </foreach>
  616. </if>
  617. </select>
  618. <select id="getStudentNames" resultType="string">
  619. SELECT username_ FROM sys_user WHERE id_ IN
  620. <foreach collection="studentIds" item="studentId" separator="," open="(" close=")">
  621. #{studentId}
  622. </foreach>
  623. </select>
  624. <select id="getStudentsWithOrgan" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  625. SELECT
  626. su.id_ userId,su.username_ userName, su.avatar_ avatar, su.phone_ phone
  627. FROM
  628. sys_user su
  629. WHERE
  630. 1=1
  631. AND su.del_flag_=0 AND su.lock_flag_=0
  632. AND FIND_IN_SET('STUDENT',su.user_type_)
  633. <if test="organIds!=null">
  634. AND su.organ_id_ IN
  635. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  636. #{organId}
  637. </foreach>
  638. </if>
  639. <if test="search != null">
  640. AND (su.username_ LIKE CONCAT('%', #{search}, '%') OR su.phone_ LIKE CONCAT('%', #{search}, '%'))
  641. </if>
  642. ORDER BY su.id_
  643. <include refid="global.limit"/>
  644. </select>
  645. <select id="countStudentsWithOrgan" resultType="int">
  646. SELECT
  647. COUNT(su.id_)
  648. FROM
  649. sys_user su
  650. WHERE
  651. 1=1
  652. AND su.del_flag_=0 AND su.lock_flag_=0
  653. AND FIND_IN_SET('STUDENT',su.user_type_)
  654. <if test="organIds!=null">
  655. AND su.organ_id_ IN
  656. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  657. #{organId}
  658. </foreach>
  659. </if>
  660. <if test="search != null">
  661. AND (su.username_ LIKE CONCAT('%', #{search}, '%') OR su.phone_ LIKE CONCAT('%', #{search}, '%'))
  662. </if>
  663. </select>
  664. <select id="getStudentTeacher" resultMap="Student">
  665. SELECT s.user_id_,t.real_name_ teacher_name_ FROM student s
  666. LEFT JOIN sys_user t ON t.id_ = s.teacher_id_
  667. WHERE s.user_id_ IN
  668. <foreach collection="studentIds" item="id" open="(" close=")" separator=",">
  669. #{id}
  670. </foreach>
  671. </select>
  672. <select id="findByStudentIds" resultMap="Student">
  673. SELECT * FROM student WHERE user_id_ IN
  674. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  675. #{studentId}
  676. </foreach>
  677. </select>
  678. <select id="lockStudents" resultMap="Student">
  679. SELECT * FROM student WHERE user_id_ IN
  680. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  681. #{studentId}
  682. </foreach>
  683. FOR UPDATE
  684. </select>
  685. <select id="queryCloseServiceTagIds" resultType="java.lang.Integer">
  686. SELECT s.user_id_ FROM student s
  687. LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = s.user_id_
  688. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  689. LEFT JOIN student_registration sr ON sr.user_id_ = s.user_id_
  690. LEFT JOIN music_group mg ON mg.id_ = sr.music_group_id_
  691. WHERE s.service_tag_ = 1
  692. GROUP BY s.user_id_ HAVING COUNT(CASE WHEN cs.status_ = 'NOT_START' THEN 1 ELSE NULL END) = 0
  693. AND COUNT(CASE WHEN sr.music_group_status_ = 'NORMAL' AND mg.status_ = 'PROGRESS' THEN 1 ELSE NULL END) = 0;
  694. </select>
  695. <select id="getStudentSubjects" resultMap="com.ym.mec.biz.dal.dao.SubjectDao.Subject">
  696. SELECT
  697. DISTINCT sub.*
  698. FROM
  699. student stu
  700. LEFT JOIN `subject` sub ON FIND_IN_SET( sub.id_, stu.subject_id_list_ )
  701. WHERE
  702. stu.user_id_ IN
  703. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  704. #{studentId}
  705. </foreach>
  706. AND sub.id_ IS NOT NULL
  707. ORDER BY sub.id_ DESC
  708. </select>
  709. <select id="queryByIds" resultMap="Student">
  710. SELECT * FROM student
  711. WHERE user_id_ IN
  712. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  713. #{studentId}
  714. </foreach>
  715. ORDER BY user_id_
  716. <include refid="global.limit"></include>
  717. </select>
  718. <select id="countByIds" resultType="int">
  719. SELECT count(user_id_) FROM student
  720. WHERE user_id_ IN
  721. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  722. #{studentId}
  723. </foreach>
  724. </select>
  725. <select id="getNoTeacherOrNoSubjectStudent" resultMap="Student">
  726. SELECT * FROM student WHERE teacher_id_ IS NULL OR subject_id_list_ IS NULL OR cooperation_organ_id_ IS NULL;
  727. </select>
  728. <select id="getHasVipCourseStudentIdsFromNewStudents" resultType="int">
  729. SELECT DISTINCT s.user_id_
  730. FROM student s
  731. LEFT JOIN course_schedule_student_payment cssp ON s.user_id_=cssp.user_id_
  732. WHERE s.is_new_user_=1 AND cssp.group_type_='VIP'
  733. </select>
  734. <select id="getMemberNum" resultType="int">
  735. SELECT COUNT(0) FROM student WHERE member_rank_setting_id_ IS NOT NULL AND FIND_IN_SET(user_id_,#{studentIdsStr})
  736. </select>
  737. <select id="queryPushMemberRenew" resultType="java.lang.Integer">
  738. SELECT s.user_id_ FROM student s
  739. LEFT JOIN cloud_teacher_order cto ON cto.student_id_ = s.user_id_ AND cto.status_ IN (1,2)
  740. GROUP BY s.user_id_ HAVING (MAX(cto.id_) IS NULL OR MIN(cto.status_) > 1)
  741. AND DATEDIFF(MAX(cto.end_time_),NOW()) = #{pushMemberRenew}
  742. </select>
  743. <select id="getOrganStudentNum" resultType="int">
  744. SELECT COUNT(DISTINCT user_id_)
  745. FROM ((SELECT sr.user_id_
  746. FROM student_registration sr
  747. LEFT JOIN music_group mg ON sr.music_group_id_=mg.id_
  748. LEFT JOIN sys_user su ON sr.user_id_=su.id_
  749. WHERE su.del_flag_=0
  750. AND mg.status_='PROGRESS'
  751. AND sr.music_group_status_='NORMAL'
  752. AND su.organ_id_ = #{organId})
  753. UNION ALL
  754. (SELECT
  755. cssp.user_id_
  756. FROM
  757. course_schedule_student_payment cssp
  758. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
  759. LEFT JOIN sys_user su ON cssp.user_id_ = su.id_
  760. WHERE
  761. cssp.group_type_ IN ('VIP', 'PRACTICE')
  762. AND cs.status_='NOT_START'
  763. AND su.del_flag_ = 0
  764. AND su.organ_id_ = #{organId})) t
  765. WHERE t.user_id_ NOT IN (SELECT user_id_ FROM student WHERE subject_id_list_ REGEXP '21|25|26|27|28|29')
  766. </select>
  767. <select id="getOrgansTotalStudentNum" resultType="int">
  768. SELECT COUNT(DISTINCT user_id_)
  769. FROM ((SELECT sr.user_id_
  770. FROM student_registration sr
  771. LEFT JOIN music_group mg ON sr.music_group_id_=mg.id_
  772. WHERE mg.status_='PROGRESS'
  773. AND sr.music_group_status_='NORMAL')
  774. UNION ALL
  775. (SELECT
  776. cssp.user_id_
  777. FROM
  778. course_schedule_student_payment cssp
  779. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
  780. LEFT JOIN sys_user su ON cssp.user_id_ = su.id_
  781. WHERE
  782. cssp.group_type_ IN ('VIP', 'PRACTICE')
  783. AND cs.status_='NOT_START')) t
  784. LEFT JOIN sys_user su ON t.user_id_=su.id_
  785. WHERE su.del_flag_=0
  786. <if test="organIds!=null and organIds.size()>0">
  787. AND su.organ_id_ IN
  788. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  789. #{organId}
  790. </foreach>
  791. </if>
  792. </select>
  793. <select id="getOrgansStudentNum" resultType="map">
  794. SELECT su.organ_id_ 'key',COUNT(DISTINCT user_id_) 'value'
  795. FROM ((SELECT sr.user_id_
  796. FROM student_registration sr
  797. LEFT JOIN music_group mg ON sr.music_group_id_=mg.id_
  798. WHERE mg.status_='PROGRESS'
  799. AND sr.music_group_status_='NORMAL')
  800. UNION ALL
  801. (SELECT
  802. cssp.user_id_
  803. FROM
  804. course_schedule_student_payment cssp
  805. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
  806. WHERE
  807. cssp.group_type_ IN ('VIP', 'PRACTICE')
  808. AND cs.status_='NOT_START')) t
  809. LEFT JOIN sys_user su ON t.user_id_=su.id_
  810. WHERE su.del_flag_=0 AND t.user_id_ NOT IN (SELECT user_id_ FROM student WHERE subject_id_list_ REGEXP '21|25|26|27|28|29')
  811. <!-- <if test="organIds!=null and organIds.size()>0">-->
  812. <!-- AND su.organ_id_ IN-->
  813. <!-- <foreach collection="organIds" item="organId" open="(" close=")" separator=",">-->
  814. <!-- #{organId}-->
  815. <!-- </foreach>-->
  816. <!-- </if>-->
  817. GROUP BY su.organ_id_
  818. </select>
  819. <select id="getOrganTeacherStudentNum" resultType="map">
  820. SELECT stu.teacher_id_ 'key',COUNT(DISTINCT t.user_id_) 'value'
  821. FROM ((SELECT sr.user_id_
  822. FROM student_registration sr
  823. LEFT JOIN music_group mg ON sr.music_group_id_=mg.id_
  824. WHERE mg.status_='PROGRESS' AND sr.music_group_status_='NORMAL')
  825. UNION ALL
  826. (SELECT
  827. cssp.user_id_
  828. FROM
  829. course_schedule_student_payment cssp
  830. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
  831. WHERE
  832. cssp.group_type_ IN ('VIP', 'PRACTICE')
  833. AND cs.status_='NOT_START')) t
  834. LEFT JOIN student stu ON t.user_id_=stu.user_id_
  835. LEFT JOIN sys_user su ON t.user_id_ = su.id_
  836. LEFT JOIN teacher tea ON stu.teacher_id_=tea.id_
  837. WHERE su.del_flag_=0
  838. <if test="organId!=null">
  839. AND tea.organ_id_=#{organId}
  840. </if>
  841. <if test="teacherIds!=null and teacherIds.size()>0">
  842. AND stu.teacher_id_ IN
  843. <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
  844. #{teacherId}
  845. </foreach>
  846. </if>
  847. GROUP BY stu.teacher_id_
  848. </select>
  849. <select id="getOrganNoTeacherStudentNum" resultType="int">
  850. SELECT COUNT(DISTINCT stu.user_id_)
  851. FROM student stu
  852. LEFT JOIN sys_user su ON stu.user_id_ = su.id_
  853. WHERE su.del_flag_=0 AND stu.teacher_id_ IS NULL
  854. <if test="organId!=null">
  855. AND su.organ_id_=#{organId}
  856. </if>
  857. </select>
  858. <select id="getCloudStudyStudentNum" resultType="int">
  859. SELECT
  860. COUNT(DISTINCT smcr.user_id_)
  861. FROM sys_music_compare_record smcr
  862. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  863. LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
  864. WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL AND su.organ_id_=#{organId};
  865. </select>
  866. <select id="getOrgansTotalCloudStudyStudentNum" resultType="int">
  867. SELECT
  868. COUNT(DISTINCT smcr.user_id_)
  869. FROM sys_music_compare_record smcr
  870. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  871. LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
  872. WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL
  873. <if test="organIds!=null and organIds.size()>0">
  874. AND su.organ_id_ IN
  875. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  876. #{organId}
  877. </foreach>
  878. </if>
  879. </select>
  880. <select id="getOrgansTodayTotalCloudStudyStudentNum" resultType="int">
  881. SELECT
  882. COUNT(DISTINCT smcr.user_id_)
  883. FROM sys_music_compare_record smcr
  884. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  885. LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
  886. WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL
  887. AND DATE(smcr.create_time_) = CURDATE()
  888. <if test="organIds!=null and organIds.size()>0">
  889. AND su.organ_id_ IN
  890. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  891. #{organId}
  892. </foreach>
  893. </if>
  894. </select>
  895. <select id="getOrganCloudStudyStudentNum" resultType="map">
  896. SELECT
  897. su.organ_id_ 'key',
  898. COUNT(DISTINCT smcr.user_id_) 'value'
  899. FROM sys_music_compare_record smcr
  900. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  901. LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
  902. WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL
  903. <if test="organIds!=null and organIds.size()>0">
  904. AND su.organ_id_ IN
  905. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  906. #{organId}
  907. </foreach>
  908. </if>
  909. GROUP BY su.organ_id_
  910. </select>
  911. <select id="getOrganTeacherCloudStudyStudentNum" resultType="map">
  912. SELECT
  913. stu.teacher_id_ 'key',
  914. COUNT(DISTINCT smcr.user_id_) 'value'
  915. FROM sys_music_compare_record smcr
  916. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  917. LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
  918. LEFT JOIN teacher tea ON stu.teacher_id_=tea.id_
  919. WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL
  920. <if test="organId!=null">
  921. AND tea.organ_id_=#{organId}
  922. </if>
  923. <if test="teacherIds!=null and teacherIds.size()>0">
  924. AND stu.teacher_id_ IN
  925. <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
  926. #{teacherId}
  927. </foreach>
  928. </if>
  929. GROUP BY stu.teacher_id_
  930. </select>
  931. <select id="getCloudStudyLivelyStudentNum" resultType="int">
  932. SELECT COUNT(user_id_)
  933. FROM (SELECT
  934. smcr.user_id_,
  935. COUNT(DISTINCT(CASE WHEN DATEDIFF(NOW(), smcr.create_time_)&lt;=15 THEN DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') ELSE NULL END)) days
  936. FROM sys_music_compare_record smcr
  937. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  938. LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
  939. WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL AND su.organ_id_=#{organId}
  940. GROUP BY smcr.user_id_) t WHERE t.days>=5
  941. </select>
  942. <select id="getOrganTotalCloudStudyLivelyStudentNum" resultType="int">
  943. SELECT COUNT(user_id_)
  944. FROM (SELECT
  945. smcr.user_id_,
  946. COUNT(DISTINCT(CASE WHEN DATEDIFF(NOW(), smcr.create_time_)&lt;=15 THEN DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') ELSE NULL END)) days
  947. FROM sys_music_compare_record smcr
  948. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  949. LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
  950. WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL
  951. <if test="organIds!=null and organIds.size()>0">
  952. AND su.organ_id_ IN
  953. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  954. #{organId}
  955. </foreach>
  956. </if>
  957. GROUP BY smcr.user_id_) t WHERE t.days>=5
  958. </select>
  959. <select id="getOrganCloudStudyLivelyStudentNum" resultType="map">
  960. SELECT
  961. t.organ_id_ 'key',
  962. COUNT(user_id_) 'value'
  963. FROM (SELECT
  964. su.organ_id_,
  965. smcr.user_id_,
  966. COUNT(DISTINCT(CASE WHEN DATEDIFF(NOW(), smcr.create_time_)&lt;=15 THEN DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') ELSE NULL END)) days
  967. FROM sys_music_compare_record smcr
  968. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  969. LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
  970. WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL
  971. <if test="organIds!=null and organIds.size()>0">
  972. AND su.organ_id_ IN
  973. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  974. #{organId}
  975. </foreach>
  976. </if>
  977. GROUP BY smcr.user_id_) t WHERE t.days>=5
  978. GROUP BY t.organ_id_
  979. </select>
  980. <sql id="queryCloudStudyStudentDataCondition">
  981. <where>
  982. su.del_flag_=0 AND t.user_id_ NOT IN (SELECT user_id_ FROM student WHERE subject_id_list_ REGEXP '21|25|26|27|28|29')
  983. <if test="organId!=null">
  984. AND su.organ_id_=#{organId}
  985. </if>
  986. <if test="search!=null and search!=''">
  987. AND (t.user_id_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  988. </if>
  989. </where>
  990. </sql>
  991. <select id="queryCloudStudyStudentData" resultType="com.ym.mec.biz.dal.dto.EduOrganStudentListDto">
  992. SELECT
  993. stu.user_id_ studentId,
  994. su.username_ studentName,
  995. stu.teacher_id_ teacherId,
  996. tea.real_name_ teacherName,
  997. sub.name_ subjectName,
  998. stu.cloud_study_sequence_days_ cloudStudyRunningDays,
  999. COUNT(DISTINCT smcr.behavior_id_) cloudStudyUseNum,
  1000. SUM(CASE WHEN smcr.play_time_ IS NULL THEN 0 ELSE play_time_ END) cloudStudyUseTime,
  1001. COUNT(DISTINCT DATE(smcr.create_time_)) cloudStudyUseDays,
  1002. stu.membership_end_time_ membershipEndTime
  1003. FROM (SELECT DISTINCT t1.user_id_ FROM ((
  1004. SELECT
  1005. sr.user_id_
  1006. FROM
  1007. student_registration sr
  1008. LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
  1009. WHERE
  1010. mg.status_ = 'PROGRESS'
  1011. AND sr.music_group_status_ = 'NORMAL'
  1012. ) UNION ALL
  1013. (
  1014. SELECT
  1015. cssp.user_id_
  1016. FROM
  1017. course_schedule_student_payment cssp
  1018. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  1019. WHERE
  1020. cssp.group_type_ IN ( 'VIP', 'PRACTICE' )
  1021. AND cs.status_ = 'NOT_START'
  1022. )) t1) t
  1023. LEFT JOIN student stu ON t.user_id_=stu.user_id_
  1024. LEFT JOIN sys_user su ON stu.user_id_=su.id_
  1025. LEFT JOIN sys_user tea ON stu.teacher_id_=tea.id_
  1026. LEFT JOIN `subject` sub ON stu.subject_id_list_ = sub.id_
  1027. LEFT JOIN sys_music_compare_record smcr ON stu.user_id_ = smcr.user_id_
  1028. <include refid="queryCloudStudyStudentDataCondition" />
  1029. GROUP BY stu.user_id_
  1030. <trim prefix="ORDER BY " suffixOverrides=",">
  1031. <if test="cloudStudyUseTime==null and cloudStudyRunningDays==null">
  1032. stu.user_id_,
  1033. </if>
  1034. <if test="cloudStudyUseTime!=null">
  1035. cloudStudyUseTime ${cloudStudyUseTime},
  1036. </if>
  1037. <if test="cloudStudyRunningDays!=null">
  1038. cloudStudyRunningDays ${cloudStudyRunningDays}
  1039. </if>
  1040. </trim>
  1041. <include refid="global.limit"></include>
  1042. </select>
  1043. <select id="countCloudStudyStudentData" resultType="int">
  1044. SELECT
  1045. COUNT( DISTINCT user_id_ )
  1046. FROM
  1047. ((
  1048. SELECT
  1049. sr.user_id_
  1050. FROM
  1051. student_registration sr
  1052. LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
  1053. WHERE
  1054. mg.status_ = 'PROGRESS'
  1055. AND sr.music_group_status_ = 'NORMAL'
  1056. ) UNION ALL
  1057. (
  1058. SELECT
  1059. cssp.user_id_
  1060. FROM
  1061. course_schedule_student_payment cssp
  1062. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  1063. WHERE
  1064. cssp.group_type_ IN ( 'VIP', 'PRACTICE' )
  1065. AND cs.status_ = 'NOT_START'
  1066. )) t
  1067. LEFT JOIN sys_user su ON t.user_id_ = su.id_
  1068. <include refid="queryCloudStudyStudentDataCondition" />
  1069. </select>
  1070. <select id="getOrganEVipStudentNum" resultType="int">
  1071. SELECT COUNT(DISTINCT stu.user_id_)
  1072. FROM student stu
  1073. LEFT JOIN cloud_teacher_order cto ON stu.user_id_=cto.student_id_
  1074. LEFT JOIN sys_user su ON su.id_=stu.user_id_
  1075. WHERE su.del_flag_=0 AND su.organ_id_=#{organId} AND stu.experience_member_rank_setting_id_ IS NOT NULL
  1076. AND NOT EXISTS (SELECT student_id_ FROM cloud_teacher_order WHERE student_id_=stu.user_id_ AND status_ IN (1,2))
  1077. </select>
  1078. <select id="getOrgansTotalEVipStudentNum" resultType="int">
  1079. SELECT COUNT(DISTINCT stu.user_id_)
  1080. FROM student stu
  1081. LEFT JOIN cloud_teacher_order cto ON stu.user_id_=cto.student_id_
  1082. LEFT JOIN sys_user su ON su.id_=stu.user_id_
  1083. WHERE su.del_flag_=0 AND stu.experience_member_rank_setting_id_ IS NOT NULL AND (cto.id_ IS NULL OR cto.status_ NOT IN (1, 2))
  1084. <if test="organIds!=null and organIds.size()>0">
  1085. AND su.organ_id_ IN
  1086. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  1087. #{organId}
  1088. </foreach>
  1089. </if>
  1090. </select>
  1091. <select id="getOrgansEVipStudentNum" resultType="map">
  1092. SELECT
  1093. su.organ_id_ 'key',
  1094. COUNT(DISTINCT stu.user_id_) 'value'
  1095. FROM student stu
  1096. LEFT JOIN cloud_teacher_order cto ON stu.user_id_=cto.student_id_
  1097. LEFT JOIN sys_user su ON su.id_=stu.user_id_
  1098. WHERE su.del_flag_=0 AND stu.experience_member_rank_setting_id_ IS NOT NULL
  1099. AND stu.user_id_ NOT IN (SELECT DISTINCT student_id_ FROM cloud_teacher_order WHERE status_ IN (1,2))
  1100. <if test="organIds!=null and organIds.size()>0">
  1101. AND su.organ_id_ IN
  1102. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  1103. #{organId}
  1104. </foreach>
  1105. </if>
  1106. GROUP BY su.organ_id_
  1107. </select>
  1108. <select id="getTeacherExperienceMemberStudentNum" resultType="map">
  1109. SELECT
  1110. stu.teacher_id_ 'key',
  1111. COUNT(DISTINCT stu.user_id_) 'value'
  1112. FROM student stu
  1113. LEFT JOIN cloud_teacher_order cto ON stu.user_id_=cto.student_id_
  1114. LEFT JOIN sys_user su ON su.id_=stu.user_id_
  1115. WHERE su.del_flag_=0 AND stu.experience_member_rank_setting_id_ IS NOT NULL AND (cto.id_ IS NULL OR cto.status_ NOT IN (1, 2))
  1116. <if test="organId!=null">
  1117. AND su.organ_id_=#{organId}
  1118. </if>
  1119. <if test="teacherIds!=null and teacherIds.size()>0">
  1120. AND stu.teacher_id_ IN
  1121. <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
  1122. #{teacherId}
  1123. </foreach>
  1124. </if>
  1125. GROUP BY stu.teacher_id_
  1126. </select>
  1127. <select id="getStudentSubjectMapList" resultType="java.util.Map">
  1128. SELECT stu.user_id_ 'key',sub.name_ 'value'
  1129. FROM student stu
  1130. LEFT JOIN `subject` sub ON stu.subject_id_list_ = sub.id_
  1131. WHERE stu.user_id_ IN
  1132. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  1133. #{studentId}
  1134. </foreach>
  1135. </select>
  1136. <select id="groupOrganId" resultMap="com.ym.mec.biz.dal.dao.IndexBaseMonthDataDao.IndexBaseMonthData">
  1137. SELECT su.organ_id_,CURDATE() month_,
  1138. COUNT(DISTINCT su.id_) total_num_ ,
  1139. COUNT(DISTINCT su.id_) activate_num_ ,
  1140. COUNT(DISTINCT su.id_) percent_
  1141. FROM sys_user su
  1142. WHERE 1 = 1
  1143. <if test="userIds!=null and userIds.size() > 0">
  1144. AND su.id_ IN
  1145. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  1146. #{userId}
  1147. </foreach>
  1148. </if>
  1149. <if test="organIds!=null and organIds.size() > 0">
  1150. AND su.organ_id_ IN
  1151. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  1152. #{organId}
  1153. </foreach>
  1154. </if>
  1155. GROUP BY su.organ_id_
  1156. </select>
  1157. <update id="updateGrade"><![CDATA[
  1158. UPDATE student SET current_grade_num_=current_grade_num_+1
  1159. WHERE current_grade_num_>=1
  1160. AND current_grade_num_<= 11
  1161. ]]>
  1162. </update>
  1163. <update id="updateNewStudentsToOld">
  1164. UPDATE student SET is_new_user_=0
  1165. WHERE user_id_ IN
  1166. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  1167. #{userId}
  1168. </foreach>
  1169. </update>
  1170. <update id="cleanStudentMember">
  1171. UPDATE student SET member_rank_setting_id_ = NULL WHERE NOW() > membership_end_time_
  1172. </update>
  1173. <update id="cleanExperienceStudentMember">
  1174. UPDATE student SET experience_member_rank_setting_id_ = NULL WHERE NOW() > experience_membership_end_time_
  1175. </update>
  1176. <update id="cleanMember">
  1177. UPDATE student SET member_rank_setting_id_ = NULL,membership_start_time_ = NULL,membership_end_time_ = NULL
  1178. WHERE user_id_ = #{userId}
  1179. </update>
  1180. <update id="updateMemberExperience">
  1181. UPDATE student SET
  1182. member_rank_setting_id_ = #{rankId},membership_start_time_ = NOW(),membership_end_time_ = #{endTime},
  1183. experience_member_rank_setting_id_ = #{rankId},experience_membership_start_time_ = NOW(),experience_membership_end_time_ = #{endTime}
  1184. WHERE member_rank_setting_id_ IS NULL AND experience_member_rank_setting_id_ IS NULL
  1185. AND FIND_IN_SET(user_id_,#{studentIds})
  1186. </update>
  1187. <update id="addStudentCloudStudySequenceDays">
  1188. UPDATE student SET cloud_study_sequence_days_=cloud_study_sequence_days_+1,cloud_study_use_last_day_=curdate() WHERE user_id_=#{userId} AND (cloud_study_use_last_day_ IS NULL OR cloud_study_use_last_day_=date_sub(curdate(), interval 1 day))
  1189. </update>
  1190. <update id="updateStudentsCloudStudySequenceDays">
  1191. UPDATE student SET cloud_study_sequence_days_=#{days} WHERE user_id_=#{userId}
  1192. </update>
  1193. <update id="cleanStudentCloudStudySequenceDays">
  1194. UPDATE student SET cloud_study_sequence_days_=0,cloud_study_use_last_day_=date_sub(curdate(), interval 1 day) WHERE cloud_study_use_last_day_&lt;date_sub(curdate(), interval 1 day)
  1195. </update>
  1196. </mapper>