PracticeGroupMapper.xml 36 KB

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