PracticeGroupMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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.PracticeGroupDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.PracticeGroup" id="PracticeGroup">
  9. <result column="id_" property="id"/>
  10. <result column="name_" property="name"/>
  11. <result column="type_" property="type"
  12. typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  13. <result column="subject_id_" property="subjectId"/>
  14. <result column="user_id_" property="userId"/>
  15. <result column="student_id_" property="studentId"/>
  16. <result column="single_class_minutes_" property="singleClassMinutes"/>
  17. <result column="organ_id_" property="organId"/>
  18. <result column="courses_start_date_" property="coursesStartDate"/>
  19. <result column="courses_expire_date_" property="coursesExpireDate"/>
  20. <result column="create_time_" property="createTime"/>
  21. <result column="update_time_" property="updateTime"/>
  22. <result column="memo_" property="memo"/>
  23. <result column="buy_months_" property="buyMonths"/>
  24. <result column="drill_times_on_week_" property="drillTimesOnWeek"/>
  25. <result column="drill_times_json_" property="drillTimesJson"/>
  26. <result column="group_status_" property="groupStatus"
  27. typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  28. <result column="be_renew_group_id_" property="beRenewGroupId"/>
  29. <result column="educational_teacher_id_" property="educationalTeacherId"/>
  30. </resultMap>
  31. <resultMap id="PracticeCourseDto" type="com.ym.mec.biz.dal.dto.PracticeCourseDto" extends="PracticeGroup">
  32. <result property="teacherName" column="real_name_"/>
  33. <result property="avatar" column="avatar_"/>
  34. <result property="subjectName" column="subject_name_"/>
  35. <result property="eduTeacherName" column="edu_teacher_name_"/>
  36. </resultMap>
  37. <resultMap type="com.ym.mec.biz.dal.dto.PracticeGroupDto" id="PracticeGroupDto" extends="PracticeGroup">
  38. <result column="id_" property="id"/>
  39. <result column="name_" property="name"/>
  40. <result column="subject_id_" property="subjectId"/>
  41. <result column="user_id_" property="userId"/>
  42. <result column="single_class_minutes_" property="singleClassMinutes"/>
  43. <result column="organ_id_" property="organId"/>
  44. <result column="courses_start_date_" property="coursesStartDate"/>
  45. <result column="courses_start_dates_" property="coursesStartDates"/>
  46. <result column="courses_expire_date_" property="coursesExpireDate"/>
  47. <result column="create_time_" property="createTime"/>
  48. <result column="update_time_" property="updateTime"/>
  49. <result column="memo_" property="memo"/>
  50. <result column="subject_name_" property="subjectName"/>
  51. <result column="teacher_name_" property="teacherName"/>
  52. <result column="evaluate_id_" property="evaluateId"/>
  53. <result column="evaluate_status_" property="evaluateStatus"/>
  54. </resultMap>
  55. <update id="updateUserId">
  56. UPDATE practice_group
  57. SET user_id_ = #{teacherId},
  58. update_time_ = NOW()
  59. WHERE id_ = #{practiceGroupId}
  60. </update>
  61. <update id="update" parameterType="com.ym.mec.biz.dal.entity.PracticeGroup">
  62. UPDATE practice_group
  63. <set>
  64. <if test="subjectId!=null">
  65. subject_id_=#{subjectId},
  66. </if>
  67. <if test="memo!=null">
  68. memo_=#{memo},
  69. </if>
  70. <if test="name!=null">
  71. name_=#{name},
  72. </if>
  73. <if test="coursesStartDate != null">
  74. courses_start_date_=#{coursesStartDate},
  75. </if>
  76. <if test="coursesExpireDate != null">
  77. courses_expire_date_ = #{coursesExpireDate},
  78. </if>
  79. <if test="groupStatus!=null">
  80. group_status_=#{groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  81. </if>
  82. <if test="type!=null">
  83. type_ =#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  84. </if>
  85. <if test="educationalTeacherId!=null">
  86. educational_teacher_id_=#{educationalTeacherId},
  87. </if>
  88. update_time_ = NOW()
  89. </set>
  90. WHERE id_ = #{id}
  91. </update>
  92. <update id="batchUpdate">
  93. <foreach collection="groups" item="group" separator=";">
  94. UPDATE practice_group
  95. <set>
  96. <if test="group.groupStatus!=null">
  97. group_status_=#{group.groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  98. </if>
  99. update_time_ = NOW()
  100. </set>
  101. WHERE id_ = #{group.id}
  102. </foreach>
  103. </update>
  104. <update id="updateMemo">
  105. UPDATE practice_group SET memo_ = #{memo},update_time_ = NOW() WHERE id_ = #{groupId}
  106. </update>
  107. <!-- 根据主键查询一条记录 -->
  108. <select id="get" resultMap="PracticeGroup">
  109. SELECT *
  110. FROM practice_group
  111. WHERE id_ = #{id}
  112. </select>
  113. <!-- 全查询 -->
  114. <select id="findAll" resultMap="PracticeGroup">
  115. SELECT *
  116. FROM practice_group
  117. </select>
  118. <!-- 向数据库增加一条记录 -->
  119. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.PracticeGroup" useGeneratedKeys="true" keyColumn="id"
  120. keyProperty="id">
  121. <!--
  122. <selectKey resultClass="int" keyProperty="id" >
  123. SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
  124. </selectKey>
  125. -->
  126. INSERT INTO practice_group
  127. (id_,name_,type_,subject_id_,user_id_,student_id_,single_class_minutes_,organ_id_,courses_start_date_,courses_expire_date_,create_time_,update_time_,memo_,buy_months_,drill_times_on_week_,drill_times_json_,group_status_,be_renew_group_id_,educational_teacher_id_)
  128. VALUES(#{id},#{name},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{subjectId},#{userId},#{studentId},#{singleClassMinutes},#{organId},#{coursesStartDate},#{coursesExpireDate},NOW(),NOW(),#{memo},#{buyMonths},#{drillTimesOnWeek},#{drillTimesJson},#{groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{beRenewGroupId},#{educationalTeacherId})
  129. </insert>
  130. <select id="getUserFreePracticeGroup" resultMap="PracticeGroup">
  131. SELECT *
  132. FROM practice_group
  133. WHERE student_id_ = #{userId}
  134. AND type_='FREE'
  135. </select>
  136. <!-- 分页查询 -->
  137. <select id="queryPage" resultMap="PracticeGroup" parameterType="map">
  138. SELECT * FROM practice_group
  139. <include refid="global.limit"/>
  140. </select>
  141. <!-- 查询当前表的总记录数 -->
  142. <select id="queryCount" resultType="int">
  143. SELECT COUNT(*)
  144. FROM practice_group
  145. </select>
  146. <select id="getUserPracticeCoursesWithDateRange" resultMap="PracticeGroup">
  147. SELECT *
  148. FROM practice_group
  149. WHERE user_id_ = #{userId}
  150. AND (courses_start_date_ BETWEEN DATE_FORMAT(#{startDate}, '%Y-%m-%d') AND DATE_FORMAT(#{endDate}, '%Y-%m-%d'))
  151. </select>
  152. <select id="countUserPracticeApplyRecord" resultType="int">
  153. SELECT COUNT(*)
  154. FROM practice_group
  155. WHERE student_id_ = #{userId}
  156. AND group_status_ = 'NORMAL'
  157. AND type_='FREE'
  158. AND create_time_ > '2020-03-25'
  159. </select>
  160. <select id="countPracticeGroupByOrgan" resultType="java.lang.Integer">
  161. SELECT count(*) FROM practice_group pg
  162. <include refid="practiceGroupQueryCondition"/>
  163. </select>
  164. <select id="findAllByOrgan" resultMap="PracticeGroupDto">
  165. SELECT pg.*,
  166. su.real_name_ teacher_name_
  167. FROM
  168. practice_group pg
  169. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  170. <include refid="practiceGroupQueryCondition"/>
  171. ORDER BY pg.id_ DESC
  172. <include refid="global.limit"/>
  173. </select>
  174. <select id="countPracticeGroupOverCourse" resultType="java.util.Map">
  175. </select>
  176. <select id="findUserLatestPracticeGroup" resultMap="PracticeGroup">
  177. SELECT *
  178. FROM practice_group
  179. WHERE student_id_ = #{userId}
  180. AND type_='CHARGE'
  181. ORDER BY create_time_ DESC
  182. LIMIT 1;
  183. </select>
  184. <select id="findUserBuyPracticeGroups" resultMap="PracticeCourseDto">
  185. SELECT pg.*,
  186. su.real_name_,
  187. su.avatar_,
  188. s.name_ subject_name_
  189. FROM practice_group pg
  190. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  191. LEFT JOIN `subject` s ON pg.subject_id_ = s.id_
  192. WHERE student_id_ = #{userId}
  193. AND (pg.group_status_ = 'NORMAL' OR pg.group_status_ = 'LOCK')
  194. AND pg.type_='CHARGE'
  195. </select>
  196. <select id="findUserBuyPracticeGroupsWithDate" resultMap="PracticeCourseDto">
  197. SELECT pg.*,
  198. su.real_name_,
  199. su.avatar_,
  200. s.name_ subject_name_
  201. FROM practice_group pg
  202. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  203. LEFT JOIN `subject` s ON pg.subject_id_ = s.id_
  204. WHERE student_id_ = #{userId}
  205. AND courses_start_date_ = #{date}
  206. AND group_status_ = 'LOCK'
  207. AND pg.type_='CHARGE'
  208. </select>
  209. <select id="findUserPracticeGroup" resultMap="PracticeGroup">
  210. SELECT *
  211. FROM practice_group
  212. WHERE student_id_ = #{userId}
  213. AND id_ = #{groupId};
  214. </select>
  215. <select id="findUserPracticeGroup2" resultMap="PracticeGroupDto">
  216. SELECT pg.*, su.real_name_ teacher_name_
  217. FROM practice_group pg
  218. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  219. WHERE pg.student_id_ = #{userId}
  220. AND pg.id_ = #{groupId};
  221. </select>
  222. <select id="findHistoryPracticeGroups" resultMap="PracticeGroup">
  223. SELECT *
  224. FROM practice_group
  225. WHERE courses_expire_date_ &lt; NOW()
  226. AND group_status_ = 'NORMAL'
  227. </select>
  228. <sql id="practiceGroupQueryCondition">
  229. <where>
  230. <if test="hasEducationalTeacherId != null and hasEducationalTeacherId == true">
  231. AND pg.educational_teacher_id_ IS NOT NULL
  232. </if>
  233. <if test="hasEducationalTeacherId != null and hasEducationalTeacherId == false">
  234. AND pg.educational_teacher_id_ IS NULL
  235. </if>
  236. <if test="search!=null and search!=''">
  237. AND (pg.name_ LIKE CONCAT('%',#{search},'%') OR pg.id_= #{search})
  238. </if>
  239. <if test="teacherId != null">
  240. AND pg.user_id_=#{teacherId}
  241. </if>
  242. <if test="studentId != null">
  243. AND pg.student_id_ = #{studentId}
  244. </if>
  245. <if test="groupStatus != null and groupStatus != ''">
  246. AND pg.group_status_ = #{groupStatus}
  247. </if>
  248. <if test="groupStatus == null or groupStatus == ''">
  249. AND pg.group_status_ IN ('NORMAL', 'FINISH')
  250. </if>
  251. <if test="organId != null">
  252. AND FIND_IN_SET(pg.organ_id_,#{organId})
  253. </if>
  254. <if test="educationalTeacherId!=null">
  255. AND pg.educational_teacher_id_=#{educationalTeacherId}
  256. </if>
  257. <if test="type != null and type == 1">
  258. AND pg.be_renew_group_id_ IS NULL AND pg.type_='CHARGE'
  259. </if>
  260. <if test="type != null and type == 0">
  261. AND pg.be_renew_group_id_ IS NOT NULL AND pg.type_='CHARGE'
  262. </if>
  263. <if test="type != null and type == 2">
  264. AND pg.type_='FREE'
  265. </if>
  266. <if test="practiceGroupType != null">
  267. AND pg.type_=#{practiceGroupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  268. </if>
  269. </where>
  270. </sql>
  271. <!-- 根据主键查询一条记录 -->
  272. <select id="lockPracticeGroup" resultMap="PracticeGroup">
  273. SELECT *
  274. FROM practice_group
  275. WHERE id_ = #{groupId} FOR
  276. UPDATE
  277. </select>
  278. <select id="findUserStatusPracticeGroups" resultMap="PracticeGroup">
  279. SELECT *
  280. FROM practice_group
  281. WHERE student_id_ = #{userId}
  282. AND group_status_ = #{groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  283. </select>
  284. <select id="findUserLockPracticeGroupWithDate" resultMap="PracticeGroup">
  285. SELECT *
  286. FROM practice_group
  287. WHERE student_id_ = #{userId}
  288. AND courses_start_date_ = #{date}
  289. AND group_status_ = 'LOCK'
  290. </select>
  291. <select id="findUserLockPracticeGroupWithDateBefore" resultMap="PracticeGroup">
  292. SELECT *
  293. FROM practice_group
  294. WHERE student_id_ = #{userId}
  295. AND courses_start_date_ &lt;= #{date}
  296. AND group_status_ = 'LOCK'
  297. </select>
  298. <sql id="practiceGroupReviewsQueryCondition">
  299. <where>
  300. pg.group_status_ != 'LOCK'
  301. <if test="month != null">
  302. AND DATE_FORMAT(cse.create_time_, '%Y-%m') = #{month}
  303. </if>
  304. <if test="search!=null and search!=''">
  305. AND (pg.name_ LIKE CONCAT('%',#{search},'%') OR pg.id_= #{search})
  306. </if>
  307. <if test="teacherId!=null">
  308. AND pg.user_id_=#{teacherId}
  309. </if>
  310. <if test="organId != null">
  311. AND FIND_IN_SET(pg.organ_id_,#{organId})
  312. </if>
  313. <if test="month != null">
  314. AND pg.courses_expire_date_ >= #{month}
  315. </if>
  316. <if test='isFree !=null and isFree=="0"'>
  317. AND pg.type_='CHARGE'
  318. </if>
  319. <if test='isFree !=null and isFree=="1"'>
  320. AND pg.type_='FREE'
  321. </if>
  322. <if test='isOver !=null and isOver=="0"'>
  323. <![CDATA[AND pg.group_status_ = 'NORMAL'
  324. ]]>
  325. </if>
  326. <if test='isOver !=null and isOver=="1"'>
  327. <![CDATA[ AND pg.group_status_ ='FINISH'
  328. ]]></if>
  329. <if test='hasReport !=null and hasReport=="0"'>
  330. <![CDATA[AND cse.status_ =0
  331. ]]>
  332. </if>
  333. <if test='hasReport !=null and hasReport=="1"'>
  334. <![CDATA[ AND cse.status_ = 1
  335. ]]></if>
  336. </where>
  337. </sql>
  338. <select id="findPracticeGroupsReviews" resultMap="PracticeGroupDto">
  339. SELECT pg.*,cse.id_ evaluate_id_,cse.status_ evaluate_status_,
  340. su.real_name_ teacher_name_
  341. FROM
  342. practice_group pg
  343. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  344. LEFT JOIN course_schedule_evaluate cse ON pg.id_=cse.music_group_id_
  345. <include refid="practiceGroupReviewsQueryCondition"/>
  346. ORDER BY pg.id_ DESC
  347. <include refid="global.limit"/>
  348. </select>
  349. <select id="countPracticeGroupReviews" resultType="java.lang.Integer">
  350. SELECT count(*) FROM practice_group pg
  351. LEFT JOIN course_schedule_evaluate cse ON pg.id_=cse.music_group_id_
  352. <include refid="practiceGroupReviewsQueryCondition"/>
  353. </select>
  354. <select id="getNeedPostReportPracticeGroups"
  355. resultMap="com.ym.mec.biz.dal.dao.CourseScheduleEvaluateDao.CourseScheduleEvaluate">
  356. <![CDATA[
  357. SELECT pg.id_ music_group_id_,
  358. pg.user_id_ teacher_id_,
  359. cg.id_ class_group_id_,
  360. pg.single_class_minutes_ total_minutes_,
  361. pg.subject_id_
  362. FROM practice_group pg
  363. LEFT JOIN class_group cg on pg.id_ = cg.music_group_id_ AND cg.group_type_ = 'PRACTICE'
  364. WHERE pg.group_status_ IN ('NORMAL','FINISH') AND cg.group_type_ = 'PRACTICE'
  365. AND pg.buy_months_ >= 1
  366. AND pg.courses_start_date_ <= #{nowDate,jdbcType=DATE}
  367. AND pg.courses_expire_date_ >= #{afterDate,jdbcType=DATE}
  368. ]]>
  369. <if test="afterDateIsLastDay == false">
  370. AND DATE_FORMAT(pg.courses_expire_date_, '%d') = DATE_FORMAT(#{afterDate}, '%d')
  371. </if>
  372. <if test="afterDateIsLastDay == true">
  373. <![CDATA[ AND DATE_FORMAT(pg.courses_expire_date_, '%d') >= DATE_FORMAT(#{afterDate}, '%d') ]]>
  374. </if>
  375. AND cg.del_flag_ = 0
  376. </select>
  377. <select id="getReportCourseTimes" resultMap="com.ym.mec.biz.dal.dao.ClassGroupDao.ClassGroup">
  378. SELECT COUNT(*) total_class_times_,class_group_id_ id_ from course_schedule WHERE class_group_id_ IN
  379. <foreach collection="classGroupIds" item="classGroupId" open="(" separator="," close=")">
  380. #{classGroupId}
  381. </foreach>
  382. <![CDATA[AND class_date_ >= #{startDate,jdbcType=DATE} AND class_date_ <=#{endDate,jdbcType=DATE} ]]>
  383. AND (del_flag_ =0 OR del_flag_ IS NULL)
  384. GROUP BY class_group_id_
  385. </select>
  386. <select id="findByGroupId" resultMap="PracticeCourseDto">
  387. SELECT pg.*, s.name_ subject_name_, su.real_name_ edu_teacher_name_
  388. FROM practice_group pg
  389. LEFT JOIN subject s on pg.subject_id_ = s.id_
  390. LEFT JOIN sys_user su on pg.educational_teacher_id_ = su.id_
  391. WHERE pg.id_ = #{id}
  392. </select>
  393. <select id="countStudentBuys" resultType="java.lang.Integer">
  394. SELECT COUNT(a.student_id_) FROM
  395. (SELECT DISTINCT(pg.`student_id_`),pg.`organ_id_` FROM `practice_group` pg WHERE pg.`group_status_` in
  396. ('NORMAL','FINISH')) a
  397. LEFT JOIN (SELECT pg.`student_id_` ,max(concat(cs.`class_date_`,' ',cs.`end_class_time_` )) lastClassDate FROM
  398. `practice_group` pg
  399. LEFT JOIN `course_schedule` cs on cs.`music_group_id_` = pg.`id_` and cs.`group_type_` = 'PRACTICE'
  400. WHERE pg.type_='FREE' AND cs.`group_type_` = 'PRACTICE'
  401. GROUP BY pg.`student_id_` ) b on a.student_id_ = b.student_id_
  402. left join (SELECT pg.`student_id_` ,min(pg.`create_time_`) firstBuyTime
  403. FROM `practice_group` pg WHERE pg.type_='CHARGE' AND pg.`group_status_` in ('NORMAL','FINISH') GROUP
  404. BY pg.`student_id_` ) c
  405. on a.student_id_ = c.student_id_
  406. left join `sys_user` u on u.`id_` = a.student_id_
  407. left join `organization` o on o.`id_` = a.organ_id_
  408. <include refid="queryStudentBuysSql"/>
  409. </select>
  410. <resultMap id="queryStudentBuysMap" type="com.ym.mec.biz.dal.dto.StudentBuyPracticeDto">
  411. <result property="organName" column="organ_name_"/>
  412. <result property="phone" column="phone_"/>
  413. <result property="studentId" column="student_id_"/>
  414. <result property="studentName" column="student_name_"/>
  415. <result property="teacherName" column="teacher_name_"/>
  416. <result property="courseGroupTeacherName" column="course_group_teacher_"/>
  417. <result property="firstBuyTime" column="first_buy_time_"/>
  418. <result property="intervalDay" column="interval_day_"/>
  419. <result property="lastClassDate" column="last_class_date_"/>
  420. <result property="buyPractice" column="buy_practice_"
  421. typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  422. </resultMap>
  423. <select id="queryStudentBuys" resultMap="queryStudentBuysMap">
  424. SELECT o.`name_` organ_name_,a.student_id_,u.`username_` student_name_,u.phone_,
  425. b.lastClassDate last_class_date_,c.firstBuyTime first_buy_time_,
  426. CASE WHEN DATEDIFF(c.firstBuyTime,b.lastClassDate) &lt; 0 THEN 0 ELSE DATEDIFF(c.firstBuyTime,b.lastClassDate)
  427. END interval_day_,
  428. CASE WHEN c.firstBuyTime IS NULL THEN 0 ELSE 1 END buy_practice_,d.teacher_name_,d.course_group_teacher_
  429. FROM
  430. (SELECT DISTINCT(pg.`student_id_`),pg.`organ_id_` FROM `practice_group` pg WHERE pg.`group_status_` in
  431. ('NORMAL','FINISH')) a
  432. LEFT JOIN (SELECT pg.`student_id_` ,max(concat(cs.`class_date_`,' ',cs.`end_class_time_` )) lastClassDate FROM
  433. `practice_group` pg
  434. LEFT JOIN `course_schedule` cs on cs.`music_group_id_` = pg.`id_`
  435. WHERE pg.type_='FREE' AND cs.`group_type_` = 'PRACTICE'
  436. GROUP BY pg.`student_id_` ) b on a.student_id_ = b.student_id_
  437. left join (SELECT pg.`student_id_` ,min(pg.`create_time_`) firstBuyTime
  438. FROM `practice_group` pg
  439. WHERE pg.type_='CHARGE' AND pg.`group_status_` IN ('NORMAL','FINISH') GROUP
  440. BY pg.`student_id_` ) c ON a.student_id_ = c.student_id_
  441. LEFT JOIN (SELECT GROUP_CONCAT(DISTINCT su.real_name_) teacher_name_,pg.student_id_,GROUP_CONCAT(DISTINCT suc.real_name_) course_group_teacher_
  442. FROM `practice_group` pg
  443. LEFT JOIN `course_schedule` cs ON cs.`music_group_id_` = pg.`id_`
  444. LEFT JOIN sys_user su ON su.id_ = cs.actual_teacher_id_
  445. LEFT JOIN sys_user suc ON suc.id_ = pg.user_id_
  446. WHERE cs.`group_type_` = 'PRACTICE' AND pg.`group_status_` IN ('NORMAL','FINISH') GROUP BY pg.`student_id_` ) d ON a.student_id_ = d.student_id_
  447. LEFT JOIN `sys_user` u ON u.`id_` = a.student_id_
  448. LEFT JOIN `organization` o ON o.`id_` = a.organ_id_
  449. <include refid="queryStudentBuysSql"/>
  450. <include refid="global.limit"/>
  451. </select>
  452. <sql id="queryStudentBuysSql">
  453. <where>
  454. <if test="search != null and search != ''">
  455. (u.id_ = #{search} OR u.`username_` LIKE CONCAT('%',#{search},'%'))
  456. </if>
  457. <if test="buyPractice != null and buyPractice == false">
  458. AND c.firstBuyTime IS NULL
  459. </if>
  460. <if test="buyPractice != null and buyPractice == true">
  461. AND c.firstBuyTime IS NOT NULL
  462. </if>
  463. <if test="organId != null">
  464. AND FIND_IN_SET(a.organ_id_,#{organId})
  465. </if>
  466. </where>
  467. </sql>
  468. <resultMap id="courseGroupExport" type="com.ym.mec.biz.dal.dto.CourseGroupExportDto">
  469. <result column="organ_name_" property="organName"/>
  470. <result column="student_id_" property="studentId"/>
  471. <result column="student_name_" property="studentName"/>
  472. <result column="teacher_id_" property="teacherId"/>
  473. <result column="teacher_ids_" property="teacherIds"/>
  474. <result column="teacher_name_" property="teacherName"/>
  475. <result column="expire_date_" property="expireDate"/>
  476. <result column="class_start_date_" property="classStartDate"/>
  477. <result column="class_end_date_" property="classEndDate"/>
  478. <result column="total_class_times_" property="totalClassTimes"/>
  479. <result column="no_start_class_times_" property="noStartClassTimes"/>
  480. <result column="buy_practice_" property="buyPractice" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  481. </resultMap>
  482. <select id="getPracticeGroupExport" resultMap="courseGroupExport">
  483. SELECT pg.student_id_,
  484. su.username_ student_name_,
  485. o.name_ organ_name_,
  486. MAX(pg.courses_expire_date_) expire_date_,
  487. CASE WHEN type_='FREE' THEN 0 ELSE 1 END buy_practice_
  488. FROM practice_group pg
  489. LEFT JOIN organization o on o.id_ = pg.organ_id_
  490. LEFT JOIN sys_user su ON su.id_ = pg.student_id_
  491. WHERE pg.group_status_ IN ('NORMAL','FINISH')
  492. <if test="organIds != null and organIds != ''">
  493. AND FIND_IN_SET(pg.organ_id_, #{organIds})
  494. </if>
  495. GROUP BY pg.student_id_,o.id_
  496. </select>
  497. <select id="findConvertDefeatStudents" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  498. SELECT
  499. DISTINCT su.id_ userId,su.username_ userName, su.avatar_ avatar, su.phone_ phone
  500. FROM
  501. sys_user su
  502. WHERE
  503. 1=1
  504. AND FIND_IN_SET('STUDENT',su.user_type_)
  505. <if test="organIdList!=null">
  506. AND su.organ_id_ IN
  507. <foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
  508. #{organId}
  509. </foreach>
  510. </if>
  511. <if test="search != null">
  512. AND (su.username_ LIKE CONCAT('%', #{search}, '%') OR su.phone_ LIKE CONCAT('%', #{search}, '%'))
  513. </if>
  514. AND su.id_ NOT IN (
  515. SELECT student_id_ FROM practice_group WHERE type_='CHARGE' AND group_status_ IN ('NORMAL', 'FINISH')
  516. )
  517. AND NOT EXISTS (
  518. SELECT user_id_ FROM course_schedule_student_payment cssp
  519. LEFT JOIN course_schedule cs ON cs.id_=cssp.course_schedule_id_
  520. WHERE cssp.user_id_=su.id_ AND cs.teach_mode_='ONLINE'
  521. AND NOT EXISTS(SELECT student_id_ FROM practice_group WHERE cssp.music_group_id_=id_ AND cssp.group_type_='PRACTICE' AND type_='TRIAL')
  522. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) > NOW()
  523. )
  524. ORDER BY su.id_
  525. <include refid="global.limit"/>
  526. </select>
  527. <select id="countConvertDefeatStudents" resultType="int">
  528. SELECT
  529. COUNT(DISTINCT su.id_)
  530. FROM
  531. sys_user su
  532. WHERE
  533. 1=1
  534. AND FIND_IN_SET('STUDENT',su.user_type_)
  535. <if test="organIdList!=null">
  536. AND su.organ_id_ IN
  537. <foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
  538. #{organId}
  539. </foreach>
  540. </if>
  541. <if test="search != null">
  542. AND (su.username_ LIKE CONCAT('%', #{search}, '%') OR su.phone_ LIKE CONCAT('%', #{search}, '%'))
  543. </if>
  544. AND su.id_ NOT IN (
  545. SELECT student_id_ FROM practice_group WHERE type_='CHARGE' AND group_status_ IN ('NORMAL', 'FINISH')
  546. )
  547. AND NOT EXISTS (
  548. SELECT user_id_ FROM course_schedule_student_payment cssp
  549. LEFT JOIN course_schedule cs ON cs.id_=cssp.course_schedule_id_
  550. WHERE cssp.user_id_=su.id_ AND cs.teach_mode_='ONLINE'
  551. AND NOT EXISTS(SELECT student_id_ FROM practice_group WHERE cssp.music_group_id_=id_ AND cssp.group_type_='PRACTICE' AND type_='TRIAL')
  552. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) > NOW()
  553. )
  554. </select>
  555. <select id="findEnableAssignTeachers" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
  556. SELECT su.id_ userId,su.username_ userName,su.avatar_ avatar
  557. FROM teacher t
  558. LEFT JOIN sys_user su ON t.id_=su.id_
  559. WHERE
  560. FIND_IN_SET(#{subjectId}, t.subject_id_)
  561. AND (t.organ_id_ = #{studentOrganId} OR FIND_IN_SET(#{studentOrganId},t.flow_organ_range_))
  562. AND NOT EXISTS (SELECT
  563. cs.actual_teacher_id_
  564. FROM
  565. course_schedule_student_payment cssp
  566. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  567. LEFT JOIN practice_group pg ON cssp.music_group_id_=pg.id_
  568. WHERE
  569. cssp.user_id_ = #{studentId}
  570. AND cs.actual_teacher_id_ = t.id_
  571. AND pg.type_='TRIAL'
  572. AND cssp.group_type_ = 'PRACTICE')
  573. </select>
  574. <select id="findLastPracticeSubject" resultType="int">
  575. SELECT pg.subject_id_ FROM course_schedule_student_payment cssp LEFT JOIN course_schedule cs ON cs.id_=cssp.course_schedule_id_
  576. LEFT JOIN practice_group pg ON cssp.music_group_id_=pg.id_
  577. WHERE cssp.group_type_='PRACTICE' AND cssp.user_id_=#{studentId} ORDER BY CONCAT(cs.class_date_, ' ', cs.start_class_time_) DESC LIMIT 1
  578. </select>
  579. <select id="findStudentTrialPractices" resultMap="PracticeGroupDto">
  580. SELECT
  581. pg.id_,
  582. pg.name_,
  583. pg.user_id_,
  584. su.real_name_ teacher_name_,
  585. GROUP_CONCAT(CONCAT(cs.class_date_, ' ', cs.start_class_time_)) courses_start_dates_,
  586. pg.memo_
  587. FROM
  588. practice_group pg
  589. LEFT JOIN course_schedule cs ON cs.music_group_id_ = pg.id_
  590. LEFT JOIN sys_user su ON su.id_=pg.user_id_
  591. WHERE
  592. pg.student_id_ = #{studentId}
  593. AND cs.group_type_ = 'PRACTICE'
  594. AND pg.type_ = 'TRIAL'
  595. GROUP BY pg.id_
  596. ORDER BY pg.id_
  597. </select>
  598. <select id="countStudentTrialPractices" resultType="int">
  599. SELECT
  600. COUNT( DISTINCT pg.id_ )
  601. FROM
  602. course_schedule cs
  603. LEFT JOIN practice_group pg ON pg.id_ = cs.music_group_id_
  604. WHERE
  605. pg.student_id_ = #{studentId}
  606. AND cs.group_type_ = 'PRACTICE'
  607. AND pg.type_ = 'TRIAL'
  608. </select>
  609. <select id="findStudentAndTeacherTrialPractices" resultMap="com.ym.mec.biz.dal.dao.CourseScheduleDao.CourseSchedule">
  610. SELECT
  611. cs.id_,
  612. cs.music_group_id_,
  613. cs.group_type_,
  614. cs.class_group_id_,
  615. cs.status_,
  616. cs.subsidy_,
  617. cs.class_date_,
  618. CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
  619. CONCAT(cs.class_date_, ' ', cs.end_class_time_) end_class_time_,
  620. cs.teacher_id_,
  621. cs.actual_teacher_id_,
  622. cs.create_time_,
  623. cs.update_time_,
  624. cs.teach_mode_,
  625. cs.type_,
  626. cs.name_,
  627. cs.student_num_,
  628. cs.leave_student_num_,
  629. cs.teaching_content_,
  630. cs.note_,
  631. cs.schoole_id_
  632. FROM
  633. practice_group pg
  634. LEFT JOIN course_schedule cs ON cs.music_group_id_ = pg.id_
  635. WHERE
  636. pg.type_ = 'TRIAL'
  637. AND pg.user_id_ = #{teacherId}
  638. AND pg.student_id_ = #{studentId}
  639. AND cs.group_type_ = 'PRACTICE'
  640. </select>
  641. <select id="countStudentAndTeacherTrialPractices" resultType="int">
  642. SELECT COUNT(pg.id_)
  643. FROM course_schedule cs
  644. LEFT JOIN practice_group pg ON cs.music_group_id_=pg.id_
  645. WHERE
  646. pg.type_ = 'TRIAL'
  647. AND cs.actual_teacher_id_ = #{teacherId}
  648. AND pg.student_id_ = #{studentId}
  649. </select>
  650. <select id="checkStudentExitChargePractice" resultType="int">
  651. SELECT COUNT(id_) FROM practice_group WHERE type_='CHARGE' AND student_id_=#{studentId} AND group_status_ IN ('NORMAL', 'FINISH')
  652. </select>
  653. </mapper>