| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <!--
- 这个文件是自动生成的。
- 不要修改此文件。所有改动将在下次重新自动生成时丢失。
- -->
- <mapper namespace="com.ym.mec.biz.dal.dao.StudentDao">
- <resultMap type="com.ym.mec.biz.dal.entity.Student" id="Student">
- <result column="user_id_" property="userId"/>
- <result column="subject_id_list_" property="subjectIdList"/>
- <result column="service_tag_" property="serviceTag"/>
- <result column="operating_tag_" property="operatingTag"/>
- <result column="operating_temp_tag_" property="operatingTempTag"/>
- <result column="teacher_id_" property="teacherId"/>
- <result column="create_time_" property="createTime"/>
- <result column="update_time_" property="updateTime"/>
- </resultMap>
- <!-- 根据主键查询一条记录 -->
- <select id="get" resultMap="Student">
- SELECT *
- FROM student
- WHERE user_id_ = #{id}
- </select>
- <!-- 全查询 -->
- <select id="findAll" resultMap="Student">
- SELECT *
- FROM student
- </select>
- <select id="lockUser" resultType="int" useCache="false" flushCache="true">
- SELECT id_
- FROM sys_user
- WHERE id_ = #{userId} FOR
- UPDATE
- </select>
- <!-- 向数据库增加一条记录 -->
- <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Student" useGeneratedKeys="true" keyColumn="id"
- keyProperty="id">
- INSERT INTO student (user_id_,subject_id_list_,
- <if test="serviceTag != null">
- service_tag_,
- </if>
- <if test="operatingTag != null">
- operating_tag_,
- </if>
- <if test="operatingTempTag != null">
- operating_temp_tag_,
- </if>
- teacher_id_,create_time_,update_time_)
- VALUES
- (#{userId},#{subjectIdList},
- <if test="serviceTag != null">
- #{serviceTag},
- </if>
- <if test="operatingTag != null">
- #{operatingTag},
- </if>
- #{teacherId},NOW(),NOW())
- </insert>
- <update id="update" parameterType="com.ym.mec.biz.dal.entity.Student">
- UPDATE student
- <set>
- <if test="subjectIdList != null">
- subject_id_list_ = #{subjectIdList},
- </if>
- <if test="serviceTag != null">
- service_tag_ = #{serviceTag},
- </if>
- <if test="operatingTag != null">
- operating_tag_ = #{operatingTag},
- </if>
- <if test="operatingTempTag != null">
- operating_temp_tag_ = #{operatingTempTag},
- </if>
- <if test="teacherId != null">
- teacher_id_=#{teacherId},
- </if>
- <if test="updateTime != null">
- update_time_ = #{updateTime},
- </if>
- <if test="updateTime == null">
- update_time_ = NOW()
- </if>
- </set>
- WHERE user_id_ = #{userId}
- </update>
- <!-- 分页查询 -->
- <select id="queryPage" resultMap="Student" parameterType="map">
- SELECT * FROM student
- <include refid="global.limit"/>
- </select>
- <!-- 查询当前表的总记录数 -->
- <select id="queryCount" resultType="int">
- SELECT COUNT(*)
- FROM student
- </select>
- <select id="findStudents" resultMap="com.ym.mec.biz.dal.dao.TeacherDao.SysUser">
- SELECT id_, username_, phone_,avatar_ FROM sys_user
- <include refid="studentQueryCondition"/>
- ORDER BY id_
- <include refid="global.limit"/>
- </select>
- <select id="countStudents" resultType="int">
- SELECT COUNT(id_) FROM sys_user
- <include refid="studentQueryCondition"/>
- </select>
- <sql id="studentQueryCondition">
- <where>
- <if test="organIdList!=null">
- organ_id_ IN
- <foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
- #{organId}
- </foreach>
- </if>
- <if test="search!=null">
- AND (username_ LIKE CONCAT('%', #{search}, '%') OR phone_ LIKE CONCAT('%', #{search}, '%'))
- </if>
- AND FIND_IN_SET("STUDENT", user_type_)
- </where>
- </sql>
- <select id="queryByOperatingTempTag" resultMap="Student">
- SELECT *
- FROM student
- WHERE operating_temp_tag_ = #{operatingTempTag}
- </select>
- <update id="batchUpdate" parameterType="java.util.List">
- <foreach collection="studentList" item="item" index="index" open="" close="" separator=";">
- UPDATE student
- <set>
- <if test="item.subjectIdList != null">
- subject_id_list_ = #{item.subjectIdList},
- </if>
- <if test="item.serviceTag != null">
- service_tag_ = #{item.serviceTag},
- </if>
- <if test="item.operatingTag != null">
- operating_tag_ = #{item.operatingTag},
- </if>
- <if test="item.operatingTempTag != null">
- operating_temp_tag_ = #{item.operatingTempTag},
- </if>
- <if test="item.teacherId != null">
- teacher_id_=#{item.teacherId},
- </if>
- <if test="item.updateTime != null">
- update_time_ = #{item.updateTime},
- </if>
- <if test="item.updateTime == null">
- update_time_ = NOW()
- </if>
- </set>
- WHERE user_id_ = #{item.userId}
- </foreach>
- </update>
- <resultMap id="student4operating" type="com.ym.mec.biz.dal.dto.Student4operating">
- <result column="organ_name_" property="organName"/>
- <result column="organ_id_" property="organId"/>
- <result column="student_name_" property="studentName"/>
- <result column="student_id_" property="studentId"/>
- <result column="teacher_id_" property="teacherId"/>
- <result column="teacher_name_" property="teacherName"/>
- <result column="operating_tag_" property="operatingTag"/>
- <result column="vip_times_" property="vipTimes"/>
- <result column="free_practice_times_" property="freePracticeTimes"/>
- <result column="buy_practice_times_" property="buyPracticeTimes"/>
- <result column="student_num_" property="studentNum"/>
- </resultMap>
- <select id="getOperatingStudents" resultMap="student4operating">
- SELECT su.organ_id_,
- o.name_ organ_name_,
- su.username_ student_name_,
- s.user_id_ student_id_,
- tsu.id_ teacher_id_,
- tsu.real_name_ teacher_name_,
- s.operating_tag_,
- a.vip_times_,
- a.buy_practice_times_,
- p.free_practice_times_
- FROM student s
- LEFT JOIN sys_user su ON s.user_id_ = su.id_
- LEFT JOIN sys_user tsu ON tsu.id_ = s.teacher_id_
- LEFT JOIN organization o ON o.id_ = su.organ_id_
- LEFT JOIN (
- SELECT cssp.user_id_,
- SUM(case when (cs.group_type_ = 'VIP' AND cs.teach_mode_='ONLINE') then 1 ELSE 0 END) vip_times_,
- SUM(case when (pg.type_='FREE') then 1 ELSE 0 END) buy_practice_times_
- FROM course_schedule_student_payment cssp
- LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
- LEFT JOIN practice_group pg ON pg.`id_` = cs.`music_group_id_` AND cs.`group_type_` = 'PRACTICE'
- WHERE cs.status_ IN ('NOT_START','UNDERWAY') AND (cs.is_lock_ IS NULL OR cs.is_lock_=0)
- GROUP BY cssp.user_id_
- ) a on a.user_id_ = s.user_id_
- LEFT JOIN (
- SELECT student_id_, count(id_) free_practice_times_
- FROM practice_group
- WHERE type_='FREE'
- GROUP BY student_id_
- ) p ON p.student_id_ = s.user_id_
- <include refid="student4OperatingQueryCondition"/>
- ORDER BY s.user_id_
- <include refid="global.limit"/>
- </select>
- <select id="countOperatingStudents" resultType="int">
- SELECT COUNT(s.user_id_) FROM student s
- LEFT JOIN sys_user su ON s.user_id_ = su.id_
- LEFT JOIN sys_user tsu ON tsu.id_ = s.teacher_id_
- LEFT JOIN (
- SELECT cssp.user_id_,
- SUM(case when (cs.group_type_ = 'VIP' AND cs.teach_mode_='ONLINE') then 1 ELSE 0 END) vip_times_,
- SUM(case when (pg.buy_months_ > 0) then 1 ELSE 0 END) buy_practice_times_
- FROM course_schedule_student_payment cssp
- LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
- LEFT JOIN practice_group pg ON pg.`id_` = cs.`music_group_id_` AND cs.`group_type_` = 'PRACTICE'
- WHERE cs.status_ IN ('NOT_START','UNDERWAY') AND (cs.is_lock_ IS NULL OR cs.is_lock_=0)
- GROUP BY cssp.user_id_
- ) a on a.user_id_ = s.user_id_
- LEFT JOIN (
- SELECT student_id_, count(id_) free_practice_times_
- FROM practice_group
- WHERE type_='FREE'
- GROUP BY student_id_
- ) p ON p.student_id_ = s.user_id_
- <include refid="student4OperatingQueryCondition"/>
- </select>
- <sql id="student4OperatingQueryCondition">
- <where>
- su.user_type_ LIKE '%STUDENT%'
- <if test="search != null and search != ''">
- AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_
- LIKE CONCAT('%',#{search},'%'))
- </if>
- <if test="organId != null and organId != ''">
- AND FIND_IN_SET(su.organ_id_,#{organId})
- </if>
- <if test="teacherId!=null">
- AND s.teacher_id_ = #{teacherId}
- </if>
- <if test="operatingTag !=null">
- AND s.operating_tag_ = #{operatingTag}
- </if>
- <if test='hasVip != null and hasVip=="1"'>
- AND a.vip_times_ >=1
- </if>
- <if test='hasVip != null and hasVip=="0"'>
- AND (a.vip_times_ =0 OR a.vip_times_ IS NULL)
- </if>
- <if test='hasFreePractice != null and hasFreePractice=="1"'>
- AND p.free_practice_times_ >=1
- </if>
- <if test='hasFreePractice != null and hasFreePractice=="0"'>
- AND (p.free_practice_times_ =0 OR p.free_practice_times_ IS NULL)
- </if>
- <if test='hasBuyPractice != null and hasBuyPractice=="1"'>
- AND a.buy_practice_times_ >=1
- </if>
- <if test='hasBuyPractice != null and hasBuyPractice=="0"'>
- AND (a.buy_practice_times_ =0 OR a.buy_practice_times_ IS NULL)
- </if>
- </where>
- </sql>
- <select id="getTeacherOperatingStudentsNum" resultType="java.util.Map">
- select teacher_id_ 'key', count(*) 'value'
- FROM student
- WHERE FIND_IN_SET(teacher_id_, #{teacherIds})
- AND operating_tag_ = 1
- GROUP BY teacher_id_
- </select>
- <select id="getBuyNums" resultType="java.util.Map">
- SELECT s.teacher_id_ 'key', COUNT(DISTINCT cssp.user_id_) 'value'
- FROM course_schedule_student_payment cssp
- LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_ AND cs.teach_mode_ = 'ONLINE'
- LEFT JOIN student s ON s.user_id_ = cssp.user_id_
- <if test="groupType != null and groupType==@com.ym.mec.biz.dal.enums.GroupType@PRACTICE">
- LEFT JOIN practice_group pg ON cssp.music_group_id_ = pg.id_ AND cssp.group_type_ = 'PRACTICE'
- </if>
- WHERE FIND_IN_SET(s.teacher_id_, #{teacherIds})
- AND cs.status_ IN ('NOT_START', 'UNDERWAY')
- AND (cs.is_lock_ IS NULL OR cs.is_lock_ = 0)
- <if test="groupType != null">
- AND cs.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
- </if>
- <if test="groupType != null and groupType==@com.ym.mec.biz.dal.enums.GroupType@PRACTICE">
- AND pg.group_status_ IN ('NORMAL', 'FINISH')
- AND pg.buy_months_ >= 1
- </if>
- GROUP BY s.teacher_id_
- </select>
- <select id="getPracticeAndVipNums" resultType="java.util.Map">
- SELECT s.teacher_id_ 'key', COUNT(DISTINCT pg.student_id_) 'value'
- FROM practice_group pg
- LEFT JOIN student s on s.user_id_ = pg.student_id_
- LEFT JOIN course_schedule_student_payment vcssp
- ON vcssp.user_id_ = pg.student_id_ AND vcssp.group_type_ = 'VIP'
- LEFT JOIN course_schedule_student_payment pcssp
- ON pcssp.user_id_ = pg.student_id_ AND pcssp.group_type_ = 'PRACTICE'
- LEFT JOIN course_schedule vcs ON vcs.id_ = vcssp.course_schedule_id_ AND vcs.teach_mode_ = 'ONLINE'
- LEFT JOIN course_schedule pcs ON pcs.id_ = pcssp.course_schedule_id_
- WHERE FIND_IN_SET(s.teacher_id_, #{teacherIds})
- AND pg.group_status_ IN ('NORMAL', 'FINISH')
- AND vcs.status_ IN ('NOT_START', 'UNDERWAY')
- AND pcs.status_ IN ('NOT_START', 'UNDERWAY')
- AND (vcs.is_lock_ IS NULL OR vcs.is_lock_ = 0)
- AND (pcs.is_lock_ IS NULL OR pcs.is_lock_ = 0)
- AND pg.buy_months_ >= 1
- GROUP BY s.teacher_id_
- </select>
- </mapper>
|