StudentMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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.StudentDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.Student" id="Student">
  9. <result column="user_id_" property="userId"/>
  10. <result column="subject_id_list_" property="subjectIdList"/>
  11. <result column="service_tag_" property="serviceTag"/>
  12. <result column="operating_tag_" property="operatingTag"/>
  13. <result column="operating_temp_tag_" property="operatingTempTag"/>
  14. <result column="teacher_id_" property="teacherId"/>
  15. <result column="create_time_" property="createTime"/>
  16. <result column="update_time_" property="updateTime"/>
  17. </resultMap>
  18. <!-- 根据主键查询一条记录 -->
  19. <select id="get" resultMap="Student">
  20. SELECT *
  21. FROM student
  22. WHERE user_id_ = #{id}
  23. </select>
  24. <!-- 全查询 -->
  25. <select id="findAll" resultMap="Student">
  26. SELECT *
  27. FROM student
  28. </select>
  29. <select id="lockUser" resultType="int" useCache="false" flushCache="true">
  30. SELECT id_
  31. FROM sys_user
  32. WHERE id_ = #{userId} FOR
  33. UPDATE
  34. </select>
  35. <!-- 向数据库增加一条记录 -->
  36. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Student" useGeneratedKeys="true" keyColumn="id"
  37. keyProperty="id">
  38. INSERT INTO student (user_id_,subject_id_list_,
  39. <if test="serviceTag != null">
  40. service_tag_,
  41. </if>
  42. <if test="operatingTag != null">
  43. operating_tag_,
  44. </if>
  45. <if test="operatingTempTag != null">
  46. operating_temp_tag_,
  47. </if>
  48. teacher_id_,create_time_,update_time_)
  49. VALUES
  50. (#{userId},#{subjectIdList},
  51. <if test="serviceTag != null">
  52. #{serviceTag},
  53. </if>
  54. <if test="operatingTag != null">
  55. #{operatingTag},
  56. </if>
  57. #{teacherId},NOW(),NOW())
  58. </insert>
  59. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Student">
  60. UPDATE student
  61. <set>
  62. <if test="subjectIdList != null">
  63. subject_id_list_ = #{subjectIdList},
  64. </if>
  65. <if test="serviceTag != null">
  66. service_tag_ = #{serviceTag},
  67. </if>
  68. <if test="operatingTag != null">
  69. operating_tag_ = #{operatingTag},
  70. </if>
  71. <if test="operatingTempTag != null">
  72. operating_temp_tag_ = #{operatingTempTag},
  73. </if>
  74. <if test="teacherId != null">
  75. teacher_id_=#{teacherId},
  76. </if>
  77. <if test="updateTime != null">
  78. update_time_ = #{updateTime},
  79. </if>
  80. <if test="updateTime == null">
  81. update_time_ = NOW()
  82. </if>
  83. </set>
  84. WHERE user_id_ = #{userId}
  85. </update>
  86. <!-- 分页查询 -->
  87. <select id="queryPage" resultMap="Student" parameterType="map">
  88. SELECT * FROM student
  89. <include refid="global.limit"/>
  90. </select>
  91. <!-- 查询当前表的总记录数 -->
  92. <select id="queryCount" resultType="int">
  93. SELECT COUNT(*)
  94. FROM student
  95. </select>
  96. <select id="findStudents" resultMap="com.ym.mec.biz.dal.dao.TeacherDao.SysUser">
  97. SELECT id_, username_, phone_,avatar_ FROM sys_user
  98. <include refid="studentQueryCondition"/>
  99. ORDER BY id_
  100. <include refid="global.limit"/>
  101. </select>
  102. <select id="countStudents" resultType="int">
  103. SELECT COUNT(id_) FROM sys_user
  104. <include refid="studentQueryCondition"/>
  105. </select>
  106. <sql id="studentQueryCondition">
  107. <where>
  108. <if test="organIdList!=null">
  109. organ_id_ IN
  110. <foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
  111. #{organId}
  112. </foreach>
  113. </if>
  114. <if test="search!=null">
  115. AND (username_ LIKE CONCAT('%', #{search}, '%') OR phone_ LIKE CONCAT('%', #{search}, '%'))
  116. </if>
  117. AND FIND_IN_SET("STUDENT", user_type_)
  118. </where>
  119. </sql>
  120. <select id="queryByOperatingTempTag" resultMap="Student">
  121. SELECT *
  122. FROM student
  123. WHERE operating_temp_tag_ = #{operatingTempTag}
  124. </select>
  125. <update id="batchUpdate" parameterType="java.util.List">
  126. <foreach collection="studentList" item="item" index="index" open="" close="" separator=";">
  127. UPDATE student
  128. <set>
  129. <if test="item.subjectIdList != null">
  130. subject_id_list_ = #{item.subjectIdList},
  131. </if>
  132. <if test="item.serviceTag != null">
  133. service_tag_ = #{item.serviceTag},
  134. </if>
  135. <if test="item.operatingTag != null">
  136. operating_tag_ = #{item.operatingTag},
  137. </if>
  138. <if test="item.operatingTempTag != null">
  139. operating_temp_tag_ = #{item.operatingTempTag},
  140. </if>
  141. <if test="item.teacherId != null">
  142. teacher_id_=#{item.teacherId},
  143. </if>
  144. <if test="item.updateTime != null">
  145. update_time_ = #{item.updateTime},
  146. </if>
  147. <if test="item.updateTime == null">
  148. update_time_ = NOW()
  149. </if>
  150. </set>
  151. WHERE user_id_ = #{item.userId}
  152. </foreach>
  153. </update>
  154. <resultMap id="student4operating" type="com.ym.mec.biz.dal.dto.Student4operating">
  155. <result column="organ_name_" property="organName"/>
  156. <result column="organ_id_" property="organId"/>
  157. <result column="student_name_" property="studentName"/>
  158. <result column="student_id_" property="studentId"/>
  159. <result column="teacher_id_" property="teacherId"/>
  160. <result column="teacher_name_" property="teacherName"/>
  161. <result column="operating_tag_" property="operatingTag"/>
  162. <result column="vip_times_" property="vipTimes"/>
  163. <result column="free_practice_times_" property="freePracticeTimes"/>
  164. <result column="buy_practice_times_" property="buyPracticeTimes"/>
  165. <result column="student_num_" property="studentNum"/>
  166. </resultMap>
  167. <select id="getOperatingStudents" resultMap="student4operating">
  168. SELECT su.organ_id_,
  169. o.name_ organ_name_,
  170. su.username_ student_name_,
  171. s.user_id_ student_id_,
  172. tsu.id_ teacher_id_,
  173. tsu.real_name_ teacher_name_,
  174. s.operating_tag_,
  175. a.vip_times_,
  176. a.buy_practice_times_,
  177. p.free_practice_times_
  178. FROM student s
  179. LEFT JOIN sys_user su ON s.user_id_ = su.id_
  180. LEFT JOIN sys_user tsu ON tsu.id_ = s.teacher_id_
  181. LEFT JOIN organization o ON o.id_ = su.organ_id_
  182. LEFT JOIN (
  183. SELECT cssp.user_id_,
  184. SUM(case when (cs.group_type_ = 'VIP' AND cs.teach_mode_='ONLINE') then 1 ELSE 0 END) vip_times_,
  185. SUM(case when (pg.type_='FREE') then 1 ELSE 0 END) buy_practice_times_
  186. FROM course_schedule_student_payment cssp
  187. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  188. LEFT JOIN practice_group pg ON pg.`id_` = cs.`music_group_id_` AND cs.`group_type_` = 'PRACTICE'
  189. WHERE cs.status_ IN ('NOT_START','UNDERWAY') AND (cs.is_lock_ IS NULL OR cs.is_lock_=0)
  190. GROUP BY cssp.user_id_
  191. ) a on a.user_id_ = s.user_id_
  192. LEFT JOIN (
  193. SELECT student_id_, count(id_) free_practice_times_
  194. FROM practice_group
  195. WHERE type_='FREE'
  196. GROUP BY student_id_
  197. ) p ON p.student_id_ = s.user_id_
  198. <include refid="student4OperatingQueryCondition"/>
  199. ORDER BY s.user_id_
  200. <include refid="global.limit"/>
  201. </select>
  202. <select id="countOperatingStudents" resultType="int">
  203. SELECT COUNT(s.user_id_) FROM student s
  204. LEFT JOIN sys_user su ON s.user_id_ = su.id_
  205. LEFT JOIN sys_user tsu ON tsu.id_ = s.teacher_id_
  206. LEFT JOIN (
  207. SELECT cssp.user_id_,
  208. SUM(case when (cs.group_type_ = 'VIP' AND cs.teach_mode_='ONLINE') then 1 ELSE 0 END) vip_times_,
  209. SUM(case when (pg.buy_months_ > 0) then 1 ELSE 0 END) buy_practice_times_
  210. FROM course_schedule_student_payment cssp
  211. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  212. LEFT JOIN practice_group pg ON pg.`id_` = cs.`music_group_id_` AND cs.`group_type_` = 'PRACTICE'
  213. WHERE cs.status_ IN ('NOT_START','UNDERWAY') AND (cs.is_lock_ IS NULL OR cs.is_lock_=0)
  214. GROUP BY cssp.user_id_
  215. ) a on a.user_id_ = s.user_id_
  216. LEFT JOIN (
  217. SELECT student_id_, count(id_) free_practice_times_
  218. FROM practice_group
  219. WHERE type_='FREE'
  220. GROUP BY student_id_
  221. ) p ON p.student_id_ = s.user_id_
  222. <include refid="student4OperatingQueryCondition"/>
  223. </select>
  224. <sql id="student4OperatingQueryCondition">
  225. <where>
  226. su.user_type_ LIKE '%STUDENT%'
  227. <if test="search != null and search != ''">
  228. AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_
  229. LIKE CONCAT('%',#{search},'%'))
  230. </if>
  231. <if test="organId != null and organId != ''">
  232. AND FIND_IN_SET(su.organ_id_,#{organId})
  233. </if>
  234. <if test="teacherId!=null">
  235. AND s.teacher_id_ = #{teacherId}
  236. </if>
  237. <if test="operatingTag !=null">
  238. AND s.operating_tag_ = #{operatingTag}
  239. </if>
  240. <if test='hasVip != null and hasVip=="1"'>
  241. AND a.vip_times_ >=1
  242. </if>
  243. <if test='hasVip != null and hasVip=="0"'>
  244. AND (a.vip_times_ =0 OR a.vip_times_ IS NULL)
  245. </if>
  246. <if test='hasFreePractice != null and hasFreePractice=="1"'>
  247. AND p.free_practice_times_ >=1
  248. </if>
  249. <if test='hasFreePractice != null and hasFreePractice=="0"'>
  250. AND (p.free_practice_times_ =0 OR p.free_practice_times_ IS NULL)
  251. </if>
  252. <if test='hasBuyPractice != null and hasBuyPractice=="1"'>
  253. AND a.buy_practice_times_ >=1
  254. </if>
  255. <if test='hasBuyPractice != null and hasBuyPractice=="0"'>
  256. AND (a.buy_practice_times_ =0 OR a.buy_practice_times_ IS NULL)
  257. </if>
  258. </where>
  259. </sql>
  260. <select id="getTeacherOperatingStudentsNum" resultType="java.util.Map">
  261. select teacher_id_ 'key', count(*) 'value'
  262. FROM student
  263. WHERE FIND_IN_SET(teacher_id_, #{teacherIds})
  264. AND operating_tag_ = 1
  265. GROUP BY teacher_id_
  266. </select>
  267. <select id="getBuyNums" resultType="java.util.Map">
  268. SELECT s.teacher_id_ 'key', COUNT(DISTINCT cssp.user_id_) 'value'
  269. FROM course_schedule_student_payment cssp
  270. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_ AND cs.teach_mode_ = 'ONLINE'
  271. LEFT JOIN student s ON s.user_id_ = cssp.user_id_
  272. <if test="groupType != null and groupType==@com.ym.mec.biz.dal.enums.GroupType@PRACTICE">
  273. LEFT JOIN practice_group pg ON cssp.music_group_id_ = pg.id_ AND cssp.group_type_ = 'PRACTICE'
  274. </if>
  275. WHERE FIND_IN_SET(s.teacher_id_, #{teacherIds})
  276. AND cs.status_ IN ('NOT_START', 'UNDERWAY')
  277. AND (cs.is_lock_ IS NULL OR cs.is_lock_ = 0)
  278. <if test="groupType != null">
  279. AND cs.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  280. </if>
  281. <if test="groupType != null and groupType==@com.ym.mec.biz.dal.enums.GroupType@PRACTICE">
  282. AND pg.group_status_ IN ('NORMAL', 'FINISH')
  283. AND pg.buy_months_ >= 1
  284. </if>
  285. GROUP BY s.teacher_id_
  286. </select>
  287. <select id="getPracticeAndVipNums" resultType="java.util.Map">
  288. SELECT s.teacher_id_ 'key', COUNT(DISTINCT pg.student_id_) 'value'
  289. FROM practice_group pg
  290. LEFT JOIN student s on s.user_id_ = pg.student_id_
  291. LEFT JOIN course_schedule_student_payment vcssp
  292. ON vcssp.user_id_ = pg.student_id_ AND vcssp.group_type_ = 'VIP'
  293. LEFT JOIN course_schedule_student_payment pcssp
  294. ON pcssp.user_id_ = pg.student_id_ AND pcssp.group_type_ = 'PRACTICE'
  295. LEFT JOIN course_schedule vcs ON vcs.id_ = vcssp.course_schedule_id_ AND vcs.teach_mode_ = 'ONLINE'
  296. LEFT JOIN course_schedule pcs ON pcs.id_ = pcssp.course_schedule_id_
  297. WHERE FIND_IN_SET(s.teacher_id_, #{teacherIds})
  298. AND pg.group_status_ IN ('NORMAL', 'FINISH')
  299. AND vcs.status_ IN ('NOT_START', 'UNDERWAY')
  300. AND pcs.status_ IN ('NOT_START', 'UNDERWAY')
  301. AND (vcs.is_lock_ IS NULL OR vcs.is_lock_ = 0)
  302. AND (pcs.is_lock_ IS NULL OR pcs.is_lock_ = 0)
  303. AND pg.buy_months_ >= 1
  304. GROUP BY s.teacher_id_
  305. </select>
  306. </mapper>