<?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.LearnKnowledgeTreeMapper">
    
    <resultMap type="LearnKnowledgeTree" id="LearnKnowledgeTreeResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="pid"    column="pid"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="subjectId"    column="subjectId"    />
        <result property="sort"    column="sort"    />
        <result property="level"    column="level"    />
        <result property="questionsCount"    column="questionsCount"    />
        <result property="locations"    column="locations"    />
        <result property="examineeTypes"    column="examineeTypes"    />
    </resultMap>

    <sql id="selectLearnKnowledgeTreeVo">
        select id, name, pid, ancestors, subjectId, sort, level, questionsCount, locations, examineeTypes from learn_knowledge_tree
    </sql>

    <select id="selectLearnKnowledgeTreeList" parameterType="LearnKnowledgeTree" resultMap="LearnKnowledgeTreeResult">
        <include refid="selectLearnKnowledgeTreeVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="subjectId != null "> and subjectId = #{subjectId}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="questionsCount != null "> and questionsCount = #{questionsCount}</if>
            <if test="locations != null  and locations != ''"> and locations = #{locations}</if>
            <if test="examineeTypes != null  and examineeTypes != ''"> and examineeTypes = #{examineeTypes}</if>
        </where>
    </select>
    
    <select id="selectLearnKnowledgeTreeById" parameterType="Long" resultMap="LearnKnowledgeTreeResult">
        <include refid="selectLearnKnowledgeTreeVo"/>
        where id = #{id}
    </select>

    <insert id="insertLearnKnowledgeTree" parameterType="LearnKnowledgeTree" useGeneratedKeys="true" keyProperty="id">
        insert into learn_knowledge_tree
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="pid != null">pid,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="subjectId != null">subjectId,</if>
            <if test="sort != null">sort,</if>
            <if test="level != null">level,</if>
            <if test="questionsCount != null">questionsCount,</if>
            <if test="locations != null">locations,</if>
            <if test="examineeTypes != null">examineeTypes,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="pid != null">#{pid},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="subjectId != null">#{subjectId},</if>
            <if test="sort != null">#{sort},</if>
            <if test="level != null">#{level},</if>
            <if test="questionsCount != null">#{questionsCount},</if>
            <if test="locations != null">#{locations},</if>
            <if test="examineeTypes != null">#{examineeTypes},</if>
         </trim>
    </insert>

    <update id="updateLearnKnowledgeTree" parameterType="LearnKnowledgeTree">
        update learn_knowledge_tree
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="pid != null">pid = #{pid},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="subjectId != null">subjectId = #{subjectId},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="level != null">level = #{level},</if>
            <if test="questionsCount != null">questionsCount = #{questionsCount},</if>
            <if test="locations != null">locations = #{locations},</if>
            <if test="examineeTypes != null">examineeTypes = #{examineeTypes},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLearnKnowledgeTreeById" parameterType="Long">
        delete from learn_knowledge_tree where id = #{id}
    </delete>

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