|
|
@@ -1,5 +1,6 @@
|
|
|
package com.lingyue.document.repository;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
import com.lingyue.document.entity.DocumentElement;
|
|
|
import org.apache.ibatis.annotations.*;
|
|
|
@@ -9,6 +10,9 @@ import java.util.List;
|
|
|
/**
|
|
|
* 文档元素 Repository
|
|
|
*
|
|
|
+ * 注意:JSONB 字段(如 runs, style)需要使用 LambdaQueryWrapper 查询,
|
|
|
+ * 而不是 @Select 注解,以确保 TypeHandler 被正确应用。
|
|
|
+ *
|
|
|
* @author lingyue
|
|
|
* @since 2026-01-21
|
|
|
*/
|
|
|
@@ -17,28 +21,37 @@ public interface DocumentElementRepository extends BaseMapper<DocumentElement> {
|
|
|
|
|
|
/**
|
|
|
* 根据文档ID查询所有元素(按顺序)
|
|
|
+ * 使用 default 方法 + LambdaQueryWrapper 确保 TypeHandler 生效
|
|
|
*/
|
|
|
- @Select("SELECT * FROM document_elements WHERE document_id = #{documentId} ORDER BY element_index")
|
|
|
- List<DocumentElement> findByDocumentId(@Param("documentId") String documentId);
|
|
|
+ default List<DocumentElement> findByDocumentId(String documentId) {
|
|
|
+ return selectList(new LambdaQueryWrapper<DocumentElement>()
|
|
|
+ .eq(DocumentElement::getDocumentId, documentId)
|
|
|
+ .orderByAsc(DocumentElement::getElementIndex));
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 根据文档ID和类型查询元素
|
|
|
*/
|
|
|
- @Select("SELECT * FROM document_elements WHERE document_id = #{documentId} AND element_type = #{elementType} ORDER BY element_index")
|
|
|
- List<DocumentElement> findByDocumentIdAndType(@Param("documentId") String documentId,
|
|
|
- @Param("elementType") String elementType);
|
|
|
+ default List<DocumentElement> findByDocumentIdAndType(String documentId, String elementType) {
|
|
|
+ return selectList(new LambdaQueryWrapper<DocumentElement>()
|
|
|
+ .eq(DocumentElement::getDocumentId, documentId)
|
|
|
+ .eq(DocumentElement::getElementType, elementType)
|
|
|
+ .orderByAsc(DocumentElement::getElementIndex));
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 查询文档中的所有图片
|
|
|
*/
|
|
|
- @Select("SELECT * FROM document_elements WHERE document_id = #{documentId} AND element_type = 'image' ORDER BY element_index")
|
|
|
- List<DocumentElement> findImagesByDocumentId(@Param("documentId") String documentId);
|
|
|
+ default List<DocumentElement> findImagesByDocumentId(String documentId) {
|
|
|
+ return findByDocumentIdAndType(documentId, "image");
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 查询文档中的所有表格
|
|
|
*/
|
|
|
- @Select("SELECT * FROM document_elements WHERE document_id = #{documentId} AND element_type = 'table' ORDER BY element_index")
|
|
|
- List<DocumentElement> findTablesByDocumentId(@Param("documentId") String documentId);
|
|
|
+ default List<DocumentElement> findTablesByDocumentId(String documentId) {
|
|
|
+ return findByDocumentIdAndType(documentId, "table");
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 删除文档的所有元素
|