Compare commits

...
8 Commits
15 changed files with 96 additions and 52 deletions
+35 -8
View File
@@ -12,11 +12,8 @@ statcalc_api = APIRouter()
,summary='人员信息查询'
,description=f'查询所有超过30岁的学员的信息。'
)
def get_students( stu:StudentsQuery = Depends()
, db=Depends(get_db)
):
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
result = get_student_dao( s=s_dict , db=db )
def get_students(db=Depends(get_db)):
result = get_age_30( db=db )
if result:
return result
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
@@ -25,9 +22,7 @@ def get_students( stu:StudentsQuery = Depends()
,summary='人数统计'
,description=f'统计每个班级的人数以及男生女生的人数。'
)
def get_students( stu:StudentsQuery = Depends()
, db=Depends(get_db)
):
def get_students(db=Depends(get_db)):
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
result = get_student_dao( s=s_dict , db=db )
if result:
@@ -113,4 +108,36 @@ def get_students( stu:StudentsQuery = Depends()
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
@CURD.get('/Top5',summary='就业薪资Top5')
def salarytop5(db=Depends(get_db)):
q = db.query(Employments,Company.employment_company) \
.join(Company, Employments.company_id == Company.id) \
.filter(Employments.is_deleted == 0)\
.order_by(Employments.employment_salary.desc())\
.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)\
.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]
@CURD.get('/avgworktime',summary='学生平均就业时常')
def avgworktime(db=Depends(get_db)):
q = db.query(Employments)\
.filter(Employments.employment_open_time.isnot(None)
,Employments.offer_recived_time.isnot(None)
,Employments.is_deleted==0)\
.all()
if not q:
return {'平均就业时常': '暂无数据'}
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)
}
+13 -1
View File
@@ -1,6 +1,18 @@
# from StatCalc.model.statcalc_model import
from StatCalc.schema.statcalc_request import *
from fastapi import HTTPException
from students.model.students_model import Students
def get_age_30(db):
q = db.query(Students).filter(Students.age>=30).all()
return q
from class_management.model.class_management_model import ClassInfo
def get_class_count(db):
q = (db.query(ClassInfo.id)
.join(Students,Students.class_id==ClassInfo.id)
.filter()
.group_by(ClassInfo.id,Students.sex,)
.all())
return q
View File
View File
+1
View File
@@ -1,6 +1,7 @@
from fastapi import FastAPI,APIRouter
from Teachers.model.tea_model import *
from Teachers.api.tea_api import tea_api
from Teachers.database import *
# 合并接口
Teachers_API = APIRouter()
+1 -2
View File
@@ -1,5 +1,4 @@
from databases import engine_all,Base_all,Session
from Teachers.database import *
from datetime import datetime
from sqlalchemy import *
import enum
@@ -47,7 +46,7 @@ class Tea(Base_all):
is_delete = Column(Boolean,default=False,comment='是否删除')
delete_time = Column(DateTime)
#科目表
class Sub(Base):
class Sub(Base_all):
__tablename__ = 'subject'
id = Column(Integer
, primary_key=True
+1 -1
View File
@@ -22,7 +22,7 @@ def get_one_class(id:int,db=Depends(get_db)):
res = get_class_dao(c={'id':id},db=db)
if not res:
raise HTTPException(status_code=404, detail="该班级不存在或已删除")
return ClassResponse(total=1,data=res[0])
return ClassResponse(totals=1,data=res[0])
@class_api.get('',summary='多字段查询班级')
def get_some_classes( num:str|None = Query(None,description='班级编号')
+4 -4
View File
@@ -4,21 +4,21 @@ from scores.main import Scores_API
from stu_jiuye.main import Shtudent_Jiuye
from students.main import Students_API
from Teachers.main import Teachers_API
from StatCalc.main import StatCalc_API
# from StatCalc.main import StatCalc_API
from databases import *
app = FastAPI(title="学生管理系统")
Base_all.metadata.create_all(bind=engine_all)
app.include_router(Classes_API,tags=["classes"])
app.include_router(Scores_API,tags=["scores"])
app.include_router(Shtudent_Jiuye,tags=["Employments"])
app.include_router(Students_API,tags=["students"])
app.include_router(Teachers_API,tags=["teachers"])
app.include_router(StatCalc_API,tags=["StatCalc"])
# app.include_router(StatCalc_API,tags=["StatCalc"])
Base_all.metadata.create_all(bind=engine_all)
if __name__ == "__main__":
def main():
print("Hello from student-manage-system!")
+5 -5
View File
@@ -25,9 +25,9 @@ def add_scores(score:ScoreRequest=Depends(),db=Depends(get_db)):
raise HTTPException(status_code=500,detail='不可以')
@score_api.put('/Score',summary='成绩更新',description=f'查询条件为学号,班级号,考试序次,考试科目,然后更改这位同学此次科目的成绩')
def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,tsub:str,db=Depends(get_db)):
a = score.model_dump(exclude_unset=True,exclude={'id','sid','cid','num','tsub'})
aa = update_scores_dao(sid = sid,cid = cid,num = num,tsub = tsub,update_data = a,db=db)
def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,t_subject:int,db=Depends(get_db)):
a = score.model_dump(exclude_unset=True,exclude={'id','sid','cid','num','t_subject'})
aa = update_scores_dao(sid = sid,cid = cid,num = num,t_subject = t_subject,update_data = a,db=db)
if aa==-1:
raise HTTPException(status_code=500,detail='没有更新')
if aa==0:
@@ -35,8 +35,8 @@ def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,tsub:str,db=Depends
return {'message':'更新成功','data':a}
@score_api.delete('/Score',summary='成绩删除',description=f'查询条件为学号,班级号,考试科目,然后进行删除')
def delete_scores(sid:int,cid:int,tsub:str,db=Depends(get_db)):
aaa = delete_scores_dao(sid,cid,tsub,db)
def delete_scores(sid:int,cid:int,t_subject:int,db=Depends(get_db)):
aaa = delete_scores_dao(sid,cid,t_subject,db)
if aaa==1:
raise HTTPException(status_code=500,detail='删除失败')
if aaa==0:
+8 -8
View File
@@ -13,13 +13,13 @@ def get_scores_dao(s,db):
ab = ab.filter(Score.num==s.get('num'))
if s.get('score'):
ab = ab.filter(Score.score==s.get('score'))
if s.get('tsub'):
ab = ab.filter(Score.tsub==s.get('tsub'))
if s.get('t_subject'):
ab = ab.filter(Score.t_subject==s.get('t_subject'))
aa = ab.all()
if aa:
return [{'id':i.id,'sid':i.sid
,'cid':i.cid,'num':i.num
,'score': i.score,'tsub':i.tsub
,'score': i.score,'t_subject':i.tsub
,'create_date':i.create_date,'update_date':i.update_date
,'is_deleted': i.is_deleted,'deleted_date': i.deleted_date
}for i in aa]
@@ -29,7 +29,7 @@ def get_scores_dao(s,db):
def add_scores_dao(b,db):
try:
aa = db.query(Score).filter(Score.sid==b['sid']
,Score.tsub==b['tsub']).all()
,Score.t_subject==b['t_subject']).all()
if aa:
raise ValueError
else:
@@ -43,7 +43,7 @@ def add_scores_dao(b,db):
db.commit()
return True
def update_scores_dao(sid:int,cid:int,num:int,tsub:str,update_data:dict,db):
def update_scores_dao(sid:int,cid:int,num:int,t_subject:int,update_data:dict,db):
if not update_data:
return 0
update_data['update_date']=datetime.now()
@@ -51,7 +51,7 @@ def update_scores_dao(sid:int,cid:int,num:int,tsub:str,update_data:dict,db):
aa = db.query(Score).filter(Score.sid == sid
,Score.cid == cid
,Score.num == num
,Score.tsub == tsub ).update(update_data)
,Score.t_subject == t_subject ).update(update_data)
db.commit()
return aa
except Exception :
@@ -59,11 +59,11 @@ def update_scores_dao(sid:int,cid:int,num:int,tsub:str,update_data:dict,db):
return -1
def delete_scores_dao(sid:int,cid:int,tsub:str,db):
def delete_scores_dao(sid:int,cid:int,t_subject:int,db):
try:
aaa = db.query(Score).filter(Score.sid ==sid
,Score.cid == cid
,Score.tsub == tsub
,Score.t_subject == t_subject
,Score.is_deleted==0
).update({'is_deleted':1
,'deleted_date':datetime.now()})
+3 -4
View File
@@ -2,8 +2,7 @@ from databases import engine_all,Base_all,Session
from scores.database import Base
from datetime import datetime
from sqlalchemy import DateTime,Column,Integer,String,Float,ForeignKey
class Score(Base):
from sqlalchemy import DateTime,Column,Integer,String,Float
class Score(Base_all):
__tablename__='scores'
id = Column(Integer
@@ -23,8 +22,8 @@ class Score(Base_all):
,comment ='考试序次'
)
score = Column(Integer,nullable = False)
tsub = Column(String(100)
, ForeignKey('subject.id')
t_subject = Column(Integer
,ForeignKey('subject.id')
,nullable = False
)
create_date = Column(DateTime
+2 -2
View File
@@ -6,7 +6,7 @@ class ScoreRequest(BaseModel):
cid:int
num:int
score:int
tsub:str
t_subject:int
class ScoreQuery(BaseModel):
id:int|None = None
@@ -14,7 +14,7 @@ class ScoreQuery(BaseModel):
cid:int|None = None
num:int|None = None
score:int|None = None
tsub:str|None = None
t_subject:int|None = None
class ScoreResponse(BaseModel):
code:int = 200
+9 -3
View File
@@ -96,7 +96,7 @@ def delete_stuinfo( #删除模块
raise HTTPException(status_code=500, detail='没有删除!') #失败返回错误信息
return {'code': 200, 'totals': rows, 'detail': '删除成功'} #成功返回信息
'''
@CURD.get('/Top5',summary='就业薪资Top5')
def salarytop5(db=Depends(get_db)):
q = db.query(Employments,Company.employment_company) \
@@ -112,7 +112,11 @@ def worktime(db=Depends(get_db)):
.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]
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',summary='学生平均就业时常')
@@ -129,4 +133,6 @@ def avgworktime(db=Depends(get_db)):
return {
'人数': len(q),
'平均就业时常(天)': round(avg_days, 2)
}
}
'''
+5 -14
View File
@@ -1,11 +1,8 @@
from databases import engine_all,Base_all,Session
from sqlalchemy import ForeignKey
from stu_jiuye.database import DATETIME,Base,Column,Integer,String,DATE
from datetime import datetime
class Employments(Base_all): #学生就业信息基类
__tablename__ = 'Employments' #表名
id = Column(Integer #主键,自增主键
@@ -14,25 +11,19 @@ class Employments(Base_all): #学生
# , ForeignKey('student.id')
, comment='自增主键'
)
sname = Column(String(50)
# , ForeignKey='student.name'
num = Column(Integer
, ForeignKey('students.num')
) #学生姓名,冗余字段
class_num = Column(Integer
# , ForeignKey='class.id'
, ForeignKey('classes.id')
) #学生班级,冗余字段
# compname=Column(String(50)
# ,nullable=False
# )
company_id = Column(Integer #公司id,外键匹配公司表
, ForeignKey('Company.id')
, nullable=True
)
# address_id = Column(Integer
# , ForeignKey('Address.id')
# , nullable=False
# )
employment_salary = Column(Integer, nullable=True) #薪资
employment_open_time = Column(DATE, nullable=True) #就业开放时间
+9
View File
@@ -14,3 +14,12 @@ select * from students limit 50;
desc students;
select *
from cast(student_manage_system as BINARY)
where age >30
join on
group by
having
order by
limit