后端开发结构设计.md 28 KB

灵越智报 2.0 - 后端开发结构设计

设计时间: 2026-02-12
设计依据: 数据库设计文档-0211会议版.md + 前端交互原型
技术栈: Spring Boot 3.x + PostgreSQL + 图数据库架构


一、核心设计理念

1.1 图数据库思想

  • 节点驱动: 所有业务实体(项目、模板、报告、附件、实体、规则)均为节点
  • 关系驱动: 通过边(Edge)描述节点间的关联关系
  • 属性灵活: 节点和边的属性通过 KV 存储,支持动态扩展
  • 视图组合: 通过数据库视图组合出业务接口,底层表结构不变

1.2 前后端分离

  • 前端: Vue 3 + TypeScript + Vite
  • 后端: Spring Boot 3.x + MyBatis-Plus
  • 通信: RESTful API + WebSocket (实时推送)

1.3 微服务架构(可选)

当前设计为单体应用,但保留微服务拆分能力:

  • 核心服务(graph-service):图数据操作
  • AI服务(ai-service):NER、LLM调用
  • 文件服务(file-service):文件上传、解析

二、模块划分

2.1 核心模块结构

lingyue-zhibao-backend/
├── common/                          # 公共模块
│   ├── core/                        # 核心工具
│   │   ├── exception/              # 统一异常处理
│   │   ├── result/                 # 统一返回结果
│   │   ├── config/                 # 全局配置
│   │   └── util/                   # 工具类
│   ├── security/                    # 安全模块
│   │   ├── jwt/                    # JWT工具
│   │   ├── filter/                 # 安全过滤器
│   │   └── handler/                # 认证处理器
│   └── graph/                       # 图数据库基础
│       ├── entity/                 # 图实体基类
│       ├── mapper/                 # 图Mapper基类
│       └── service/                # 图服务基类
│
├── modules/                         # 业务模块
│   ├── system/                     # 系统管理模块
│   │   ├── controller/
│   │   │   ├── UserController.java
│   │   │   ├── RoleController.java
│   │   │   ├── PermissionController.java
│   │   │   ├── DictController.java
│   │   │   └── ConfigController.java
│   │   ├── service/
│   │   ├── mapper/
│   │   └── entity/
│   │
│   ├── graph/                      # 图数据核心模块 ⭐
│   │   ├── controller/
│   │   │   ├── NodeController.java          # 节点通用操作
│   │   │   ├── EdgeController.java          # 关系通用操作
│   │   │   ├── PropertyController.java      # 属性操作
│   │   │   └── GraphQueryController.java    # 图查询
│   │   ├── service/
│   │   │   ├── NodeService.java
│   │   │   ├── EdgeService.java
│   │   │   ├── PropertyService.java
│   │   │   └── GraphQueryService.java
│   │   ├── mapper/
│   │   │   ├── NodeMapper.java
│   │   │   ├── EdgeMapper.java
│   │   │   └── PropertyMapper.java
│   │   └── entity/
│   │       ├── Node.java
│   │       ├── Edge.java
│   │       ├── NodeProperty.java
│   │       └── EdgeProperty.java
│   │
│   ├── project/                    # 项目管理模块
│   │   ├── controller/
│   │   │   └── ProjectController.java
│   │   ├── service/
│   │   │   ├── ProjectService.java
│   │   │   └── ProjectQueryService.java
│   │   ├── dto/
│   │   │   ├── ProjectCreateDTO.java
│   │   │   ├── ProjectUpdateDTO.java
│   │   │   └── ProjectVO.java
│   │   └── enums/
│   │       └── ProjectStatus.java
│   │
│   ├── template/                   # 模板管理模块
│   │   ├── controller/
│   │   │   ├── TemplateController.java
│   │   │   └── ElementController.java
│   │   ├── service/
│   │   │   ├── TemplateService.java
│   │   │   ├── ElementService.java
│   │   │   └── TemplateParseService.java
│   │   ├── dto/
│   │   │   ├── TemplateCreateDTO.java
│   │   │   ├── ElementDefineDTO.java
│   │   │   └── TemplateVO.java
│   │   └── enums/
│   │       ├── ElementType.java      # text/paragraph/table
│   │       └── TemplateStatus.java
│   │
│   ├── report/                     # 报告管理模块 ⭐
│   │   ├── controller/
│   │   │   ├── ReportController.java
│   │   │   ├── ReportValueController.java
│   │   │   └── ReportExportController.java
│   │   ├── service/
│   │   │   ├── ReportService.java
│   │   │   ├── ReportValueService.java
│   │   │   ├── ReportCopyService.java
│   │   │   └── ReportExportService.java
│   │   ├── dto/
│   │   │   ├── ReportCreateDTO.java
│   │   │   ├── ReportValueUpdateDTO.java
│   │   │   └── ReportVO.java
│   │   └── enums/
│   │       └── ReportStatus.java
│   │
│   ├── attachment/                 # 附件管理模块
│   │   ├── controller/
│   │   │   └── AttachmentController.java
│   │   ├── service/
│   │   │   ├── AttachmentService.java
│   │   │   ├── AttachmentParseService.java
│   │   │   └── AttachmentUploadService.java
│   │   ├── dto/
│   │   │   ├── AttachmentUploadDTO.java
│   │   │   └── AttachmentVO.java
│   │   └── enums/
│   │       ├── AttachmentType.java   # pdf/docx/xlsx
│   │       └── ParseStatus.java
│   │
│   ├── entity/                     # 实体管理模块(NER结果)
│   │   ├── controller/
│   │   │   └── EntityController.java
│   │   ├── service/
│   │   │   ├── EntityService.java
│   │   │   ├── EntityMergeService.java
│   │   │   └── EntityExtractionService.java
│   │   ├── dto/
│   │   │   ├── EntityCreateDTO.java
│   │   │   ├── EntityMergeDTO.java
│   │   │   └── EntityVO.java
│   │   └── enums/
│   │       ├── EntityType.java       # ORG/PERSON/DATE/NUMBER/LOCATION
│   │       └── BusinessLabel.java
│   │
│   ├── rule/                       # 规则引擎模块 ⭐
│   │   ├── controller/
│   │   │   └── RuleController.java
│   │   ├── service/
│   │   │   ├── RuleService.java
│   │   │   ├── RuleExecutor.java
│   │   │   └── RuleConfigService.java
│   │   ├── executor/               # 规则执行器
│   │   │   ├── DirectEntityExecutor.java    # 直接引用实体
│   │   │   ├── RegexExtractExecutor.java    # 正则提取
│   │   │   ├── LLMGenerateExecutor.java     # LLM生成
│   │   │   └── TableAggregateExecutor.java  # 表格聚合
│   │   ├── dto/
│   │   │   ├── RuleCreateDTO.java
│   │   │   ├── RuleExecuteDTO.java
│   │   │   └── RuleVO.java
│   │   └── enums/
│   │       ├── RuleType.java         # direct_entity/extraction/llm/aggregate
│   │       └── ActionType.java
│   │
│   ├── file/                       # 文件服务模块
│   │   ├── controller/
│   │   │   ├── FileUploadController.java
│   │   │   └── FileDownloadController.java
│   │   ├── service/
│   │   │   ├── FileStorageService.java
│   │   │   ├── FileParseService.java
│   │   │   └── FilePreviewService.java
│   │   ├── parser/                 # 文件解析器
│   │   │   ├── PdfParser.java
│   │   │   ├── DocxParser.java
│   │   │   └── XlsxParser.java
│   │   └── dto/
│   │       ├── FileUploadVO.java
│   │       └── FileParseResult.java
│   │
│   ├── ai/                         # AI服务模块
│   │   ├── controller/
│   │   │   ├── NerController.java
│   │   │   ├── LLMController.java
│   │   │   └── AIAssistantController.java
│   │   ├── service/
│   │   │   ├── NerService.java
│   │   │   ├── LLMService.java
│   │   │   ├── AIAssistantService.java
│   │   │   └── PromptService.java
│   │   ├── client/                 # 外部AI服务客户端
│   │   │   ├── OpenAIClient.java
│   │   │   └── NerServiceClient.java
│   │   └── dto/
│   │       ├── NerRequest.java
│   │       ├── NerResult.java
│   │       └── LLMRequest.java
│   │
│   └── websocket/                  # WebSocket模块
│       ├── handler/
│       │   ├── ParseProgressHandler.java
│       │   ├── AIAssistantHandler.java
│       │   └── NotificationHandler.java
│       └── config/
│           └── WebSocketConfig.java
│
└── Application.java                # 启动类

