81 lines
3.0 KiB
Python
81 lines
3.0 KiB
Python
from datetime import date
|
|
|
|
from fastapi import HTTPException
|
|
from pydantic import Field
|
|
from sqlalchemy import and_
|
|
from sqlalchemy.orm import Session
|
|
#导入表模型
|
|
from model.work import Work
|
|
#导入请求模型 StudentWorkCreate,是学生就业信息表的第一个请求模型用于方法一,
|
|
# StudentWorkCreate1,是学生就业信息表的第二个请求模型用于方法二
|
|
# StudentWroks,是学生信息表的请求模型
|
|
from scheme.works import StudentWorkCreate,StudentWorks,StudentWorkCreate1
|
|
|
|
class WorkDao:
|
|
@staticmethod
|
|
#这是一个增加学生就业信息的方法
|
|
def add_s_w(db: Session,student_work_info: StudentWorkCreate ):
|
|
u1 = Work(**student_work_info.model_dump())
|
|
db.add(u1)
|
|
db.commit()
|
|
print("已添加成功")
|
|
return u1
|
|
#这是获取学生就业信息(包含学生姓名与学生编号)的方法(三个必填版)
|
|
@staticmethod
|
|
def get_s_w(db: Session,student_work_info: StudentWorkCreate1):
|
|
u2 =db.query(Work).filter(and_(Work.sid == student_work_info.sid,
|
|
Work.company_name==student_work_info.company_name,
|
|
Work.salary==student_work_info.salary)).first()
|
|
|
|
print("信息查询成功")
|
|
return {"学生姓名":u2.student.name,"学生班级编号":u2.student.cid,
|
|
"学生offer下发时间":u2.offer_time,"学生就业时间":u2.open_time,"公司姓名":u2.company_name,
|
|
"月薪":u2.salary}
|
|
#这是修改学生就业信息的方法
|
|
@staticmethod
|
|
def update_s_w(db:Session,student_work_info: StudentWorks):
|
|
i = db.query(Work).filter(Work.sid == student_work_info.sid).first()
|
|
if i is not None:
|
|
|
|
if student_work_info.company_name!="0":
|
|
i.company_name = student_work_info.company_name
|
|
db.commit()
|
|
if float(student_work_info.salary)!=0:
|
|
i.salary = student_work_info.salary
|
|
db.commit()
|
|
if student_work_info.open_time!=date(1970,1,1):
|
|
i.work_time = student_work_info.open_time
|
|
db.commit()
|
|
if student_work_info.offer_time!=date(1970,1,1):
|
|
i.offer_time = student_work_info.offer_time
|
|
db.commit()
|
|
return {"message": f"{student_work_info.sid}号学生已经修改成功"}
|
|
|
|
else:
|
|
raise HTTPException(status_code= 422,detail="输入学生学号错误")
|
|
|
|
#这是删除学生信息的方法
|
|
@staticmethod
|
|
def delete_s_w(db: Session,user_id:int=Field(...,ge=0,le=100000)):
|
|
u0 = db.query(Work).all()
|
|
for i in u0:
|
|
if i.sid == user_id:
|
|
u1 = db.query(Work).filter(Work.sid == i.sid).first()
|
|
u1.flag = 0
|
|
return {"message":f"{user_id}号学生已经删除成功"}
|
|
else:
|
|
raise HTTPException(status_code=422,detail="输入的学生编号错误")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|