Merge remote-tracking branch 'origin/conding' into conding
This commit is contained in:
@@ -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:
|
||||
@@ -22,7 +22,7 @@ def get_class_dao(n,m,session):
|
||||
except:
|
||||
raise HTTPException(status_code=406,detail="输入查询信息有误,请重新输入!")
|
||||
|
||||
def update_class_dao(id:int,req:ClassManagement,session):
|
||||
def update_class_dao(id:int,req:claRequest,session):
|
||||
try:
|
||||
session.query(ClassManagement).filter(ClassManagement.class_id==id)\
|
||||
.filter(ClassManagement.delete_status==0).update(req.model_dump(exclude_unset=True))
|
||||
@@ -40,44 +40,7 @@ def delete_class_dao(id:int,session):
|
||||
raise HTTPException(status_code=404, detail="删除异常,请重新核对之后删除!")
|
||||
return '删除成功,请核对信息!'
|
||||
|
||||
def get_class_for_delete(id: int, session):
|
||||
try:
|
||||
obj = (
|
||||
session.query(ClassManagement).filter(ClassManagement.class_id == id,ClassManagement.delete_status == 0).first()
|
||||
)
|
||||
if not obj:
|
||||
raise HTTPException(status_code=404, detail="班级不存在")
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常,请重新核对!")
|
||||
|
||||
return {
|
||||
"class_id": obj.class_id,
|
||||
"class_name": obj.class_name,
|
||||
"start_class_date": obj.start_class_date,
|
||||
"head_teacher_id": obj.head_teacher_id,
|
||||
"class_teacher_id": obj.class_teacher_id,
|
||||
}
|
||||
|
||||
def hard_delete_class(id: int, session):
|
||||
try:
|
||||
obj = (
|
||||
session.query(ClassManagement).filter(ClassManagement.class_id == id,ClassManagement.delete_status == 0)
|
||||
.first()
|
||||
)
|
||||
if not obj:
|
||||
raise HTTPException(status_code=404, detail="班级不存在")
|
||||
|
||||
session.delete(obj)
|
||||
session.commit()
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
session.rollback()
|
||||
raise HTTPException(status_code=500, detail="删除异常,请重新核对之后删除!")
|
||||
|
||||
return '删除成功,请核对信息!'
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,46 +1,67 @@
|
||||
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):
|
||||
q = db.query(Employment_info.emp_id
|
||||
,Employment_info.stu_id
|
||||
,Student_Model.stu_name
|
||||
,Student_Model.class_id
|
||||
,Employment_info.email
|
||||
,Employment_info.employment_opening_date
|
||||
,Employment_info.offer_issuance_date
|
||||
,Employment_info.company_name
|
||||
,Employment_info.company_address
|
||||
,Employment_info.salary)\
|
||||
.join(Student_Model,Employment_info.stu_id == Student_Model.stu_id)\
|
||||
.join(ClassManagement,Student_Model.class_id == ClassManagement.class_id)\
|
||||
.filter(Employment_info.delete_status == 0)\
|
||||
.filter(Student_Model.delete_status == 0)\
|
||||
.filter(ClassManagement.delete_status == 0)
|
||||
|
||||
if stu_id:
|
||||
q = q.filter(Employment_info.stu_id == stu_id)
|
||||
if class_id:
|
||||
q = q.filter(ClassManagement.class_id == class_id)
|
||||
if company_name:
|
||||
q = q.filter(Employment_info.company_name == company_name)
|
||||
if min_salary:
|
||||
q = q.filter(Employment_info.salary >= min_salary)
|
||||
if max_salary:
|
||||
q = q.filter(Employment_info.salary <= max_salary)
|
||||
|
||||
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
|
||||
]
|
||||
|
||||
|
||||
|
||||
def add_emp_dao(o:dict,db):
|
||||
try:
|
||||
q = db.query(Employment_info).\
|
||||
join(Student_Model,Employment_info.stu_id == Student_Model.stu_id).\
|
||||
join(ClassManagement,Student_Model.class_id == ClassManagement.class_id).\
|
||||
filter(Employment_info.delete_status == 0).\
|
||||
filter(Student_Model.delete_status == 0).\
|
||||
filter(ClassManagement.delete_status == 0)
|
||||
if stu_id:
|
||||
q = q.filter(Employment_info.stu_id == stu_id)
|
||||
if class_id:
|
||||
q = q.filter(ClassManagement.class_id == class_id)
|
||||
if company_name:
|
||||
q = q.filter(Employment_info.company_name == company_name)
|
||||
if min_salary:
|
||||
q = q.filter(Employment_info.salary >= min_salary)
|
||||
if max_salary:
|
||||
q = q.filter(Employment_info.salary <= max_salary)
|
||||
stu = db.query(Student_Model).filter(Student_Model.stu_id == o['stu_id']
|
||||
, Student_Model.delete_status == 0).first()
|
||||
if not stu:
|
||||
raise HTTPException(status_code=404, detail='该学生不存在,无法添加就业信息')
|
||||
|
||||
r = q.all()
|
||||
exist = (db.query(Employment_info).filter(Employment_info.stu_id == o['stu_id']
|
||||
,Employment_info.delete_status == 0).first())
|
||||
if exist:
|
||||
raise HTTPException(status_code=409, detail='该学生已有就业信息,请勿重复增加!')
|
||||
|
||||
if r:
|
||||
return [{'emp_id':i.emp_id
|
||||
,'stu_id': i.stu_id
|
||||
,'stu_name':i.Student_Model.stu_name
|
||||
,'class_id':i.Student_Model.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
|
||||
]
|
||||
except:
|
||||
raise HTTPException(status_code=404,detail='信息不存在!')
|
||||
|
||||
def add_emp_dao(o,db):
|
||||
try:
|
||||
e1 = Employment_info(**o)
|
||||
db.add(e1)
|
||||
db.commit()
|
||||
@@ -49,13 +70,11 @@ def add_emp_dao(o,db):
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
||||
|
||||
def check_stu_dao(stu_id,db):
|
||||
stu = db.query(Student_Model).filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0).first()
|
||||
return stu
|
||||
|
||||
def update_emp_dao(stu_id,o,db):
|
||||
def update_emp_dao(emp_id:int,db):
|
||||
try:
|
||||
rows = db.query(Employment_info).filter(Employment_info.stu_id == stu_id,Employment_info.delete_status == 0).first()
|
||||
rows = db.query(Employment_info).filter(Employment_info.emp_id == emp_id
|
||||
,Employment_info.delete_status == 0).first()
|
||||
|
||||
db.commit()
|
||||
return rows
|
||||
except:
|
||||
@@ -63,9 +82,12 @@ def update_emp_dao(stu_id,o,db):
|
||||
raise HTTPException(status_code=404,detail='该就业记录已存在')
|
||||
|
||||
|
||||
def delete_emp_dao(stu_id,db):
|
||||
def delete_emp_dao(emp_id:int,db):
|
||||
try:
|
||||
rows = db.query(Employment_info).filter(Employment_info.stu_id == stu_id,Employment_info.delete_status == 0).delete()
|
||||
rows = db.query(Employment_info)\
|
||||
.filter(Employment_info.emp_id == emp_id
|
||||
,Employment_info.delete_status == 0)\
|
||||
.update({'delete_status':1,'delete_time': datetime.now()})
|
||||
db.commit()
|
||||
except:
|
||||
db.rollback()
|
||||
|
||||
@@ -7,20 +7,38 @@ from model.all_model import *
|
||||
# 根据id查询单条有效成绩
|
||||
def get_score_by_id_dao(score_id:int, db):
|
||||
return db.query(WlScore).filter(
|
||||
WlScore.id == score_id
|
||||
,WlScore.delete_status==1
|
||||
WlScore.score_id == score_id
|
||||
,WlScore.delete_status==0
|
||||
).first()
|
||||
|
||||
# 根据stu_id+exam_order查重(新增、修改时校验重复)
|
||||
def get_score_by_stu_exam_order_dao(stu_id:str,exam_order:int,db):
|
||||
return db.query(WlScore).filter(WlScore.stu_id==stu_id,WlScore.exam_order==exam_order,WlScore.delete_status==0).first()
|
||||
return db.query(WlScore).filter(WlScore.stu_id==stu_id
|
||||
,WlScore.exam_order==exam_order
|
||||
,WlScore.delete_status==0).first()
|
||||
|
||||
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="学生不存在")
|
||||
|
||||
@@ -52,7 +70,7 @@ def delete_grade_dao(stu_id:int,db):
|
||||
rows = db.query(WlScore).filter(
|
||||
WlScore.stu_id == stu_id,
|
||||
WlScore.delete_status == 0
|
||||
).update({'delete_status':1})
|
||||
).update({'delete_status':1,'delete_time':datetime.now()})
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
|
||||
@@ -23,7 +23,17 @@ 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()
|
||||
return l1
|
||||
all_cnt = sum(i.cnt for i in l1)
|
||||
|
||||
l2 = []
|
||||
for i in l1:
|
||||
l2.append({
|
||||
"all_cnt": all_cnt,
|
||||
"class_id": i.class_id,
|
||||
"gender": i.gender,
|
||||
"cnt": i.cnt
|
||||
})
|
||||
return l2
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
@@ -32,12 +42,23 @@ def select_score(min_score,max_score,db):
|
||||
try:
|
||||
if min_score is None and max_score is None:
|
||||
raise HTTPException(status_code=400, detail="请至少传入一个参数")
|
||||
db = db.query(Student_Model,WlScore.score,WlScore.score)\
|
||||
db = db.query(WlScore.score
|
||||
,Student_Model.stu_name
|
||||
,Student_Model.age
|
||||
,Student_Model.gender
|
||||
,Student_Model.native_place
|
||||
,Student_Model.school
|
||||
,Student_Model.major
|
||||
,Student_Model.degree
|
||||
,Student_Model.admission_date
|
||||
,Student_Model.graduation_date
|
||||
,Student_Model.progress
|
||||
)\
|
||||
.join(WlScore,WlScore.stu_id == Student_Model.stu_id)\
|
||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)
|
||||
if min_score is not None:
|
||||
db = db.filter(WlScore.score >= min_score)
|
||||
if min_score is not None:
|
||||
if max_score is not None:
|
||||
db = db.filter(WlScore.score <= max_score)
|
||||
return db.all()
|
||||
except HTTPException:
|
||||
@@ -60,7 +81,17 @@ def select_avg_score(db):
|
||||
# 实现统计薪资最高的前五名的学员信息
|
||||
def select_salary(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model,Employment_info.salary)\
|
||||
l1 = db.query(Employment_info.salary
|
||||
,Student_Model.stu_name
|
||||
,Student_Model.age
|
||||
,Student_Model.gender
|
||||
,Student_Model.native_place
|
||||
,Student_Model.school
|
||||
,Student_Model.major
|
||||
,Student_Model.degree
|
||||
,Student_Model.admission_date
|
||||
,Student_Model.graduation_date
|
||||
,Student_Model.progress)\
|
||||
.join(Employment_info,Employment_info.stu_id==Student_Model.stu_id)\
|
||||
.filter(Employment_info.delete_status==0,Student_Model.delete_status == 0)\
|
||||
.order_by(Employment_info.salary.desc())\
|
||||
@@ -70,7 +101,7 @@ def select_salary(db):
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计每个班级的平均就业时长
|
||||
def select_days(db):
|
||||
def select_avg_days(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,
|
||||
func.coalesce(
|
||||
@@ -84,27 +115,20 @@ def select_days(db):
|
||||
Employment_info.delete_status == 0,
|
||||
Employment_info.employment_opening_date.isnot(None),
|
||||
Employment_info.offer_issuance_date.isnot(None),)\
|
||||
.group_by( Student_Model.class_id)\
|
||||
.group_by(Student_Model.class_id)\
|
||||
.order_by(func.avg(func.datediff(Employment_info.offer_issuance_date,Student_Model.admission_date)).desc()).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
|
||||
#统计每个学⽣的就业时⻓
|
||||
def select_days2(db):
|
||||
def select_days(db):
|
||||
try:
|
||||
l2 =db.query(
|
||||
Employment_info.stu_id
|
||||
,Employment_info.employment_opening_date
|
||||
,Employment_info.offer_issuance_date
|
||||
,func.datediff(
|
||||
Employment_info.offer_issuance_date
|
||||
,Employment_info.employment_opening_date
|
||||
)
|
||||
.label("employment_duration_day")
|
||||
).filter(
|
||||
Employment_info.delete_status == 0
|
||||
).all()
|
||||
l2 =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
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
@@ -1,5 +1,6 @@
|
||||
from fastapi import HTTPException
|
||||
from model.all_model import Teacher_Model
|
||||
from datetime import datetime
|
||||
|
||||
def add_teacher(teacher,session):
|
||||
try:
|
||||
@@ -34,7 +35,7 @@ def update_teacher(id:int,req,session):
|
||||
def delete_teacher(id:int,session):
|
||||
try:
|
||||
r=session.query(Teacher_Model).filter(Teacher_Model.teac_id==id,Teacher_Model.delete_status==0)\
|
||||
.update({'delete_status':1})
|
||||
.update({'delete_status':1,'delete_time':datetime.now()})
|
||||
except:
|
||||
session.rollback()
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user