|
@@ -1,10 +1,10 @@
|
|
|
package com.lingyue.document.repository;
|
|
package com.lingyue.document.repository;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
import com.lingyue.document.entity.DocumentBlock;
|
|
import com.lingyue.document.entity.DocumentBlock;
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
-import org.apache.ibatis.annotations.Select;
|
|
|
|
|
import org.apache.ibatis.annotations.Delete;
|
|
import org.apache.ibatis.annotations.Delete;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -12,6 +12,9 @@ import java.util.List;
|
|
|
/**
|
|
/**
|
|
|
* 文档块 Repository
|
|
* 文档块 Repository
|
|
|
*
|
|
*
|
|
|
|
|
+ * 注意:使用 default 方法代替 @Select 注解,确保 TypeHandler 正确工作。
|
|
|
|
|
+ * MyBatis-Plus 的 @Select 注解不会自动使用 autoResultMap,导致 JSONB 字段反序列化失败。
|
|
|
|
|
+ *
|
|
|
* @author lingyue
|
|
* @author lingyue
|
|
|
* @since 2026-01-21
|
|
* @since 2026-01-21
|
|
|
*/
|
|
*/
|
|
@@ -20,24 +23,36 @@ public interface DocumentBlockRepository extends BaseMapper<DocumentBlock> {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据文档ID查询所有块(按顺序)
|
|
* 根据文档ID查询所有块(按顺序)
|
|
|
|
|
+ * 使用 MyBatis-Plus 内置方法确保 TypeHandler 正确工作
|
|
|
*/
|
|
*/
|
|
|
- @Select("SELECT * FROM document_blocks WHERE document_id = #{documentId} ORDER BY block_index")
|
|
|
|
|
- List<DocumentBlock> findByDocumentId(@Param("documentId") String documentId);
|
|
|
|
|
|
|
+ default List<DocumentBlock> findByDocumentId(String documentId) {
|
|
|
|
|
+ LambdaQueryWrapper<DocumentBlock> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(DocumentBlock::getDocumentId, documentId)
|
|
|
|
|
+ .orderByAsc(DocumentBlock::getBlockIndex);
|
|
|
|
|
+ return selectList(wrapper);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据文档ID和块类型查询
|
|
* 根据文档ID和块类型查询
|
|
|
*/
|
|
*/
|
|
|
- @Select("SELECT * FROM document_blocks WHERE document_id = #{documentId} AND block_type = #{blockType} ORDER BY block_index")
|
|
|
|
|
- List<DocumentBlock> findByDocumentIdAndType(@Param("documentId") String documentId,
|
|
|
|
|
- @Param("blockType") String blockType);
|
|
|
|
|
|
|
+ default List<DocumentBlock> findByDocumentIdAndType(String documentId, String blockType) {
|
|
|
|
|
+ LambdaQueryWrapper<DocumentBlock> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(DocumentBlock::getDocumentId, documentId)
|
|
|
|
|
+ .eq(DocumentBlock::getBlockType, blockType)
|
|
|
|
|
+ .orderByAsc(DocumentBlock::getBlockIndex);
|
|
|
|
|
+ return selectList(wrapper);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据字符位置查找所属块
|
|
* 根据字符位置查找所属块
|
|
|
|
|
+ * 注意:此方法需要数据库表有 char_start 和 char_end 列
|
|
|
|
|
+ * 如果表结构没有这些列,此方法将返回 null
|
|
|
*/
|
|
*/
|
|
|
- @Select("SELECT * FROM document_blocks WHERE document_id = #{documentId} " +
|
|
|
|
|
- "AND char_start <= #{charPos} AND char_end >= #{charPos} LIMIT 1")
|
|
|
|
|
- DocumentBlock findByCharPosition(@Param("documentId") String documentId,
|
|
|
|
|
- @Param("charPos") Integer charPos);
|
|
|
|
|
|
|
+ default DocumentBlock findByCharPosition(String documentId, Integer charPos) {
|
|
|
|
|
+ // 暂时禁用此方法,因为 DocumentBlock 实体没有 charStart/charEnd 字段
|
|
|
|
|
+ // 如果需要此功能,需要先在实体和数据库表中添加这些字段
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 删除文档的所有块
|
|
* 删除文档的所有块
|