三、核心业务流程设计

3.1 项目创建流程

用户操作: 新建报告
    ↓
1. 创建 PROJECT 节点
    ↓
2. 选择模板 → 创建 REPORT 节点
    ↓
3. 建立关系:
   - REPORT --INSTANCE_OF--> TEMPLATE
   - REPORT --BELONGS_TO--> PROJECT
    ↓
4. 初始化要素值:
   - 为每个 ELEMENT 创建空的 VALUE 节点
   - 建立 REPORT --HAS_VALUE--> VALUE
   - 建立 VALUE --FOR_ELEMENT--> ELEMENT
    ↓
5. 返回报告ID,跳转到编辑器

接口设计:

POST /api/v1/reports
{
  "projectId": 10,
  "templateId": 200,
  "title": "成都院2024年复审报告"
}

Response:
{
  "code": 200,
  "data": {
    "reportId": 300,
    "title": "成都院2024年复审报告",
    "status": "draft",
    "templateName": "电力安全生产标准化复审报告模板",
    "elementCount": 8,
    "filledCount": 1
  }
}

3.2 附件上传与解析流程

用户操作: 上传附件
    ↓
1. 文件上传到 OSS/本地存储
    ↓
2. 创建 ATTACHMENT 节点
   - 保存文件路径、类型、大小等
   - 建立 REPORT --HAS_ATTACHMENT--> ATTACHMENT
    ↓
