# 表结构设计
**本文档引用的文件**
- [backend/app/models/models.py](file://backend/app/models/models.py)
- [backend/app/models/finance.py](file://backend/app/models/finance.py)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py)
- [backend/alembic/versions/002_template.py](file://backend/alembic/versions/002_template.py)
- [backend/alembic/env.py](file://backend/alembic/env.py)
- [backend/alembic.ini](file://backend/alembic.ini)
- [backend/init_db.py](file://backend/init_db.py)
- [backend/create_menu_tables.py](file://backend/create_menu_tables.py)
- [backend/create_plan_tables.py](file://backend/create_plan_tables.py)
- [backend/init_indicator_templates.py](file://backend/init_indicator_templates.py)
- [backend/app/core/database.py](file://backend/app/core/database.py)
- [backend/app/core/config.py](file://backend/app/core/config.py)
- [backend/app/schemas/schemas.py](file://backend/app/schemas/schemas.py)
## 目录
1. [简介](#简介)
2. [项目结构](#项目结构)
3. [核心组件](#核心组件)
4. [架构概览](#架构概览)
5. [详细组件分析](#详细组件分析)
6. [依赖关系分析](#依赖关系分析)
7. [性能考虑](#性能考虑)
8. [故障排除指南](#故障排除指南)
9. [结论](#结论)
10. [附录](#附录)
## 简介
本文件为医院绩效考核管理系统的数据库表结构设计文档。系统围绕"科室-员工-指标-考核-工资-计划-模板-菜单-财务"等核心业务实体构建,采用SQLAlchemy ORM映射,支持平衡计分卡(BSC)维度管理、多层级组织架构、灵活的绩效计划与模板化指标体系,并提供财务核算能力。
## 项目结构
后端采用分层架构:
- 数据模型层:定义ORM模型与枚举类型
- 迁移层:Alembic版本化管理数据库演进
- 核心配置:数据库连接与应用配置
- 服务层:业务逻辑封装
- API层:接口定义与数据校验
```mermaid
graph TB
subgraph "数据模型层"
M1["models.py
核心业务模型"]
M2["finance.py
财务核算模型"]
end
subgraph "迁移层"
V1["001_initial.py
初始版本"]
V2["002_template.py
模板扩展"]
ENV["env.py
迁移环境"]
CONF["alembic.ini
迁移配置"]
end
subgraph "核心配置"
DB["database.py
数据库连接"]
CFG["config.py
应用配置"]
end
subgraph "初始化脚本"
INIT["init_db.py
基础数据初始化"]
MENU["create_menu_tables.py
菜单表创建"]
PLAN["create_plan_tables.py
计划表创建"]
TEMPLATE["init_indicator_templates.py
指标模板初始化"]
end
M1 --> DB
M2 --> DB
V1 --> ENV
V2 --> ENV
ENV --> DB
CONF --> ENV
INIT --> DB
MENU --> DB
PLAN --> DB
TEMPLATE --> DB
CFG --> DB
```
**图表来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L1-L438)
- [backend/app/models/finance.py](file://backend/app/models/finance.py#L1-L79)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L1-L183)
- [backend/alembic/versions/002_template.py](file://backend/alembic/versions/002_template.py#L1-L96)
- [backend/alembic/env.py](file://backend/alembic/env.py#L1-L66)
- [backend/alembic.ini](file://backend/alembic.ini#L1-L44)
- [backend/init_db.py](file://backend/init_db.py#L1-L83)
- [backend/create_menu_tables.py](file://backend/create_menu_tables.py#L1-L27)
- [backend/create_plan_tables.py](file://backend/create_plan_tables.py#L1-L20)
- [backend/init_indicator_templates.py](file://backend/init_indicator_templates.py#L1-L375)
- [backend/app/core/database.py](file://backend/app/core/database.py#L1-L39)
- [backend/app/core/config.py](file://backend/app/core/config.py#L1-L47)
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L1-L438)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L1-L183)
- [backend/alembic/versions/002_template.py](file://backend/alembic/versions/002_template.py#L1-L96)
- [backend/app/core/database.py](file://backend/app/core/database.py#L1-L39)
- [backend/app/core/config.py](file://backend/app/core/config.py#L1-L47)
## 核心组件
系统包含以下核心数据表:
- 科室信息表(departments)
- 员工信息表(staff)
- 考核指标表(indicators)
- 考核记录表(assessments)
- 考核明细表(assessment_details)
- 工资核算记录表(salary_records)
- 系统用户表(users)
- 绩效计划表(performance_plans)
- 计划指标关联表(plan_kpi_relations)
- 系统菜单表(menus)
- 考核指标模板表(indicator_templates)
- 模板指标关联表(template_indicators)
- 科室财务记录表(department_finances)
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L62-L86)
- [backend/app/models/models.py](file://backend/app/models/models.py#L88-L114)
- [backend/app/models/models.py](file://backend/app/models/models.py#L117-L146)
- [backend/app/models/models.py](file://backend/app/models/models.py#L149-L178)
- [backend/app/models/models.py](file://backend/app/models/models.py#L181-L202)
- [backend/app/models/models.py](file://backend/app/models/models.py#L205-L230)
- [backend/app/models/models.py](file://backend/app/models/models.py#L244-L260)
- [backend/app/models/models.py](file://backend/app/models/models.py#L270-L296)
- [backend/app/models/models.py](file://backend/app/models/models.py#L314-L338)
- [backend/app/models/models.py](file://backend/app/models/models.py#L347-L372)
- [backend/app/models/models.py](file://backend/app/models/models.py#L387-L408)
- [backend/app/models/models.py](file://backend/app/models/models.py#L411-L437)
- [backend/app/models/finance.py](file://backend/app/models/finance.py#L45-L74)
## 架构概览
系统采用异步数据库连接,通过Alembic进行版本化迁移管理。模型层定义了完整的业务实体关系,服务层负责业务逻辑处理,API层提供REST接口与数据校验。
```mermaid
graph TB
subgraph "数据库层"
DB["PostgreSQL/SQLite"]
IDX["索引与约束"]
end
subgraph "模型层"
BASE["Base(ORM基类)"]
ENUM["枚举类型"]
MODELS["业务模型"]
end
subgraph "迁移层"
ALEMBIC["Alembic迁移"]
VERSIONS["版本文件"]
end
subgraph "应用层"
API["FastAPI接口"]
SERVICE["业务服务"]
SCHEMA["Pydantic校验"]
end
MODELS --> BASE
ENUM --> MODELS
ALEMBIC --> VERSIONS
ALEMBIC --> DB
MODELS --> DB
API --> SERVICE
SERVICE --> MODELS
SCHEMA --> API
```
**图表来源**
- [backend/app/core/database.py](file://backend/app/core/database.py#L23-L39)
- [backend/alembic/env.py](file://backend/alembic/env.py#L18-L66)
- [backend/app/schemas/schemas.py](file://backend/app/schemas/schemas.py#L1-L743)
## 详细组件分析
### 科室信息表(departments)
**用途**:存储医院组织架构,支持多层级科室管理,支持上下级关系。
**字段定义**:
- id:整型,自增主键
- name:字符串(100),非空,科室名称
- code:字符串(20),非空且唯一,科室编码
- dept_type:字符串,非空,科室类型(枚举)
- parent_id:整型,外键指向自身id,上级科室
- level:整型,默认1,层级
- sort_order:整型,默认0,排序
- is_active:布尔,默认true,是否启用
- description:文本,描述
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 唯一约束:code
- 外键:parent_id 引用 departments.id
- 索引:idx_dept_type(dept_type),idx_dept_parent(parent_id)
**业务含义与取值范围**:
- dept_type涵盖临床、医技、护理、行政、财务、后勤等类型
- 支持无限层级的树形结构
- is_active用于逻辑删除或停用
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE departments (
id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL COMMENT '科室名称',
code VARCHAR(20) NOT NULL COMMENT '科室编码',
dept_type VARCHAR(20) NOT NULL COMMENT '科室类型',
parent_id INTEGER COMMENT '上级科室',
level INTEGER COMMENT '层级',
sort_order INTEGER DEFAULT 0 COMMENT '排序',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否启用',
description TEXT COMMENT '描述',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
UNIQUE (code),
FOREIGN KEY (parent_id) REFERENCES departments(id)
);
CREATE INDEX idx_dept_type ON departments (dept_type);
CREATE INDEX idx_dept_parent ON departments (parent_id);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L62-L86)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L22-L41)
### 员工信息表(staff)
**用途**:存储员工基本信息、薪资系数、状态等。
**字段定义**:
- id:整型,自增主键
- employee_id:字符串(20),非空且唯一,工号
- name:字符串(50),非空,姓名
- department_id:整型,非空,所属科室(外键)
- position:字符串(50),非空,职位
- title:字符串(50),可空,职称
- phone:字符串(20),可空,联系电话
- email:字符串(100),可空,邮箱
- base_salary:数值(10,2),默认0,基本工资
- performance_ratio:数值(5,2),默认1.0,绩效系数
- status:字符串,枚举,默认active,员工状态
- hire_date:时间戳,可空,入职日期
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 唯一约束:employee_id
- 外键:department_id 引用 departments.id
- 索引:idx_staff_dept(department_id),idx_staff_status(status)
**业务含义与取值范围**:
- performance_ratio用于绩效工资计算的浮动系数
- status支持在职、休假、离职、退休等状态管理
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE staff (
id INTEGER NOT NULL AUTO_INCREMENT,
employee_id VARCHAR(20) NOT NULL COMMENT '工号',
name VARCHAR(50) NOT NULL COMMENT '姓名',
department_id INTEGER NOT NULL COMMENT '所属科室',
position VARCHAR(50) NOT NULL COMMENT '职位',
title VARCHAR(50) COMMENT '职称',
phone VARCHAR(20) COMMENT '联系电话',
email VARCHAR(100) COMMENT '邮箱',
base_salary NUMERIC(10,2) DEFAULT 0 COMMENT '基本工资',
performance_ratio NUMERIC(5,2) DEFAULT 1.0 COMMENT '绩效系数',
status VARCHAR(20) DEFAULT 'active' COMMENT '状态',
hire_date DATETIME COMMENT '入职日期',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
UNIQUE (employee_id),
FOREIGN KEY (department_id) REFERENCES departments(id)
);
CREATE INDEX idx_staff_dept ON staff (department_id);
CREATE INDEX idx_staff_status ON staff (status);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L88-L114)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L42-L64)
### 考核指标表(indicators)
**用途**:定义绩效考核指标,支持平衡计分卡维度、权重、目标值等。
**字段定义**:
- id:整型,自增主键
- name:字符串(100),非空,指标名称
- code:字符串(20),非空且唯一,指标编码
- indicator_type:字符串,非空,指标类型(质量、数量、效率、服务、成本)
- bs_dimension:字符串,非空,平衡计分卡维度(财务、客户、内部流程、学习与成长)
- weight:数值(5,2),默认1.0,权重(>0)
- max_score:数值(5,2),默认100.0,最高分值
- target_value:数值(10,2),可空,目标值
- target_unit:字符串(50),可空,目标值单位
- calculation_method:文本,可空,计算方法/公式
- assessment_method:文本,可空,考核方法
- deduction_standard:文本,可空,扣分标准
- data_source:字符串(100),可空,数据来源
- applicable_dept_types:文本,可空,适用科室类型(JSON数组)
- is_veto:布尔,默认false,是否一票否决指标
- is_active:布尔,默认true,是否启用
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 唯一约束:code
- 检查约束:ck_indicator_weight(weight > 0)
- 索引:idx_indicator_type(indicator_type)
**业务含义与取值范围**:
- 支持BSC四维度指标设计
- applicable_dept_types通过JSON存储适用科室类型集合
- is_veto用于强制性否决指标(如院感控制达标率)
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE indicators (
id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL COMMENT '指标名称',
code VARCHAR(20) NOT NULL COMMENT '指标编码',
indicator_type VARCHAR(20) NOT NULL COMMENT '指标类型',
bs_dimension VARCHAR(30) NOT NULL COMMENT '平衡计分卡维度',
weight NUMERIC(5,2) DEFAULT 1.0 COMMENT '权重',
max_score NUMERIC(5,2) DEFAULT 100.0 COMMENT '最高分值',
target_value NUMERIC(10,2) COMMENT '目标值',
target_unit VARCHAR(50) COMMENT '目标值单位',
calculation_method TEXT COMMENT '计算方法/公式',
assessment_method TEXT COMMENT '考核方法',
deduction_standard TEXT COMMENT '扣分标准',
data_source VARCHAR(100) COMMENT '数据来源',
applicable_dept_types TEXT COMMENT '适用科室类型 (JSON数组)',
is_veto BOOLEAN DEFAULT FALSE COMMENT '是否一票否决指标',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否启用',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
UNIQUE (code)
);
CREATE INDEX idx_indicator_type ON indicators (indicator_type);
ALTER TABLE indicators ADD CONSTRAINT ck_indicator_weight CHECK (weight > 0);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L117-L146)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L66-L86)
- [backend/alembic/versions/002_template.py](file://backend/alembic/versions/002_template.py#L65-L91)
### 考核记录表(assessments)
**用途**:记录员工的绩效考核结果,支持多周期、多状态管理。
**字段定义**:
- id:整型,自增主键
- staff_id:整型,非空,员工ID(外键)
- period_year:整型,非空,考核年度
- period_month:整型,非空,考核月份
- period_type:字符串(20),默认monthly,考核周期类型
- total_score:数值(5,2),默认0,总分
- weighted_score:数值(5,2),默认0,加权得分
- status:字符串,枚举,默认draft,状态(草稿、已提交、已审核、已确认、已驳回)
- assessor_id:整型,可空,考核人(外键)
- reviewer_id:整型,可空,审核人(外键)
- submit_time:时间戳,可空,提交时间
- review_time:时间戳,可空,审核时间
- remark:文本,可空,备注
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 外键:staff_id 引用 staff.id;assessor_id/reviewer_id 引用 staff.id
- 索引:idx_assessment_staff(staff_id),idx_assessment_period(period_year, period_month),idx_assessment_status(status)
**业务含义与取值范围**:
- 支持月度、季度等周期类型
- 多级审批流程(考核人→审核人)
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE assessments (
id INTEGER NOT NULL AUTO_INCREMENT,
staff_id INTEGER NOT NULL COMMENT '员工ID',
period_year INTEGER NOT NULL COMMENT '考核年度',
period_month INTEGER NOT NULL COMMENT '考核月份',
period_type VARCHAR(20) DEFAULT 'monthly' COMMENT '考核周期类型',
total_score NUMERIC(5,2) DEFAULT 0 COMMENT '总分',
weighted_score NUMERIC(5,2) DEFAULT 0 COMMENT '加权得分',
status VARCHAR(20) DEFAULT 'draft' COMMENT '状态',
assessor_id INTEGER COMMENT '考核人',
reviewer_id INTEGER COMMENT '审核人',
submit_time DATETIME COMMENT '提交时间',
review_time DATETIME COMMENT '审核时间',
remark TEXT COMMENT '备注',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
FOREIGN KEY (staff_id) REFERENCES staff(id),
FOREIGN KEY (assessor_id) REFERENCES staff(id),
FOREIGN KEY (reviewer_id) REFERENCES staff(id)
);
CREATE INDEX idx_assessment_staff ON assessments (staff_id);
CREATE INDEX idx_assessment_period ON assessments (period_year, period_month);
CREATE INDEX idx_assessment_status ON assessments (status);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L149-L178)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L87-L112)
### 考核明细表(assessment_details)
**用途**:记录单个考核周期内每位员工各项指标的实际值与得分。
**字段定义**:
- id:整型,自增主键
- assessment_id:整型,非空,考核记录ID(外键)
- indicator_id:整型,非空,指标ID(外键)
- actual_value:数值(10,2),可空,实际值
- score:数值(5,2),默认0,得分
- evidence:文本,可空,佐证材料
- remark:文本,可空,备注
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 外键:assessment_id 引用 assessments.id;indicator_id 引用 indicators.id
- 索引:idx_detail_assessment(assessment_id),idx_detail_indicator(indicator_id)
**业务含义与取值范围**:
- 支持多指标、多周期的细粒度考核
- evidence用于保存原始数据证明材料
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE assessment_details (
id INTEGER NOT NULL AUTO_INCREMENT,
assessment_id INTEGER NOT NULL COMMENT '考核记录ID',
indicator_id INTEGER NOT NULL COMMENT '指标ID',
actual_value NUMERIC(10,2) COMMENT '实际值',
score NUMERIC(5,2) DEFAULT 0 COMMENT '得分',
evidence TEXT COMMENT '佐证材料',
remark TEXT COMMENT '备注',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
FOREIGN KEY (assessment_id) REFERENCES assessments(id),
FOREIGN KEY (indicator_id) REFERENCES indicators(id)
);
CREATE INDEX idx_detail_assessment ON assessment_details (assessment_id);
CREATE INDEX idx_detail_indicator ON assessment_details (indicator_id);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L181-L202)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L114-L131)
### 工资核算记录表(salary_records)
**用途**:记录员工每月工资核算详情,支持基本工资、绩效奖金、扣款、补贴等。
**字段定义**:
- id:整型,自增主键
- staff_id:整型,非空,员工ID(外键)
- period_year:整型,非空,年度
- period_month:整型,非空,月份
- base_salary:数值(10,2),默认0,基本工资
- performance_score:数值(5,2),默认0,绩效得分
- performance_bonus:数值(10,2),默认0,绩效奖金
- deduction:数值(10,2),默认0,扣款
- allowance:数值(10,2),默认0,补贴
- total_salary:数值(10,2),默认0,应发工资
- status:字符串(20),默认pending,状态
- remark:文本,可空,备注
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 外键:staff_id 引用 staff.id
- 索引:idx_salary_staff(staff_id),idx_salary_period(period_year, period_month)
**业务含义与取值范围**:
- total_salary = base_salary + performance_bonus - deduction + allowance
- status支持待处理、已发放等状态
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE salary_records (
id INTEGER NOT NULL AUTO_INCREMENT,
staff_id INTEGER NOT NULL COMMENT '员工ID',
period_year INTEGER NOT NULL COMMENT '年度',
period_month INTEGER NOT NULL COMMENT '月份',
base_salary NUMERIC(10,2) DEFAULT 0 COMMENT '基本工资',
performance_score NUMERIC(5,2) DEFAULT 0 COMMENT '绩效得分',
performance_bonus NUMERIC(10,2) DEFAULT 0 COMMENT '绩效奖金',
deduction NUMERIC(10,2) DEFAULT 0 COMMENT '扣款',
allowance NUMERIC(10,2) DEFAULT 0 COMMENT '补贴',
total_salary NUMERIC(10,2) DEFAULT 0 COMMENT '应发工资',
status VARCHAR(20) DEFAULT 'pending' COMMENT '状态',
remark TEXT COMMENT '备注',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
FOREIGN KEY (staff_id) REFERENCES staff(id)
);
CREATE INDEX idx_salary_staff ON salary_records (staff_id);
CREATE INDEX idx_salary_period ON salary_records (period_year, period_month);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L205-L230)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L133-L154)
### 系统用户表(users)
**用途**:系统用户管理,支持角色与登录状态。
**字段定义**:
- id:整型,自增主键
- username:字符串(50),非空且唯一,用户名
- password_hash:字符串(255),非空,密码哈希
- staff_id:整型,可空,关联员工(外键)
- role:字符串(20),默认staff,角色(admin/manager/staff)
- is_active:布尔,默认true,是否启用
- last_login:时间戳,可空,最后登录
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 唯一约束:username
- 外键:staff_id 引用 staff.id
- 索引:idx_user_username(username)
**业务含义与取值范围**:
- 支持多角色权限控制
- last_login用于审计与安全
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE users (
id INTEGER NOT NULL AUTO_INCREMENT,
username VARCHAR(50) NOT NULL COMMENT '用户名',
password_hash VARCHAR(255) NOT NULL COMMENT '密码哈希',
staff_id INTEGER COMMENT '关联员工',
role VARCHAR(20) DEFAULT 'staff' COMMENT '角色',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否启用',
last_login DATETIME COMMENT '最后登录',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
UNIQUE (username),
FOREIGN KEY (staff_id) REFERENCES staff(id)
);
CREATE INDEX idx_user_username ON users (username);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L244-L260)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L156-L172)
### 绩效计划表(performance_plans)
**用途**:定义不同层级(医院级、科室级、个人级)的绩效计划,支持审批流程。
**字段定义**:
- id:整型,自增主键
- plan_name:字符串(200),非空,计划名称
- plan_code:字符串(50),非空且唯一,计划编码
- plan_level:字符串,非空,计划层级(hospital/department/individual)
- plan_year:整型,非空,计划年度
- plan_month:整型,可空,计划月份(月度计划)
- plan_type:字符串(20),默认annual,计划类型(annual/monthly)
- department_id:整型,可空,所属科室ID(外键)
- staff_id:整型,可空,责任人ID(外键)
- parent_plan_id:整型,可空,上级计划ID(外键)
- description:文本,可空,计划描述
- strategic_goals:文本,可空,战略目标
- key_initiatives:文本,可空,关键举措
- status:字符串,枚举,默认draft,状态(草稿、待审批、已批准、已驳回、执行中、已完成、已取消)
- submitter_id:整型,可空,提交人ID(外键)
- submit_time:时间戳,可空,提交时间
- approver_id:整型,可空,审批人ID(外键)
- approve_time:时间戳,可空,审批时间
- approve_remark:文本,可空,审批意见
- version:整型,默认1,版本号
- is_active:布尔,默认true,是否启用
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 唯一约束:plan_code
- 外键:department_id 引用 departments.id;staff_id 引用 staff.id;parent_plan_id 引用自身id;submitter_id/approver_id 引用 users.id
- 索引:idx_plan_level(plan_level),idx_plan_year(plan_year),idx_plan_department(department_id),idx_plan_status(status)
**业务含义与取值范围**:
- 支持树形计划结构
- 多级审批流程
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE performance_plans (
id INTEGER NOT NULL AUTO_INCREMENT,
plan_name VARCHAR(200) NOT NULL COMMENT '计划名称',
plan_code VARCHAR(50) NOT NULL COMMENT '计划编码',
plan_level VARCHAR(20) NOT NULL COMMENT '计划层级',
plan_year INTEGER NOT NULL COMMENT '计划年度',
plan_month INTEGER COMMENT '计划月份 (月度计划)',
plan_type VARCHAR(20) DEFAULT 'annual' COMMENT '计划类型 (annual/monthly)',
department_id INTEGER COMMENT '所属科室 ID',
staff_id INTEGER COMMENT '责任人 ID',
parent_plan_id INTEGER COMMENT '上级计划 ID',
description TEXT COMMENT '计划描述',
strategic_goals TEXT COMMENT '战略目标',
key_initiatives TEXT COMMENT '关键举措',
status VARCHAR(20) DEFAULT 'draft' COMMENT '状态',
submitter_id INTEGER COMMENT '提交人 ID',
submit_time DATETIME COMMENT '提交时间',
approver_id INTEGER COMMENT '审批人 ID',
approve_time DATETIME COMMENT '审批时间',
approve_remark TEXT COMMENT '审批意见',
version INTEGER DEFAULT 1 COMMENT '版本号',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否启用',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
UNIQUE (plan_code),
FOREIGN KEY (department_id) REFERENCES departments(id),
FOREIGN KEY (staff_id) REFERENCES staff(id),
FOREIGN KEY (parent_plan_id) REFERENCES performance_plans(id),
FOREIGN KEY (submitter_id) REFERENCES users(id),
FOREIGN KEY (approver_id) REFERENCES users(id)
);
CREATE INDEX idx_plan_level ON performance_plans (plan_level);
CREATE INDEX idx_plan_year ON performance_plans (plan_year);
CREATE INDEX idx_plan_department ON performance_plans (department_id);
CREATE INDEX idx_plan_status ON performance_plans (status);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L270-L296)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L1-L183)
### 计划指标关联表(plan_kpi_relations)
**用途**:将指标与绩效计划关联,支持目标值、权重、评分方法等个性化配置。
**字段定义**:
- id:整型,自增主键
- plan_id:整型,非空,计划ID(外键)
- indicator_id:整型,非空,指标ID(外键)
- target_value:数值(10,2),可空,目标值
- target_unit:字符串(50),可空,目标值单位
- weight:数值(5,2),默认1.0,权重
- scoring_method:字符串(50),可空,评分方法
- scoring_params:文本,可空,评分参数(JSON)
- remark:文本,可空,备注
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 外键:plan_id 引用 performance_plans.id;indicator_id 引用 indicators.id
- 索引:idx_relation_plan(plan_id),idx_relation_indicator(indicator_id),idx_relation_unique(plan_id, indicator_id,唯一)
**业务含义与取值范围**:
- 支持同一指标在不同计划中的差异化配置
- scoring_params用于存储复杂评分算法参数
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE plan_kpi_relations (
id INTEGER NOT NULL AUTO_INCREMENT,
plan_id INTEGER NOT NULL COMMENT '计划 ID',
indicator_id INTEGER NOT NULL COMMENT '指标 ID',
target_value NUMERIC(10,2) COMMENT '目标值',
target_unit VARCHAR(50) COMMENT '目标值单位',
weight NUMERIC(5,2) DEFAULT 1.0 COMMENT '权重',
scoring_method VARCHAR(50) COMMENT '评分方法',
scoring_params TEXT COMMENT '评分参数 (JSON)',
remark TEXT COMMENT '备注',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
FOREIGN KEY (plan_id) REFERENCES performance_plans(id),
FOREIGN KEY (indicator_id) REFERENCES indicators(id)
);
CREATE INDEX idx_relation_plan ON plan_kpi_relations (plan_id);
CREATE INDEX idx_relation_indicator ON plan_kpi_relations (indicator_id);
CREATE UNIQUE INDEX idx_relation_unique ON plan_kpi_relations (plan_id, indicator_id);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L314-L338)
- [backend/alembic/versions/002_template.py](file://backend/alembic/versions/002_template.py#L41-L63)
### 系统菜单表(menus)
**用途**:系统菜单与按钮权限管理,支持树形菜单结构。
**字段定义**:
- id:整型,自增主键
- parent_id:整型,可空,父菜单ID(外键)
- menu_type:字符串,默认menu,菜单类型(菜单/按钮)
- menu_name:字符串(100),非空,菜单名称
- menu_icon:字符串(50),可空,菜单图标
- path:字符串(200),非空,路由路径
- component:字符串(200),可空,组件路径
- permission:字符串(100),可空,权限标识
- sort_order:整型,默认0,排序
- is_visible:布尔,默认true,是否可见
- is_active:布尔,默认true,是否启用
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 外键:parent_id 引用自身id
- 索引:idx_menu_parent(parent_id),idx_menu_type(menu_type),idx_menu_visible(is_visible)
**业务含义与取值范围**:
- 支持菜单与按钮两级权限控制
- permission用于前端路由与操作权限控制
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE menus (
id INTEGER NOT NULL AUTO_INCREMENT,
parent_id INTEGER COMMENT '父菜单 ID',
menu_type VARCHAR(20) DEFAULT 'menu' COMMENT '菜单类型',
menu_name VARCHAR(100) NOT NULL COMMENT '菜单名称',
menu_icon VARCHAR(50) COMMENT '菜单图标',
path VARCHAR(200) NOT NULL COMMENT '路由路径',
component VARCHAR(200) COMMENT '组件路径',
permission VARCHAR(100) COMMENT '权限标识',
sort_order INTEGER DEFAULT 0 COMMENT '排序',
is_visible BOOLEAN DEFAULT TRUE COMMENT '是否可见',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否启用',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
FOREIGN KEY (parent_id) REFERENCES menus(id)
);
CREATE INDEX idx_menu_parent ON menus (parent_id);
CREATE INDEX idx_menu_type ON menus (menu_type);
CREATE INDEX idx_menu_visible ON menus (is_visible);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L347-L372)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L1-L183)
### 考核指标模板表(indicator_templates)
**用途**:定义按科室类型的标准化指标模板,支持维度权重配置。
**字段定义**:
- id:整型,自增主键
- template_name:字符串(200),非空,模板名称
- template_code:字符串(50),非空且唯一,模板编码
- template_type:字符串,非空,模板类型(通用、手术、非手术有病房、非手术无病房、医技、护理、行政、后勤)
- description:文本,可空,模板描述
- dimension_weights:文本,可空,维度权重(JSON)
- assessment_cycle:字符串(20),默认monthly,考核周期
- is_active:布尔,默认true,是否启用
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 唯一约束:template_code
- 索引:idx_template_type(template_type),idx_template_active(is_active)
**业务含义与取值范围**:
- dimension_weights用于存储BSC四维度的权重配置
- 支持按科室类型快速生成标准化指标集
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE indicator_templates (
id INTEGER NOT NULL AUTO_INCREMENT,
template_name VARCHAR(200) NOT NULL COMMENT '模板名称',
template_code VARCHAR(50) NOT NULL COMMENT '模板编码',
template_type VARCHAR(30) NOT NULL COMMENT '模板类型',
description TEXT COMMENT '模板描述',
dimension_weights TEXT COMMENT '维度权重 (JSON)',
assessment_cycle VARCHAR(20) DEFAULT 'monthly' COMMENT '考核周期',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否启用',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
UNIQUE (template_code)
);
CREATE INDEX idx_template_type ON indicator_templates (template_type);
CREATE INDEX idx_template_active ON indicator_templates (is_active);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L387-L408)
- [backend/alembic/versions/002_template.py](file://backend/alembic/versions/002_template.py#L21-L40)
### 模板指标关联表(template_indicators)
**用途**:将指标与模板关联,支持分类、目标值、权重、评分方法等配置。
**字段定义**:
- id:整型,自增主键
- template_id:整型,非空,模板ID(外键)
- indicator_id:整型,非空,指标ID(外键)
- category:字符串(100),可空,指标分类(二级指标)
- target_value:数值(10,2),可空,目标值
- target_unit:字符串(50),可空,目标值单位
- weight:数值(5,2),默认1.0,权重
- scoring_method:字符串(50),可空,评分方法
- scoring_params:文本,可空,评分参数(JSON)
- sort_order:整型,默认0,排序
- remark:文本,可空,备注
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 外键:template_id 引用 indicator_templates.id;indicator_id 引用 indicators.id
- 索引:idx_ti_template(template_id),idx_ti_indicator(indicator_id),idx_ti_unique(template_id, indicator_id,唯一)
**业务含义与取值范围**:
- 支持模板化复用指标
- category用于二级指标分类管理
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE template_indicators (
id INTEGER NOT NULL AUTO_INCREMENT,
template_id INTEGER NOT NULL COMMENT '模板 ID',
indicator_id INTEGER NOT NULL COMMENT '指标 ID',
category VARCHAR(100) COMMENT '指标分类 (二级指标)',
target_value NUMERIC(10,2) COMMENT '目标值',
target_unit VARCHAR(50) COMMENT '目标值单位',
weight NUMERIC(5,2) DEFAULT 1.0 COMMENT '权重',
scoring_method VARCHAR(50) COMMENT '评分方法',
scoring_params TEXT COMMENT '评分参数 (JSON)',
sort_order INTEGER DEFAULT 0 COMMENT '排序',
remark TEXT COMMENT '备注',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
FOREIGN KEY (template_id) REFERENCES indicator_templates(id),
FOREIGN KEY (indicator_id) REFERENCES indicators(id)
);
CREATE INDEX idx_ti_template ON template_indicators (template_id);
CREATE INDEX idx_ti_indicator ON template_indicators (indicator_id);
CREATE UNIQUE INDEX idx_ti_unique ON template_indicators (template_id, indicator_id);
```
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L411-L437)
- [backend/alembic/versions/002_template.py](file://backend/alembic/versions/002_template.py#L41-L63)
### 科室财务记录表(department_finances)
**用途**:记录各科室的财务收支数据,支持收入与支出分类统计。
**字段定义**:
- id:整型,自增主键
- department_id:整型,非空,科室ID(外键)
- period_year:整型,非空,年度
- period_month:整型,非空,月份
- finance_type:字符串,非空,财务类型(收入/支出)
- category:字符串(50),非空,类别
- amount:数值(12,2),默认0,金额(≥0)
- source:字符串(100),可空,数据来源
- remark:文本,可空,备注
- created_at:时间戳,默认当前UTC时间
- updated_at:时间戳,默认当前UTC时间,更新时自动更新
**约束与索引**:
- 主键:id
- 外键:department_id 引用 departments.id
- 检查约束:ck_finance_amount(amount ≥ 0)
- 索引:idx_finance_dept(department_id),idx_finance_period(period_year, period_month),idx_finance_type(finance_type),idx_finance_category(category)
**业务含义与取值范围**:
- 支持按月度统计科室收支结余
- category涵盖检查费、检验费、床位费、治疗费、手术费、材料费、人员支出等
**DDL语句**(基于迁移文件):
```sql
CREATE TABLE department_finances (
id INTEGER NOT NULL AUTO_INCREMENT,
department_id INTEGER NOT NULL COMMENT '科室ID',
period_year INTEGER NOT NULL COMMENT '年度',
period_month INTEGER NOT NULL COMMENT '月份',
finance_type VARCHAR(20) NOT NULL COMMENT '财务类型',
category VARCHAR(50) NOT NULL COMMENT '类别',
amount NUMERIC(12,2) DEFAULT 0 COMMENT '金额',
source VARCHAR(100) COMMENT '数据来源',
remark TEXT COMMENT '备注',
created_at DATETIME COMMENT '创建时间',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
FOREIGN KEY (department_id) REFERENCES departments(id)
);
CREATE INDEX idx_finance_dept ON department_finances (department_id);
CREATE INDEX idx_finance_period ON department_finances (period_year, period_month);
CREATE INDEX idx_finance_type ON department_finances (finance_type);
CREATE INDEX idx_finance_category ON department_finances (category);
ALTER TABLE department_finances ADD CONSTRAINT ck_finance_amount CHECK (amount >= 0);
```
**章节来源**
- [backend/app/models/finance.py](file://backend/app/models/finance.py#L45-L74)
- [backend/alembic/versions/001_initial.py](file://backend/alembic/versions/001_initial.py#L1-L183)
## 依赖关系分析
系统表之间的依赖关系如下:
```mermaid
erDiagram
DEPARTMENTS {
integer id PK
string name
string code UK
string dept_type
integer parent_id FK
integer level
integer sort_order
boolean is_active
text description
datetime created_at
datetime updated_at
}
STAFF {
integer id PK
string employee_id UK
string name
integer department_id FK
string position
string title
string phone
string email
numeric base_salary
numeric performance_ratio
string status
datetime hire_date
datetime created_at
datetime updated_at
}
INDICATORS {
integer id PK
string name
string code UK
string indicator_type
string bs_dimension
numeric weight
numeric max_score
numeric target_value
string target_unit
text calculation_method
text assessment_method
text deduction_standard
string data_source
text applicable_dept_types
boolean is_veto
boolean is_active
datetime created_at
datetime updated_at
}
ASSESSMENTS {
integer id PK
integer staff_id FK
integer period_year
integer period_month
string period_type
numeric total_score
numeric weighted_score
string status
integer assessor_id FK
integer reviewer_id FK
datetime submit_time
datetime review_time
text remark
datetime created_at
datetime updated_at
}
ASSESSMENT_DETAILS {
integer id PK
integer assessment_id FK
integer indicator_id FK
numeric actual_value
numeric score
text evidence
text remark
datetime created_at
datetime updated_at
}
SALARY_RECORDS {
integer id PK
integer staff_id FK
integer period_year
integer period_month
numeric base_salary
numeric performance_score
numeric performance_bonus
numeric deduction
numeric allowance
numeric total_salary
string status
text remark
datetime created_at
datetime updated_at
}
USERS {
integer id PK
string username UK
string password_hash
integer staff_id FK
string role
boolean is_active
datetime last_login
datetime created_at
datetime updated_at
}
PERFORMANCE_PLANS {
integer id PK
string plan_name
string plan_code UK
string plan_level
integer plan_year
integer plan_month
string plan_type
integer department_id FK
integer staff_id FK
integer parent_plan_id FK
text description
text strategic_goals
text key_initiatives
string status
integer submitter_id FK
datetime submit_time
integer approver_id FK
datetime approve_time
text approve_remark
integer version
boolean is_active
datetime created_at
datetime updated_at
}
PLAN_KPI_RELATIONS {
integer id PK
integer plan_id FK
integer indicator_id FK
numeric target_value
string target_unit
numeric weight
string scoring_method
text scoring_params
text remark
datetime created_at
datetime updated_at
}
MENUS {
integer id PK
integer parent_id FK
string menu_type
string menu_name
string menu_icon
string path
string component
string permission
integer sort_order
boolean is_visible
boolean is_active
datetime created_at
datetime updated_at
}
INDICATOR_TEMPLATES {
integer id PK
string template_name
string template_code UK
string template_type
text description
text dimension_weights
string assessment_cycle
boolean is_active
datetime created_at
datetime updated_at
}
TEMPLATE_INDICATORS {
integer id PK
integer template_id FK
integer indicator_id FK
string category
numeric target_value
string target_unit
numeric weight
string scoring_method
text scoring_params
integer sort_order
text remark
datetime created_at
datetime updated_at
}
DEPARTMENT_FINANCES {
integer id PK
integer department_id FK
integer period_year
integer period_month
string finance_type
string category
numeric amount
string source
text remark
datetime created_at
datetime updated_at
}
DEPARTMENTS ||--o{ STAFF : "has"
DEPARTMENTS ||--o{ PERFORMANCE_PLANS : "has"
DEPARTMENTS ||--o{ DEPARTMENT_FINANCES : "has"
STAFF ||--o{ ASSESSMENTS : "has"
STAFF ||--o{ SALARY_RECORDS : "has"
STAFF ||--|| USERS : "may link"
INDICATORS ||--o{ ASSESSMENT_DETAILS : "has"
INDICATORS ||--o{ PLAN_KPI_RELATIONS : "has"
INDICATORS ||--o{ TEMPLATE_INDICATORS : "has"
ASSESSMENTS ||--o{ ASSESSMENT_DETAILS : "has"
ASSESSMENTS ||--o{ SALARY_RECORDS : "drives"
PERFORMANCE_PLANS ||--o{ PLAN_KPI_RELATIONS : "has"
PERFORMANCE_PLANS ||--o{ PERFORMANCE_PLANS : "hierarchical"
MENUS ||--o{ MENUS : "hierarchical"
```
**图表来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L62-L437)
- [backend/app/models/finance.py](file://backend/app/models/finance.py#L45-L74)
**章节来源**
- [backend/app/models/models.py](file://backend/app/models/models.py#L62-L437)
- [backend/app/models/finance.py](file://backend/app/models/finance.py#L45-L74)
## 性能考虑
- 索引策略:为高频查询字段建立索引(如staff_id、department_id、period_year+period_month、status等),平衡查询性能与写入开销。
- 数据类型选择:数值类型采用精确的精度和标度,避免浮点运算误差;文本字段使用合适长度限制。
- 外键约束:确保数据一致性的同时,注意外键查询的性能影响。
- 迁移管理:使用Alembic进行版本化迁移,确保数据库结构演进的可控性。
- 异步连接:采用异步数据库连接池,提升高并发场景下的吞吐量。
## 故障排除指南
- 数据库连接失败:检查DATABASE_URL配置,确认数据库服务可用。
- 迁移执行错误:查看Alembic日志,确认版本文件完整性与依赖关系正确。
- 字段缺失:模板迁移中对现有字段的添加需检查字段是否存在,避免重复添加。
- 数据一致性问题:利用外键约束与检查约束保证数据完整性,定期执行数据校验脚本。
**章节来源**
- [backend/app/core/config.py](file://backend/app/core/config.py#L18-L21)
- [backend/alembic/env.py](file://backend/alembic/env.py#L42-L65)
- [backend/alembic/versions/002_template.py](file://backend/alembic/versions/002_template.py#L65-L91)
## 结论
本系统通过规范化的表结构设计,实现了从组织架构到绩效考核、从指标模板到财务核算的完整业务闭环。采用平衡计分卡维度与多层级计划管理,结合模板化指标体系,既满足了医院管理的复杂需求,又保持了良好的扩展性与维护性。建议在生产环境中配合完善的备份策略、监控告警与权限控制机制,确保系统的稳定运行。
## 附录
- 初始化脚本:提供基础数据与默认菜单的初始化功能
- 模板数据:包含多种科室类型的指标模板数据
- 配置文件:数据库连接、应用配置与迁移配置
**章节来源**
- [backend/init_db.py](file://backend/init_db.py#L11-L83)
- [backend/create_menu_tables.py](file://backend/create_menu_tables.py#L10-L26)
- [backend/create_plan_tables.py](file://backend/create_plan_tables.py#L9-L19)
- [backend/init_indicator_templates.py](file://backend/init_indicator_templates.py#L11-L375)
- [backend/alembic.ini](file://backend/alembic.ini#L7-L7)