Merge remote-tracking branch 'origin/conding' into conding
This commit is contained in:
@@ -31,13 +31,13 @@ def get_emp_info2(stu_id:int = Path(description='学生编号')
|
|||||||
raise HTTPException(status_code=404,detail='该学生就业信息不存在!')
|
raise HTTPException(status_code=404,detail='该学生就业信息不存在!')
|
||||||
return l1
|
return l1
|
||||||
|
|
||||||
@emp_api.post('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='新增学生就业信息')
|
@emp_api.post('/employment/student/{stu_id}',summary='新增学生就业信息')
|
||||||
def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)):
|
def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)):
|
||||||
d=emp.model_dump(exclude_unset=False)
|
d=emp.model_dump(exclude_unset=False)
|
||||||
r=add_emp_dao(d,db)
|
r=add_emp_dao(d,db)
|
||||||
if not r:
|
if not r:
|
||||||
raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!')
|
raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!')
|
||||||
return r
|
return {'code':200,'detail':'插入成功!'}
|
||||||
|
|
||||||
@emp_api.put('/employment/students/{stu_id}',summary='更新学生就业信息')
|
@emp_api.put('/employment/students/{stu_id}',summary='更新学生就业信息')
|
||||||
def update_emp_info(stu_id:int,emp:UpdateEmpRequest,db=Depends(get_db)):
|
def update_emp_info(stu_id:int,emp:UpdateEmpRequest,db=Depends(get_db)):
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from fastapi import APIRouter,HTTPException,Depends
|
from fastapi import APIRouter, HTTPException, Depends, Query, Path
|
||||||
from dao.student_dao import *
|
from dao.student_dao import *
|
||||||
from schema.student_schema import *
|
from schema.student_schema import *
|
||||||
from util.database import get_db
|
from util.database import get_db
|
||||||
@@ -6,24 +6,6 @@ from util.database import get_db
|
|||||||
|
|
||||||
StudentAPI = APIRouter(tags=['学生基本信息管理模块'])
|
StudentAPI = APIRouter(tags=['学生基本信息管理模块'])
|
||||||
|
|
||||||
@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
|
|
||||||
,db=Depends(get_db)
|
|
||||||
,page:int=1
|
|
||||||
,page_size:int=10):
|
|
||||||
r, total = get_student_dao(stu_id=stu_id
|
|
||||||
,stu_name=stu_name
|
|
||||||
,class_id=class_id
|
|
||||||
,page=page
|
|
||||||
,page_size=page_size
|
|
||||||
,db=db)
|
|
||||||
return StuPageResponse(page=page,
|
|
||||||
page_size=page_size,
|
|
||||||
totals=total,
|
|
||||||
data=r)
|
|
||||||
|
|
||||||
@StudentAPI.post('/students',response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息')
|
@StudentAPI.post('/students',response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息')
|
||||||
def add_students(s:StudentRequest
|
def add_students(s:StudentRequest
|
||||||
,db=Depends(get_db)):
|
,db=Depends(get_db)):
|
||||||
@@ -37,6 +19,24 @@ def add_students(s:StudentRequest
|
|||||||
raise HTTPException(status_code=500, detail='添加失败,请稍后重试')
|
raise HTTPException(status_code=500, detail='添加失败,请稍后重试')
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
@StudentAPI.get('/students',response_model=StuPageResponse,summary='学生信息查询接口',description='查询学生信息')
|
||||||
|
def get_students(stu_id:int=Query(None,description='学生id')
|
||||||
|
,stu_name:str=Query(None,description='学生姓名')
|
||||||
|
,class_id:int=Query(None,description='班级编号')
|
||||||
|
,db=Depends(get_db)
|
||||||
|
,page:int=Query(None,description='页数')
|
||||||
|
,page_size:int=Query(None,description='行数')):
|
||||||
|
r, total = get_student_dao(stu_id=stu_id
|
||||||
|
,stu_name=stu_name
|
||||||
|
,class_id=class_id
|
||||||
|
,page=page
|
||||||
|
,page_size=page_size
|
||||||
|
,db=db)
|
||||||
|
return StuPageResponse(page=page
|
||||||
|
,page_size=page_size
|
||||||
|
,totals=total
|
||||||
|
,data=r)
|
||||||
|
|
||||||
@StudentAPI.put('/students/{stu_id}',summary='学生信息更新接口',description='更新学生信息')
|
@StudentAPI.put('/students/{stu_id}',summary='学生信息更新接口',description='更新学生信息')
|
||||||
def update_students(stu_id:int
|
def update_students(stu_id:int
|
||||||
,s:StuUpdateRequest
|
,s:StuUpdateRequest
|
||||||
@@ -53,7 +53,7 @@ def update_students(stu_id:int
|
|||||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||||
|
|
||||||
@StudentAPI.delete('/students/{stu_id}',response_model= StudelResponse,summary='学生信息删除接口',description='删除学生信息')
|
@StudentAPI.delete('/students/{stu_id}',response_model= StudelResponse,summary='学生信息删除接口',description='删除学生信息')
|
||||||
def del_students(stu_id:int
|
def del_students(stu_id:int= Path(description='班级编号')
|
||||||
,db=Depends(get_db)):
|
,db=Depends(get_db)):
|
||||||
rows=delete_student_dao( stu_id=stu_id,db=db )
|
rows=delete_student_dao( stu_id=stu_id,db=db )
|
||||||
if not rows:
|
if not rows:
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def add_emp_dao(o,db):
|
|||||||
e1 = Employment_info(**o)
|
e1 = Employment_info(**o)
|
||||||
db.add(e1)
|
db.add(e1)
|
||||||
db.commit()
|
db.commit()
|
||||||
return e1
|
return o
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ from sqlalchemy.exc import IntegrityError
|
|||||||
|
|
||||||
def add_student_dao(o,db):
|
def add_student_dao(o,db):
|
||||||
if o.get('id_card'):
|
if o.get('id_card'):
|
||||||
conflict = (db.query(Student_Model)
|
o1 = (db.query(Student_Model)
|
||||||
.filter(Student_Model.id_card == o['id_card'],
|
.filter(Student_Model.id_card == o['id_card'],
|
||||||
Student_Model.delete_status == 0)
|
Student_Model.delete_status == 0)
|
||||||
.first())
|
.first())
|
||||||
if conflict:
|
if o1:
|
||||||
return 'conflict'
|
return 'conflict'
|
||||||
try:
|
try:
|
||||||
o2 = Student_Model(**o)
|
o2 = Student_Model(**o)
|
||||||
@@ -23,35 +23,6 @@ def add_student_dao(o,db):
|
|||||||
db.rollback()
|
db.rollback()
|
||||||
return 'error'
|
return 'error'
|
||||||
|
|
||||||
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()}))
|
|
||||||
db.commit()
|
|
||||||
return rows
|
|
||||||
except Exception:
|
|
||||||
db.rollback()
|
|
||||||
raise
|
|
||||||
|
|
||||||
def update_student_dao(stu_id, update_data, db):
|
|
||||||
if not update_data:
|
|
||||||
return 0
|
|
||||||
try:
|
|
||||||
rows = (db.query(Student_Model)
|
|
||||||
.filter(Student_Model.stu_id == stu_id,
|
|
||||||
Student_Model.delete_status == 0)
|
|
||||||
.update(update_data))
|
|
||||||
db.commit()
|
|
||||||
except IntegrityError:
|
|
||||||
db.rollback()
|
|
||||||
return 'conflict'
|
|
||||||
except Exception:
|
|
||||||
db.rollback()
|
|
||||||
return 'error'
|
|
||||||
return rows
|
|
||||||
|
|
||||||
def get_student_dao(stu_id:Optional[int]
|
def get_student_dao(stu_id:Optional[int]
|
||||||
,stu_name:Optional[str]
|
,stu_name:Optional[str]
|
||||||
,class_id:Optional[int]
|
,class_id:Optional[int]
|
||||||
@@ -69,3 +40,32 @@ def get_student_dao(stu_id:Optional[int]
|
|||||||
total = q.count()
|
total = q.count()
|
||||||
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
||||||
return r, total
|
return r, total
|
||||||
|
|
||||||
|
def update_student_dao(stu_id, update_data, db):
|
||||||
|
if not update_data:
|
||||||
|
return 0
|
||||||
|
try:
|
||||||
|
rows = (db.query(Student_Model)
|
||||||
|
.filter(Student_Model.stu_id == stu_id,
|
||||||
|
Student_Model.delete_status == 0)
|
||||||
|
.update(update_data))
|
||||||
|
db.commit()
|
||||||
|
except IntegrityError:
|
||||||
|
db.rollback()
|
||||||
|
return 'conflict'
|
||||||
|
except Exception:
|
||||||
|
db.rollback()
|
||||||
|
return 'error'
|
||||||
|
return rows
|
||||||
|
|
||||||
|
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()}))
|
||||||
|
db.commit()
|
||||||
|
return rows
|
||||||
|
except Exception:
|
||||||
|
db.rollback()
|
||||||
|
raise
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
from typing import Self,List
|
from typing import Self,List,Optional
|
||||||
from pydantic import BaseModel, field_serializer, field_validator,model_validator,ConfigDict
|
from pydantic import BaseModel, field_serializer, field_validator,model_validator,ConfigDict
|
||||||
|
|
||||||
|
|
||||||
@@ -53,6 +53,13 @@ class StuUpdateRequest(BaseModel):
|
|||||||
raise ValueError('年龄不能为负数')
|
raise ValueError('年龄不能为负数')
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
@field_validator('id_card')
|
||||||
|
@classmethod
|
||||||
|
def check_id_card(cls, v):
|
||||||
|
if len(v) != 18 or len(v) != 19 :
|
||||||
|
raise ValueError('身份证输入有误')
|
||||||
|
return v
|
||||||
|
|
||||||
@model_validator(mode='after')
|
@model_validator(mode='after')
|
||||||
def check_admission_graduation(self) -> Self:
|
def check_admission_graduation(self) -> Self:
|
||||||
if self.admission_date and self.graduation_date:
|
if self.admission_date and self.graduation_date:
|
||||||
@@ -77,7 +84,7 @@ class StugetResponse(BaseModel):
|
|||||||
degree: str | None = None
|
degree: str | None = None
|
||||||
admission_date: date | None = None
|
admission_date: date | None = None
|
||||||
graduation_date: date | None = None
|
graduation_date: date | None = None
|
||||||
progress: int
|
progress: Optional[int]
|
||||||
|
|
||||||
@field_serializer('progress')
|
@field_serializer('progress')
|
||||||
def progress_to_label(self, progress):
|
def progress_to_label(self, progress):
|
||||||
|
|||||||
Reference in New Issue
Block a user