Ver Fonte

feat(graph-service): 添加核心实体类和Repository层

实体类:
- GraphNode: 图节点实体,支持多种类型(text/table/image/entity)
- GraphRelation: 图关系实体,支持多种关系类型和动作
- Rule: 规则实体,支持规则链定义
- DataSource: 数据源实体,支持节点绑定
- Template: 模板实体,支持占位符映射
- TextStorage: 文本存储实体,记录TXT文件路径

Repository层:
- 为每个实体创建对应的Repository接口
- 继承MyBatis Plus的BaseMapper
- 添加常用查询方法

特性:
- 使用JacksonTypeHandler处理JSONB字段
- 完整的Swagger注解
- 支持级联查询
- 符合MyBatis Plus规范
何文松 há 1 mês atrás
pai
commit
491ccb8764

+ 55 - 0
backend/graph-service/src/main/java/com/lingyue/graph/entity/DataSource.java

@@ -0,0 +1,55 @@
+package com.lingyue.graph.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.lingyue.common.domain.entity.SimpleModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 数据源实体
+ * 用于管理数据源配置和节点绑定
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@TableName(value = "data_sources", autoResultMap = true)
+@Schema(description = "数据源实体")
+public class DataSource extends SimpleModel {
+    
+    @Schema(description = "用户ID")
+    @TableField("user_id")
+    private String userId;
+    
+    @Schema(description = "文档ID")
+    @TableField("document_id")
+    private String documentId;
+    
+    @Schema(description = "数据源名称")
+    @TableField("name")
+    private String name;
+    
+    @Schema(description = "数据源类型", example = "table/text/image")
+    @TableField("type")
+    private String type;
+    
+    @Schema(description = "来源类型", example = "file/manual/rule_result")
+    @TableField("source_type")
+    private String sourceType;
+    
+    @Schema(description = "关联的节点ID数组")
+    @TableField(value = "node_ids", typeHandler = JacksonTypeHandler.class)
+    private Object nodeIds;
+    
+    @Schema(description = "数据源配置")
+    @TableField(value = "config", typeHandler = JacksonTypeHandler.class)
+    private Object config;
+    
+    @Schema(description = "元数据")
+    @TableField(value = "metadata", typeHandler = JacksonTypeHandler.class)
+    private Object metadata;
+}

+ 59 - 0
backend/graph-service/src/main/java/com/lingyue/graph/entity/GraphNode.java

@@ -0,0 +1,59 @@
+package com.lingyue.graph.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.lingyue.common.domain.entity.SimpleModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 图节点实体
+ * 用于存储文档中提取的各类实体节点
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@TableName(value = "graph_nodes", autoResultMap = true)
+@Schema(description = "图节点实体")
+public class GraphNode extends SimpleModel {
+    
+    @Schema(description = "文档ID")
+    @TableField("document_id")
+    private String documentId;
+    
+    @Schema(description = "用户ID")
+    @TableField("user_id")
+    private String userId;
+    
+    @Schema(description = "节点名称")
+    @TableField("name")
+    private String name;
+    
+    @Schema(description = "节点类型", example = "text/table/image/number/date/company/person/device")
+    @TableField("type")
+    private String type;
+    
+    @Schema(description = "节点值")
+    @TableField("value")
+    private String value;
+    
+    @Schema(description = "位置信息", example = "{\"file_id\": \"xxx\", \"page\": 1, \"line\": 5}")
+    @TableField(value = "position", typeHandler = JacksonTypeHandler.class)
+    private Object position;
+    
+    @Schema(description = "父节点ID")
+    @TableField("parent_id")
+    private String parentId;
+    
+    @Schema(description = "层级", example = "0")
+    @TableField("level")
+    private Integer level = 0;
+    
+    @Schema(description = "元数据")
+    @TableField(value = "metadata", typeHandler = JacksonTypeHandler.class)
+    private Object metadata;
+}

+ 55 - 0
backend/graph-service/src/main/java/com/lingyue/graph/entity/GraphRelation.java

