Merge remote-tracking branch 'origin/geyuan_hhy_teacher' into lon_students_merge_code_test

# Conflicts:
#	README.md
This commit is contained in:
Orangeeee
2026-09-22 16:45:53 +08:00
8 changed files with 112 additions and 306 deletions
+29 -288
View File
@@ -1,291 +1,32 @@
# 教培系统架构设计与开发
# 学生管理系统
## 教师篇
**main:主程序文件、测试接口**\
1 下面所有配置文件的接口全部导入并建表\
2 创建fastapi接口并本地运行\
**api:接口文件**\
*教师表Teacher的功能接口:*\
1.教师信息的查询\
2.教师信息的新增\
3.教师信息的更新\
4.教师信息的逻辑删除\
**dao数据筛选文件**\
1.查询 get_tea_dao:\
2.新增 add_tea_dao:\
3.更新 update_tea_dao:\
4.逻辑删除 delete_tea_dao:\
**tea_model数据库建表文件**\
1.教师表\
字段名:id、name、sex、class_id、sub(学科)\
home_place specialty(专业)、start_time(入职时间)\
work_experience、collage、creat_date、update_date\
is_delete、delete_time\
2.学科表\
字段名:id,name(科目名字)
**schema 请求体、响应体**\
请求体:设置了两个,一个带自增组件用于查询\
一个不带自增组件,新增用;\
响应体:用于返回给前端
本项目旨在开发一个基于FastAPI的学生管理系统,提供**学生基本信息管理、考核成绩管理和就业管理**三大核心功能模块。
系统将采用RESTful API设计,支持前后端分离架构。
## 需求分期
团队对需求管理按照模块化解耦拆分开发,按照三个阶段开发
1. 基础需求:按照开发任务,完成5 + 1 统计模块的开发
> todo: 每个人补充一下自己对本模块的理解
2. 特色需求:
- 数据源配置
- 鉴权管理
- 添加部门管理,顾问管理模块
- 添加用户认证模块
- 开发前端应用
- 开发更多的分析查询接口
- 增加AI智能体和知识库开发
3. 脚手架集成
### 第一阶段 - 基础需求
按照开发任务,完成5 + 1 统计模块的开发
- 学生
- 班级
- 老师
- 成绩
- 就业
- 统计分析
### 第二阶段 - 特色需求
- 数据源配置
- 鉴权管理
- 添加部门管理,顾问管理模块
- 添加用户认证模块
- 开发前端应用
- 开发更多的分析查询接口
- 增加AI智能体和知识库开发
### 第三阶段 - 脚手架集成
核心组件
- 服务状态监控 - utc时区[还有哪些可替代?]
- db ,中间件等组件是否活跃
- 自身服务是否活跃
- 认证模块: oauth2_scheme
-
-
## 业务拆分
> 业务范围划分
>
> - 实体
> - 学生基本信息管理
> - 考核成绩管理
> - 就业管理
> - 班级
> - 老师
> - 统计分析
## 数据架构设计
数据关系
- 学生:班级 = N: 1, 班级:老师 = 1 : 1 / [N:1], 学生: 成绩 = 1:N , 学生:就业 = 1:1,
- 统计分析:
表结构优化
- 索引设置
-
```sql
create database student_management_system;
use student_management_system;
-- students
create table if not exists students(
id int auto_increment primary key,
snum int not null comment '学生编号',
sname varchar(30) not null,
age int not null,
sex int not null,
home_place varchar(50) null comment '家乡',
college varchar(50) null comment '毕业院校',
specialty varchar(50) null comment '专业',
enrollment_time datetime null comment '入学时间',
graduate_time datetime null comment '毕业时间',
education varchar(50) null comment '学历',
class_id int not null,
advisor_id int null comment '顾问id',
advisor_num int null comment '顾问编号',
-- 通用字段
create_time datetime not null,
update_time datetime not null,
is_detleted int not null comment '0 未删除,1'
);
-- teachers
create table if not exists teachers(
id int auto_increment primary key,
tnum int not null comment '老师编号',
tname int not null,
age int not null,
sex int not null,
home_place varchar(50) null comment '家乡',
college varchar(50) null comment '毕业院校',
specialty varchar(50) null comment '专业',
enrollment_time datetime null comment '入学时间',
graduate_time datetime null comment '毕业时间',
education varchar(50) null comment '学历',
-- 额外信息:工作经验/教学评级 ,教学方向:应用,项目,算法;
work_experience text null comment '工作经验',
coach_area text null comment '教学方向:应用,项目,算法',
-- 通用字段
create_time datetime not null,
update_time datetime not null,
is_detleted int not null comment '0 未删除,1'
);
-- classes
create table if not exists classes(
id int auto_increment primary key,
class_num int not null comment '班级编号',
class_start_time datetime null comment '开课时间',
head_teacher_id int null comment '班主任',
head_teacher_num int null comment '班主任编号',
coach_teacher_id int null comment '授课老师',
coach_teacher_num int null comment '授课老师编号',
tutor_teacher_id int null comment '助教老师',
tutor_teacher_num int null comment '助教老师编号',
-- 通用字段
create_time datetime not null,
update_time datetime not null,
is_detleted int not null comment '0 未删除,1'
);
-- scores
create table if not exists scores(
id int auto_increment primary key,
sid int not null,
snum int not null,
score_num int not null comment '考核序次',
score decimal(10,2) not null,
-- 通用字段
create_time datetime not null,
update_time datetime not null,
is_detleted int not null comment '0 未删除,1'
);
-- employment
create table if not exists employment(
id int auto_increment primary key,
sid int not null,
snum int not null,
sname varchar(30) not null,
class_id int not null,
class_num int not null comment '班级编号',
employment_open_time datetime null comment '就业开放时间',
offer_recived_time datetime null comment 'offer下发时间',
employment_company varchar(50) null comment '就业公司',
employment_salary decimal(10,2) null comment '就业薪资',
-- 通用字段
create_time datetime not null,
update_time datetime not null,
is_detleted int not null comment '0 未删除,1'
);
```
## 技术架构设计
### git 协作
- 按照业务模块,每个人新建自己的分支,分支名称:user_module
- main 分支:发版分支,test分支:做集成测试用
### 构建环境适配
```bash
# uv 统一
pip install uv
uv init
uv add fastapi[standard] pymsql sqlalchemy # 添加依赖
# 运行测试
uv run uvicorn main:app --reload # uv run fastapi dev
# 其他平台: sync 同步即可
uv sync
```
### 基础架构适配
- 后端框架:
- web route / api docs / 数据校验 : FastAPI
- ORM 框架: pymysql, sqlarchemy
- 日志系统:loguru,
-
- 数据库:多数据源适配
- dev : sqlite3
- prod: MySQL, PG
- 前端框架:
- vue3
-
### 脚手架设计
+7
View File
@@ -0,0 +1,7 @@
# .env(放项目根目录,每个人自己建,不提交 Git)
# 用来修改数据库账户密码
DB_USER=root
DB_PASSWORD=123456
DB_HOST=localhost
DB_PORT=3306
DB_NAME=student_manage_system
+13 -3
View File
@@ -27,10 +27,20 @@ def delete_tea(id:int|None,db=Depends(get_db)):
raise HTTPException(status_code=500,detail='删除失败!')
return {'detail':'删除成功!'}
@tea_api.put('/tea/{id}',summary='修改老师信息',description='输入更改的信息,老师的姓名和性别不能为空,其余可以为空')
@tea_api.put('/tea/{id}',summary='更新老师信息',description='输入更改的信息,可以为空')
def update_tea(id:int,tea:NewTeaRequest,db=Depends(get_db)):
t = tea.model_dump(exclude_unset= True)
r = update_tea_dao(id=id,update_data=t,db=db)
r = update_tea_dao(id=id,t=t,db=db)
if not r:
raise HTTPException(status_code=404,detail='老师不存在')
return {'detail':'修改成功'}
return {'detail':'更新成功'}
#根据任意信息删除
@tea_api.delete('/tea',summary='根据任意信息逻辑删除',description='输入任意信息删除')
def delete_other_tea_dao1(t:TeaRequest,db=Depends(get_db)):
row1 = delete_other_tea_dao(t.model_dump(exclude_unset=True),db)
if not row1:
raise HTTPException(status_code=404,detail='没有找到符合条件的老师')
return{'code':200,'data':row1}
+46 -12
View File
@@ -14,17 +14,15 @@ def add_tea_dao(t,db):
return True
#更新
def add_tea_dao(t, db):
def update_tea_dao(id,t, db):
try:
t1 = Tea(**t)
db.add(t1)
except Exception as e:
row = db.query(Tea).filter(Tea.id == id,Tea.is_delete ==False ).update(t)
except:
db.rollback()
print('新增失败原因:', e)
return False
else:
db.commit()
return True
return row
#查询
def get_tea_dao(t,db):
@@ -36,7 +34,7 @@ def get_tea_dao(t,db):
if t.get("sex"):
query = query.filter(Tea.sex == t.get('sex') )
if t.get('class_id'):
query = query.filter(Tea.class_id == t.get('claa_id') )
query = query.filter(Tea.class_id == t.get('class_id') )
if t.get('sub'):
query = query.filter(Tea.sub == t.get('sub') )
if t.get('home_place'):
@@ -49,11 +47,11 @@ def get_tea_dao(t,db):
query = query.filter(Tea.work_experience == t.get('work_experience') )
if t.get('education'):
query = query.filter(Tea.education == t.get('education') )
if t.get('college'):
query = query.filter(Tea.collage == t.get('college') )
if t.get('collage'):
query = query.filter(Tea.collage == t.get('collage') )
r = query.all()
return [{'id':i.id,'name':i.name,'class_id':i.class_id,'sub':i.sub,'tea.sex':i.sex,'home_place':i.home_place
,'specialty':i.specialty,'start_time':i.start_time,'work_experience':i.work_experience,'college':i.college} for i in r]
return [{'id':i.id,'name':i.name,'class_id':i.class_id,'sub':i.sub,'sex':i.sex,'home_place':i.home_place
,'specialty':i.specialty,'start_time':i.start_time,'work_experience':i.work_experience,'collage':i.collage} for i in r]
#删除
def delete_tea_dao(id,db):
@@ -64,9 +62,45 @@ def delete_tea_dao(id,db):
except:
db.rollback()
row = 0
return
return row
else:
db.commit()
return row
def delete_other_tea_dao(t,db):
if not t:
return False
try:
query1 = db.query(Tea).filter(Tea.is_delete == False)
if t.get('id'):
query1 = query1.filter(Tea.id == t.get('id') )
if t.get('name'):
query1 = query1.filter(Tea.name == t.get('name') )
if t.get('sex'):
query1 = query1.filter(Tea.sex == t.get('sex'))
if t.get('class_id'):
query1 = query1.filter(Tea.class_id == t.get('class_id'))
if t.get('sub'):
query1 = query1.filter(Tea.sub == t.get('sub'))
if t.get('home_place'):
query1 = query1.filter(Tea.home_place == t.get('home_place'))
if t.get('collage'):
query1 = query1.filter(Tea.collage == t.get('collage'))
if t.get('education'):
query1 = query1.filter(Tea.education == t.get('education'))
if t.get('work_experience'):
query1 = query1.filter(Tea.work_experience == t.get('work_experience'))
if t.get('start_time'):
query1 = query1.filter(Tea.start_time == t.get('start_time'))
if t.get('specialty'):
query1 = query1.filter(Tea.specialty == t.get('specialty'))
row = query1.update({'is_delete':True,'delete_time':datetime.now()})
db.commit()
return row
except Exception as e:
db.rollback()
print('删除失败',e)
return '删除失败'
+1 -1
View File
@@ -8,7 +8,7 @@ Teachers_API.include_router(tea_api)
# 自测接口
app = FastAPI()
app.include_router(tea_api)
app.include_router(tea_api,tags=["老师"])
Base.metadata.create_all(engine1)
+12 -1
View File
@@ -7,6 +7,7 @@ import enum
class Gender(str,enum.Enum):
m = '男'
f = '女'
h = '未知'
class Tea(Base_all):
__tablename__ = 'teachers'
@@ -45,5 +46,15 @@ class Tea(Base_all):
,comment='更新时间')
is_delete = Column(Boolean,default=False,comment='是否删除')
delete_time = Column(DateTime)
#科目表
class Sub(Base):
__tablename__ = 'subject'
id = Column(Integer
, primary_key=True
, nullable=False
, autoincrement=True
, comment='id')
name = Column(String(50)
,nullable=False
,comment='科目名字')
+1 -1
View File
@@ -16,7 +16,7 @@ class TeaRequest(BaseModel):
specialty: str|None = None
#更新、新增使用请求体(无法覆盖)
#更新、任意逻辑删除、新增使用请求体,没有自增键
class NewTeaRequest(BaseModel):
name: str | None = None
sex: Gender
+3
View File
@@ -0,0 +1,3 @@
# 教培系统架构设计与开发##
## 2
### 3