更新debug
This commit is contained in:
+17
-9
@@ -73,9 +73,13 @@ def updata_stuinfo( #更新数据模块
|
||||
,db=Depends(get_db)
|
||||
): #根据id选择对象
|
||||
d = up.model_dump(exclude_unset=True) #解析
|
||||
d.pop('create_time', None)
|
||||
d.pop('is_deleted', None)
|
||||
r = update_emp_dao(id=id, update_data=d, db=db) #调用更新函数
|
||||
if not d:
|
||||
raise HTTPException(status_code=400, detail='没有需要更新的字段')
|
||||
if not r:
|
||||
raise HTTPException(status_code=500, detail='没有更新!') #失败返回错误信息
|
||||
raise HTTPException(status_code=404, detail='未找到对应记录') #失败返回错误信息
|
||||
return {'code': 200, 'totals': r, 'detail': '更新成功'} #成功返回信息
|
||||
|
||||
@CURD.delete('/emp/{id}',summary='删除就业信息')
|
||||
@@ -95,12 +99,14 @@ def salarytop5(db=Depends(get_db)):
|
||||
.join(Company, Employments.company_id == Company.id) \
|
||||
.filter(Employments.is_deleted == 0)\
|
||||
.order_by(Employments.employment_salary.desc())\
|
||||
.offset(0).limit(5) .all()
|
||||
.limit(5) .all()
|
||||
return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q]
|
||||
|
||||
@CURD.get('/worktime',summary='学生就业时常')
|
||||
def worktime(db=Depends(get_db)):
|
||||
q = db.query(Employments).all()
|
||||
q = db.query(Employments)\
|
||||
.filter(Employments.is_deleted==0)\
|
||||
.all()
|
||||
|
||||
return [{'学生姓名':i.sname,'就业时常':f'{i.offer_recived_time-i.employment_open_time}' if i.offer_recived_time and i.employment_open_time else '暂无数据'} for i in q]
|
||||
|
||||
@@ -109,12 +115,14 @@ def worktime(db=Depends(get_db)):
|
||||
def avgworktime(db=Depends(get_db)):
|
||||
q = db.query(Employments)\
|
||||
.filter(Employments.employment_open_time.isnot(None)
|
||||
,Employments.offer_recived_time.isnot(None))\
|
||||
,Employments.offer_recived_time.isnot(None)
|
||||
,Employments.is_deleted==0)\
|
||||
.all()
|
||||
if not q:
|
||||
return {'平均就业时常': '暂无数据'}
|
||||
s=0
|
||||
for i in q:
|
||||
s+=(i.offer_recived_time - i.employment_open_time)
|
||||
avg=s/len(q)
|
||||
return f'平均就业时常:{avg}'
|
||||
total = sum((i.offer_recived_time - i.employment_open_time).total_seconds() for i in q)
|
||||
avg_days=total /len(q)/86400 #一天86400秒
|
||||
return {
|
||||
'人数': len(q),
|
||||
'平均就业时常(天)': round(avg_days, 2)
|
||||
}
|
||||
Reference in New Issue
Block a user