fix: 知识库文档管理搜索条件修改

This commit is contained in:
wenjinbo 2025-09-29 09:35:03 +08:00
parent 996bb9481a
commit e29ac67a91
2 changed files with 28 additions and 17 deletions

View File

@ -37,15 +37,21 @@
FROM t_dataset_files FROM t_dataset_files
WHERE dify_dataset_id = #{difyDatasetId} WHERE dify_dataset_id = #{difyDatasetId}
AND is_deleted = false AND is_deleted = false
<choose>
<when test="fileName != null and fileName != ''">
<!-- 当 fileName 不为空时,忽略 parentId 条件 -->
AND name ILIKE CONCAT('%', #{fileName}, '%')
</when>
<otherwise>
<!-- 当 fileName 为空时,应用 parentId 条件 -->
<if test="parentId != null"> <if test="parentId != null">
AND parent_id = #{parentId} AND parent_id = #{parentId}
</if> </if>
<if test="parentId == null"> <if test="parentId == null">
AND parent_id IS NULL AND parent_id IS NULL
</if> </if>
<if test="fileName != null and fileName != ''"> </otherwise>
AND name ILIKE CONCAT('%', #{fileName}, '%') </choose>
</if>
<if test="orderBy != null and orderBy != ''"> <if test="orderBy != null and orderBy != ''">
ORDER BY ORDER BY
CASE WHEN type = 'folder' THEN 0 ELSE 1 END, CASE WHEN type = 'folder' THEN 0 ELSE 1 END,
@ -64,6 +70,9 @@
</if> </if>
</select> </select>
<!-- 根据知识库id和parent_id 查询总数 --> <!-- 根据知识库id和parent_id 查询总数 -->
<select id="countByDatasetIdAndParentId" resultType="int"> <select id="countByDatasetIdAndParentId" resultType="int">
SELECT COUNT(*) SELECT COUNT(*)
@ -81,6 +90,8 @@
</if> </if>
</select> </select>
<!-- 根据知识库id和name查询 文件/文件夹 --> <!-- 根据知识库id和name查询 文件/文件夹 -->
<select id="selectByDatasetIdAndName" resultMap="TDatasetFilesResultMap"> <select id="selectByDatasetIdAndName" resultMap="TDatasetFilesResultMap">
SELECT <include refid="Base_Column_List"/> SELECT <include refid="Base_Column_List"/>