first
This commit is contained in:
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.14 (wl_student_manager_system)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (wl_student_manager_system)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (wl_student_manager_system)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,45 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from database import get_db
|
||||
from scheme.wl_student_scheme import StudentCreate, StudentUpdate, StudentOut
|
||||
from dao import wl_student_dao
|
||||
|
||||
router = APIRouter(prefix="/students", tags=["学生管理"])
|
||||
|
||||
|
||||
@router.get("", response_model=list[StudentOut])
|
||||
def list_students(
|
||||
stu_no: str = Query(None),
|
||||
stu_name: str = Query(None),
|
||||
class_id: int = Query(None),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
return wl_student_dao.search_students(db, stu_no, stu_name, class_id)
|
||||
|
||||
|
||||
@router.post("", response_model=StudentOut)
|
||||
def create_student(data: StudentCreate, db: Session = Depends(get_db)):
|
||||
return wl_student_dao.create_student(db, data)
|
||||
|
||||
|
||||
@router.get("/{stu_no}", response_model=StudentOut)
|
||||
def get_student(stu_no: str, db: Session = Depends(get_db)):
|
||||
stu = wl_student_dao.get_student_by_no(db, stu_no)
|
||||
if not stu:
|
||||
raise HTTPException(404, "学生不存在")
|
||||
return stu
|
||||
|
||||
|
||||
@router.put("/{stu_no}", response_model=StudentOut)
|
||||
def update_student(stu_no: str, data: StudentUpdate, db: Session = Depends(get_db)):
|
||||
stu = wl_student_dao.update_student(db, stu_no, data)
|
||||
if not stu:
|
||||
raise HTTPException(404, "学生不存在")
|
||||
return stu
|
||||
|
||||
|
||||
@router.delete("/{stu_no}")
|
||||
def delete_student(stu_no: str, db: Session = Depends(get_db)):
|
||||
if not wl_student_dao.delete_student(db, stu_no):
|
||||
raise HTTPException(404, "学生不存在")
|
||||
return {"msg": "删除成功"}
|
||||
@@ -0,0 +1,74 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import func
|
||||
from model.wl_student_model import Student
|
||||
# from model.class_ import Class # 你同学写的
|
||||
from scheme.wl_student_scheme import StudentCreate, StudentUpdate
|
||||
|
||||
|
||||
# ---- 学号生成 ----
|
||||
def generate_stu_no(db: Session, class_id: int, seq: int = None) -> str:
|
||||
cls = db.query(Class).filter_by(id=class_id).first()
|
||||
if not cls or not cls.start_date:
|
||||
raise ValueError("班级不存在或未设置开班时间")
|
||||
date_str = cls.start_date.strftime("%Y%m%d")
|
||||
if seq is None:
|
||||
count = db.query(func.count(Student.stu_id)) \
|
||||
.filter(Student.class_id == class_id).scalar() or 0
|
||||
seq = count + 1
|
||||
return f"{date_str}{seq:03d}"
|
||||
|
||||
|
||||
# ---- 增 ----
|
||||
def create_student(db: Session, data: StudentCreate) -> Student:
|
||||
stu_no = generate_stu_no(db, data.class_id)
|
||||
stu = Student(stu_no=stu_no, **data.model_dump())
|
||||
db.add(stu)
|
||||
db.commit()
|
||||
db.refresh(stu)
|
||||
return stu
|
||||
|
||||
|
||||
# ---- 查(多条件)----
|
||||
def search_students(db: Session, stu_no=None, stu_name=None,
|
||||
class_id=None, advisor_id=None, status=None):
|
||||
q = db.query(Student).filter(Student.is_deleted == 0) # 若加了逻辑删除字段
|
||||
if stu_no:
|
||||
q = q.filter(Student.stu_no.like(f"%{stu_no}%"))
|
||||
if stu_name:
|
||||
q = q.filter(Student.stu_name.like(f"%{stu_name}%"))
|
||||
if class_id:
|
||||
q = q.filter(Student.class_id == class_id)
|
||||
if advisor_id:
|
||||
q = q.filter(Student.advisor_id == advisor_id)
|
||||
if status:
|
||||
q = q.filter(Student.status == status)
|
||||
return q.all()
|
||||
|
||||
|
||||
def get_student_by_no(db: Session, stu_no: str) -> Student | None:
|
||||
return db.query(Student).filter(
|
||||
Student.stu_no == stu_no,
|
||||
Student.is_deleted == 0
|
||||
).first()
|
||||
|
||||
|
||||
# ---- 改 ----
|
||||
def update_student(db: Session, stu_no: str, data: StudentUpdate) -> Student | None:
|
||||
stu = get_student_by_no(db, stu_no)
|
||||
if not stu:
|
||||
return None
|
||||
for k, v in data.model_dump(exclude_unset=True).items():
|
||||
setattr(stu, k, v)
|
||||
db.commit()
|
||||
db.refresh(stu)
|
||||
return stu
|
||||
|
||||
|
||||
# ---- 逻辑删 ----
|
||||
def delete_student(db: Session, stu_no: str) -> bool:
|
||||
stu = get_student_by_no(db, stu_no)
|
||||
if not stu:
|
||||
return False
|
||||
stu.is_deleted = 1
|
||||
db.commit()
|
||||
return True
|
||||
@@ -0,0 +1,19 @@
|
||||
#项目初始化入口
|
||||
from fastapi import FastAPI
|
||||
from api import wl_student_api # 周学灵的路由
|
||||
from database import Base, engine
|
||||
from model import wl_student_model as student_model
|
||||
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI(title="沃林学生管理系统")
|
||||
app.include_router(wl_student_api.router)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="127.0.0.1", port=8000)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from model import wl_student_model
|
||||
@@ -0,0 +1,29 @@
|
||||
from sqlalchemy import ( Column,Date,DateTime,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
SmallInteger,
|
||||
String,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from database import Base
|
||||
|
||||
|
||||
class Advisor(Base):
|
||||
|
||||
__tablename__ = "advisor"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True, comment="顾问编号")
|
||||
name = Column(String(50), nullable=False, index=True, comment="顾问姓名")
|
||||
gender = Column(String(8), comment="性别")
|
||||
phone = Column(String(20), index=True, comment="手机号")
|
||||
email = Column(String(64), comment="邮箱")
|
||||
region = Column(String(64), comment="负责区域/招生渠道")
|
||||
is_deleted = Column(SmallInteger,nullable=False, default=0,server_default="0",
|
||||
index=True,comment="1=已删除",)
|
||||
|
||||
students = relationship("Student",primaryjoin="and_(Advisor.id == Student.advisor_id, Student.is_deleted == 0)",
|
||||
foreign_keys="Student.advisor_id",viewonly=True,lazy="selectin",)
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#班级管理 熊浩钦
|
||||
from sqlalchemy import Column, Integer, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from database import Base
|
||||
|
||||
class WlClass(Base):
|
||||
__tablename__ = "wl_class"
|
||||
class_id = Column(Integer, primary_key=True, index=True, comment="班级编号")
|
||||
start_time = Column(DateTime, comment="开课时间")
|
||||
is_deleted = Column(Integer, default=0, comment="逻辑删除标记(0正常,1已删)")
|
||||
@@ -0,0 +1,36 @@
|
||||
#学生就业 赵康宁
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import *
|
||||
|
||||
db_url = "sqlalchemy+pymysql://root:123456@localhost/Student"
|
||||
engine = create_engine(db_url, pool_size=8)
|
||||
Base = declarative_base()
|
||||
|
||||
emp_stu = Table('emp_stu',
|
||||
Base.metadata,
|
||||
Column('stu_id', Integer, ForeignKey('stu_id'), primary_key=True))
|
||||
|
||||
class emp(Base):
|
||||
__tablename__ = "wl_emp"
|
||||
|
||||
stu_id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
emp_open_time = Column(DateTime, default="2026-11-30 18:18:18")
|
||||
offer_time = Column(DateTime, default=func.now())
|
||||
company_name = Column(String(100), nullable=False)
|
||||
salary = Column(Integer, nullable=False, default=15000)
|
||||
|
||||
student = relationship("wl_student", back_populates="wl_emp")
|
||||
|
||||
def __repr__(self):
|
||||
pass
|
||||
|
||||
|
||||
SessionLocal = sessionmaker(bind=engine)
|
||||
db_session = SessionLocal()
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
"""
|
||||
数据增删改查
|
||||
"""
|
||||
db_session.close()
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#学生考核成绩 圣国伟
|
||||
from sqlalchemy import Column, Integer, Float
|
||||
|
||||
from database import Base
|
||||
class StudentScore(Base):
|
||||
__tablename__ = "student_score"
|
||||
|
||||
stu_id = Column(Integer, primary_key=True, comment="学生编号")
|
||||
exam_order = Column(Integer, primary_key=True, comment="考核序次")
|
||||
score = Column(Float, nullable=False, comment="成绩")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#学生基本信息 周学灵
|
||||
from database import Base
|
||||
from sqlalchemy import Column, Integer, String, Date, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
||||
class Student(Base):
|
||||
__tablename__ = 'wl_student'
|
||||
# ---------- 内部主键(隐藏,不对外)----------
|
||||
stu_id = Column(Integer, primary_key=True, autoincrement=True, comment='内部主键')
|
||||
# ---------- 业务学号(对外,按规则生成)----------
|
||||
stu_no = Column(String(20), unique=True, nullable=False, index=True, comment='学号')
|
||||
# class_id = Column(Integer, ForeignKey('wl_class.id'), nullable=True, comment='班级ID')
|
||||
stu_name = Column(String(30), nullable=True, comment='学生姓名')
|
||||
native_place = Column(String(50), nullable=True, comment='籍贯')
|
||||
graduate_school=Column(String(128), nullable=True, comment='毕业学校')
|
||||
major= Column(String(64), nullable=True, comment='专业')
|
||||
in_time= Column(Date, nullable=True, comment='入学时间')
|
||||
out_time= Column(Date, nullable=True, comment='毕业时间')
|
||||
edu= Column(String(32), nullable=True, comment='学历')
|
||||
# advisor_id = Column(Integer, ForeignKey('wl_advisor.id'), nullable=True, comment='顾问ID')
|
||||
stu_age = Column(Integer, nullable=True, comment='年龄')
|
||||
stu_gender = Column(String(8), nullable=True, comment='性别')
|
||||
|
||||
# class_ = relationship("Class", back_populates="students")
|
||||
# advisor = relationship("Advisor", back_populates="students")
|
||||
|
||||
is_deleted = Column(Integer, default=0, comment='逻辑删除: 0正常 1删除')
|
||||
def __repr__(self):
|
||||
return f"<Student(id={self.stu_id}, name='{self.stu_name}')>"
|
||||
@@ -0,0 +1,23 @@
|
||||
#老师管理模块 刘盼
|
||||
from sqlalchemy import create_engine
|
||||
from database import Base, engine
|
||||
|
||||
class Teacher(Base):
|
||||
__tablename__ = 'wl_teacher'
|
||||
t_id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
teacher_no = Column(String(20), unique=True, nullable=False)
|
||||
t_name = Column(String(50), nullable=False)
|
||||
t_phone = Column(String(20), unique=True, nullable=True)
|
||||
t_email = Column(String(20), unique=False)
|
||||
class_id = Column(Integer, ForeignKey("wl_class.id"), nullable=False)
|
||||
role = Column(String(50), nullable=False)
|
||||
is_deleted = Column(Integer, default=0)
|
||||
|
||||
def generate_teacher_no(db: Session, hire_date: date):
|
||||
"""
|
||||
工号规则:T + 入职日期(YYYYMMDD) + 3位当天序号
|
||||
例如:T20250912001、T20250912002
|
||||
"""
|
||||
date_str = hire_date.strftime("%Y%m%d")
|
||||
prefix = f"T{date_str}"
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
from pydantic import BaseModel
|
||||
from datetime import date
|
||||
from typing import Optional
|
||||
class StudentCreate(BaseModel):
|
||||
class_id: Optional[int] = None
|
||||
advisor_id: Optional[int] = None
|
||||
stu_name: Optional[str] = None
|
||||
native_place: Optional[str] = None
|
||||
graduate_school: Optional[str] = None
|
||||
major: Optional[str] = None
|
||||
in_time: Optional[date] = None
|
||||
out_time: Optional[date] = None
|
||||
edu: Optional[str] = None
|
||||
stu_age: Optional[int] = None
|
||||
stu_gender: Optional[str] = None
|
||||
# status: Optional[str] = None
|
||||
|
||||
class StudentUpdate(BaseModel):
|
||||
class_id: Optional[int] = None
|
||||
advisor_id: Optional[int] = None
|
||||
stu_name: Optional[str] = None
|
||||
native_place: Optional[str] = None
|
||||
graduate_school: Optional[str] = None
|
||||
major: Optional[str] = None
|
||||
in_time: Optional[date] = None
|
||||
out_time: Optional[date] = None
|
||||
edu: Optional[str] = None
|
||||
stu_age: Optional[int] = None
|
||||
stu_gender: Optional[str] = None
|
||||
# status: Optional[str] = None
|
||||
|
||||
class StudentOut(BaseModel):
|
||||
stu_no: str
|
||||
stu_name: Optional[str] = None
|
||||
class_id: Optional[int] = None
|
||||
advisor_id: Optional[int] = None
|
||||
native_place: Optional[str] = None
|
||||
graduate_school: Optional[str] = None
|
||||
major: Optional[str] = None
|
||||
in_time: Optional[date] = None
|
||||
out_time: Optional[date] = None
|
||||
edu: Optional[str] = None
|
||||
stu_age: Optional[int] = None
|
||||
stu_gender: Optional[str] = None
|
||||
# status: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
Reference in New Issue
Block a user