<?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.ruoyi.learn.mapper.LearnPlanMapper">
    
    <resultMap type="LearnPlan" id="LearnPlanResult">
        <result property="id"    column="id"    />
        <result property="studentId"    column="studentId"    />
        <result property="videoTime"    column="video_time"    />
        <result property="questionCnt"    column="question_cnt"    />
        <result property="status"    column="status"    />
        <result property="beginTime"    column="begin_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="stats"    column="stats"    />
    </resultMap>

    <sql id="selectLearnPlanVo">
        select id, studentId, video_time, question_cnt, status, begin_time, create_time, stats from learn_plan
    </sql>

    <select id="selectLearnPlanList" parameterType="LearnPlan" resultMap="LearnPlanResult">
        <include refid="selectLearnPlanVo"/>
        <where>  
            <if test="studentId != null "> and studentId = #{studentId}</if>
            <if test="videoTime != null "> and video_time = #{videoTime}</if>
            <if test="questionCnt != null "> and question_cnt = #{questionCnt}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="beginTime != null "> and begin_time = #{beginTime}</if>
            <if test="stats != null  and stats != ''"> and stats = #{stats}</if>
        </where>
    </select>
    
    <select id="selectLearnPlanById" parameterType="String" resultMap="LearnPlanResult">
        <include refid="selectLearnPlanVo"/>
        where id = #{id}
    </select>

    <insert id="insertLearnPlan" parameterType="LearnPlan" useGeneratedKeys="true" keyProperty="id">
        insert into learn_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="studentId != null">studentId,</if>
            <if test="videoTime != null">video_time,</if>
            <if test="questionCnt != null">question_cnt,</if>
            <if test="status != null">status,</if>
            <if test="beginTime != null">begin_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="stats != null">stats,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="studentId != null">#{studentId},</if>
            <if test="videoTime != null">#{videoTime},</if>
            <if test="questionCnt != null">#{questionCnt},</if>
            <if test="status != null">#{status},</if>
            <if test="beginTime != null">#{beginTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="stats != null">#{stats},</if>
         </trim>
    </insert>

    <update id="updateLearnPlan" parameterType="LearnPlan">
        update learn_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="studentId != null">studentId = #{studentId},</if>
            <if test="videoTime != null">video_time = #{videoTime},</if>
            <if test="questionCnt != null">question_cnt = #{questionCnt},</if>
            <if test="status != null">status = #{status},</if>
            <if test="beginTime != null">begin_time = #{beginTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="stats != null">stats = #{stats},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLearnPlanById" parameterType="String">
        delete from learn_plan where id = #{id}
    </delete>

    <delete id="deleteLearnPlanByIds" parameterType="String">
        delete from learn_plan where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>