更新字段
This commit is contained in:
+20
-13
@@ -7,7 +7,7 @@ from database import get_db
|
|||||||
CURD=APIRouter()
|
CURD=APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@CURD.get('/emp',tags=['查询就业信息'])
|
@CURD.get('/emp',summary='查询就业信息')
|
||||||
def get_stuinfo( #查询学生就业信息
|
def get_stuinfo( #查询学生就业信息
|
||||||
sname:str| None = None
|
sname:str| None = None
|
||||||
,class_num:int| None = None
|
,class_num:int| None = None
|
||||||
@@ -34,7 +34,7 @@ def get_stuinfo( #查询学生就业信息
|
|||||||
return r #成功返回
|
return r #成功返回
|
||||||
raise HTTPException(status_code=404, detail='名单不存在!') #失败返回错误信息
|
raise HTTPException(status_code=404, detail='名单不存在!') #失败返回错误信息
|
||||||
|
|
||||||
@CURD.post('/emp',response_model=EmpResponse,tags=['新增就业信息'])
|
@CURD.post('/emp',response_model=EmpResponse,summary='新增就业信息')
|
||||||
def add_stuinfo( #新增学生就业信息
|
def add_stuinfo( #新增学生就业信息
|
||||||
p:PostRequest,db=Depends(get_db)
|
p:PostRequest,db=Depends(get_db)
|
||||||
): #调用请求体
|
): #调用请求体
|
||||||
@@ -44,7 +44,7 @@ def add_stuinfo( #新增学生就业信
|
|||||||
raise HTTPException(status_code=500, detail='服务器繁忙,请稍后添加!') #失败返回错误
|
raise HTTPException(status_code=500, detail='服务器繁忙,请稍后添加!') #失败返回错误
|
||||||
return EmpResponse(totals=1, data=d) #成功返回响应体
|
return EmpResponse(totals=1, data=d) #成功返回响应体
|
||||||
|
|
||||||
@CURD.post('/emp/company',response_model=CompResponse,tags=['新增公司信息'])
|
@CURD.post('/emp/company',response_model=CompResponse,summary='新增公司信息')
|
||||||
def add_company( #新增公司表信息
|
def add_company( #新增公司表信息
|
||||||
c:CompRequest,db=Depends(get_db)
|
c:CompRequest,db=Depends(get_db)
|
||||||
):
|
):
|
||||||
@@ -55,7 +55,7 @@ def add_company( #新增公司表信息
|
|||||||
return CompResponse(totals=1, data=d) #成功返回响应体
|
return CompResponse(totals=1, data=d) #成功返回响应体
|
||||||
|
|
||||||
|
|
||||||
@CURD.post('/emp/company/address',response_model=AddResponse,tags=['新增公司所在区域'])
|
@CURD.post('/emp/company/address',response_model=AddResponse,summary='新增公司所在区域')
|
||||||
def add_address( #新增公司地址区域信息
|
def add_address( #新增公司地址区域信息
|
||||||
add:AddRequest,db=Depends(get_db)
|
add:AddRequest,db=Depends(get_db)
|
||||||
):
|
):
|
||||||
@@ -66,7 +66,7 @@ def add_address( #新增公司地址区
|
|||||||
return AddResponse(totals=1, data=d) #成功返回响应体
|
return AddResponse(totals=1, data=d) #成功返回响应体
|
||||||
|
|
||||||
|
|
||||||
@CURD.put('/emp',tags=['更改就业信息'])
|
@CURD.put('/emp',summary='更改就业信息')
|
||||||
def updata_stuinfo( #更新数据模块
|
def updata_stuinfo( #更新数据模块
|
||||||
up:PostRequest
|
up:PostRequest
|
||||||
,id:int
|
,id:int
|
||||||
@@ -78,7 +78,7 @@ def updata_stuinfo( #更新数据模块
|
|||||||
raise HTTPException(status_code=500, detail='没有更新!') #失败返回错误信息
|
raise HTTPException(status_code=500, detail='没有更新!') #失败返回错误信息
|
||||||
return {'code': 200, 'totals': r, 'detail': '更新成功'} #成功返回信息
|
return {'code': 200, 'totals': r, 'detail': '更新成功'} #成功返回信息
|
||||||
|
|
||||||
@CURD.delete('/emp/{id}',tags=['删除就业信息'])
|
@CURD.delete('/emp/{id}',summary='删除就业信息')
|
||||||
def delete_stuinfo( #删除模块
|
def delete_stuinfo( #删除模块
|
||||||
id:int
|
id:int
|
||||||
,db=Depends(get_db)
|
,db=Depends(get_db)
|
||||||
@@ -89,7 +89,7 @@ def delete_stuinfo( #删除模块
|
|||||||
return {'code': 200, 'totals': rows, 'detail': '删除成功'} #成功返回信息
|
return {'code': 200, 'totals': rows, 'detail': '删除成功'} #成功返回信息
|
||||||
|
|
||||||
|
|
||||||
@CURD.get('/Top5',tags=['就业薪资Top5'])
|
@CURD.get('/Top5',summary='就业薪资Top5')
|
||||||
def salarytop5(db=Depends(get_db)):
|
def salarytop5(db=Depends(get_db)):
|
||||||
q = db.query(Employments,Company.employment_company) \
|
q = db.query(Employments,Company.employment_company) \
|
||||||
.join(Company, Employments.company_id == Company.id) \
|
.join(Company, Employments.company_id == Company.id) \
|
||||||
@@ -98,16 +98,23 @@ def salarytop5(db=Depends(get_db)):
|
|||||||
.offset(0).limit(5) .all()
|
.offset(0).limit(5) .all()
|
||||||
return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q]
|
return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q]
|
||||||
|
|
||||||
@CURD.get('/worktime',tags=['学生就业时常'])
|
@CURD.get('/worktime',summary='学生就业时常')
|
||||||
def worktime(db=Depends(get_db)):
|
def worktime(db=Depends(get_db)):
|
||||||
q = db.query(Employments).all()
|
q = db.query(Employments).all()
|
||||||
|
|
||||||
return [{'学生姓名':i.stuname,'就业时常':f'{i.offer_recived_time-i.employment_open_time}'} for i in q]
|
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]
|
||||||
|
|
||||||
|
|
||||||
@CURD.get('/avgworktime',tags=['学生平均就业时常'])
|
@CURD.get('/avgworktime',summary='学生平均就业时常')
|
||||||
def worktime(db=Depends(get_db)):
|
def avgworktime(db=Depends(get_db)):
|
||||||
q = db.query(Employments)\
|
q = db.query(Employments)\
|
||||||
.filter(Employments.employment_open_time is not None)\
|
.filter(Employments.employment_open_time.isnot(None)
|
||||||
|
,Employments.offer_recived_time.isnot(None))\
|
||||||
.all()
|
.all()
|
||||||
return [{'学生姓名':i.stuname,'平均就业时常':f'{(i.offer_recived_time-i.employment_open_time)/len(q)}'} for i in q]
|
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}'
|
||||||
@@ -6,6 +6,9 @@ def add_employment_dao(o,db): #新增就业信息函数
|
|||||||
try:
|
try:
|
||||||
# r = db.query(Employments).filter(Employments.id == o['id'] ).all() #
|
# r = db.query(Employments).filter(Employments.id == o['id'] ).all() #
|
||||||
o.pop('id', None) #摘除id字段,自增字段无需手动添加
|
o.pop('id', None) #摘除id字段,自增字段无需手动添加
|
||||||
|
o.pop('create_time', None)
|
||||||
|
o.pop('update_time', None)
|
||||||
|
o.pop('is_deleted', None)
|
||||||
o1 = Employments( **o) #实例化参数
|
o1 = Employments( **o) #实例化参数
|
||||||
db.add(o1) #添加数据进入表
|
db.add(o1) #添加数据进入表
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
from sqlalchemy import ForeignKey
|
from sqlalchemy import ForeignKey
|
||||||
|
|
||||||
from database import DATETIME,Base,Column,Integer,String,engine
|
from database import DATETIME,Base,Column,Integer,String,DATE
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
@@ -55,9 +55,9 @@ class Employments(Base): #学生就
|
|||||||
# )
|
# )
|
||||||
employment_salary = Column(Integer) #薪资
|
employment_salary = Column(Integer) #薪资
|
||||||
|
|
||||||
employment_open_time = Column(DATETIME) #就业开放时间
|
employment_open_time = Column(DATE) #就业开放时间
|
||||||
|
|
||||||
offer_recived_time = Column(DATETIME) #offer下发时间
|
offer_recived_time = Column(DATE) #offer下发时间
|
||||||
|
|
||||||
create_time = Column(DATETIME #创建数据时间
|
create_time = Column(DATETIME #创建数据时间
|
||||||
, default=datetime.now
|
, default=datetime.now
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ class PostRequest(BaseModel): #学生就
|
|||||||
employment_salary: int|None=None
|
employment_salary: int|None=None
|
||||||
employment_open_time:date|None=None
|
employment_open_time:date|None=None
|
||||||
offer_recived_time:date|None=None
|
offer_recived_time:date|None=None
|
||||||
create_time:date|None=None
|
|
||||||
is_deleted:int=0
|
|
||||||
class EmpResponse(BaseModel): #学生就业信息响应体
|
class EmpResponse(BaseModel): #学生就业信息响应体
|
||||||
code: int = 200
|
code: int = 200
|
||||||
detail: str = 'OK'
|
detail: str = 'OK'
|
||||||
|
|||||||
Reference in New Issue
Block a user