@@ -0,0 +1,55 @@
+package com.lingyue.graph.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.lingyue.common.domain.entity.SimpleModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 图关系实体
+ * 用于存储节点之间的关系和动作
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@TableName(value = "graph_relations", autoResultMap = true)
+@Schema(description = "图关系实体")
+public class GraphRelation extends SimpleModel {
+    
+    @Schema(description = "源节点ID")
+    @TableField("from_node_id")
+    private String fromNodeId;
+    
+    @Schema(description = "目标节点ID")
+    @TableField("to_node_id")
+    private String toNodeId;
+    
+    @Schema(description = "关系类型", example = "DEP/ADD/SUB/MUL/DIV/UNION/INTERSECT/AI")
+    @TableField("relation_type")
+    private String relationType;
+    
+    @Schema(description = "动作类型", example = "calculate/extract/generate")
+    @TableField("action_type")
+    private String actionType;
+    
+    @Schema(description = "动作配置", example = "{\"model_id\": \"qwen-7b\", \"prompt\": \"...\"}")
+    @TableField(value = "action_config", typeHandler = JacksonTypeHandler.class)
+    private Object actionConfig;
+    
+    @Schema(description = "顺序索引", example = "0")
+    @TableField("order_index")
+    private Integer orderIndex = 0;
+    
+    @Schema(description = "条件表达式", example = "value > 100")
+    @TableField("condition_expr")
+    private String conditionExpr;
+    
+    @Schema(description = "元数据")
+    @TableField(value = "metadata", typeHandler = JacksonTypeHandler.class)
+    private Object metadata;
+}

+ 55 - 0
backend/graph-service/src/main/java/com/lingyue/graph/entity/Rule.java

@@ -0,0 +1,55 @@
+package com.lingyue.graph.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.lingyue.common.domain.entity.SimpleModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 规则实体
+ * 用于存储用户定义的规则链
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@TableName(value = "rules", autoResultMap = true)
+@Schema(description = "规则实体")
+public class Rule extends SimpleModel {
+    
+    @Schema(description = "用户ID")
+    @TableField("user_id")
+    private String userId;
+    
+    @Schema(description = "规则名称")
+    @TableField("name")
+    private String name;
+    
+    @Schema(description = "规则描述")
+    @TableField("description")
+    private String description;
+    
+    @Schema(description = "入口节点ID")
+    @TableField("entry_node_id")
+    private String entryNodeId;
+    
+    @Schema(description = "出口节点ID")
+    @TableField("exit_node_id")
+    private String exitNodeId;
+    
+    @Schema(description = "规则链", example = "[\"node1\", \"node2\", \"node3\"]")
+    @TableField(value = "rule_chain", typeHandler = JacksonTypeHandler.class)
+    private Object ruleChain;
+    
+    @Schema(description = "状态", example = "active/inactive")
+    @TableField("status")
+    private String status = "active";
+    
+    @Schema(description = "元数据")
+    @TableField(value = "metadata", typeHandler = JacksonTypeHandler.class)
+    private Object metadata;
+}

+ 51 - 0
backend/graph-service/src/main/java/com/lingyue/graph/entity/Template.java

@@ -0,0 +1,51 @@
+package com.lingyue.graph.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
+import com.lingyue.common.domain.entity.SimpleModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 模板实体
+ * 用于管理报告模板和占位符映射
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@TableName(value = "templates", autoResultMap = true)
+@Schema(description = "模板实体")
+public class Template extends SimpleModel {
+    
+    @Schema(description = "用户ID")
+    @TableField("user_id")
+    private String userId;
+    
+    @Schema(description = "模板名称")
+    @TableField("name")
+    private String name;
+    
+    @Schema(description = "模板内容(带占位符)")
+    @TableField("content")
+    private String content;
+    
+    @Schema(description = "占位符映射", example = "{\"{{ds1}}\": \"dataSourceId1\"}")
+    @TableField(value = "placeholder_mapping", typeHandler = JacksonTypeHandler.class)
+    private Object placeholderMapping;
+    
+    @Schema(description = "复制来源模板ID")
+    @TableField("source_template_id")
+    private String sourceTemplateId;
+    
+    @Schema(description = "状态", example = "active/inactive")
+    @TableField("status")
+    private String status = "active";
+    
+    @Schema(description = "元数据")
+    @TableField(value = "metadata", typeHandler = JacksonTypeHandler.class)
+    private Object metadata;
+}

+ 38 - 0
backend/graph-service/src/main/java/com/lingyue/graph/entity/TextStorage.java

@@ -0,0 +1,38 @@
+package com.lingyue.graph.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.lingyue.common.domain.entity.SimpleModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 文本存储实体
+ * 用于记录TXT文件存储路径
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@TableName("text_storage")
+@Schema(description = "文本存储实体")
+public class TextStorage extends SimpleModel {
+    
+    @Schema(description = "文档ID")
+    @TableField("document_id")
+    private String documentId;
+    
+    @Schema(description = "TXT文件路径")
+    @TableField("file_path")
+    private String filePath;
+    
+    @Schema(description = "文件大小(字节)")
+    @TableField("file_size")
+    private Long fileSize;
+    
+    @Schema(description = "文件校验和(MD5)")
+    @TableField("checksum")
+    private String checksum;
+}

