From 601e3b7d3944041fe1364924fa263c168dfb43aa Mon Sep 17 00:00:00 2001 From: Windows <2209639385@qq.com> Date: Tue, 22 Sep 2026 12:24:51 +0800 Subject: [PATCH 01/31] nb --- PythonProject/api/grade_api.py | 8 ++++++-- PythonProject/dao/grade_dao.py | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/PythonProject/api/grade_api.py b/PythonProject/api/grade_api.py index f1988c8..c0b266c 100644 --- a/PythonProject/api/grade_api.py +++ b/PythonProject/api/grade_api.py @@ -7,11 +7,15 @@ from fastapi import APIRouter, Depends, HTTPException, Body gradeAPI = APIRouter(tags=['学生考核成绩管理模块']) -@gradeAPI.get("/grade/{stu_id}",response_model=list[GradeResponse],summary="根据学生id查询成绩") +@gradeAPI.get("/grade/{stu_id}",summary="根据学生id查询成绩") def get_grade(stu_id: int,db=Depends(get_db)): try: res=get_grade_dao(stu_id,db) - return res + return { + "code": 200, + "detail": "查询成功", + "data": res + } except Exception as e: raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}') diff --git a/PythonProject/dao/grade_dao.py b/PythonProject/dao/grade_dao.py index 358645e..2619fac 100644 --- a/PythonProject/dao/grade_dao.py +++ b/PythonProject/dao/grade_dao.py @@ -19,10 +19,26 @@ def get_score_by_stu_exam_order_dao(stu_id:str,exam_order:int,db): def get_grade_dao( stu_id:int , db): - r1 =db.query(WlScore).filter(WlScore.stu_id == stu_id,WlScore.delete_status == 0).all() + r1 =(db.query( WlScore.score_id + ,WlScore.stu_id + ,Student_Model.stu_name + ,WlScore.exam_order + ,WlScore.score + ) + .join(Student_Model,WlScore.stu_id == Student_Model.stu_id) + .filter(WlScore.stu_id == stu_id,WlScore.delete_status == 0,Student_Model.delete_status == 0) + .all()) if r1: - - return r1 + data_list = [] + for row in r1: + data_list.append({ + "score_id": row.score_id, + "stu_id": row.stu_id, + "stu_name": row.stu_name, + "exam_order": row.exam_order, + "score": row.score + }) + return data_list else: raise HTTPException(status_code=404,detail="学生不存在") -- 2.54.0 From 6cb4c4a1af9f68b8d291886db1d5a0e5641e6cf7 Mon Sep 17 00:00:00 2001 From: Windows <2209639385@qq.com> Date: Tue, 22 Sep 2026 12:46:31 +0800 Subject: [PATCH 02/31] nb --- PythonProject/model/all_model.py | 2 +- PythonProject/schema/grade_schema.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/PythonProject/model/all_model.py b/PythonProject/model/all_model.py index 9743859..cd68351 100644 --- a/PythonProject/model/all_model.py +++ b/PythonProject/model/all_model.py @@ -1,4 +1,4 @@ -from sqlalchemy import DATETIME,Column,Integer,String,DATE,ForeignKey,Numeric +from sqlalchemy import DATETIME,Column,Integer,String,DATE,ForeignKey,Numeric,UniqueConstraint from datetime import datetime from util.database import Base,engine diff --git a/PythonProject/schema/grade_schema.py b/PythonProject/schema/grade_schema.py index 4d89cd4..a381ab9 100644 --- a/PythonProject/schema/grade_schema.py +++ b/PythonProject/schema/grade_schema.py @@ -1,5 +1,5 @@ -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, field_validator class GradeRequest(BaseModel): @@ -7,6 +7,18 @@ class GradeRequest(BaseModel): exam_order:int = Field(description='考核序次') score:float = Field(description='成绩') + @field_validator("score") + def check_score(cls, v): + if not (0 <= v <= 100): + raise ValueError("成绩必须在0~100之间") + return v + + @field_validator("exam_order") + def check_exam_order(cls, v): + if v <= 0: + raise ValueError("考核序次必须大于0") + return v + class GradeResponse(BaseModel): code: int = 200 detail: str = 'OK' -- 2.54.0 From d9fc0b97a0f29b8cbc7247eed912faf96025eda6 Mon Sep 17 00:00:00 2001 From: 0919word <835535015@qq.com> Date: Tue, 22 Sep 2026 13:24:19 +0800 Subject: [PATCH 03/31] =?UTF-8?q?=E8=92=8B=E7=AB=8B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/dao/cla_dao.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PythonProject/dao/cla_dao.py b/PythonProject/dao/cla_dao.py index f491b9f..23267a9 100644 --- a/PythonProject/dao/cla_dao.py +++ b/PythonProject/dao/cla_dao.py @@ -3,17 +3,17 @@ from fastapi import HTTPException from schema.cla_schema import claRequest -def add_class_dao(c:claRequest,session): +def add_class_dao(c: claRequest, session): try: data = c.model_dump() d = ClassManagement(**data) session.add(d) + session.commit() + session.refresh(d) + return d except: session.rollback() - return '输入有误,请重新添加班级!' - else: - session.commit() - return '添加成功!' + raise HTTPException(400, "输入有误,请重新添加班级!") def get_class_dao(n,m,session): try: -- 2.54.0 From fba5750c6d3a345d5d01d94c25cb351bafdb80c8 Mon Sep 17 00:00:00 2001 From: 0919word <835535015@qq.com> Date: Tue, 22 Sep 2026 14:13:25 +0800 Subject: [PATCH 04/31] =?UTF-8?q?=E8=92=8B=E7=AB=8B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/model/all_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PythonProject/model/all_model.py b/PythonProject/model/all_model.py index cd68351..6b5a50b 100644 --- a/PythonProject/model/all_model.py +++ b/PythonProject/model/all_model.py @@ -54,7 +54,7 @@ class ClassManagement(Base): class_id= Column(Integer, primary_key=True, autoincrement=True,comment='班级编号') - class_name = Column(String(100), comment='班级姓名') + class_name = Column(String(100), comment='班级名字') start_class_date = Column(DATE,comment='开课时间') @@ -68,7 +68,7 @@ class ClassManagement(Base): delete_status = Column(Integer,default=0,comment='删除状态:0未删除,1已删除') - delete_time = Column(DATETIME,comment='删除时间') + delete_time = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='删除时间') class Teacher_Model(Base): __tablename__ = 'wl_teacher' -- 2.54.0 From a4136ea6485ddc9d5e1ae0ddf383b9739e94fbe6 Mon Sep 17 00:00:00 2001 From: 00MSJ1122 <1253313142@qq.com> Date: Tue, 22 Sep 2026 14:34:22 +0800 Subject: [PATCH 05/31] 1 --- PythonProject/api/student_api.py | 20 +++++++++------- PythonProject/dao/student_dao.py | 33 ++++++++++++++++---------- PythonProject/model/all_model.py | 2 ++ PythonProject/schema/student_schema.py | 6 ++++- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 981de80..6cbed4a 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter,Depends,HTTPException +from fastapi import APIRouter,HTTPException from dao.student_dao import * from schema.student_schema import * from util.database import get_db @@ -33,10 +33,10 @@ def update_students(s:StudentRequest ,db=Depends(get_db)): d = s.model_dump(exclude_unset=True) if not d: - raise HTTPException(status_code=400, detail='更新内容不能为空!') + raise HTTPException(status_code=400, detail='更新内容不能为空') r = update_student_dao( stu_id=stu_id,update_data=d,db=db ) if not r: - raise HTTPException(status_code=500, detail='没有更新!') + raise HTTPException(status_code=500, detail='没有更新') return {'code':200,'totals':r,'detail':'更新成功'} @StudentAPI.delete('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息删除接口',description='删除学生信息') @@ -50,8 +50,12 @@ def del_students(stu_id:int @StudentAPI.post('/students',tags=['学⽣基本信息管理模块'],response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息') def add_students(s:StudentRequest ,db=Depends(get_db)): - d=s.model_dump(exclude_unset=True) - stu_new=add_student_dao(o=d,db=db) - if not stu_new: - raise HTTPException(status_code=404,detail='添加失败') - return stu_new + d = s.model_dump(exclude_unset=True) + if not d: + raise HTTPException(status_code=400, detail='添加内容不能为空') + r = add_student_dao( o=d, db=db) + if r == 'conflict': + raise HTTPException(status_code=409, detail='身份证号已存在,请勿重复添加') + if r == 'error': + raise HTTPException(status_code=500, detail='更添加失败,请稍后重试') + return r diff --git a/PythonProject/dao/student_dao.py b/PythonProject/dao/student_dao.py index 9f755ac..0822d9d 100644 --- a/PythonProject/dao/student_dao.py +++ b/PythonProject/dao/student_dao.py @@ -1,19 +1,28 @@ -from fastapi import Depends -from util.database import get_db from model.all_model import Student_Model from typing import List, Optional, Dict, Any from datetime import datetime +from sqlalchemy.exc import IntegrityError def add_student_dao(o,db): + if o.get('id_card'): + conflict = (db.query(Student_Model) + .filter(Student_Model.id_card == o['id_card'], + Student_Model.delete_status == 0) + .first()) + if conflict: + return 'conflict' try: - o1 = Student_Model( **o) - db.add(o1) + o2 = Student_Model(**o) + db.add(o2) db.commit() - stu_id=o1.stu_id - return db.query(Student_Model).filter(Student_Model.stu_id == stu_id).first() - except: + db.refresh(o2) # 回填自增的 stu_id + return o2 + except IntegrityError: db.rollback() - return None + return 'conflict' + except Exception: + db.rollback() + return 'error' def delete_student_dao(stu_id,db): try: @@ -28,14 +37,14 @@ def delete_student_dao(stu_id,db): def update_student_dao(stu_id,update_data,db): try: - rows = (db.query( Student_Model ) - .filter( Student_Model.stu_id == stu_id,Student_Model.delete_status == 0) - .update( update_data )) - db.commit() + rows=(db.query(Student_Model) + .fiter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0) + .update(update_data)) except: db.rollback() return False else: + db.commit() return rows def get_student_dao(stu_id:Optional[int] diff --git a/PythonProject/model/all_model.py b/PythonProject/model/all_model.py index fb48980..3fe8237 100644 --- a/PythonProject/model/all_model.py +++ b/PythonProject/model/all_model.py @@ -23,6 +23,8 @@ class Student_Model(Base): native_place=Column(String(200),comment='籍贯') + id_card=Column(String(18),unique=True,comment='身份证号') + birthday=Column(DATE,comment='生日') school=Column(String(100),comment='毕业学校') diff --git a/PythonProject/schema/student_schema.py b/PythonProject/schema/student_schema.py index 58894ec..f699b21 100644 --- a/PythonProject/schema/student_schema.py +++ b/PythonProject/schema/student_schema.py @@ -9,6 +9,7 @@ class StudentRequest(BaseModel): stu_name:str age:int |None = None gender:str |None = None + id_card:str native_place:str |None = None birthday:date |None = None school:str |None = None @@ -57,6 +58,7 @@ class StugetResponse(BaseModel): stu_name: str | None = None age: int | None = None gender: str | None = None + id_card: str native_place: str | None = None birthday: date | None = None school: str | None = None @@ -81,4 +83,6 @@ class StudentPageResponse(BaseModel): page: int page_size: int totals: int - data: List[StugetResponse] \ No newline at end of file + data: List[StugetResponse] + + -- 2.54.0 From bf44ac9450da9976c44e71853b9d94bacef5165b Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Tue, 22 Sep 2026 14:36:43 +0800 Subject: [PATCH 06/31] mrz --- PythonProject/api/employment_api.py | 23 +++++++++---------- PythonProject/api/student_api.py | 2 +- PythonProject/dao/employment_dao.py | 27 ++++++----------------- PythonProject/schema/employment_schema.py | 15 +++++++++++++ 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/PythonProject/api/employment_api.py b/PythonProject/api/employment_api.py index a3aa6d7..fd6f2aa 100644 --- a/PythonProject/api/employment_api.py +++ b/PythonProject/api/employment_api.py @@ -1,7 +1,7 @@ from fastapi import APIRouter, Query, Depends, HTTPException, Path,Form from dao import employment_dao from dao.employment_dao import add_emp_dao, update_emp_dao, delete_emp_dao -from schema.employment_schema import EmploymentRequest,EmploymentResponse +from schema.employment_schema import EmploymentRequest,UpdateEmpRequest,EmploymentResponse from util.database import get_db from typing import Optional emp_api = APIRouter(tags=['学生就业管理模块']) @@ -22,8 +22,8 @@ def get_emp_info2(class_id: Optional[int]=Path(description='班级编号') return e2 raise HTTPException(status_code=404, detail='该班级就业信息不存在') -@emp_api.get('/employment',response_model=EmploymentResponse,summary='按照学⽣编号,公司名字,⼯资范围查询学⽣就业信息') -def get_emp_info3(stu_id:int|None = Query(None, description='学生编号') +@emp_api.get('/employment/class/{stu_id}',response_model=list[EmploymentResponse],summary='按照学⽣编号,公司名字,⼯资范围查询学⽣就业信息') +def get_emp_info3(stu_id:int = Path(description='学生编号') ,company_name: str|None = Query(None,description='公司名称') ,min_salary: float|None = Query(None,ge=0,description='最低工资') ,max_salary: float|None = Query(None,ge=0,description='最高工资') @@ -31,11 +31,11 @@ def get_emp_info3(stu_id:int|None = Query(None, description='学生编号') if min_salary and max_salary: if min_salary > max_salary: raise HTTPException(status_code=404, detail='最低工资不能大于最高工资') - return [employment_dao.get_emp_dao(stu_id=stu_id - ,company_name=company_name - ,min_salary=min_salary - ,max_salary=max_salary - ,db=db)] + l1 = employment_dao.get_emp_dao(db, stu_id=stu_id + , company_name=company_name + , min_salary=min_salary + , max_salary=max_salary) + return l1 @emp_api.post('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='新增学生就业信息') def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)): @@ -45,10 +45,9 @@ def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)): raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!') return r -@emp_api.put('/employment/students/{emp_id}',response_model=EmploymentResponse,summary='更新学生就业信息') -def update_emp_info(emp_id:int,emp:EmploymentRequest,db=Depends(get_db)): - d = emp.model_dump(exclude_unset=True) - r = update_emp_dao(emp_id=emp_id,db=db) +@emp_api.put('/employment/students/{emp_id}',summary='更新学生就业信息') +def update_emp_info(emp_id:int,emp:UpdateEmpRequest,db=Depends(get_db)): + r = update_emp_dao(emp_id,emp.model_dump(exclude_unset=True),db) if not r: raise HTTPException(status_code=500,detail='没有更新!') return {'code':200,'totals':r,'detail':'更新成功!'} diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index b48fdc1..3b1bb2b 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter,HTTPException +from fastapi import APIRouter,HTTPException,Depends from dao.student_dao import * from schema.student_schema import * from util.database import get_db diff --git a/PythonProject/dao/employment_dao.py b/PythonProject/dao/employment_dao.py index 6168d87..2a7e1fc 100644 --- a/PythonProject/dao/employment_dao.py +++ b/PythonProject/dao/employment_dao.py @@ -2,7 +2,7 @@ from fastapi import HTTPException from model.all_model import Employment_info, ClassManagement, Student_Model from datetime import datetime -def get_emp_dao(stu_id=None,class_id=None,company_name=None,min_salary=None,max_salary=None,db=None): +def get_emp_dao(db,stu_id=None,class_id=None,company_name=None,min_salary=None,max_salary=None): q = db.query(Employment_info.emp_id ,Employment_info.stu_id ,Student_Model.stu_name @@ -33,24 +33,11 @@ def get_emp_dao(stu_id=None,class_id=None,company_name=None,min_salary=None,max_ r = q.all() if not r: raise HTTPException(status_code=500,detail='查询异常,没有结果!') - return [ - {'emp_id':i.emp_id - ,'stu_id': i.stu_id - ,'stu_name':i.stu_name - ,'class_id':i.class_id - ,'email':i.email - ,'employment_opening_date':i.employment_opening_date - ,'offer_issuance_date':i.offer_issuance_date - ,'company_name':i.company_name - ,'company_address':i.company_address - ,'salary':i.salary - } - for i in r - ] + return r -def add_emp_dao(o:dict,db): +def add_emp_dao(o,db): try: stu = db.query(Student_Model).filter(Student_Model.stu_id == o['stu_id'] , Student_Model.delete_status == 0).first() @@ -70,11 +57,11 @@ def add_emp_dao(o:dict,db): db.rollback() raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}') -def update_emp_dao(emp_id:int,db): +def update_emp_dao(emp_id,emp,db): try: - rows = db.query(Employment_info).filter(Employment_info.emp_id == emp_id - ,Employment_info.delete_status == 0).first() - + rows = db.query(Employment_info)\ + .filter(Employment_info.emp_id == emp_id,Employment_info.delete_status == 0)\ + .update(emp) db.commit() return rows except: diff --git a/PythonProject/schema/employment_schema.py b/PythonProject/schema/employment_schema.py index 4c5dd52..1505868 100644 --- a/PythonProject/schema/employment_schema.py +++ b/PythonProject/schema/employment_schema.py @@ -18,6 +18,21 @@ class EmploymentRequest(BaseModel): raise ValueError('offer下发日期不能早于就业开放日期') return self +class UpdateEmpRequest(BaseModel): + email: Optional[str] = Field(None, description='邮箱') + employment_opening_date:Optional[date] = Field(None, description='就业开放日期') + offer_issuance_date:Optional[date] = Field(None, description='offer下发日期') + company_name:Optional[str] = Field(None, description='公司名称') + company_address:Optional[str] = Field(None, description='公司地址') + salary:Optional[float] = Field(None, description='薪资') + + @model_validator(mode='after') + def check_date(self): + if self.employment_opening_date and self.offer_issuance_date: + if self.employment_opening_date > self.offer_issuance_date: + raise ValueError('offer下发日期不能早于就业开放日期') + return self + class EmploymentResponse(BaseModel): code:int = 200 detail:str = 'OK' -- 2.54.0 From 7d8971fc83f8a662c659f567a9510d8dce29fe1a Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Tue, 22 Sep 2026 14:40:54 +0800 Subject: [PATCH 07/31] mrz --- PythonProject/api/employment_api.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/PythonProject/api/employment_api.py b/PythonProject/api/employment_api.py index fd6f2aa..8a53b57 100644 --- a/PythonProject/api/employment_api.py +++ b/PythonProject/api/employment_api.py @@ -6,14 +6,6 @@ from util.database import get_db from typing import Optional emp_api = APIRouter(tags=['学生就业管理模块']) -@emp_api.get('/employment/class/{stu_id}',response_model=EmploymentResponse,summary='获取学生就业信息') -def get_emp_info1(stu_id: Optional[int]=Path(description='学生编号') - ,db=Depends(get_db)): - e1 = employment_dao.get_emp_dao(stu_id=stu_id, db=db) - if e1: - return e1[0] - raise HTTPException(status_code=404, detail='该学生就业信息不存在') - @emp_api.get('/employment/class/{class_id}',response_model=EmploymentResponse,summary='获取班级学生就业信息') def get_emp_info2(class_id: Optional[int]=Path(description='班级编号') ,db=Depends(get_db)): -- 2.54.0 From e9086e842b198049fffdb2521f02ff8e1316f807 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 14:50:43 +0800 Subject: [PATCH 08/31] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/api/statistics_api.py | 8 +++++++- PythonProject/dao/statistics_dao.py | 23 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/PythonProject/api/statistics_api.py b/PythonProject/api/statistics_api.py index c1804ef..e327bf3 100644 --- a/PythonProject/api/statistics_api.py +++ b/PythonProject/api/statistics_api.py @@ -40,4 +40,10 @@ def get_days(db=Depends(get_db)): @StatisticsAPI.get('/emp',response_model=AllEmpResponse,tags=['统计分析模块'],summary='统计每个学生的就业时长') def get_emp(db=Depends(get_db)): l= select_days2(db) - return l \ No newline at end of file + return l + +# 薪资区间分布:统计薪资在5k以下、5k-10k、10k-15k、15k以上的人数分布,反映学生的整体就业质量。 +@StatisticsAPI.get('/salaries',tags=['统计分析模块'],summary='统计薪资分布') +def get_salaries(db=Depends(get_db)): + s=classify_salary(db) + return s \ No newline at end of file diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index 68780c6..5f79595 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -107,4 +107,25 @@ def select_days2(db): ).all() return l2 except Exception: - raise HTTPException(status_code=500, detail="查询异常") \ No newline at end of file + raise HTTPException(status_code=500, detail="查询异常") + + +# 薪资区间分布:统计薪资在5k以下、5k-10k、10k-15k、15k以上的人数分布,反映学生的整体就业质量。 +def classify_salary(db): + try: + a=b=c=d=0 + l=db.query(Employment_info).filter(Employment_info.delete_status==0).all() + for i in l: + if i.salary is None: + continue + elif i.salary<5000: + a+=1 + elif 5000<=i.salary<10000: + b+=1 + elif 10000<=i.salary<15000: + c+=1 + else: + d+=1 + return {'5k以下': a, '5k-10k': b, '10k-15k': c, '15k': d} + except: + raise HTTPException(status_code=500,detail='查询异常!') -- 2.54.0 From f7911c89115090ff800c03744ebdb32a1cb1740e Mon Sep 17 00:00:00 2001 From: Windows <2209639385@qq.com> Date: Tue, 22 Sep 2026 14:52:15 +0800 Subject: [PATCH 09/31] nb --- PythonProject/api/grade_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PythonProject/api/grade_api.py b/PythonProject/api/grade_api.py index c0b266c..fb3d5cf 100644 --- a/PythonProject/api/grade_api.py +++ b/PythonProject/api/grade_api.py @@ -19,7 +19,7 @@ def get_grade(stu_id: int,db=Depends(get_db)): except Exception as e: raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}') -@gradeAPI.post('/grade',response_model=GradeResponse,summary='添加学生成绩') +@gradeAPI.post('/grade',summary='添加学生成绩') def post_grade(o:GradeRequest,db=Depends(get_db)): d=o.model_dump() r=add_grade_dao(g=d,db=db) -- 2.54.0 From 43c558d5bc38d49e2eeff709200a3240bcca6331 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 14:54:25 +0800 Subject: [PATCH 10/31] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/api/statistics_api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PythonProject/api/statistics_api.py b/PythonProject/api/statistics_api.py index 401efd1..c5f0032 100644 --- a/PythonProject/api/statistics_api.py +++ b/PythonProject/api/statistics_api.py @@ -40,3 +40,8 @@ def get_days(db=Depends(get_db)): def get_emp(db=Depends(get_db)): l= select_days(db) return l + +@StatisticsAPI.get('/salaries',summary='统计薪资分布') +def get_salaries(db=Depends(get_db)): + s=classify_salary(db) + return s \ No newline at end of file -- 2.54.0 From acb4036589f977b0a23e9c17984fb20d9afaf2b4 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 14:55:31 +0800 Subject: [PATCH 11/31] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/dao/statistics_dao.py | 1 + 1 file changed, 1 insertion(+) diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index 81e140b..edcc645 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -153,3 +153,4 @@ def classify_salary(db): return {'5k以下': a, '5k-10k': b, '10k-15k': c, '15k': d} except: raise HTTPException(status_code=500,detail='查询异常!') + -- 2.54.0 From 957e826e0f1187795265b54d57cc03a194563f11 Mon Sep 17 00:00:00 2001 From: 00MSJ1122 <1253313142@qq.com> Date: Tue, 22 Sep 2026 14:58:51 +0800 Subject: [PATCH 12/31] 1 --- PythonProject/api/student_api.py | 7 ++++++- PythonProject/dao/student_dao.py | 29 +++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 3b1bb2b..2cf2f1d 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -32,11 +32,16 @@ def update_students(s:StudentRequest ,stu_id:int ,db=Depends(get_db)): d = s.model_dump(exclude_unset=True) + d.pop('stu_id', None) if not d: raise HTTPException(status_code=400, detail='更新内容不能为空') r = update_student_dao( stu_id=stu_id,update_data=d,db=db ) + if r == 'conflict': + raise HTTPException(status_code=409, detail = '身份证号已被其他学生占用') + if r == 'error': + raise HTTPException(status_code=500, detail='更新失败,请稍后重试') if not r: - raise HTTPException(status_code=500, detail='没有更新') + raise HTTPException(status_code=404, detail='没有更新') return {'code':200,'totals':r,'detail':'更新成功'} @StudentAPI.delete('/{stu_id}',summary='学生信息删除接口',description='删除学生信息') diff --git a/PythonProject/dao/student_dao.py b/PythonProject/dao/student_dao.py index 0822d9d..d947d0d 100644 --- a/PythonProject/dao/student_dao.py +++ b/PythonProject/dao/student_dao.py @@ -36,16 +36,29 @@ def delete_student_dao(stu_id,db): return rows def update_student_dao(stu_id,update_data,db): + if update_data.get('id_card'): + conflict = (db.query(Student_Model) + .filter(Student_Model.id_card == update_data['id_card'], + Student_Model.stu_id != stu_id, + Student_Model.delete_status == 0) + .first()) + if conflict: + return 'conflict' + try: - rows=(db.query(Student_Model) - .fiter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0) - .update(update_data)) - except: - db.rollback() - return False - else: + rows = (db.query(Student_Model) + .filter(Student_Model.stu_id == stu_id, + Student_Model.delete_status == 0) + .update(update_data)) db.commit() - return rows + except IntegrityError: + db.rollback() + return 'conflict' + except Exception: + db.rollback() + return 'error' + + return rows def get_student_dao(stu_id:Optional[int] ,stu_name:Optional[str] -- 2.54.0 From 0813204469beeba6b50d996b4b972123b7ad47da Mon Sep 17 00:00:00 2001 From: 0919word <835535015@qq.com> Date: Tue, 22 Sep 2026 15:01:11 +0800 Subject: [PATCH 13/31] =?UTF-8?q?=E8=92=8B=E7=AB=8B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/model/all_model.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PythonProject/model/all_model.py b/PythonProject/model/all_model.py index 6b5a50b..2ae2fa6 100644 --- a/PythonProject/model/all_model.py +++ b/PythonProject/model/all_model.py @@ -1,5 +1,7 @@ -from sqlalchemy import DATETIME,Column,Integer,String,DATE,ForeignKey,Numeric,UniqueConstraint -from datetime import datetime + + +from sqlalchemy import DATETIME,Column,Integer,String,DATE,ForeignKey,Numeric,Date +from datetime import datetime,date from util.database import Base,engine class Student_Model(Base): @@ -62,7 +64,7 @@ class ClassManagement(Base): class_teacher_id = Column(Integer,ForeignKey('wl_teacher.teac_id'),comment='授课教师') - Entry_date= Column(DATETIME,default=datetime.now,comment='录入时间') + Entry_date= Column(Date,default=date.today,comment='录入时间') update_date = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='更新时间') -- 2.54.0 From 4dbb23e5c5ab7cee829cf80b58037d418d4749c1 Mon Sep 17 00:00:00 2001 From: Windows <2209639385@qq.com> Date: Tue, 22 Sep 2026 15:10:16 +0800 Subject: [PATCH 14/31] nb --- PythonProject/schema/grade_schema.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/PythonProject/schema/grade_schema.py b/PythonProject/schema/grade_schema.py index a381ab9..d6babdc 100644 --- a/PythonProject/schema/grade_schema.py +++ b/PythonProject/schema/grade_schema.py @@ -27,6 +27,3 @@ class GradeResponse(BaseModel): exam_order:int score:float -# class GradeUpdate(BaseModel): -# exam_order: int | None = Field( None,description="考核序次") -# score: float | None = Field( None,description="成绩") -- 2.54.0 From 55d99e17e05636bf7b4a8378f17d1ff1cd33ec10 Mon Sep 17 00:00:00 2001 From: 0919word <835535015@qq.com> Date: Tue, 22 Sep 2026 15:10:42 +0800 Subject: [PATCH 15/31] =?UTF-8?q?=E8=92=8B=E7=AB=8B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/model/all_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PythonProject/model/all_model.py b/PythonProject/model/all_model.py index 55a9790..cc21a42 100644 --- a/PythonProject/model/all_model.py +++ b/PythonProject/model/all_model.py @@ -60,13 +60,13 @@ class ClassManagement(Base): class_name = Column(String(100), comment='班级名字') - start_class_date = Column(DATE,comment='开课时间') + start_class_date = Column(Date,default=date.today,comment='开课时间') head_teacher_id= Column(Integer,ForeignKey('wl_teacher.teac_id'),comment='班主任') class_teacher_id = Column(Integer,ForeignKey('wl_teacher.teac_id'),comment='授课教师') - Entry_date= Column(Date,default=date.today,comment='录入时间') + Entry_date= Column(Date,default=datetime.now,comment='录入时间') update_date = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='更新时间') -- 2.54.0 From a67828a29fdf5bbdfa008ffb0b8a6ed991628809 Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Tue, 22 Sep 2026 15:11:32 +0800 Subject: [PATCH 16/31] mrz --- PythonProject/api/employment_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PythonProject/api/employment_api.py b/PythonProject/api/employment_api.py index 8a53b57..2a09422 100644 --- a/PythonProject/api/employment_api.py +++ b/PythonProject/api/employment_api.py @@ -6,7 +6,7 @@ from util.database import get_db from typing import Optional emp_api = APIRouter(tags=['学生就业管理模块']) -@emp_api.get('/employment/class/{class_id}',response_model=EmploymentResponse,summary='获取班级学生就业信息') +@emp_api.get('/employment/class/{class_id}',response_model=list[EmploymentResponse],summary='获取班级学生就业信息') def get_emp_info2(class_id: Optional[int]=Path(description='班级编号') ,db=Depends(get_db)): e2 = employment_dao.get_emp_dao(class_id=class_id, db=db) @@ -14,7 +14,7 @@ def get_emp_info2(class_id: Optional[int]=Path(description='班级编号') return e2 raise HTTPException(status_code=404, detail='该班级就业信息不存在') -@emp_api.get('/employment/class/{stu_id}',response_model=list[EmploymentResponse],summary='按照学⽣编号,公司名字,⼯资范围查询学⽣就业信息') +@emp_api.get('/employment/students/{stu_id}',response_model=list[EmploymentResponse],summary='按照学⽣编号,公司名字,⼯资范围查询学⽣就业信息') def get_emp_info3(stu_id:int = Path(description='学生编号') ,company_name: str|None = Query(None,description='公司名称') ,min_salary: float|None = Query(None,ge=0,description='最低工资') -- 2.54.0 From 4f8114c9a13b9492bb2bb8b4f5d2c09d7bb68b61 Mon Sep 17 00:00:00 2001 From: 0919word <835535015@qq.com> Date: Tue, 22 Sep 2026 15:30:15 +0800 Subject: [PATCH 17/31] =?UTF-8?q?=E8=92=8B=E7=AB=8B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/model/all_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PythonProject/model/all_model.py b/PythonProject/model/all_model.py index cc21a42..69f6c99 100644 --- a/PythonProject/model/all_model.py +++ b/PythonProject/model/all_model.py @@ -66,7 +66,7 @@ class ClassManagement(Base): class_teacher_id = Column(Integer,ForeignKey('wl_teacher.teac_id'),comment='授课教师') - Entry_date= Column(Date,default=datetime.now,comment='录入时间') + Entry_date= Column(DATETIME,default=datetime.now,comment='录入时间') update_date = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='更新时间') -- 2.54.0 From 0c099b5f9c01c8733010afc97e057f5a46c7924d Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Tue, 22 Sep 2026 15:34:10 +0800 Subject: [PATCH 18/31] mrz --- PythonProject/api/statistics_api.py | 2 +- PythonProject/dao/statistics_dao.py | 14 ++++++++++---- PythonProject/model/all_model.py | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/PythonProject/api/statistics_api.py b/PythonProject/api/statistics_api.py index c5f0032..a5f2867 100644 --- a/PythonProject/api/statistics_api.py +++ b/PythonProject/api/statistics_api.py @@ -44,4 +44,4 @@ def get_emp(db=Depends(get_db)): @StatisticsAPI.get('/salaries',summary='统计薪资分布') def get_salaries(db=Depends(get_db)): s=classify_salary(db) - return s \ No newline at end of file + return s diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index edcc645..fd8251d 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -23,16 +23,22 @@ def select_all(db): try: l1 = db.query(Student_Model.class_id,Student_Model.gender,func.count(1).label('cnt'))\ .group_by(Student_Model.class_id,Student_Model.gender).all() - all_cnt = sum(i.cnt for i in l1) + + d1 = {} + for i in l1: + if i.class_id not in d1: + d1[i.class_id] = 0 + d1[i.class_id] += i.cnt l2 = [] for i in l1: l2.append({ - "all_cnt": all_cnt, + "all_cnt": d1[i.class_id], "class_id": i.class_id, "gender": i.gender, "cnt": i.cnt }) + return l2 except Exception: raise HTTPException(status_code=500,detail="查询异常") @@ -69,11 +75,11 @@ def select_score(min_score,max_score,db): # 实现统计每次考试每个班级的平均分并排序的功能 def select_avg_score(db): try: - l1 = db.query(Student_Model.class_id,func.avg(WlScore.score).label('avg_score'))\ + l1 = db.query(Student_Model.class_id,func.round(func.avg(WlScore.score),1).label('avg_score'))\ .join(Student_Model,WlScore.stu_id == Student_Model.stu_id)\ .filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\ .group_by(Student_Model.class_id)\ - .order_by(func.avg(WlScore.score)).all() + .order_by(func.round(func.avg(WlScore.score),1)).all() return l1 except Exception: raise HTTPException(status_code=500,detail="查询异常") diff --git a/PythonProject/model/all_model.py b/PythonProject/model/all_model.py index 55a9790..8834864 100644 --- a/PythonProject/model/all_model.py +++ b/PythonProject/model/all_model.py @@ -72,7 +72,7 @@ class ClassManagement(Base): delete_status = Column(Integer,default=0,comment='删除状态:0未删除,1已删除') - delete_time = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='删除时间') + delete_time = Column(DATETIME,comment='删除时间') class Teacher_Model(Base): __tablename__ = 'wl_teacher' @@ -149,7 +149,7 @@ class Employment_info(Base): delete_status = Column( Integer,default=0,comment='删除状态:0未删除,1已删除') - delete_time = Column(DATETIME,default=None,comment='删除时间') + delete_time = Column(DATETIME,comment='删除时间') class WlScore(Base): __tablename__ = 'wl_score' -- 2.54.0 From b829e4063fb8289ed6cf2a5180faedffe42e657d Mon Sep 17 00:00:00 2001 From: wolin_chenyulin001 <123@163.com> Date: Tue, 22 Sep 2026 15:36:24 +0800 Subject: [PATCH 19/31] ceshi --- PythonProject/api/employment_api.py | 2 ++ PythonProject/dao/employment_dao.py | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/PythonProject/api/employment_api.py b/PythonProject/api/employment_api.py index 2a09422..785aa3c 100644 --- a/PythonProject/api/employment_api.py +++ b/PythonProject/api/employment_api.py @@ -27,6 +27,8 @@ def get_emp_info3(stu_id:int = Path(description='学生编号') , company_name=company_name , min_salary=min_salary , max_salary=max_salary) + if not l1: + raise HTTPException(status_code=404,detail='该学生就业信息不存在!') return l1 @emp_api.post('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='新增学生就业信息') diff --git a/PythonProject/dao/employment_dao.py b/PythonProject/dao/employment_dao.py index 2a7e1fc..9e0f8b7 100644 --- a/PythonProject/dao/employment_dao.py +++ b/PythonProject/dao/employment_dao.py @@ -31,12 +31,9 @@ def get_emp_dao(db,stu_id=None,class_id=None,company_name=None,min_salary=None,m q = q.filter(Employment_info.salary <= max_salary) r = q.all() - if not r: - raise HTTPException(status_code=500,detail='查询异常,没有结果!') return r - def add_emp_dao(o,db): try: stu = db.query(Student_Model).filter(Student_Model.stu_id == o['stu_id'] -- 2.54.0 From 85b0d97a3db86ef37ef1d43a71ecd439823f3fc4 Mon Sep 17 00:00:00 2001 From: 00MSJ1122 <1253313142@qq.com> Date: Tue, 22 Sep 2026 15:38:53 +0800 Subject: [PATCH 20/31] 1 --- PythonProject/api/student_api.py | 57 ++++++++++++-------------- PythonProject/dao/student_dao.py | 50 +++++++++++----------- PythonProject/schema/student_schema.py | 54 +++++++++++++++--------- 3 files changed, 85 insertions(+), 76 deletions(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 2cf2f1d..5006068 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -6,7 +6,7 @@ from util.database import get_db StudentAPI = APIRouter(tags=['学生基本信息管理模块']) -@StudentAPI.get('/students',response_model=StudentPageResponse,summary='学生信息查询接口',description='查询学生信息') +@StudentAPI.get('/students',response_model=StuPageResponse,summary='学生信息查询接口',description='查询学生信息') def get_students(stu_id:int|None=None ,stu_name:str|None=None ,class_id:int|None=None @@ -19,39 +19,11 @@ def get_students(stu_id:int|None=None ,page=page ,page_size=page_size ,db=db) - - if not r: - raise HTTPException(status_code=404,detail='学生不存在') return StudentPageResponse(page=page, page_size=page_size, totals=total, data=r) -@StudentAPI.put('/{stu_id}',summary='学生信息更新接口',description='更新学生信息') -def update_students(s:StudentRequest - ,stu_id:int - ,db=Depends(get_db)): - d = s.model_dump(exclude_unset=True) - d.pop('stu_id', None) - if not d: - raise HTTPException(status_code=400, detail='更新内容不能为空') - r = update_student_dao( stu_id=stu_id,update_data=d,db=db ) - if r == 'conflict': - raise HTTPException(status_code=409, detail = '身份证号已被其他学生占用') - if r == 'error': - raise HTTPException(status_code=500, detail='更新失败,请稍后重试') - if not r: - raise HTTPException(status_code=404, detail='没有更新') - return {'code':200,'totals':r,'detail':'更新成功'} - -@StudentAPI.delete('/{stu_id}',summary='学生信息删除接口',description='删除学生信息') -def del_students(stu_id:int - ,db=Depends(get_db)): - rows=delete_student_dao( stu_id=stu_id,db=db ) - if not rows: - raise HTTPException(status_code=404,detail='对象已被删除') - return {'code':200,'totals':rows,'detail':'删除成功'} - @StudentAPI.post('/students',response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息') def add_students(s:StudentRequest ,db=Depends(get_db)): @@ -62,5 +34,30 @@ def add_students(s:StudentRequest if r == 'conflict': raise HTTPException(status_code=409, detail='身份证号已存在,请勿重复添加') if r == 'error': - raise HTTPException(status_code=500, detail='更添加失败,请稍后重试') + raise HTTPException(status_code=500, detail='添加失败,请稍后重试') return r + +@StudentAPI.put('/students/{stu_id}',summary='学生信息更新接口',description='更新学生信息') +def update_students(stu_id:int + ,s:StuUpdateRequest + ,db=Depends(get_db)): + d = s.model_dump(exclude_unset=True) + d.pop('stu_id', None) + if not d: + raise HTTPException(status_code=400, detail='更新内容不能为空') + r = update_student_dao( stu_id=stu_id,update_data=d,db=db ) + if r == 'conflict': + raise HTTPException(status_code=409, detail = '身份证号已被其他学生占用') + if r == 'error': + raise HTTPException(status_code=500, detail='更新失败,请稍后重试') + if not r: + raise HTTPException(status_code=404, detail='学生不存在或已被删除,更新失败') + return {'code':200,'totals':r,'detail':'更新成功'} + +@StudentAPI.delete('/students/{stu_id}',response_model= StugetResponse,summary='学生信息删除接口',description='删除学生信息') +def del_students(stu_id:int + ,db=Depends(get_db)): + rows=delete_student_dao( stu_id=stu_id,db=db ) + if not rows: + raise HTTPException(status_code=404,detail='学生不存在或已被删除') + return {'code':200,'totals':rows,'detail':'删除成功'} diff --git a/PythonProject/dao/student_dao.py b/PythonProject/dao/student_dao.py index d947d0d..0b5b5e8 100644 --- a/PythonProject/dao/student_dao.py +++ b/PythonProject/dao/student_dao.py @@ -15,7 +15,6 @@ def add_student_dao(o,db): o2 = Student_Model(**o) db.add(o2) db.commit() - db.refresh(o2) # 回填自增的 stu_id return o2 except IntegrityError: db.rollback() @@ -24,27 +23,30 @@ def add_student_dao(o,db): db.rollback() return 'error' -def delete_student_dao(stu_id,db): +def delete_student_dao(stu_id, db): try: - rows = db.query(Student_Model).filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0)\ - .update({'delete_status':1,'delete_time': datetime.now()}) + rows = (db.query(Student_Model) + .filter(Student_Model.stu_id == stu_id, + Student_Model.delete_status == 0) + .update({'delete_status': 1, 'delete_time': datetime.now()})) db.commit() - except: - db.rollback() - rows = 0 - finally: return rows + except Exception: + db.rollback() + raise -def update_student_dao(stu_id,update_data,db): - if update_data.get('id_card'): +def update_student_dao(stu_id, update_data, db): + if not update_data: + return 0 + id_card = update_data.get('id_card') + if id_card: conflict = (db.query(Student_Model) - .filter(Student_Model.id_card == update_data['id_card'], + .filter(Student_Model.id_card == id_card, Student_Model.stu_id != stu_id, Student_Model.delete_status == 0) .first()) if conflict: return 'conflict' - try: rows = (db.query(Student_Model) .filter(Student_Model.stu_id == stu_id, @@ -67,17 +69,13 @@ def get_student_dao(stu_id:Optional[int] ,page_size: int ,db ) -> tuple[List[Dict[str, Any]], int]: - try: - q = db.query(Student_Model).filter(Student_Model.delete_status == 0) - if stu_id: - q = q.filter(Student_Model.stu_id == stu_id) - if stu_name and stu_name.strip() != "": - q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%")) - if class_id: - q= q.filter(Student_Model.class_id == class_id) - total = q.count() - r = q.offset((page - 1) * page_size).limit(page_size).all() - return r,total - except: - db.rollback() - return [],0 + q = db.query(Student_Model).filter(Student_Model.delete_status == 0) + if stu_id: + q = q.filter(Student_Model.stu_id == stu_id) + if stu_name and stu_name.strip() != "": + q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%")) + if class_id: + q = q.filter(Student_Model.class_id == class_id) + total = q.count() + r = q.offset((page - 1) * page_size).limit(page_size).all() + return r, total diff --git a/PythonProject/schema/student_schema.py b/PythonProject/schema/student_schema.py index 53579eb..208c576 100644 --- a/PythonProject/schema/student_schema.py +++ b/PythonProject/schema/student_schema.py @@ -31,23 +31,34 @@ class StudentRequest(BaseModel): raise ValueError ('入学日期不能晚于毕业日期') return self +class StuUpdateRequest(BaseModel): + class_id: int | None = None + stu_name: str | None = None + age: int | None = None + gender: str | None = None + id_card: str | None = None + native_place: str | None = None + birthday: date | None = None + school: str | None = None + major: str | None = None + degree: str | None = None + admission_date: date | None = None + graduation_date: date | None = None + progress: int | None = None -class StudentResponse(BaseModel): - code:int = 200 - detail:str = 'ok' - stu_name:str - age:int - gender:str - progress:int + @field_validator('age') + @classmethod + def check_age(cls, v): + if v is not None and v < 0: + raise ValueError('年龄不能为负数') + return v - @field_serializer('progress') - def int_to_string(self,progress:int): - d1 ={ - 0:'学习中', - 1:'求职中', - 2:'已就业' - } - return d1.get(progress,'暂不明确') + @model_validator(mode='after') + def check_admission_graduation(self) -> Self: + if self.admission_date and self.graduation_date: + if self.admission_date > self.graduation_date: + raise ValueError('入学日期不能晚于毕业日期') + return self class StugetResponse(BaseModel): model_config = ConfigDict(from_attributes=True) @@ -58,7 +69,7 @@ class StugetResponse(BaseModel): stu_name: str | None = None age: int | None = None gender: str | None = None - id_card: str + id_card: str | None = None native_place: str | None = None birthday: date | None = None school: str | None = None @@ -66,18 +77,21 @@ class StugetResponse(BaseModel): degree: str | None = None admission_date: date | None = None graduation_date: date | None = None - progress: int = 0 + progress: int @field_serializer('progress') - def int_to_string(self, progress: int): + def progress_to_label(self, progress): d1 = { 0: '学习中', 1: '求职中', 2: '已就业' } - return d1.get(progress, '暂不明确') + try: + return d1.get(int(progress), '暂不明确') + except (TypeError, ValueError): + return progress -class StudentPageResponse(BaseModel): +class StuPageResponse(BaseModel): code: int = 200 detail: str = "ok" page: int -- 2.54.0 From 40a6d79b37adfc443952c6466d9b70dd586f3b7b Mon Sep 17 00:00:00 2001 From: 0919word <835535015@qq.com> Date: Tue, 22 Sep 2026 15:43:19 +0800 Subject: [PATCH 21/31] =?UTF-8?q?=E8=92=8B=E7=AB=8B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/dao/cla_dao.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PythonProject/dao/cla_dao.py b/PythonProject/dao/cla_dao.py index 23267a9..a75a7e4 100644 --- a/PythonProject/dao/cla_dao.py +++ b/PythonProject/dao/cla_dao.py @@ -1,6 +1,7 @@ from model.all_model import ClassManagement from fastapi import HTTPException from schema.cla_schema import claRequest +from datetime import datetime def add_class_dao(c: claRequest, session): @@ -34,7 +35,7 @@ def update_class_dao(id:int,req:claRequest,session): def delete_class_dao(id:int,session): try: session.query(ClassManagement).filter(ClassManagement.class_id==id,ClassManagement.delete_status==0)\ - .update({'delete_status': 1}) + .update({'delete_status': 1,'delete_time': datetime.now()}) session.commit() except: raise HTTPException(status_code=404, detail="删除异常,请重新核对之后删除!") -- 2.54.0 From 7a25cf6f681bb3d30b177dafecf41e0c40ca3523 Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Tue, 22 Sep 2026 15:44:56 +0800 Subject: [PATCH 22/31] mrz --- PythonProject/api/statistics_api.py | 2 +- PythonProject/dao/statistics_dao.py | 30 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/PythonProject/api/statistics_api.py b/PythonProject/api/statistics_api.py index a5f2867..649c779 100644 --- a/PythonProject/api/statistics_api.py +++ b/PythonProject/api/statistics_api.py @@ -6,7 +6,7 @@ from util.database import get_db StatisticsAPI = APIRouter(tags=['统计分析模块']) -@StatisticsAPI.get("/age",response_model=list[StudentResponse],summary='根据年龄查询学生信息') +@StatisticsAPI.get("/age",response_model=list[StugetResponse],summary='根据年龄查询学生信息') def get_students(min_age:int|None=Query(None,ge=0,le=150),max_age:int|None=Query(None,ge=0,le=150),db=Depends(get_db)): l = select_age(min_age,max_age,db) return l diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index fd8251d..0306a61 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -38,8 +38,11 @@ def select_all(db): "gender": i.gender, "cnt": i.cnt }) - + if not l2: + raise HTTPException(status_code=404, detail="没有数据") return l2 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500,detail="查询异常") @@ -66,7 +69,10 @@ def select_score(min_score,max_score,db): db = db.filter(WlScore.score >= min_score) if max_score is not None: db = db.filter(WlScore.score <= max_score) - return db.all() + l1 = db.all() + if not l1: + raise HTTPException(status_code=404, detail="没有数据") + return l1 except HTTPException: raise except Exception: @@ -80,7 +86,11 @@ def select_avg_score(db): .filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\ .group_by(Student_Model.class_id)\ .order_by(func.round(func.avg(WlScore.score),1)).all() + if not l1: + raise HTTPException(status_code=404, detail="没有数据") return l1 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500,detail="查询异常") @@ -102,7 +112,11 @@ def select_salary(db): .filter(Employment_info.delete_status==0,Student_Model.delete_status == 0)\ .order_by(Employment_info.salary.desc())\ .limit(5).all() + if not l1: + raise HTTPException(status_code=404, detail="没有数据") return l1 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500,detail="查询异常") @@ -123,19 +137,27 @@ def select_avg_days(db): Employment_info.offer_issuance_date.isnot(None),)\ .group_by(Student_Model.class_id)\ .order_by(func.avg(func.datediff(Employment_info.offer_issuance_date,Student_Model.admission_date)).desc()).all() + if not l1: + raise HTTPException(status_code=404, detail="没有数据") return l1 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500, detail="查询异常") #统计每个学⽣的就业时⻓ def select_days(db): try: - l2 =db.query(Employment_info.stu_id + l1 =db.query(Employment_info.stu_id ,func.coalesce(func.datediff(Employment_info.offer_issuance_date ,Employment_info.employment_opening_date),0)\ .label("diff_days") ).filter(Employment_info.delete_status == 0).all() - return l2 + if not l1: + raise HTTPException(status_code=404, detail="没有数据") + return l1 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500, detail="查询异常") -- 2.54.0 From 664741e52f74507cdb14691ebedfa047db5d0635 Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Tue, 22 Sep 2026 15:46:20 +0800 Subject: [PATCH 23/31] mrz --- PythonProject/api/student_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 5006068..6dbddd2 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -19,7 +19,7 @@ def get_students(stu_id:int|None=None ,page=page ,page_size=page_size ,db=db) - return StudentPageResponse(page=page, + return StuPageResponse(page=page, page_size=page_size, totals=total, data=r) -- 2.54.0 From 847b908c4f24a66b888cf4c2b1e2b01b9c627993 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 16:02:51 +0800 Subject: [PATCH 24/31] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/api/statistics_api.py | 5 +++++ PythonProject/dao/statistics_dao.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/PythonProject/api/statistics_api.py b/PythonProject/api/statistics_api.py index 649c779..86c09e2 100644 --- a/PythonProject/api/statistics_api.py +++ b/PythonProject/api/statistics_api.py @@ -45,3 +45,8 @@ def get_emp(db=Depends(get_db)): def get_salaries(db=Depends(get_db)): s=classify_salary(db) return s + +@StatisticsAPI.get('/avg_salaries',summary='统计每个班级平均薪资') +def get_avg_salaries(db=Depends(get_db)): + s=avg_salary(db) + return s diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index 0306a61..f6576b5 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -182,3 +182,15 @@ def classify_salary(db): except: raise HTTPException(status_code=500,detail='查询异常!') +#统计每个班的平均就业薪资 +def avg_salary(db): + try: + l=db.query(Student_Model.class_id,func.avg(Employment_info.salary).label('avg_salaries'))\ + .join(Employment_info,Employment_info.stu_id == Student_Model.stu_id)\ + .filter(Employment_info.salary>0,Employment_info.delete_status==0,Student_Model.delete_status==0)\ + .group_by(Student_Model.class_id)\ + .order_by(func.avg(Employment_info.salary).desc()).all() + return l + except: + raise HTTPException(status_code=500,detail='统计异常!') + -- 2.54.0 From a132eb47b2bb3817b70d5e877d3f78d202799fbb Mon Sep 17 00:00:00 2001 From: 00MSJ1122 <1253313142@qq.com> Date: Tue, 22 Sep 2026 16:48:01 +0800 Subject: [PATCH 25/31] 1 --- PythonProject/api/student_api.py | 2 -- PythonProject/dao/student_dao.py | 10 ---------- 2 files changed, 12 deletions(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 5006068..a99a1cf 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -46,8 +46,6 @@ def update_students(stu_id:int if not d: raise HTTPException(status_code=400, detail='更新内容不能为空') r = update_student_dao( stu_id=stu_id,update_data=d,db=db ) - if r == 'conflict': - raise HTTPException(status_code=409, detail = '身份证号已被其他学生占用') if r == 'error': raise HTTPException(status_code=500, detail='更新失败,请稍后重试') if not r: diff --git a/PythonProject/dao/student_dao.py b/PythonProject/dao/student_dao.py index 0b5b5e8..9b528cc 100644 --- a/PythonProject/dao/student_dao.py +++ b/PythonProject/dao/student_dao.py @@ -38,15 +38,6 @@ def delete_student_dao(stu_id, db): def update_student_dao(stu_id, update_data, db): if not update_data: return 0 - id_card = update_data.get('id_card') - if id_card: - conflict = (db.query(Student_Model) - .filter(Student_Model.id_card == id_card, - Student_Model.stu_id != stu_id, - Student_Model.delete_status == 0) - .first()) - if conflict: - return 'conflict' try: rows = (db.query(Student_Model) .filter(Student_Model.stu_id == stu_id, @@ -59,7 +50,6 @@ def update_student_dao(stu_id, update_data, db): except Exception: db.rollback() return 'error' - return rows def get_student_dao(stu_id:Optional[int] -- 2.54.0 From 6ff3d5974d854c4d455fbfc0b45a007502aca7a0 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 16:48:47 +0800 Subject: [PATCH 26/31] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/dao/statistics_dao.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index f6576b5..9202154 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -186,11 +186,11 @@ def classify_salary(db): def avg_salary(db): try: l=db.query(Student_Model.class_id,func.avg(Employment_info.salary).label('avg_salaries'))\ - .join(Employment_info,Employment_info.stu_id == Student_Model.stu_id)\ - .filter(Employment_info.salary>0,Employment_info.delete_status==0,Student_Model.delete_status==0)\ - .group_by(Student_Model.class_id)\ - .order_by(func.avg(Employment_info.salary).desc()).all() - return l + .join(Employment_info,Employment_info.stu_id == Student_Model.stu_id)\ + .filter(Employment_info.salary>0,Employment_info.delete_status==0,Student_Model.delete_status==0)\ + .group_by(Student_Model.class_id)\ + .order_by(func.avg(Employment_info.salary).desc()).all() + return [{'class_id':i[0],'avg_salaries':i[1]} for i in l] except: raise HTTPException(status_code=500,detail='统计异常!') -- 2.54.0 From 30ae0af56e9c9ad61c015e5f94a4c01edd756e4e Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 16:52:57 +0800 Subject: [PATCH 27/31] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/dao/statistics_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index 9202154..85b59f9 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -178,7 +178,7 @@ def classify_salary(db): c+=1 else: d+=1 - return {'5k以下': a, '5k-10k': b, '10k-15k': c, '15k': d} + return {'5k以下': a, '5k-10k': b, '10k-15k': c, '15k以上': d} except: raise HTTPException(status_code=500,detail='查询异常!') -- 2.54.0 From 739c8887fc22d0603ccfe575396283a84da97950 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 17:12:05 +0800 Subject: [PATCH 28/31] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PythonProject/main.py b/PythonProject/main.py index 3474b17..8bee816 100644 --- a/PythonProject/main.py +++ b/PythonProject/main.py @@ -14,7 +14,7 @@ tags_metadata = [ {"name": "学生就业管理模块"}, {"name": "统计分析模块"}, ] -app = FastAPI(title='沃林学⽣管理系统',openapi_tags=tags_metadata) +app = FastAPI(title='沃林学生管理系统',openapi_tags=tags_metadata) app.include_router(StudentAPI) -- 2.54.0 From 4e99cfd3b150491f7588ede5984bf5743eea6cfc Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 17:15:08 +0800 Subject: [PATCH 29/31] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/dao/teacher_dao.py | 1 - 1 file changed, 1 deletion(-) diff --git a/PythonProject/dao/teacher_dao.py b/PythonProject/dao/teacher_dao.py index fe97b02..f2f2da3 100644 --- a/PythonProject/dao/teacher_dao.py +++ b/PythonProject/dao/teacher_dao.py @@ -10,7 +10,6 @@ def add_teacher(teacher,session): return teacher except: session.rollback() - # raise HTTPException(status_code=500,detail='添加异常!') return None def get_teacher(id,session): -- 2.54.0 From 4849e73771ce7e39a783751d6f1e11f6228cbfe6 Mon Sep 17 00:00:00 2001 From: 00MSJ1122 <1253313142@qq.com> Date: Tue, 22 Sep 2026 17:20:17 +0800 Subject: [PATCH 30/31] 1 --- PythonProject/api/student_api.py | 2 +- PythonProject/schema/student_schema.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 59bd97f..b39f4b4 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -52,7 +52,7 @@ def update_students(stu_id:int raise HTTPException(status_code=404, detail='学生不存在或已被删除,更新失败') return {'code':200,'totals':r,'detail':'更新成功'} -@StudentAPI.delete('/students/{stu_id}',response_model= StugetResponse,summary='学生信息删除接口',description='删除学生信息') +@StudentAPI.delete('/students/{stu_id}',response_model= StudelResponse,summary='学生信息删除接口',description='删除学生信息') def del_students(stu_id:int ,db=Depends(get_db)): rows=delete_student_dao( stu_id=stu_id,db=db ) diff --git a/PythonProject/schema/student_schema.py b/PythonProject/schema/student_schema.py index 208c576..540b2d6 100644 --- a/PythonProject/schema/student_schema.py +++ b/PythonProject/schema/student_schema.py @@ -99,4 +99,10 @@ class StuPageResponse(BaseModel): totals: int data: List[StugetResponse] +class StudelResponse(BaseModel): + code: int = 200 + detail: str = "ok" + totals: int + + -- 2.54.0 From 1af01f94eed8370a4c9aacba1206d534d723a251 Mon Sep 17 00:00:00 2001 From: wolin_chenyulin001 <123@163.com> Date: Tue, 22 Sep 2026 19:51:46 +0800 Subject: [PATCH 31/31] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B0=8F=E7=91=95?= =?UTF-8?q?=E7=96=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/api/employment_api.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PythonProject/api/employment_api.py b/PythonProject/api/employment_api.py index 785aa3c..6faec0e 100644 --- a/PythonProject/api/employment_api.py +++ b/PythonProject/api/employment_api.py @@ -7,15 +7,15 @@ from typing import Optional emp_api = APIRouter(tags=['学生就业管理模块']) @emp_api.get('/employment/class/{class_id}',response_model=list[EmploymentResponse],summary='获取班级学生就业信息') -def get_emp_info2(class_id: Optional[int]=Path(description='班级编号') +def get_emp_info1(class_id: Optional[int]=Path(description='班级编号') ,db=Depends(get_db)): - e2 = employment_dao.get_emp_dao(class_id=class_id, db=db) - if e2: - return e2 + e1 = employment_dao.get_emp_dao(class_id=class_id, db=db) + if e1: + return e1 raise HTTPException(status_code=404, detail='该班级就业信息不存在') @emp_api.get('/employment/students/{stu_id}',response_model=list[EmploymentResponse],summary='按照学⽣编号,公司名字,⼯资范围查询学⽣就业信息') -def get_emp_info3(stu_id:int = Path(description='学生编号') +def get_emp_info2(stu_id:int = Path(description='学生编号') ,company_name: str|None = Query(None,description='公司名称') ,min_salary: float|None = Query(None,ge=0,description='最低工资') ,max_salary: float|None = Query(None,ge=0,description='最高工资') -- 2.54.0