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

    <resultMap type="com.ym.mec.biz.dal.entity.StudentPauseInfo" id="StudentPauseInfo">
        <result column="id_" property="id"/>
        <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="music_group_id_" property="musicGroupId"/>
        <result column="class_group_id_" property="classGroupId"/>
        <result column="user_id_" property="userId"/>
        <result column="courses_json_" property="coursesJson"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time_" property="updateTime"/>
        <result column="del_flag_" property="delFlag"/>
        <result column="surplus_course_num" property="surplusCourseNum"/>
        <result column="tenant_id_" property="tenantId"/>
    </resultMap>

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

    <!-- 全查询 -->
    <select id="findAll" resultMap="StudentPauseInfo">
		SELECT * FROM student_pause_info WHERE del_flag_ = 0 where tenant_id_ = #{tenantId} ORDER BY id_
	</select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentPauseInfo" useGeneratedKeys="true"
            keyColumn="id"
            keyProperty="id">
        INSERT INTO student_pause_info (group_type_,music_group_id_,class_group_id_,user_id_,courses_json_,create_time_,update_time_,surplus_course_num,tenant_id_)
        VALUES(#{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{musicGroupId},#{classGroupId},#{userId},#{coursesJson},now(),now(),#{surplusCourseNum},#{tenantId})
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentPauseInfo">
        UPDATE student_pause_info
        <set>
            <if test="delFlag != null">
                group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="musicGroupId != null">
                music_group_id_ = #{musicGroupId},
            </if>
            <if test="classGroupId != null">
                class_group_id_ = #{classGroupId},
            </if>
            <if test="userId != null">
                user_id_ = #{userId},
            </if>
            <if test="coursesJson != null">
                courses_json_ = #{coursesJson},
            </if>
            <if test="delFlag != null">
                del_flag_ = #{delFlag},
            </if>
            <if test="surplusCourseNum != null">
                surplus_course_num = #{surplusCourseNum},
            </if>
            update_time_ = NOW()
        </set>
        WHERE id_ = #{id} and tenant_id_ = #{tenantId}
    </update>

    <!-- 根据主键删除一条记录 -->
    <delete id="delete">
		DELETE FROM student_pause_info WHERE id_ = #{id}
	</delete>
    <update id="deleteUserPauseInfoWithGroup">
        UPDATE student_pause_info SET del_flag_ = 1
        WHERE
            group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
            AND music_group_id_ = #{groupId}
            AND user_id_ = #{userId}
    </update>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="StudentPauseInfo" parameterType="map">
        SELECT * FROM student_pause_info where tenant_id_ = #{tenantId}
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM student_pause_info where tenant_id_ = #{tenantId}
	</select>
    <select id="findByGroupAndUser" resultMap="StudentPauseInfo">
        SELECT * FROM student_pause_info
        WHERE group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
            AND music_group_id_ = #{groupId}
            AND user_id_ = #{userId}
            AND del_flag_ = 0
    </select>
    <select id="findByGroup" resultMap="StudentPauseInfo">
        SELECT * FROM student_pause_info
        WHERE
          group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
            AND music_group_id_ = #{groupId}
            AND del_flag_ = 0
    </select>
</mapper>