3. 异步解析任务:
   a. 文档解析(提取文本)
   b. NER实体识别
   c. 创建 ENTITY 节点
   d. 建立 ATTACHMENT --HAS_ENTITY--> ENTITY
    ↓
4. WebSocket推送解析进度
    ↓
5. 解析完成,返回实体列表

接口设计:

POST /api/v1/reports/{reportId}/attachments/upload
Content-Type: multipart/form-data

Response:
{
  "code": 200,
  "data": {
    "attachmentId": 400,
    "fileName": "复审通知.docx",
    "fileType": "docx",
    "fileSize": 512000,
    "parseStatus": "parsing",
    "taskId": "task_20240212_001"
  }
}

WebSocket推送:
{
  "type": "parse_progress",
  "taskId": "task_20240212_001",
  "status": "parsing",
  "progress": 30,
  "currentStep": "文档解析中...",
  "steps": [
    {"name": "文档解析", "status": "completed"},
    {"name": "实体识别", "status": "active"},
    {"name": "关系抽取", "status": "pending"}
  ]
}

3.3 规则创建与执行流程

用户操作: 从附件实体添加规则
    ↓
1. 选择实体(如"BZ-0092-2024")
2. 选择目标要素(如"项目编号")
    ↓
3. 创建 RULE 节点:
   - rule_type: "direct_entity"
   - action_type: "use_entity_value"
    ↓
4. 建立关系:
   - REPORT --HAS_RULE--> RULE
   - RULE --FOR_ELEMENT--> ELEMENT
   - RULE --INPUT_FROM--> ENTITY
    ↓
5. 执行规则:
   - 获取 ENTITY.name
   - 更新 VALUE 节点的 value_text
   - 更新 is_filled = true
    ↓
