<?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.CloudTeacherDao">
    <resultMap id="CloudTeacher" type="com.ym.mec.biz.dal.entity.CloudTeacher">
        <!--@mbg.generated-->
        <!--@Table cloud_teacher-->
        <id column="id_" property="id"/>
        <result column="student_id_" property="studentId"/>
        <result column="level_" property="level"/>
        <result column="start_time_" property="startTime"/>
        <result column="end_time_" property="endTime"/>
        <result column="version_" property="version"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time_" property="updateTime"/>
    </resultMap>

    <select id="get" parameterType="java.lang.Integer" resultMap="CloudTeacher">
        <!--@mbg.generated-->
        select * from cloud_teacher
        where id_ = #{id}
    </select>
    <delete id="delete" parameterType="java.lang.Integer">
        <!--@mbg.generated-->
        delete from cloud_teacher
        where id_ = #{id}
    </delete>
    <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.CloudTeacher"
            useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into cloud_teacher (student_id_, level_, start_time_, end_time_, version_, create_time_,
        update_time_)
        values (#{studentId}, #{level}, #{startTime}, #{endTime}, #{version}, NOW(),NOW())
    </insert>
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.CloudTeacher">
        <!--@mbg.generated-->
        update cloud_teacher
        <set>
            <if test="studentId != null">
                student_id_ = #{studentId},
            </if>
            <if test="level != null">
                level_ = #{level},
            </if>
            <if test="startTime != null">
                start_time_ = #{startTime},
            </if>
            <if test="endTime != null">
                end_time_ = #{endTime},
            </if>
            <if test="createTime != null">
                create_time_ = #{createTime},
            </if>
            update_time_ = NOW(),
            version_ = version_+1
        </set>
        where id_ = #{id} AND version_ = #{version}
    </update>

    <!-- 全查询 -->
    <select id="findAll" resultMap="CloudTeacher">
        SELECT *
        FROM cloud_teacher
    </select>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="CloudTeacher" parameterType="map">
        SELECT * FROM cloud_teacher
        <include refid="global.limit"/>
    </select>

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

    <select id="getByStudentId" resultMap="CloudTeacher">
        SELECT *
        FROM cloud_teacher
        WHERE student_id_ = #{studentId}
    </select>
</mapper>