+ 47 - 0
backend/graph-service/src/main/java/com/lingyue/graph/repository/DataSourceRepository.java

@@ -0,0 +1,47 @@
+package com.lingyue.graph.repository;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.lingyue.graph.entity.DataSource;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * 数据源Repository
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@Mapper
+public interface DataSourceRepository extends BaseMapper<DataSource> {
+    
+    /**
+     * 根据用户ID查询数据源列表
+     * 
+     * @param userId 用户ID
+     * @return 数据源列表
+     */
+    @Select("SELECT * FROM data_sources WHERE user_id = #{userId} ORDER BY created_at DESC")
+    List<DataSource> findByUserId(@Param("userId") String userId);
+    
+    /**
+     * 根据文档ID查询数据源列表
+     * 
+     * @param documentId 文档ID
+     * @return 数据源列表
+     */
+    @Select("SELECT * FROM data_sources WHERE document_id = #{documentId} ORDER BY created_at DESC")
+    List<DataSource> findByDocumentId(@Param("documentId") String documentId);
+    
+    /**
+     * 根据类型查询数据源
+     * 
+     * @param userId 用户ID
+     * @param type 数据源类型
+     * @return 数据源列表
+     */
+    @Select("SELECT * FROM data_sources WHERE user_id = #{userId} AND type = #{type}")
+    List<DataSource> findByUserIdAndType(@Param("userId") String userId, @Param("type") String type);
+}

+ 57 - 0
backend/graph-service/src/main/java/com/lingyue/graph/repository/GraphNodeRepository.java

@@ -0,0 +1,57 @@
+package com.lingyue.graph.repository;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.lingyue.graph.entity.GraphNode;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * 图节点Repository
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@Mapper
+public interface GraphNodeRepository extends BaseMapper<GraphNode> {
+    
+    /**
+     * 根据文档ID查询节点列表
+     * 
+     * @param documentId 文档ID
+     * @return 节点列表
+     */
+    @Select("SELECT * FROM graph_nodes WHERE document_id = #{documentId} ORDER BY level, created_at")
+    List<GraphNode> findByDocumentId(@Param("documentId") String documentId);
+    
+    /**
+     * 根据父节点ID查询子节点
+     * 
+     * @param parentId 父节点ID
+     * @return 子节点列表
+     */
+    @Select("SELECT * FROM graph_nodes WHERE parent_id = #{parentId} ORDER BY created_at")
+    List<GraphNode> findByParentId(@Param("parentId") String parentId);
+    
+    /**
+     * 根据文档ID和类型查询节点
+     * 
+     * @param documentId 文档ID
+     * @param type 节点类型
+     * @return 节点列表
+     */
+    @Select("SELECT * FROM graph_nodes WHERE document_id = #{documentId} AND type = #{type}")
+    List<GraphNode> findByDocumentIdAndType(@Param("documentId") String documentId, 
+                                            @Param("type") String type);
+    
+    /**
+     * 根据用户ID查询节点列表
+     * 
+     * @param userId 用户ID
+     * @return 节点列表
+     */
+    @Select("SELECT * FROM graph_nodes WHERE user_id = #{userId} ORDER BY created_at DESC")
+    List<GraphNode> findByUserId(@Param("userId") String userId);
+}

+ 55 - 0
backend/graph-service/src/main/java/com/lingyue/graph/repository/GraphRelationRepository.java

@@ -0,0 +1,55 @@
+package com.lingyue.graph.repository;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.lingyue.graph.entity.GraphRelation;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * 图关系Repository
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@Mapper
+public interface GraphRelationRepository extends BaseMapper<GraphRelation> {
+    
+    /**
+     * 根据源节点ID查询关系列表
+     * 
+     * @param fromNodeId 源节点ID
+     * @return 关系列表
+     */
+    @Select("SELECT * FROM graph_relations WHERE from_node_id = #{fromNodeId} ORDER BY order_index")
+    List<GraphRelation> findByFromNodeId(@Param("fromNodeId") String fromNodeId);
+    
+    /**
+     * 根据目标节点ID查询关系列表
+     * 
+     * @param toNodeId 目标节点ID
+     * @return 关系列表
+     */
+    @Select("SELECT * FROM graph_relations WHERE to_node_id = #{toNodeId}")
+    List<GraphRelation> findByToNodeId(@Param("toNodeId") String toNodeId);
+    
+    /**
+     * 查询节点的所有关系(包括作为源节点和目标节点)
+     * 
+     * @param nodeId 节点ID
+     * @return 关系列表
+     */
+    @Select("SELECT * FROM graph_relations WHERE from_node_id = #{nodeId} OR to_node_id = #{nodeId}")
+    List<GraphRelation> findByNodeId(@Param("nodeId") String nodeId);
+    
+    /**
+     * 根据关系类型查询
+     * 
+     * @param relationType 关系类型
+     * @return 关系列表
+     */
+    @Select("SELECT * FROM graph_relations WHERE relation_type = #{relationType}")
+    List<GraphRelation> findByRelationType(@Param("relationType") String relationType);
+}

