PracticeGroupMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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="subject_id_" property="subjectId"/>
  12. <result column="user_id_" property="userId"/>
  13. <result column="student_id_" property="studentId"/>
  14. <result column="single_class_minutes_" property="singleClassMinutes"/>
  15. <result column="organ_id_" property="organId"/>
  16. <result column="courses_start_date_" property="coursesStartDate"/>
  17. <result column="courses_expire_date_" property="coursesExpireDate"/>
  18. <result column="create_time_" property="createTime"/>
  19. <result column="update_time_" property="updateTime"/>
  20. <result column="memo_" property="memo"/>
  21. <result column="buy_months_" property="buyMonths"/>
  22. <result column="drill_times_on_week_" property="drillTimesOnWeek"/>
  23. <result column="drill_times_json_" property="drillTimesJson"/>
  24. <result column="group_status_" property="groupStatus"
  25. typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  26. <result column="be_renew_group_id_" property="beRenewGroupId"/>
  27. <result column="educational_teacher_id_" property="educationalTeacherId"/>
  28. </resultMap>
  29. <resultMap id="PracticeCourseDto" type="com.ym.mec.biz.dal.dto.PracticeCourseDto" extends="PracticeGroup">
  30. <result property="teacherName" column="real_name_"/>
  31. <result property="avatar" column="avatar_"/>
  32. <result property="subjectName" column="subject_name_"/>
  33. <result property="eduTeacherName" column="edu_teacher_name_"/>
  34. </resultMap>
  35. <resultMap type="com.ym.mec.biz.dal.dto.PracticeGroupDto" id="PracticeGroupDto" extends="PracticeGroup">
  36. <result column="id_" property="id"/>
  37. <result column="name_" property="name"/>
  38. <result column="subject_id_" property="subjectId"/>
  39. <result column="user_id_" property="userId"/>
  40. <result column="single_class_minutes_" property="singleClassMinutes"/>
  41. <result column="organ_id_" property="organId"/>
  42. <result column="courses_start_date_" property="coursesStartDate"/>
  43. <result column="courses_expire_date_" property="coursesExpireDate"/>
  44. <result column="create_time_" property="createTime"/>
  45. <result column="update_time_" property="updateTime"/>
  46. <result column="memo_" property="memo"/>
  47. <result column="subject_name_" property="subjectName"/>
  48. <result column="teacher_name_" property="teacherName"/>
  49. <result column="evaluate_id_" property="evaluateId"/>
  50. <result column="evaluate_status_" property="evaluateStatus"/>
  51. </resultMap>
  52. <update id="updateUserId">
  53. UPDATE practice_group
  54. SET user_id_ = #{teacherId},
  55. update_time_ = NOW()
  56. WHERE id_ = #{practiceGroupId}
  57. </update>
  58. <update id="update" parameterType="com.ym.mec.biz.dal.entity.PracticeGroup">
  59. UPDATE practice_group
  60. <set>
  61. <if test="subjectId!=null">
  62. subject_id_=#{subjectId},
  63. </if>
  64. <if test="memo!=null">
  65. memo_=#{memo},
  66. </if>
  67. <if test="name!=null">
  68. name_=#{name},
  69. </if>
  70. <if test="groupStatus!=null">
  71. group_status_=#{groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  72. </if>
  73. <if test="educationalTeacherId!=null">
  74. educational_teacher_id_=#{educationalTeacherId},
  75. </if>
  76. update_time_ = NOW()
  77. </set>
  78. WHERE id_ = #{id}
  79. </update>
  80. <update id="batchUpdate">
  81. <foreach collection="groups" item="group" separator=";">
  82. UPDATE practice_group
  83. <set>
  84. <if test="group.groupStatus!=null">
  85. group_status_=#{group.groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  86. </if>
  87. update_time_ = NOW()
  88. </set>
  89. WHERE id_ = #{group.id}
  90. </foreach>
  91. </update>
  92. <!-- 根据主键查询一条记录 -->
  93. <select id="get" resultMap="PracticeGroup">
  94. SELECT *
  95. FROM practice_group
  96. WHERE id_ = #{id}
  97. </select>
  98. <!-- 全查询 -->
  99. <select id="findAll" resultMap="PracticeGroup">
  100. SELECT *
  101. FROM practice_group
  102. </select>
  103. <!-- 向数据库增加一条记录 -->
  104. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.PracticeGroup" useGeneratedKeys="true" keyColumn="id"
  105. keyProperty="id">
  106. <!--
  107. <selectKey resultClass="int" keyProperty="id" >
  108. SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
  109. </selectKey>
  110. -->
  111. INSERT INTO practice_group
  112. (id_,name_,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_)
  113. VALUES(#{id},#{name},#{subjectId},#{userId},#{studentId},#{singleClassMinutes},#{organId},#{coursesStartDate},#{coursesExpireDate},NOW(),NOW(),#{memo},#{buyMonths},#{drillTimesOnWeek},#{drillTimesJson},#{groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{beRenewGroupId},#{educationalTeacherId})
  114. </insert>
  115. <select id="getUserFreePracticeGroup" resultMap="PracticeGroup">
  116. SELECT *
  117. FROM practice_group
  118. WHERE student_id_ = #{userId}
  119. AND buy_months_ IS NULL
  120. </select>
  121. <!-- 分页查询 -->
  122. <select id="queryPage" resultMap="PracticeGroup" parameterType="map">
  123. SELECT * FROM practice_group
  124. <include refid="global.limit"/>
  125. </select>
  126. <!-- 查询当前表的总记录数 -->
  127. <select id="queryCount" resultType="int">
  128. SELECT COUNT(*)
  129. FROM practice_group
  130. </select>
  131. <select id="getUserPracticeCoursesWithDateRange" resultMap="PracticeGroup">
  132. SELECT *
  133. FROM practice_group
  134. WHERE user_id_ = #{userId}
  135. AND (courses_start_date_ BETWEEN DATE_FORMAT(#{startDate}, '%Y-%m-%d') AND DATE_FORMAT(#{endDate}, '%Y-%m-%d'))
  136. </select>
  137. <select id="countUserPracticeApplyRecord" resultType="int">
  138. SELECT COUNT(*)
  139. FROM practice_group
  140. WHERE student_id_ = #{userId}
  141. AND group_status_ = 'NORMAL'
  142. AND buy_months_ IS NULL;
  143. </select>
  144. <select id="countPracticeGroupByOrgan" resultType="java.lang.Integer">
  145. SELECT count(*) FROM practice_group pg
  146. <include refid="practiceGroupQueryCondition"/>
  147. </select>
  148. <select id="findAllByOrgan" resultMap="PracticeGroupDto">
  149. SELECT pg.*,
  150. su.real_name_ teacher_name_
  151. FROM
  152. practice_group pg
  153. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  154. <include refid="practiceGroupQueryCondition"/>
  155. ORDER BY pg.id_ DESC
  156. <include refid="global.limit"/>
  157. </select>
  158. <select id="countPracticeGroupOverCourse" resultType="java.util.Map">
  159. </select>
  160. <select id="findUserLatestPracticeGroup" resultMap="PracticeGroup">
  161. SELECT *
  162. FROM practice_group
  163. WHERE student_id_ = #{userId}
  164. AND buy_months_ IS NOT NULL
  165. ORDER BY create_time_ DESC
  166. LIMIT 1;
  167. </select>
  168. <select id="findUserBuyPracticeGroups" resultMap="PracticeCourseDto">
  169. SELECT pg.*,
  170. su.real_name_,
  171. su.avatar_,
  172. s.name_ subject_name_
  173. FROM practice_group pg
  174. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  175. LEFT JOIN `subject` s ON pg.subject_id_ = s.id_
  176. WHERE student_id_ = #{userId}
  177. AND (pg.group_status_ = 'NORMAL' OR pg.group_status_ = 'LOCK')
  178. AND pg.buy_months_ IS NOT NULL
  179. </select>
  180. <select id="findUserBuyPracticeGroupsWithDate" resultMap="PracticeCourseDto">
  181. SELECT pg.*,
  182. su.real_name_,
  183. su.avatar_,
  184. s.name_ subject_name_
  185. FROM practice_group pg
  186. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  187. LEFT JOIN `subject` s ON pg.subject_id_ = s.id_
  188. WHERE student_id_ = #{userId}
  189. AND courses_start_date_ = #{date}
  190. AND group_status_ = 'LOCK'
  191. AND pg.buy_months_ IS NOT NULL
  192. </select>
  193. <select id="findUserPracticeGroup" resultMap="PracticeGroup">
  194. SELECT *
  195. FROM practice_group
  196. WHERE student_id_ = #{userId}
  197. AND id_ = #{groupId};
  198. </select>
  199. <select id="findUserPracticeGroup2" resultMap="PracticeGroupDto">
  200. SELECT pg.*, su.real_name_ teacher_name_
  201. FROM practice_group pg
  202. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  203. WHERE pg.student_id_ = #{userId}
  204. AND pg.id_ = #{groupId};
  205. </select>
  206. <select id="findHistoryPracticeGroups" resultMap="PracticeGroup">
  207. SELECT *
  208. FROM practice_group
  209. WHERE courses_expire_date_ &lt; NOW()
  210. AND group_status_ = 'NORMAL'
  211. </select>
  212. <sql id="practiceGroupQueryCondition">
  213. <where>
  214. pg.group_status_='NORMAL'
  215. <if test="hasEducationalTeacherId != null and hasEducationalTeacherId == true">
  216. AND pg.educational_teacher_id_ IS NOT NULL
  217. </if>
  218. <if test="hasEducationalTeacherId != null and hasEducationalTeacherId == false">
  219. AND pg.educational_teacher_id_ IS NULL
  220. </if>
  221. <if test="search!=null and search!=''">
  222. AND (pg.name_ LIKE CONCAT('%',#{search},'%') OR pg.id_= #{search})
  223. </if>
  224. <if test="teacherId!=null">
  225. AND pg.user_id_=#{teacherId}
  226. </if>
  227. <if test="organId != null">
  228. AND FIND_IN_SET(pg.organ_id_,#{organId})
  229. </if>
  230. <if test="educationalTeacherId!=null">
  231. AND pg.educational_teacher_id_=#{educationalTeacherId}
  232. </if>
  233. </where>
  234. </sql>
  235. <!-- 根据主键查询一条记录 -->
  236. <select id="lockPracticeGroup" resultMap="PracticeGroup">
  237. SELECT *
  238. FROM practice_group
  239. WHERE id_ = #{groupId} FOR
  240. UPDATE
  241. </select>
  242. <select id="findUserStatusPracticeGroups" resultMap="PracticeGroup">
  243. SELECT *
  244. FROM practice_group
  245. WHERE student_id_ = #{userId}
  246. AND group_status_ = #{groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  247. </select>
  248. <select id="findUserLockPracticeGroupWithDate" resultMap="PracticeGroup">
  249. SELECT *
  250. FROM practice_group
  251. WHERE student_id_ = #{userId}
  252. AND courses_start_date_ = #{date}
  253. AND group_status_ = 'LOCK'
  254. </select>
  255. <select id="findUserLockPracticeGroupWithDateBefore" resultMap="PracticeGroup">
  256. SELECT *
  257. FROM practice_group
  258. WHERE student_id_ = #{userId}
  259. AND courses_start_date_ &lt;= #{date}
  260. AND group_status_ = 'LOCK'
  261. </select>
  262. <sql id="practiceGroupReviewsQueryCondition">
  263. <where>
  264. pg.group_status_ != 'LOCK'
  265. <if test="month != null">
  266. AND DATE_FORMAT(cse.create_time_, '%Y-%m') = #{month}
  267. </if>
  268. <if test="search!=null and search!=''">
  269. AND (pg.name_ LIKE CONCAT('%',#{search},'%') OR pg.id_= #{search})
  270. </if>
  271. <if test="teacherId!=null">
  272. AND pg.user_id_=#{teacherId}
  273. </if>
  274. <if test="organId != null">
  275. AND FIND_IN_SET(pg.organ_id_,#{organId})
  276. </if>
  277. <if test="month != null">
  278. AND pg.courses_expire_date_ >= #{month}
  279. </if>
  280. <if test='isFree !=null and isFree=="0"'>
  281. AND pg.buy_months_ > 0
  282. </if>
  283. <if test='isFree !=null and isFree=="1"'>
  284. AND pg.buy_months_ IS NULL
  285. </if>
  286. <if test='isOver !=null and isOver=="0"'>
  287. <![CDATA[AND pg.group_status_ = 'NORMAL'
  288. ]]>
  289. </if>
  290. <if test='isOver !=null and isOver=="1"'>
  291. <![CDATA[ AND pg.group_status_ ='FINISH'
  292. ]]></if>
  293. <if test='hasReport !=null and hasReport=="0"'>
  294. <![CDATA[AND cse.status_ =0
  295. ]]>
  296. </if>
  297. <if test='hasReport !=null and hasReport=="1"'>
  298. <![CDATA[ AND cse.status_ = 1
  299. ]]></if>
  300. </where>
  301. </sql>
  302. <select id="findPracticeGroupsReviews" resultMap="PracticeGroupDto">
  303. SELECT pg.*,cse.id_ evaluate_id_,cse.status_ evaluate_status_,
  304. su.real_name_ teacher_name_
  305. FROM
  306. practice_group pg
  307. LEFT JOIN sys_user su ON pg.user_id_ = su.id_
  308. LEFT JOIN course_schedule_evaluate cse ON pg.id_=cse.music_group_id_
  309. <include refid="practiceGroupReviewsQueryCondition"/>
  310. ORDER BY pg.id_ DESC
  311. <include refid="global.limit"/>
  312. </select>
  313. <select id="countPracticeGroupReviews" resultType="java.lang.Integer">
  314. SELECT count(*) FROM practice_group pg
  315. LEFT JOIN course_schedule_evaluate cse ON pg.id_=cse.music_group_id_
  316. <include refid="practiceGroupReviewsQueryCondition"/>
  317. </select>
  318. <select id="getNeedPostReportPracticeGroups"
  319. resultMap="com.ym.mec.biz.dal.dao.CourseScheduleEvaluateDao.CourseScheduleEvaluate">
  320. <![CDATA[
  321. SELECT pg.id_ music_group_id_,
  322. pg.user_id_ teacher_id_,
  323. cg.id_ class_group_id_,
  324. pg.single_class_minutes_ total_minutes_,
  325. pg.subject_id_
  326. FROM practice_group pg
  327. LEFT JOIN class_group cg on pg.id_ = cg.music_group_id_ AND cg.group_type_ = 'PRACTICE'
  328. WHERE pg.group_status_ = 'NORMAL' AND cg.group_type_ = 'PRACTICE'
  329. AND pg.buy_months_ >= 1
  330. AND pg.courses_start_date_ <= #{nowDate,jdbcType=DATE}
  331. AND pg.courses_expire_date_ >= #{afterDate,jdbcType=DATE}
  332. ]]>
  333. <if test="afterDateIsLastDay == false">
  334. AND DATE_FORMAT(pg.courses_expire_date_, '%d') = DATE_FORMAT(#{afterDate}, '%d')
  335. </if>
  336. <if test="afterDateIsLastDay == true">
  337. <![CDATA[ AND DATE_FORMAT(pg.courses_expire_date_, '%d') >= DATE_FORMAT(#{afterDate}, '%d') ]]>
  338. </if>
  339. AND cg.del_flag_ = 0
  340. </select>
  341. <select id="getReportCourseTimes" resultMap="com.ym.mec.biz.dal.dao.ClassGroupDao.ClassGroup">
  342. SELECT COUNT(*) total_class_times_,class_group_id_ id_ from course_schedule WHERE class_group_id_ IN
  343. <foreach collection="classGroupIds" item="classGroupId" open="(" separator="," close=")">
  344. #{classGroupId}
  345. </foreach>
  346. <![CDATA[AND class_date_ >= #{startDate,jdbcType=DATE} AND class_date_ <=#{endDate,jdbcType=DATE} ]]>
  347. AND (del_flag_ =0 OR del_flag_ IS NULL)
  348. GROUP BY class_group_id_
  349. </select>
  350. <select id="findByGroupId" resultMap="PracticeCourseDto">
  351. SELECT pg.*, s.name_ subject_name_,su.real_name_ edu_teacher_name_
  352. FROM practice_group pg
  353. LEFT JOIN subject s on pg.subject_id_ = s.id_
  354. LEFT JOIN sys_user su on pg.educational_teacher_id_ = su.id_
  355. WHERE pg.id_ = #{id}
  356. </select>
  357. </mapper>