StudentMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. <select id="lockUserReturnInfo" resultMap="com.ym.mec.biz.dal.dao.TeacherDao.SysUser">
  36. SELECT *
  37. FROM sys_user
  38. WHERE id_ = #{userId} FOR UPDATE
  39. </select>
  40. <!-- 向数据库增加一条记录 -->
  41. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Student" useGeneratedKeys="true" keyColumn="id"
  42. keyProperty="id">
  43. INSERT INTO student (user_id_,subject_id_list_,
  44. <if test="serviceTag != null">
  45. service_tag_,
  46. </if>
  47. <if test="operatingTag != null">
  48. operating_tag_,
  49. </if>
  50. <if test="operatingTempTag != null">
  51. operating_temp_tag_,
  52. </if>
  53. teacher_id_,create_time_,update_time_)
  54. VALUES
  55. (#{userId},#{subjectIdList},
  56. <if test="serviceTag != null">
  57. #{serviceTag},
  58. </if>
  59. <if test="operatingTag != null">
  60. #{operatingTag},
  61. </if>
  62. #{teacherId},NOW(),NOW())
  63. </insert>
  64. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Student">
  65. UPDATE student
  66. <set>
  67. <if test="subjectIdList != null">
  68. subject_id_list_ = #{subjectIdList},
  69. </if>
  70. <if test="serviceTag != null">
  71. service_tag_ = #{serviceTag},
  72. </if>
  73. <if test="operatingTag != null">
  74. operating_tag_ = #{operatingTag},
  75. </if>
  76. <if test="operatingTempTag != null">
  77. operating_temp_tag_ = #{operatingTempTag},
  78. </if>
  79. <if test="teacherId != null">
  80. teacher_id_=#{teacherId},
  81. </if>
  82. <if test="updateTime != null">
  83. update_time_ = #{updateTime},
  84. </if>
  85. <if test="updateTime == null">
  86. update_time_ = NOW()
  87. </if>
  88. </set>
  89. WHERE user_id_ = #{userId}
  90. </update>
  91. <!-- 分页查询 -->
  92. <select id="queryPage" resultMap="Student" parameterType="map">
  93. SELECT * FROM student
  94. <include refid="global.limit"/>
  95. </select>
  96. <!-- 查询当前表的总记录数 -->
  97. <select id="queryCount" resultType="int">
  98. SELECT COUNT(*)
  99. FROM student
  100. </select>
  101. <select id="findStudents" resultMap="com.ym.mec.biz.dal.dao.TeacherDao.SysUser">
  102. SELECT id_, username_, phone_,avatar_ FROM sys_user
  103. <include refid="studentQueryCondition"/>
  104. ORDER BY id_
  105. <include refid="global.limit"/>
  106. </select>
  107. <select id="countStudents" resultType="int">
  108. SELECT COUNT(id_) FROM sys_user
  109. <include refid="studentQueryCondition"/>
  110. </select>
  111. <sql id="studentQueryCondition">
  112. <where>
  113. <if test="organIdList!=null">
  114. organ_id_ IN
  115. <foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
  116. #{organId}
  117. </foreach>
  118. </if>
  119. <if test="search!=null">
  120. AND (username_ LIKE CONCAT('%', #{search}, '%') OR phone_ LIKE CONCAT('%', #{search}, '%'))
  121. </if>
  122. AND FIND_IN_SET("STUDENT", user_type_)
  123. </where>
  124. </sql>
  125. <select id="queryByOperatingTempTag" resultMap="Student">
  126. SELECT *
  127. FROM student
  128. WHERE operating_temp_tag_ = #{operatingTempTag}
  129. </select>
  130. <update id="batchUpdate" parameterType="java.util.List">
  131. <foreach collection="studentList" item="item" index="index" open="" close="" separator=";">
  132. UPDATE student
  133. <set>
  134. <if test="item.subjectIdList != null">
  135. subject_id_list_ = #{item.subjectIdList},
  136. </if>
  137. <if test="item.serviceTag != null">
  138. service_tag_ = #{item.serviceTag},
  139. </if>
  140. <if test="item.operatingTag != null">
  141. operating_tag_ = #{item.operatingTag},
  142. </if>
  143. <if test="item.operatingTempTag != null">
  144. operating_temp_tag_ = #{item.operatingTempTag},
  145. </if>
  146. <if test="item.teacherId != null">
  147. teacher_id_=#{item.teacherId},
  148. </if>
  149. <if test="item.updateTime != null">
  150. update_time_ = #{item.updateTime},
  151. </if>
  152. <if test="item.updateTime == null">
  153. update_time_ = NOW()
  154. </if>
  155. </set>
  156. WHERE user_id_ = #{item.userId}
  157. </foreach>
  158. </update>
  159. <update id="updateStudentServiceOrOperatingTag">
  160. UPDATE student
  161. <set>
  162. <if test="serviceTag != null">
  163. service_tag_ = #{serviceTag},
  164. </if>
  165. <if test="operatingTag != null">
  166. operating_tag_ = #{operatingTag},
  167. </if>
  168. update_time_ = NOW()
  169. </set>
  170. WHERE
  171. <if test="studentId!=null">
  172. user_id_ = #{studentId}
  173. </if>
  174. <if test="studentIds!=null and studentIds.size()>0">
  175. user_id_ IN
  176. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  177. #{studentId}
  178. </foreach>
  179. </if>
  180. </update>
  181. <update id="updateStudentServiceTag">
  182. UPDATE student
  183. <set>
  184. <if test="serviceTag != null">
  185. service_tag_ = #{serviceTag},
  186. </if>
  187. update_time_ = NOW()
  188. </set>
  189. WHERE
  190. service_tag_=0
  191. <if test="studentId!=null">
  192. AND user_id_ = #{studentId}
  193. </if>
  194. <if test="studentIds!=null and studentIds.size()>0">
  195. AND user_id_ IN
  196. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  197. #{studentId}
  198. </foreach>
  199. </if>
  200. </update>
  201. <resultMap id="student4operating" type="com.ym.mec.biz.dal.dto.Student4operating">
  202. <result column="organ_name_" property="organName"/>
  203. <result column="organ_id_" property="organId"/>
  204. <result column="student_name_" property="studentName"/>
  205. <result column="student_id_" property="studentId"/>
  206. <result column="teacher_id_" property="teacherId"/>
  207. <result column="teacher_name_" property="teacherName"/>
  208. <result column="operating_tag_" property="operatingTag"/>
  209. <result column="vip_times_" property="vipTimes"/>
  210. <result column="free_practice_times_" property="freePracticeTimes"/>
  211. <result column="buy_practice_times_" property="buyPracticeTimes"/>
  212. <result column="music_netWork_times_" property="musicNetWorkTimes"/>
  213. <result column="student_num_" property="studentNum"/>
  214. </resultMap>
  215. <select id="getOperatingStudents" resultMap="student4operating">
  216. SELECT su.organ_id_,
  217. o.name_ organ_name_,
  218. su.username_ student_name_,
  219. s.user_id_ student_id_,
  220. tsu.id_ teacher_id_,
  221. tsu.real_name_ teacher_name_,
  222. s.operating_tag_,
  223. a.vip_times_,
  224. a.buy_practice_times_,
  225. a.music_netWork_times_,
  226. p.free_practice_times_
  227. FROM student s
  228. LEFT JOIN sys_user su ON s.user_id_ = su.id_
  229. LEFT JOIN sys_user tsu ON tsu.id_ = s.teacher_id_
  230. LEFT JOIN organization o ON o.id_ = su.organ_id_
  231. LEFT JOIN (
  232. SELECT cssp.user_id_,
  233. SUM(case when (cs.group_type_ = 'VIP' AND cs.teach_mode_='ONLINE') then 1 ELSE 0 END) vip_times_,
  234. SUM(case when (pg.type_='CHARGE') then 1 ELSE 0 END) buy_practice_times_,
  235. SUM(case when (cs.type_='MUSIC_NETWORK' OR cs.type_='HIGH_ONLINE') then 1 ELSE 0 END) music_netWork_times_
  236. FROM course_schedule_student_payment cssp
  237. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  238. LEFT JOIN practice_group pg ON pg.`id_` = cs.`music_group_id_` AND cs.`group_type_` = 'PRACTICE'
  239. WHERE cs.status_ IN ('NOT_START','UNDERWAY') AND (cs.is_lock_ IS NULL OR cs.is_lock_=0) AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
  240. GROUP BY cssp.user_id_
  241. ) a on a.user_id_ = s.user_id_
  242. LEFT JOIN (
  243. SELECT student_id_, count(id_) free_practice_times_
  244. FROM practice_group
  245. WHERE type_='FREE' AND group_status_ IN ('NORMAL', 'FINISH')
  246. GROUP BY student_id_
  247. ) p ON p.student_id_ = s.user_id_
  248. <include refid="student4OperatingQueryCondition"/>
  249. ORDER BY s.user_id_
  250. <include refid="global.limit"/>
  251. </select>
  252. <select id="countOperatingStudents" resultType="int">
  253. SELECT COUNT(s.user_id_) FROM student s
  254. LEFT JOIN sys_user su ON s.user_id_ = su.id_
  255. LEFT JOIN sys_user tsu ON tsu.id_ = s.teacher_id_
  256. LEFT JOIN (
  257. SELECT cssp.user_id_,
  258. SUM(case when (cs.group_type_ = 'VIP' AND cs.teach_mode_='ONLINE') then 1 ELSE 0 END) vip_times_,
  259. SUM(case when (pg.type_='CHARGE') then 1 ELSE 0 END) buy_practice_times_,
  260. SUM(case when (cs.type_='MUSIC_NETWORK' OR cs.type_='HIGH_ONLINE') then 1 ELSE 0 END) music_netWork_times_
  261. FROM course_schedule_student_payment cssp
  262. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  263. LEFT JOIN practice_group pg ON pg.`id_` = cs.`music_group_id_` AND cs.`group_type_` = 'PRACTICE'
  264. WHERE cs.status_ IN ('NOT_START','UNDERWAY') AND (cs.is_lock_ IS NULL OR cs.is_lock_=0) AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
  265. GROUP BY cssp.user_id_
  266. ) a on a.user_id_ = s.user_id_
  267. LEFT JOIN (
  268. SELECT student_id_, count(id_) free_practice_times_
  269. FROM practice_group
  270. WHERE type_='FREE' AND group_status_ IN ('NORMAL', 'FINISH')
  271. GROUP BY student_id_
  272. ) p ON p.student_id_ = s.user_id_
  273. <include refid="student4OperatingQueryCondition"/>
  274. </select>
  275. <sql id="student4OperatingQueryCondition">
  276. <where>
  277. su.user_type_ LIKE '%STUDENT%'
  278. <if test="search != null and search != ''">
  279. AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_
  280. LIKE CONCAT('%',#{search},'%'))
  281. </if>
  282. <if test="organId != null and organId != ''">
  283. AND FIND_IN_SET(su.organ_id_,#{organId})
  284. </if>
  285. <if test="teacherId!=null">
  286. AND s.teacher_id_ = #{teacherId}
  287. </if>
  288. <if test="operatingTag !=null">
  289. AND s.operating_tag_ = #{operatingTag}
  290. </if>
  291. <if test='hasVip != null and hasVip=="1"'>
  292. AND a.vip_times_ >=1
  293. </if>
  294. <if test='hasVip != null and hasVip=="0"'>
  295. AND (a.vip_times_ =0 OR a.vip_times_ IS NULL)
  296. </if>
  297. <if test='hasFreePractice != null and hasFreePractice=="1"'>
  298. AND p.free_practice_times_ >=1
  299. </if>
  300. <if test='hasFreePractice != null and hasFreePractice=="0"'>
  301. AND (p.free_practice_times_ =0 OR p.free_practice_times_ IS NULL)
  302. </if>
  303. <if test='hasBuyPractice != null and hasBuyPractice=="1"'>
  304. AND a.buy_practice_times_ >=1
  305. </if>
  306. <if test='hasBuyPractice != null and hasBuyPractice=="0"'>
  307. AND (a.buy_practice_times_ =0 OR a.buy_practice_times_ IS NULL)
  308. </if>
  309. <if test='hasMusicNetWork != null and hasMusicNetWork=="1"'>
  310. AND a.music_netWork_times_ >=1
  311. </if>
  312. <if test='hasMusicNetWork != null and hasMusicNetWork=="0"'>
  313. AND (a.music_netWork_times_ =0 OR a.music_netWork_times_ IS NULL)
  314. </if>
  315. </where>
  316. </sql>
  317. <select id="getTeacherOperatingStudentsNum" resultType="java.util.Map">
  318. select teacher_id_ 'key', count(*) 'value'
  319. FROM student
  320. WHERE FIND_IN_SET(teacher_id_, #{teacherIds})
  321. AND operating_tag_ = 1
  322. GROUP BY teacher_id_
  323. </select>
  324. <select id="getBuyNums" resultType="java.util.Map">
  325. SELECT s.teacher_id_ 'key', COUNT(DISTINCT cssp.user_id_) 'value'
  326. FROM course_schedule_student_payment cssp
  327. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_ AND cs.teach_mode_ = 'ONLINE'
  328. LEFT JOIN student s ON s.user_id_ = cssp.user_id_
  329. <if test="groupType != null and groupType==@com.ym.mec.biz.dal.enums.GroupType@PRACTICE">
  330. LEFT JOIN practice_group pg ON cssp.music_group_id_ = pg.id_ AND cssp.group_type_ = 'PRACTICE'
  331. </if>
  332. WHERE FIND_IN_SET(s.teacher_id_, #{teacherIds})
  333. AND cs.status_ IN ('NOT_START', 'UNDERWAY')
  334. AND (cs.is_lock_ IS NULL OR cs.is_lock_ = 0)
  335. <if test="groupType != null">
  336. AND cs.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  337. </if>
  338. <if test="groupType != null and groupType==@com.ym.mec.biz.dal.enums.GroupType@PRACTICE">
  339. AND pg.group_status_ IN ('NORMAL', 'FINISH')
  340. AND pg.buy_months_ >= 1
  341. </if>
  342. GROUP BY s.teacher_id_
  343. </select>
  344. <select id="getPracticeAndVipNums" resultType="java.util.Map">
  345. SELECT s.teacher_id_ 'key', COUNT(DISTINCT pg.student_id_) 'value'
  346. FROM practice_group pg
  347. LEFT JOIN student s on s.user_id_ = pg.student_id_
  348. LEFT JOIN course_schedule_student_payment vcssp
  349. ON vcssp.user_id_ = pg.student_id_ AND vcssp.group_type_ = 'VIP'
  350. LEFT JOIN course_schedule_student_payment pcssp
  351. ON pcssp.user_id_ = pg.student_id_ AND pcssp.group_type_ = 'PRACTICE'
  352. LEFT JOIN course_schedule vcs ON vcs.id_ = vcssp.course_schedule_id_ AND vcs.teach_mode_ = 'ONLINE'
  353. LEFT JOIN course_schedule pcs ON pcs.id_ = pcssp.course_schedule_id_
  354. WHERE FIND_IN_SET(s.teacher_id_, #{teacherIds})
  355. AND pg.group_status_ IN ('NORMAL', 'FINISH')
  356. AND vcs.status_ IN ('NOT_START', 'UNDERWAY')
  357. AND pcs.status_ IN ('NOT_START', 'UNDERWAY')
  358. AND (vcs.is_lock_ IS NULL OR vcs.is_lock_ = 0)
  359. AND (pcs.is_lock_ IS NULL OR pcs.is_lock_ = 0)
  360. AND pg.buy_months_ >= 1
  361. GROUP BY s.teacher_id_
  362. </select>
  363. <select id="getServiceStudents" resultMap="Student">
  364. SELECT su.id_ user_id_,s.teacher_id_ FROM sys_user su
  365. LEFT JOIN student s ON s.user_id_=su.id_
  366. WHERE s.service_tag_=1 AND FIND_IN_SET('STUDENT', su.user_type_)
  367. </select>
  368. <resultMap id="StudentServeDto" type="com.ym.mec.biz.dal.dto.StudentServeDto" extends="Student">
  369. <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  370. <result column="teach_mode_" property="teachMode" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  371. <result property="courseStartTime" column="course_start_time_"/>
  372. </resultMap>
  373. <select id="getBeServiceStudents" resultMap="StudentServeDto">
  374. SELECT
  375. s.user_id_,
  376. s.teacher_id_,
  377. cs.group_type_,
  378. cs.teach_mode_,
  379. IF(CONCAT( cs.class_date_, ' ', cs.end_class_time_ )&lt;NOW() AND (sa.status_ != 'NORMAL' OR sa.status_ IS NULL), NULL, cs.class_date_) course_start_time_
  380. FROM
  381. student s
  382. LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = s.user_id_
  383. LEFT JOIN student_attendance sa ON cssp.course_schedule_id_=sa.course_schedule_id_ AND sa.user_id_=cssp.user_id_
  384. LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  385. AND cs.group_type_ IN ('VIP', 'PRACTICE')
  386. AND CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) > #{monday}
  387. WHERE
  388. s.service_tag_ = 1
  389. </select>
  390. </mapper>