Sfoglia il codice sorgente

fix: 修复启动和运行时错误

1. 修复 Neo4j 条件注解
   - @ConditionalOnBean(Driver.class) 改为 @ConditionalOnProperty
   - 确保 neo4j.enabled=false 时不加载相关 Bean

2. 修复 SQL 字段名不一致
   - Repository 中 created_at/updated_at 改为 create_time/update_time
   - 与 SimpleModel 基类和数据库表结构保持一致

3. 开放开发阶段 API
   - /auth/**, /api/v1/documents/**, /api/v1/graph/** 等接口暂时开放
   - 便于开发测试

影响文件:
- Neo4jGraphController, Neo4jGraphService, Neo4jNodeRepository, Neo4jRelationRepository
- GraphNodeRepository, DocumentEntityRepository, TemplateRepository, DataSourceRepository, RuleRepository
- SecurityConfig
何文松 1 mese fa
parent
commit
a8d4983e40

+ 8 - 2
backend/auth-service/src/main/java/com/lingyue/auth/config/SecurityConfig.java

@@ -37,8 +37,14 @@ public class SecurityConfig {
                 .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                 // 授权配置
                 .authorizeHttpRequests((requests) -> {
-                    // 对于登录、注册、刷新Token允许匿名访问
-                    requests.requestMatchers("/auth/register", "/auth/login", "/auth/refresh").permitAll()
+                    // 对于登录、注册、刷新Token、用户信息允许匿名访问
+                    requests.requestMatchers("/auth/**").permitAll()
+                            // 文档接口(开发阶段暂时开放)
+                            .requestMatchers("/api/v1/documents/**").permitAll()
+                            // 知识图谱接口(开发阶段暂时开放)
+                            .requestMatchers("/api/v1/graph/**").permitAll()
+                            // 结构化文档接口(开发阶段暂时开放)
+                            .requestMatchers("/api/v1/ner/**").permitAll()
                             // Actuator 健康检查
                             .requestMatchers("/actuator/**").permitAll()
                             // API 文档

+ 2 - 2
backend/document-service/src/main/java/com/lingyue/document/repository/DocumentEntityRepository.java

@@ -48,13 +48,13 @@ public interface DocumentEntityRepository extends BaseMapper<DocumentEntity> {
     /**
      * 确认实体
      */
-    @Update("UPDATE document_entities SET confirmed = true, updated_at = CURRENT_TIMESTAMP WHERE id = #{entityId}")
+    @Update("UPDATE document_entities SET confirmed = true, update_time = CURRENT_TIMESTAMP WHERE id = #{entityId}")
     int confirmEntity(@Param("entityId") String entityId);
     
     /**
      * 批量确认实体
      */
