<?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.ClassGroupStudentMapperDao">

    <resultMap type="com.ym.mec.biz.dal.entity.ClassGroupStudentMapper" id="ClassGroupStudentMapper">
        <result column="id_" property="id"/>
        <result column="class_group_id_" property="classGroupId"/>
        <result column="user_id_" property="userId"/>
        <result column="create_time_" property="createTime"/>
        <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
    </resultMap>

    <!-- 根据主键查询一条记录 -->
    <select id="get" resultMap="ClassGroupStudentMapper">
		SELECT * FROM class_group_student_mapper WHERE id_ = #{id} 
	</select>

    <!-- 全查询 -->
    <select id="findAll" resultMap="ClassGroupStudentMapper">
		SELECT * FROM class_group_student_mapper ORDER BY id_
	</select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ClassGroupStudentMapper" useGeneratedKeys="true"
            keyColumn="id" keyProperty="id">
        INSERT INTO class_group_student_mapper (id_,class_group_id_,user_id_,status_,create_time_)
        VALUES(#{id},#{classGroupId},#{userId},#{status},now())
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.ClassGroupStudentMapper">
        UPDATE class_group_student_mapper
        <set>
            <if test="userId != null">
                user_id_ = #{userId},
            </if>
            <if test="classGroupId != null">
                class_group_id_ = #{classGroupId},
            </if>
            <if test="status != null">
                status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
        </set>
        WHERE id_ = #{id}
    </update>

    <!-- 根据主键删除一条记录 -->
    <delete id="delete">
		DELETE FROM class_group_student_mapper WHERE id_ = #{id} 
	</delete>
    <delete id="deleteByClassId">
        DELETE FROM class_group_student_mapper WHERE class_group_id_ = #{classGroupId}
    </delete>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="ClassGroupStudentMapper" parameterType="map">
        SELECT * FROM class_group_student_mapper ORDER BY id_
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM class_group_student_mapper
	</select>

    <!-- 班级学生批量插入 -->
    <insert id="classGroupStudentsInsert" parameterType="java.util.List">
        INSERT INTO class_group_student_mapper (class_group_id_,user_id_,status_,create_time_)
        VALUES
        <foreach collection="classGroupStudentMapperList" item="item" index="index" separator=",">
            (#{item.classGroupId},#{item.userId},#{item.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},now())
        </foreach>
    </insert>
    
    <select id="query" resultMap="ClassGroupStudentMapper" parameterType="map">
		SELECT * FROM class_group_student_mapper where class_group_id_ = #{classGroupId} and user_id_ = #{userId}
	</select>
	
    <delete id="deleteStudentByMusicGroupId" parameterType="map">
        DELETE FROM class_group_student_mapper WHERE class_group_id_ in (select id_ from class_group where music_group_id_ = #{musicGroupId}) and user_id_ = #{userId}
    </delete>

    <delete id="deleteStudentByClassGroupId">
        DELETE FROM class_group_student_mapper WHERE class_group_id_=#{classGroupId} AND user_id_=#{userId}
    </delete>
</mapper>