6. 返回执行结果

接口设计:

POST /api/v1/reports/{reportId}/rules
{
  "elementKey": "basicInfo.projectCode",
  "ruleType": "direct_entity",
  "actionType": "use_entity_value",
  "inputs": [
    {
      "inputKey": "entity",
      "sourceType": "entity",
      "sourceId": 502
    }
  ]
}

Response:
{
  "code": 200,
  "data": {
    "ruleId": 600,
    "elementKey": "basicInfo.projectCode",
    "executeStatus": "success",
    "outputValue": "BZ-0092-2024"
  }
}

3.4 报告编辑与实时保存

用户操作: 编辑报告内容
    ↓
1. 前端编辑器实时监听变化
    ↓
2. 防抖后发送保存请求(每3秒)
    ↓
3. 后端更新:
   - 更新 REPORT 节点的 content_html
   - 更新 VALUE 节点的值
   - 记录 updated_at
    ↓
4. 返回保存状态
    ↓
5. 前端显示"已保存"提示

接口设计:

PUT /api/v1/reports/{reportId}/values/{elementKey}
{
  "valueText": "BZ-0092-2024",
  "fillSource": "manual"
}

Response:
{
  "code": 200,
  "data": {
    "elementKey": "basicInfo.projectCode",
    "valueText": "BZ-0092-2024",
    "isFilled": true,
    "updatedAt": "2024-02-12T17:30:00"
  }
}

四、核心接口设计

4.1 用户管理接口

4.1.1 认证接口

方法 路径 说明
POST /api/v1/auth/login 用户登录
POST /api/v1/auth/logout 用户登出
POST /api/v1/auth/refresh 刷新Token
GET /api/v1/auth/captcha 获取验证码
POST /api/v1/auth/register 用户注册(可选)
POST /api/v1/auth/forgot-password 忘记密码
POST /api/v1/auth/reset-password 重置密码

登录接口示例:

POST /api/v1/auth/login
{
  "username": "admin",
  "password": "123456",
  "captcha": "ABCD",
  "captchaKey": "uuid-xxx"
}

Response:
{
  "code": 200,
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refreshToken": "refresh_token_xxx",
    "expiresIn": 7200,
    "user": {
      "id": 1,
      "username": "admin",
      "realName": "管理员",
      "email": "admin@example.com",
      "avatar": "https://...",
      "roles": ["admin"],
      "permissions": ["*:*:*"]
    }
  }
}

4.1.2 用户管理接口

方法 路径 说明
GET /api/v1/users 获取用户列表(分页)
GET /api/v1/users/{id} 获取用户详情
POST /api/v1/users 创建用户
PUT /api/v1/users/{id} 更新用户
DELETE /api/v1/users/{id} 删除用户
PUT /api/v1/users/{id}/status 启用/禁用用户
PUT /api/v1/users/{id}/password 重置用户密码
GET /api/v1/users/current 获取当前用户信息
PUT /api/v1/users/current/profile 更新个人资料
PUT /api/v1/users/current/password 修改个人密码
PUT /api/v1/users/current/avatar 更新头像

4.1.3 角色管理接口

方法 路径 说明
GET /api/v1/roles 获取角色列表
GET /api/v1/roles/{id} 获取角色详情
POST /api/v1/roles 创建角色
PUT /api/v1/roles/{id} 更新角色
DELETE /api/v1/roles/{id} 删除角色
GET /api/v1/roles/{id}/permissions 获取角色权限
PUT /api/v1/roles/{id}/permissions 分配角色权限
GET /api/v1/roles/{id}/users 获取角色用户列表

4.1.4 权限管理接口

方法 路径 说明
GET /api/v1/permissions 获取权限树
GET /api/v1/permissions/{id} 获取权限详情
POST /api/v1/permissions 创建权限
PUT /api/v1/permissions/{id} 更新权限
DELETE /api/v1/permissions/{id} 删除权限
GET /api/v1/permissions/menu 获取当前用户菜单

