PracticeGroupMapper.xml 39 KB

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