PracticeGroupMapper.xml 29 KB

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