4.1.5 数据字典接口

方法 路径 说明
GET /api/v1/dict/types 获取字典类型列表
POST /api/v1/dict/types 创建字典类型
PUT /api/v1/dict/types/{id} 更新字典类型
DELETE /api/v1/dict/types/{id} 删除字典类型
GET /api/v1/dict/types/{code}/items 获取字典项列表
POST /api/v1/dict/types/{code}/items 创建字典项
PUT /api/v1/dict/items/{id} 更新字典项
DELETE /api/v1/dict/items/{id} 删除字典项

4.1.6 系统配置接口

方法 路径 说明
GET /api/v1/configs 获取配置列表
GET /api/v1/configs/{key} 获取配置值
PUT /api/v1/configs/{key} 更新配置
GET /api/v1/configs/public 获取公开配置

4.1.7 操作日志接口

方法 路径 说明
GET /api/v1/logs/operations 获取操作日志列表
GET /api/v1/logs/operations/{id} 获取日志详情
DELETE /api/v1/logs/operations/{id} 删除日志
POST /api/v1/logs/operations/clear 清空日志

4.1.8 登录日志接口

方法 路径 说明
GET /api/v1/logs/logins 获取登录日志列表
GET /api/v1/logs/logins/{id} 获取登录日志详情

4.2 项目管理接口

方法 路径 说明
GET /api/v1/projects 获取项目列表(分页)
GET /api/v1/projects/{id} 获取项目详情
POST /api/v1/projects 创建项目
PUT /api/v1/projects/{id} 更新项目
DELETE /api/v1/projects/{id} 删除项目
POST /api/v1/projects/{id}/archive 归档项目

4.3 模板管理接口

方法 路径 说明
GET /api/v1/templates 获取模板列表
GET /api/v1/templates/{id} 获取模板详情
POST /api/v1/templates 创建模板
GET /api/v1/templates/{id}/elements 获取模板要素列表
POST /api/v1/templates/{id}/elements 添加要素定义

4.4 报告管理接口

方法 路径 说明
GET /api/v1/reports 获取报告列表
GET /api/v1/reports/{id} 获取报告详情
POST /api/v1/reports 创建报告
PUT /api/v1/reports/{id} 更新报告
DELETE /api/v1/reports/{id} 删除报告
GET /api/v1/reports/{id}/values 获取报告要素值列表
PUT /api/v1/reports/{id}/values/{elementKey} 更新要素值
POST /api/v1/reports/{id}/copy 复制报告
POST /api/v1/reports/{id}/export 导出报告

4.5 附件管理接口

方法 路径 说明
POST /api/v1/reports/{reportId}/attachments/upload 上传附件
GET /api/v1/reports/{reportId}/attachments 获取附件列表
GET /api/v1/attachments/{id} 获取附件详情
POST /api/v1/attachments/{id}/parse 触发附件解析
DELETE /api/v1/attachments/{id} 删除附件
GET /api/v1/attachments/{id}/entities 获取附件实体列表

4.6 实体管理接口

方法 路径 说明
GET /api/v1/attachments/{attachmentId}/entities 获取附件实体列表
GET /api/v1/reports/{reportId}/entities 获取报告所有实体
GET /api/v1/entities/{id} 获取实体详情
PUT /api/v1/entities/{id} 更新实体
POST /api/v1/entities/merge 合并实体

4.7 规则管理接口

方法 路径 说明
GET /api/v1/reports/{reportId}/rules 获取报告规则列表
GET /api/v1/rules/{id} 获取规则详情
POST /api/v1/reports/{reportId}/rules 创建规则
PUT /api/v1/rules/{id} 更新规则
DELETE /api/v1/rules/{id} 删除规则
POST /api/v1/rules/{id}/execute 执行规则
POST /api/v1/reports/{reportId}/rules/execute-all 批量执行规则

4.8 AI服务接口

