<?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.web.work.mapper.KnowledgeMapper">
    
    <select id="selectList" resultType="com.ruoyi.web.work.domain.Knowledge">
        SELECT
        k.*,
        d.dept_name AS deptName
        FROM
        tb_knowledge k
        LEFT JOIN sys_dept d ON d.dept_id = k.dept_id
        WHERE 1=1
            <if test="userId != null "> and k.user_id = #{userId}</if>
            <if test="type != null  and type != ''"> and k.type = #{type}</if>
            <if test="title != null  and title != ''"> and k.title like concat('%', #{title}, '%')</if>
            <if test="dateBegin != null  and dateBegin != ''"> AND k.create_time BETWEEN #{dateBegin} AND #{dateEnd} + INTERVAL 1 DAY</if>
            <if test="deptId != null and deptId != 0">AND (k.dept_id = #{deptId} OR k.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))</if>
            <!-- 数据范围过滤 -->
            ${params.dataScope}
    </select>

    <select id="indexList" resultType="com.ruoyi.web.work.domain.Knowledge">
        SELECT id, title,type,create_time FROM tb_knowledge WHERE state=0 ORDER BY id DESC LIMIT 5
    </select>

</mapper>