<?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.system.mapper.KnowledgeBaseMapper">
    
    <resultMap type="KnowledgeBase" id="KnowledgeBaseResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="issueType"    column="issue_type"    />
        <result property="solution"    column="solution"    />
        <result property="createTime"    column="create_time"    />
        <result property="creatBy"    column="creat_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectKnowledgeBaseVo">
        select id, title, issue_type, solution, create_time, creat_by, update_time, update_by from knowledge_base
    </sql>

    <select id="selectKnowledgeBaseList" parameterType="KnowledgeBase" resultMap="KnowledgeBaseResult">
        <include refid="selectKnowledgeBaseVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="issueType != null  and issueType != ''"> and issue_type = #{issueType}</if>
            <if test="solution != null  and solution != ''"> and solution like concat('%', #{solution}, '%')</if>
            <if test="creatBy != null  and creatBy != ''"> and creat_by = #{creatBy}</if>
        </where>
    </select>
    
    <select id="selectKnowledgeBaseById" parameterType="Long" resultMap="KnowledgeBaseResult">
        <include refid="selectKnowledgeBaseVo"/>
        where id = #{id}
    </select>

    <insert id="insertKnowledgeBase" parameterType="KnowledgeBase" useGeneratedKeys="true" keyProperty="id">
        insert into knowledge_base
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="issueType != null">issue_type,</if>
            <if test="solution != null">solution,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creatBy != null">creat_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="issueType != null">#{issueType},</if>
            <if test="solution != null">#{solution},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creatBy != null">#{creatBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateKnowledgeBase" parameterType="KnowledgeBase">
        update knowledge_base
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="issueType != null">issue_type = #{issueType},</if>
            <if test="solution != null">solution = #{solution},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creatBy != null">creat_by = #{creatBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKnowledgeBaseById" parameterType="Long">
        delete from knowledge_base where id = #{id}
    </delete>

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