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 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/statistics_dao.py b/PythonProject/dao/statistics_dao.py index c576206..edcc645 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -131,4 +131,26 @@ def select_days(db): ).filter(Employment_info.delete_status == 0).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='查询异常!') + 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] diff --git a/PythonProject/model/all_model.py b/PythonProject/model/all_model.py index eccb6e9..55a9790 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): @@ -64,7 +66,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='更新时间')