+ 47 - 0
backend/graph-service/src/main/java/com/lingyue/graph/repository/RuleRepository.java

@@ -0,0 +1,47 @@
+package com.lingyue.graph.repository;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.lingyue.graph.entity.Rule;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * 规则Repository
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@Mapper
+public interface RuleRepository extends BaseMapper<Rule> {
+    
+    /**
+     * 根据用户ID查询规则列表
+     * 
+     * @param userId 用户ID
+     * @return 规则列表
+     */
+    @Select("SELECT * FROM rules WHERE user_id = #{userId} ORDER BY created_at DESC")
+    List<Rule> findByUserId(@Param("userId") String userId);
+    
+    /**
+     * 根据用户ID和状态查询规则
+     * 
+     * @param userId 用户ID
+     * @param status 状态
+     * @return 规则列表
+     */
+    @Select("SELECT * FROM rules WHERE user_id = #{userId} AND status = #{status} ORDER BY created_at DESC")
+    List<Rule> findByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);
+    
+    /**
+     * 根据入口节点ID查询规则
+     * 
+     * @param entryNodeId 入口节点ID
+     * @return 规则列表
+     */
+    @Select("SELECT * FROM rules WHERE entry_node_id = #{entryNodeId}")
+    List<Rule> findByEntryNodeId(@Param("entryNodeId") String entryNodeId);
+}

+ 47 - 0
backend/graph-service/src/main/java/com/lingyue/graph/repository/TemplateRepository.java

@@ -0,0 +1,47 @@
+package com.lingyue.graph.repository;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.lingyue.graph.entity.Template;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * 模板Repository
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@Mapper
+public interface TemplateRepository extends BaseMapper<Template> {
+    
+    /**
+     * 根据用户ID查询模板列表
+     * 
+     * @param userId 用户ID
+     * @return 模板列表
+     */
+    @Select("SELECT * FROM templates WHERE user_id = #{userId} ORDER BY created_at DESC")
+    List<Template> findByUserId(@Param("userId") String userId);
+    
+    /**
+     * 根据用户ID和状态查询模板
+     * 
+     * @param userId 用户ID
+     * @param status 状态
+     * @return 模板列表
+     */
+    @Select("SELECT * FROM templates WHERE user_id = #{userId} AND status = #{status} ORDER BY created_at DESC")
+    List<Template> findByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);
+    
+    /**
+     * 根据来源模板ID查询衍生模板
+     * 
+     * @param sourceTemplateId 来源模板ID
+     * @return 模板列表
+     */
+    @Select("SELECT * FROM templates WHERE source_template_id = #{sourceTemplateId}")
+    List<Template> findBySourceTemplateId(@Param("sourceTemplateId") String sourceTemplateId);
+}

+ 35 - 0
backend/graph-service/src/main/java/com/lingyue/graph/repository/TextStorageRepository.java

@@ -0,0 +1,35 @@
+package com.lingyue.graph.repository;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.lingyue.graph.entity.TextStorage;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+/**
+ * 文本存储Repository
+ * 
+ * @author lingyue
+ * @since 2026-01-14
+ */
+@Mapper
+public interface TextStorageRepository extends BaseMapper<TextStorage> {
+    
+    /**
+     * 根据文档ID查询文本存储记录
+     * 
+     * @param documentId 文档ID
+     * @return 文本存储记录
+     */
+    @Select("SELECT * FROM text_storage WHERE document_id = #{documentId}")
+    TextStorage findByDocumentId(@Param("documentId") String documentId);
+    
+    /**
+     * 根据文件路径查询
+     * 
+     * @param filePath 文件路径
+     * @return 文本存储记录
+     */
+    @Select("SELECT * FROM text_storage WHERE file_path = #{filePath}")
+    TextStorage findByFilePath(@Param("filePath") String filePath);
+}