方法 路径 说明
POST /api/v1/ai/ner/extract 提取实体(同步)
POST /api/v1/ai/ner/extract/async 异步提取实体
POST /api/v1/ai/chat AI对话
POST /api/v1/ai/suggest AI建议
POST /api/v1/ai/optimize AI优化文本

五、数据访问层设计

5.1 图数据库基础服务

/**
 * 节点服务基类
 */
@Service
public class NodeService {
    
    @Autowired
    private NodeMapper nodeMapper;
    
    @Autowired
    private NodePropertyMapper propertyMapper;
    
    /**
     * 创建节点
     */
    public Long createNode(String nodeType, String nodeKey, String name, Long createdBy) {
        Node node = new Node();
        node.setNodeType(nodeType);
        node.setNodeKey(nodeKey);
        node.setName(name);
        node.setCreatedBy(createdBy);
        nodeMapper.insert(node);
        return node.getId();
    }
    
    /**
     * 设置节点属性
     */
    public void setProperty(Long nodeId, String propKey, Object value) {
        NodeProperty property = new NodeProperty();
        property.setNodeId(nodeId);
        property.setPropKey(propKey);
        
        if (value instanceof String) {
            property.setPropValue((String) value);
        } else if (value instanceof Number) {
            property.setPropNumber(new BigDecimal(value.toString()));
        } else if (value instanceof Date) {
            property.setPropDate((Date) value);
        } else {
            property.setPropJson(JSON.toJSONString(value));
        }
        
        propertyMapper.insertOrUpdate(property);
    }
    
    /**
     * 获取节点属性
     */
    public String getPropertyValue(Long nodeId, String propKey) {
        return propertyMapper.selectValue(nodeId, propKey);
    }
}

5.2 关系服务

/**
 * 关系服务
 */
@Service
public class EdgeService {
    
    @Autowired
    private EdgeMapper edgeMapper;
    
    /**
     * 创建关系
     */
    public Long createEdge(String edgeType, Long fromNodeId, Long toNodeId, Integer sortOrder) {
        Edge edge = new Edge();
        edge.setEdgeType(edgeType);
        edge.setFromNodeId(fromNodeId);
        edge.setToNodeId(toNodeId);
        edge.setSortOrder(sortOrder);
        edgeMapper.insert(edge);
        return edge.getId();
    }
    
    /**
     * 查询关系
     */
    public List<Edge> findEdges(String edgeType, Long fromNodeId) {
        return edgeMapper.selectByTypeAndFrom(edgeType, fromNodeId);
    }
    
    /**
     * 删除关系
     */
    public void deleteEdge(Long edgeId) {
        edgeMapper.deleteById(edgeId);
    }
}

5.3 视图查询服务

/**
 * 报告查询服务(基于视图)
 */
@Service
public class ReportQueryService {
    
    @Autowired
    private ReportViewMapper reportViewMapper;
    
    /**
     * 获取报告列表
     */
    public Page<ReportVO> listReports(ReportQueryDTO query) {
        return reportViewMapper.selectReportPage(query);
    }
    
    /**
     * 获取报告详情
     */
    public ReportDetailVO getReportDetail(Long reportId) {
        // 查询报告基本信息(v_reports视图)
        ReportVO report = reportViewMapper.selectById(reportId);
        
        // 查询要素值列表(v_report_element_values视图)
        List<ElementValueVO> values = reportViewMapper.selectValuesByReportId(reportId);
        
        // 查询附件列表(v_attachments视图)
        List<AttachmentVO> attachments = reportViewMapper.selectAttachmentsByReportId(reportId);
        
        // 查询规则列表(v_rules视图)
        List<RuleVO> rules = reportViewMapper.selectRulesByReportId(reportId);
        
        // 组装返回
        ReportDetailVO detail = new ReportDetailVO();
        detail.setReport(report);
        detail.setValues(values);
        detail.setAttachments(attachments);
        detail.setRules(rules);
        
        return detail;
    }
}

六、技术选型

