<?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.xunmei.core.edu.mapper.SysKnowledgeMapper">

    <resultMap type="com.xunmei.common.core.domain.edu.domain.SysKnowledge" id="SysKnowledgeResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleted" column="deleted"/>
    </resultMap>

    <sql id="selectSysKnowledgeVo">
        select id, name, create_by, create_time, update_by, update_time, deleted
        from sys_knowledge
    </sql>

    <select id="selectSysKnowledgeList" parameterType="com.xunmei.common.core.domain.edu.domain.SysKnowledge"
            resultMap="SysKnowledgeResult">
        <include refid="selectSysKnowledgeVo"/>
        <where>
            <if test="name != null  and name != ''">
                and name like concat('%', #{name}, '%')
            </if>
            <if test="deleted != null ">
                and deleted = #{deleted}
            </if>
        </where>
    </select>

    <select id="selectSysKnowledgeById" parameterType="Long"
            resultMap="SysKnowledgeResult">
        <include refid="selectSysKnowledgeVo"/>
        where id = #{id}
    </select>
    <select id="dataList" resultType="com.xunmei.common.core.domain.edu.domain.SysKnowledge">
        select id as id, `name` as name
        from sys_knowledge
        where deleted = 0
    </select>

    <insert id="insertSysKnowledge" parameterType="com.xunmei.common.core.domain.edu.domain.SysKnowledge" useGeneratedKeys="true"
            keyProperty="id">
        insert into sys_knowledge
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="deleted != null">deleted,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="deleted != null">#{deleted},
            </if>
        </trim>
    </insert>

    <update id="updateSysKnowledge" parameterType="com.xunmei.common.core.domain.edu.domain.SysKnowledge">
        update sys_knowledge
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name =
                #{name},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="deleted != null">deleted =
                #{deleted},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysKnowledgeById" parameterType="Long">
        delete
        from sys_knowledge
        where id = #{id}
    </delete>

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