PracticeGroupMapper.xml 33 KB

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