增加分段预览功能,在知识库查看文件,可以看到其分段内容与信息

This commit is contained in:
moon 2025-09-18 18:01:25 +08:00
parent 2ae5f2f4ad
commit 6f60a25b5a
7 changed files with 414 additions and 198 deletions

View File

@ -0,0 +1,9 @@
import request from '@/utils/request'
export function getSegmentList(params: { datasetId: string; documentId: string }) {
return request({
url: '/brichat-service/documentSegment/selectSegments',
method: 'get',
params,
})
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
package com.bjtds.brichat.controller;
import com.bjtds.brichat.entity.dto.SegmentDto;
import com.bjtds.brichat.service.dify.DocumentSegmentService;
import com.bjtds.brichat.util.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Comparator;
import java.util.List;
@RestController
@Slf4j
@CrossOrigin(value = "*", maxAge = 3600)
@RequestMapping("/documentSegment")
public class DocumentSegmentController {
@Autowired
private DocumentSegmentService documentSegmentService;
@GetMapping("/selectSegments")
public ResultUtils SelectSegments(@RequestParam("documentId") String documentId, @RequestParam("datasetId") String datasetId) {
List<SegmentDto> segments = documentSegmentService.SelectSegments(documentId, datasetId);
segments.sort(Comparator.comparing(SegmentDto::getPosition));
return ResultUtils.success(segments);
}
}

View File

@ -0,0 +1,13 @@
package com.bjtds.brichat.mapper.postgresql;
import com.bjtds.brichat.entity.dto.SegmentDto;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface DifyDocumentSegmentMapper {
List<SegmentDto> SelectSegmentsByDocumentIdAndDatasetId(String documentId, String datasetId);
}

View File

@ -0,0 +1,10 @@
package com.bjtds.brichat.service.dify;
import com.bjtds.brichat.entity.dto.SegmentDto;
import java.util.List;
public interface DocumentSegmentService {
List<SegmentDto> SelectSegments(String documentId, String datasetId);
}

View File

@ -0,0 +1,22 @@
package com.bjtds.brichat.service.dify.impl;
import com.bjtds.brichat.entity.dto.SegmentDto;
import com.bjtds.brichat.mapper.postgresql.DifyDocumentSegmentMapper;
import com.bjtds.brichat.service.dify.DocumentSegmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
@Service
public class DocumentSegmentServiceImpl implements DocumentSegmentService {
@Autowired
private DifyDocumentSegmentMapper difyDocumentSegmentMapper;
@Override
public List<SegmentDto> SelectSegments(String documentId, String datasetId) {
return difyDocumentSegmentMapper.SelectSegmentsByDocumentIdAndDatasetId(documentId, datasetId);
}
}

View File

@ -0,0 +1,15 @@
<?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.bjtds.brichat.mapper.postgresql.DifyDocumentSegmentMapper">
<select id="SelectSegmentsByDocumentIdAndDatasetId" resultType="com.bjtds.brichat.entity.dto.SegmentDto">
select *
from document_segments
where
<if test="documentId != null">
document_id = CAST(#{documentId} as uuid) and
</if>
<if test="datasetId != null">
dataset_id = CAST(#{datasetId} as uuid)
</if>
</select>
</mapper>