<?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.FloodKnowledgeBaseMapper">
    
    <resultMap type="FloodKnowledgeBase" id="FloodKnowledgeBaseResult">
        <result property="knowledgeId"      column="knowledge_id"      />
        <result property="knowledgeName"    column="knowledge_name"    />
        <result property="knowledgeDesc"    column="knowledge_desc"    />
        <result property="fileCount"       column="file_count"        />
        <result property="status"          column="status"            />
        <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="remark"          column="remark"           />
    </resultMap>

    <sql id="selectFloodKnowledgeBaseVo">
        select knowledge_id, knowledge_name, knowledge_desc, file_count, status, create_by, create_time, update_by, update_time, remark 
        from flood_knowledge_base
    </sql>

    <select id="selectFloodKnowledgeBaseList" parameterType="FloodKnowledgeBase" resultMap="FloodKnowledgeBaseResult">
        <include refid="selectFloodKnowledgeBaseVo"/>
        <where>  
            <if test="knowledgeName != null and knowledgeName != ''">
                and knowledge_name like concat('%', #{knowledgeName}, '%')
            </if>
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectFloodKnowledgeBaseByKnowledgeId" parameterType="Long" resultMap="FloodKnowledgeBaseResult">
        <include refid="selectFloodKnowledgeBaseVo"/>
        where knowledge_id = #{knowledgeId}
    </select>

    <select id="selectFloodKnowledgeBaseByKnowledgeName" parameterType="String" resultMap="FloodKnowledgeBaseResult">
        <include refid="selectFloodKnowledgeBaseVo"/>
        where knowledge_name = #{knowledgeName}
    </select>
        
    <insert id="insertFloodKnowledgeBase" parameterType="FloodKnowledgeBase" useGeneratedKeys="true" keyProperty="knowledgeId">
        insert into flood_knowledge_base
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="knowledgeName != null and knowledgeName != ''">knowledge_name,</if>
            <if test="knowledgeDesc != null">knowledge_desc,</if>
            <if test="fileCount != null">file_count,</if>
            <if test="status != null">status,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="knowledgeName != null and knowledgeName != ''">#{knowledgeName},</if>
            <if test="knowledgeDesc != null">#{knowledgeDesc},</if>
            <if test="fileCount != null">#{fileCount},</if>
            <if test="status != null">#{status},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateFloodKnowledgeBase" parameterType="FloodKnowledgeBase">
        update flood_knowledge_base
        <trim prefix="SET" suffixOverrides=",">
            <if test="knowledgeName != null and knowledgeName != ''">knowledge_name = #{knowledgeName},</if>
            <if test="knowledgeDesc != null">knowledge_desc = #{knowledgeDesc},</if>
            <if test="fileCount != null">file_count = #{fileCount},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where knowledge_id = #{knowledgeId}
    </update>

    <delete id="deleteFloodKnowledgeBaseByKnowledgeId" parameterType="Long">
        delete from flood_knowledge_base where knowledge_id = #{knowledgeId}
    </delete>

    <delete id="deleteFloodKnowledgeBaseByKnowledgeIds" parameterType="String">
        delete from flood_knowledge_base where knowledge_id in 
        <foreach item="knowledgeId" collection="array" open="(" separator="," close=")">
            #{knowledgeId}
        </foreach>
    </delete>

    <select id="countFloodKnowledgeBase" resultType="int">
        select count(*) from flood_knowledge_base where status = '0'
    </select>
</mapper>