-    @Update("<script>UPDATE document_entities SET confirmed = true, updated_at = CURRENT_TIMESTAMP " +
+    @Update("<script>UPDATE document_entities SET confirmed = true, update_time = CURRENT_TIMESTAMP " +
             "WHERE id IN <foreach collection='entityIds' item='id' open='(' separator=',' close=')'>#{id}</foreach></script>")
     int batchConfirmEntities(@Param("entityIds") List<String> entityIds);
     

+ 3 - 2
backend/graph-service/src/main/java/com/lingyue/graph/controller/Neo4jGraphController.java

@@ -8,7 +8,7 @@ import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -18,6 +18,7 @@ import java.util.Map;
  * Neo4j 图数据库控制器
  * 
  * 提供基于 Neo4j 的高级图查询功能
+ * 仅在 neo4j.enabled=true 时启用
  * 
  * @author lingyue
  * @since 2026-01-21
@@ -26,7 +27,7 @@ import java.util.Map;
 @RestController
 @RequestMapping("/api/v1/neo4j")
 @RequiredArgsConstructor
-@ConditionalOnBean(Neo4jGraphService.class)
+@ConditionalOnProperty(name = "neo4j.enabled", havingValue = "true")
 @Tag(name = "Neo4j 图数据库", description = "Neo4j 图查询接口")
 public class Neo4jGraphController {
     

+ 2 - 2
backend/graph-service/src/main/java/com/lingyue/graph/neo4j/Neo4jGraphService.java

@@ -9,7 +9,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.neo4j.driver.Driver;
 import org.neo4j.driver.Result;
 import org.neo4j.driver.Session;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 @RequiredArgsConstructor
-@ConditionalOnBean(Driver.class)
+@ConditionalOnProperty(name = "neo4j.enabled", havingValue = "true")
 public class Neo4jGraphService {
     
     private final Driver driver;

+ 2 - 2
backend/graph-service/src/main/java/com/lingyue/graph/neo4j/Neo4jNodeRepository.java

@@ -7,7 +7,7 @@ import org.neo4j.driver.Result;
 import org.neo4j.driver.Session;
 import org.neo4j.driver.Value;
 import org.neo4j.driver.types.Node;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Repository;
 
 import java.util.*;
@@ -23,7 +23,7 @@ import java.util.*;
 @Slf4j
 @Repository
 @RequiredArgsConstructor
-@ConditionalOnBean(Driver.class)
+@ConditionalOnProperty(name = "neo4j.enabled", havingValue = "true")
 public class Neo4jNodeRepository {
     
     private final Driver driver;

+ 2 - 2
backend/graph-service/src/main/java/com/lingyue/graph/neo4j/Neo4jRelationRepository.java

@@ -5,7 +5,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.neo4j.driver.Driver;
 import org.neo4j.driver.Result;
 import org.neo4j.driver.Session;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Repository;
 
 import java.util.*;
@@ -21,7 +21,7 @@ import java.util.*;
 @Slf4j
 @Repository
 @RequiredArgsConstructor
-@ConditionalOnBean(Driver.class)
+@ConditionalOnProperty(name = "neo4j.enabled", havingValue = "true")
 public class Neo4jRelationRepository {
     
     private final Driver driver;

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

@@ -23,7 +23,7 @@ public interface DataSourceRepository extends BaseMapper<DataSource> {
      * @param userId 用户ID
      * @return 数据源列表
      */
-    @Select("SELECT * FROM data_sources WHERE user_id = #{userId} ORDER BY created_at DESC")
+    @Select("SELECT * FROM data_sources WHERE user_id = #{userId} ORDER BY create_time DESC")
     List<DataSource> findByUserId(@Param("userId") String userId);
     
     /**
@@ -32,7 +32,7 @@ public interface DataSourceRepository extends BaseMapper<DataSource> {
      * @param documentId 文档ID
      * @return 数据源列表
      */
-    @Select("SELECT * FROM data_sources WHERE document_id = #{documentId} ORDER BY created_at DESC")
+    @Select("SELECT * FROM data_sources WHERE document_id = #{documentId} ORDER BY create_time DESC")
     List<DataSource> findByDocumentId(@Param("documentId") String documentId);
     
     /**

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

@@ -23,7 +23,7 @@ public interface GraphNodeRepository extends BaseMapper<GraphNode> {
      * @param documentId 文档ID
      * @return 节点列表
      */
-    @Select("SELECT * FROM graph_nodes WHERE document_id = #{documentId} ORDER BY level, created_at")
+    @Select("SELECT * FROM graph_nodes WHERE document_id = #{documentId} ORDER BY level, create_time")
     List<GraphNode> findByDocumentId(@Param("documentId") String documentId);
     
     /**
@@ -32,7 +32,7 @@ public interface GraphNodeRepository extends BaseMapper<GraphNode> {
      * @param parentId 父节点ID
      * @return 子节点列表
      */
-    @Select("SELECT * FROM graph_nodes WHERE parent_id = #{parentId} ORDER BY created_at")
+    @Select("SELECT * FROM graph_nodes WHERE parent_id = #{parentId} ORDER BY create_time")
     List<GraphNode> findByParentId(@Param("parentId") String parentId);
     
     /**
@@ -52,6 +52,6 @@ public interface GraphNodeRepository extends BaseMapper<GraphNode> {
      * @param userId 用户ID
      * @return 节点列表
      */
-    @Select("SELECT * FROM graph_nodes WHERE user_id = #{userId} ORDER BY created_at DESC")
+    @Select("SELECT * FROM graph_nodes WHERE user_id = #{userId} ORDER BY create_time DESC")
     List<GraphNode> findByUserId(@Param("userId") String userId);
 }

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

@@ -23,7 +23,7 @@ public interface RuleRepository extends BaseMapper<Rule> {
      * @param userId 用户ID
      * @return 规则列表
      */
-    @Select("SELECT * FROM rules WHERE user_id = #{userId} ORDER BY created_at DESC")
+    @Select("SELECT * FROM rules WHERE user_id = #{userId} ORDER BY create_time DESC")
     List<Rule> findByUserId(@Param("userId") String userId);
     
     /**
@@ -33,7 +33,7 @@ public interface RuleRepository extends BaseMapper<Rule> {
      * @param status 状态
      * @return 规则列表
      */
-    @Select("SELECT * FROM rules WHERE user_id = #{userId} AND status = #{status} ORDER BY created_at DESC")
+    @Select("SELECT * FROM rules WHERE user_id = #{userId} AND status = #{status} ORDER BY create_time DESC")
     List<Rule> findByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);
     
     /**

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

@@ -23,7 +23,7 @@ public interface TemplateRepository extends BaseMapper<Template> {
      * @param userId 用户ID
      * @return 模板列表
      */
-    @Select("SELECT * FROM templates WHERE user_id = #{userId} ORDER BY created_at DESC")
+    @Select("SELECT * FROM templates WHERE user_id = #{userId} ORDER BY create_time DESC")
     List<Template> findByUserId(@Param("userId") String userId);
     
     /**
@@ -33,7 +33,7 @@ public interface TemplateRepository extends BaseMapper<Template> {
      * @param status 状态
      * @return 模板列表
      */
-    @Select("SELECT * FROM templates WHERE user_id = #{userId} AND status = #{status} ORDER BY created_at DESC")
+    @Select("SELECT * FROM templates WHERE user_id = #{userId} AND status = #{status} ORDER BY create_time DESC")
     List<Template> findByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);
     
     /**