6.1 核心框架

  • Spring Boot: 3.2.x
  • MyBatis-Plus: 3.5.x
  • PostgreSQL: 15.x
  • Redis: 7.x

6.2 文件处理

  • Apache POI: Word/Excel解析
  • PDFBox: PDF解析
  • Tika: 通用文件解析

6.3 AI服务

  • OpenAI API: GPT-4调用
  • Python NER服务: 实体识别(独立服务)
  • Feign: 服务间调用

6.4 实时通信

  • Spring WebSocket: 实时推送
  • STOMP: 消息协议

6.5 任务调度

  • Spring Task: 异步任务
  • XXL-Job: 分布式任务调度(可选)

6.6 文件存储

  • 本地存储: 开发环境
  • MinIO/OSS: 生产环境

七、开发优先级

Phase 1: 核心功能(2周)

  1. ✅ 图数据库基础服务(NodeService, EdgeService)
  2. ✅ 项目管理(CRUD)
  3. ✅ 模板管理(CRUD + 要素定义)
  4. ✅ 报告管理(CRUD + 基于模板创建)
  5. ✅ 附件上传(文件存储)

Phase 2: 解析与实体(2周)

  1. ✅ 文件解析服务(PDF/Word/Excel)
  2. ✅ NER实体识别(调用Python服务)
  3. ✅ 实体管理(CRUD + 合并)
  4. ✅ WebSocket实时推送

Phase 3: 规则引擎(2周)

  1. ✅ 规则创建与配置
  2. ✅ 规则执行器(直接引用实体)
  3. ✅ 规则执行器(正则提取)
  4. ✅ 规则执行器(LLM生成)
  5. ✅ 批量执行规则

Phase 4: AI助手(1周)

  1. ✅ AI对话接口
  2. ✅ AI建议功能
  3. ✅ AI文本优化

Phase 5: 导出与优化(1周)

  1. ✅ 报告导出(Word/PDF)
  2. ✅ 性能优化
  3. ✅ 接口文档(Swagger)

八、关键技术点

8.1 图数据库查询优化

  • 使用数据库视图预聚合数据
  • 索引优化(node_type, edge_type组合索引)
  • 分页查询优化

8.2 文件解析异步化

  • 使用Spring @Async异步处理
  • WebSocket推送进度
  • 解析失败重试机制

8.3 规则引擎设计

  • 策略模式:不同规则类型对应不同执行器
  • 责任链模式:规则依赖关系处理
  • 缓存优化:规则执行结果缓存

8.4 实时通信

  • WebSocket连接管理
  • 心跳保活机制
  • 断线重连

8.5 安全性

  • JWT认证
  • 接口权限控制
  • 文件上传安全检查
  • SQL注入防护

九、部署架构

┌─────────────────────────────────────────────────────────────┐
│                         Nginx (反向代理)                      │
└─────────────────────────────────────────────────────────────┘
                              │
                ┌─────────────┴─────────────┐
                │                           │
                ▼                           ▼
┌──────────────────────┐      ┌──────────────────────┐
│   Spring Boot App    │      │   Python NER Service │
│   (端口: 8080)        │◄────▶│   (端口: 5000)        │
└──────────────────────┘      └──────────────────────┘
                │
    ┌───────────┼───────────┐
    │           │           │
    ▼           ▼           ▼
┌────────┐  ┌────────┐  ┌────────┐
│PostgreSQL│ │ Redis  │  │ MinIO  │
│(端口:5432)│ │(端口:6379)│ │(端口:9000)│
└────────┘  └────────┘  └────────┘

十、总结

本设计方案基于图数据库思想,采用节点-关系-属性的三元组模型,实现了:

表结构稳定: 核心表不变,扩展靠数据
业务灵活: 通过视图组合业务接口
AI友好: 结构化关系描述,易于AI理解
高扩展性: 新增报告类型无需改表
高性能: 索引优化 + 视图预聚合

下一步: 根据此设计开始编码实现。