Files
cma-management/architecture/strategic-map-enhancement.md
Hermes CI Fix 3dddd36866 init: 管理会计OS初始代码
包含前后端完整代码:
- 前端:Vue3+Vite+ElementPlus
- 后端:FastAPI+SQLAlchemy
- 模块:驾驶舱/KPI/战略地图/预警/预算/成本/预测/改善行动
- 当前版本:v1.0.0
2026-05-28 17:32:22 +08:00

159 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 战略地图配置器增强 — 技术方案 v1.0
## 1. 概述
在现有 StrategicMap 模型的基础上,补全 Epic 1 战略地图配置器的 6 个 Feature 缺口。
本次开发覆盖 P0(因果连线 + 组织层级)+ P1(目标优化 + 版本管理)+ P2(模板加载 + 拖拽关联)。
## 2. 现有系统基础(不改动)
- `strategic_maps` 表:id, title, version, status, dimensions(JSON), canvas_data(JSON), created_at, updated_at
- `kpi_definitions` 表:id, map_id(FK), kpi_code, kpi_name, dimension, objective, target_value ...
- `MapList.vue` / `MapCanvas.vue`
## 3. 各 Feature 详细方案
---
### Feature 1.3 因果连线 (P0 RED)
#### 后端变更
**现状**canvas_data.connections 字段存 JSON,但无独立 API
**方案**:不新增表,沿用 canvas_data.connections,但新增独立 CRUD API 来操作连线
```
POST /api/cma/maps/{map_id}/connections body: {from_objective_id, to_objective_id}
DELETE /api/cma/maps/{map_id}/connections/{idx}
```
**连线数据模型**
```json
{
"connections": [
{ "from": "learning-0", "to": "process-0", "style": "solid" },
{ "from": "process-0", "to": "customer-1", "style": "solid" }
]
}
```
#### 前端变更
1. **集成 @vue-flow/core**(推荐)
- 每个目标卡片作为 Flow 节点
- 拖拽手柄生成连线
- 支持 hover 高亮、右键删除
2. **备选:自建 SVG 交互层**
- 点击目标A 进入连线模式 - 点击目标B 生成连线
- hover 连线上出现删除按钮
---
### Feature 1.5 组织层级配置 (P0 RED)
#### 后端 — 新表
```sql
CREATE TABLE org_nodes (
id INT AUTO_INCREMENT PRIMARY KEY,
parent_id INT DEFAULT NULL,
name VARCHAR(100) NOT NULL,
code VARCHAR(50) UNIQUE,
level TINYINT NOT NULL, -- 1=集团 2=事业部 3=区域 4=部门 5=班组
sort_order INT DEFAULT 0,
enabled TINYINT(1) DEFAULT 1,
path VARCHAR(500),
remark VARCHAR(200),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (parent_id) REFERENCES org_nodes(id)
);
```
#### API
```
GET /api/cma/org/tree # 全量树结构
GET /api/cma/org/nodes # 平铺列表
POST /api/cma/org/nodes # 新增节点
PUT /api/cma/org/nodes/{id} # 修改节点
DELETE /api/cma/org/nodes/{id} # 删除节点
PUT /api/cma/org/nodes/{id}/toggle # 切换启用/禁用
```
#### 前端
- Element Plus `<el-tree>` 组件展示树
- 右键菜单:添加子节点 / 编辑 / 启用禁用 / 删除
- 拖拽排序
---
### Feature 1.2 战略目标管理增强 (P1 YELLOW)
新建 map_objectives 表:
```sql
CREATE TABLE map_objectives (
id INT AUTO_INCREMENT PRIMARY KEY,
map_id INT NOT NULL,
dimension_key VARCHAR(50) NOT NULL,
name VARCHAR(200) NOT NULL,
description TEXT,
icon VARCHAR(50) DEFAULT 'target',
sort_order INT DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (map_id) REFERENCES strategic_maps(id) ON DELETE CASCADE
);
```
APIGET/POST/PUT/DELETE /api/cma/maps/{map_id}/objectives
前端:弹窗增加描述字段 + 图标选择器 + 拖拽排序
---
### Feature 1.6 版本管理 (P1 YELLOW)
```sql
CREATE TABLE strategic_map_versions (
id INT AUTO_INCREMENT PRIMARY KEY,
map_id INT NOT NULL,
version VARCHAR(20) NOT NULL,
dimensions JSON NOT NULL,
canvas_data JSON NOT NULL,
comment VARCHAR(500),
created_by INT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (map_id) REFERENCES strategic_maps(id) ON DELETE CASCADE
);
```
API:版本列表 + 创建快照 + 回滚
前端:MapList 页增加版本历史按钮 + VersionListDialog
---
## 4. 开发顺序与依赖关系
```
P0a: 因果连线 —— 无依赖
P0b: 组织层级 —— 完全独立
=> 两个P0可并行
P1a: 目标管理增强 —— 依赖新 objectives 表
P1b: 版本管理 —— 依赖 StrategicMap 已有结构
P2: KPI拖拽关联 —— 依赖 objectives 模型
```
推荐执行:P0a+P0b(并行) → P1a+P1b(并行) → P2
## 5. 风险
| 风险 | 应对 |
|------|------|
| @vue-flow/core 样式冲突 | 隔离CSS / 使用自建SVG |
| 组织树 >500节点性能 | 后端懒加载 + el-tree lazy |
| 版本快照膨胀 | 保留最近50版本 |
| 回滚后画布状态不一致 | 回滚后强制刷新页面 |