Compare commits

...
Author SHA1 Message Date
chen 60a72dd297 模块解释 2026-09-23 10:24:03 +08:00
chen 6515bd811c 模块解释 2026-09-22 22:07:46 +08:00
chen ff03df7d8d 统计 2026-09-22 21:03:15 +08:00
chen 98d08cff64 统计 2026-09-22 20:39:18 +08:00
chen 9c39c69fa1 dao改动 2026-09-22 19:56:12 +08:00
Orangeeee 91d86d4ea9 统计分析模块更新,待测试,试运行通过,外键已绑定完毕。 2026-09-22 19:19:09 +08:00
Orangeeee d7ac0027af Merge remote-tracking branch 'origin/geyuan_hhy_teacher' into lon_students_merge_code_test 2026-09-22 19:14:36 +08:00
geyuan be1edae34c 增加科目表的id 2026-09-22 19:14:04 +08:00
Orangeeee 7839178625 统计分析模块更新,待测试,模块更新80分以上成绩学生信息查询。 2026-09-22 19:04:39 +08:00
Orangeeee c88c6bc27e 统计分析模块更新,待测试,模块更新。 2026-09-22 18:29:31 +08:00
Orangeeee 35bfdb56eb Merge remote-tracking branch 'origin/lon_students_merge_code_test_coffee' into lon_students_merge_code_test
# Conflicts:
#	stu_jiuye/model.py
2026-09-22 18:29:07 +08:00
Coffee b497e6e2a1 更新id 2026-09-22 18:26:40 +08:00
Orangeeee 6775da7f89 统计分析模块更新,待测试,成绩模块更新。 2026-09-22 18:23:13 +08:00
Orangeeee 6a39e1d56f Merge remote-tracking branch 'origin/xiaoyang_score' into lon_students_merge_code_test 2026-09-22 18:02:33 +08:00
chen 1558103dfa 外键 2026-09-22 18:00:55 +08:00
chen 5c671020d7 外键 2026-09-22 17:55:57 +08:00
Orangeeee 657f97cc38 Merge remote-tracking branch 'origin/lon_students_merge_code_test_coffee' into lon_students_merge_code_test 2026-09-22 17:32:42 +08:00
Coffee 5020eeb640 statcalc就业统计模块更新 2026-09-22 17:02:59 +08:00
Orangeeee 0cdecadd79 Merge remote-tracking branch 'origin/coffee_all' into lon_students_merge_code_test 2026-09-22 16:58:57 +08:00
Coffee 10cf1b64e8 修改外键 2026-09-22 16:55:05 +08:00
25 changed files with 378 additions and 98 deletions
+40 -15
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,11 +22,10 @@ def get_students( stu:StudentsQuery = Depends()
,summary='人数统计'
,description=f'统计每个班级的人数以及男生女生的人数。'
)
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(g:get_student_dao = Depends()
,db=Depends(get_db)
):
result = get_class_count( g=g , db=db )
if result:
return result
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
@@ -38,11 +34,8 @@ def get_students( stu:StudentsQuery = Depends()
,summary='80分以上成绩学生信息查询'
,description=f'查询每次考试成绩都在80分以上的学生的编号,姓名和成绩。'
)
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_student_dao( db=db )
if result:
return result
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
@@ -113,4 +106,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)
}
+43 -1
View File
@@ -1,6 +1,48 @@
# from StatCalc.model.statcalc_model import
from pygments.lexers import sql
from sentry_sdk.integrations import sqlalchemy
from StatCalc.schema.statcalc_request import *
from fastapi import HTTPException
from sqlalchemy import *
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(g , db):
if g == "班级人数":
q = (db.query(ClassInfo.id,ClassInfo.name,func.count(ClassInfo.id) )
.join(Students,Students.class_id==ClassInfo.id)
.group_by(ClassInfo.id,ClassInfo.name,Students.sex)
.all())
elif g == "男女人数":
q = (db.query(Students.sex,func.count(ClassInfo.id) )
.join(Students,Students.class_id==ClassInfo.id)
.group_by(Students.sex)
.all())
elif g == "班级中男女人数":
q = (db.query(ClassInfo.id,ClassInfo.name,Students.sex,func.count(ClassInfo.id) )
.join(Students,Students.class_id==ClassInfo.id)
.group_by(ClassInfo.id,ClassInfo.name,Students.sex)
.all())
else:
return False
return q
from scores.model.score_model import Score
def get_score_80(db):
q = (db.query(Score)
.filter(Score.score>=80)
.all())
return q
View File
View File
+4 -1
View File
@@ -4,6 +4,9 @@ from pydantic import BaseModel , Field , field_validator
from datetime import datetime
import enum
class get_student_dao(enum.Enum):
get_class = "班级人数"
get_sex = "男女人数"
get_class_sex = "班级中男女人数"
+4 -4
View File
@@ -3,19 +3,19 @@ from Teachers.schema import *
from Teachers.database import *
from Teachers.model.tea_model import *
from Teachers.dao.tea_dao import *
from Teachers.schema.tea_request import TeaRequest,NewTeaRequest
from Teachers.schema.tea_request import TeaRequest,NewTeaRequest,NewTeaRequest1
from Teachers.schema.tea_response import TeaResponse
tea_api = APIRouter()
@tea_api.post('/tea',response_model=TeaResponse,summary='新增老师',description='输入新增的老师信息,除去姓名外可以为空')
def add_tea(tea: NewTeaRequest,db=Depends(get_db)):
def add_tea(tea: NewTeaRequest=Depends(),db=Depends(get_db)):
r = add_tea_dao(tea.model_dump(),db)
if not r:
raise HTTPException(status_code=500,detail='添加失败!')
return TeaResponse(totals=1,data=tea.model_dump())
@tea_api.get('/tea',response_model=TeaResponse,summary='查询老师',description='任意选择输入的信息数量,不输入则查询全部老师')
def get_tea(t:TeaRequest=Depends(),db=Depends(get_db)): #开启会话窗口
def get_tea(t:NewTeaRequest1=Depends(),db=Depends(get_db)): #开启会话窗口
r = get_tea_dao(t.model_dump(),db=db)
if not r:
raise HTTPException(status_code=404,detail='老师不存在')
@@ -37,7 +37,7 @@ def update_tea(id:int,tea:NewTeaRequest,db=Depends(get_db)):
#根据任意信息删除
@tea_api.delete('/tea',summary='根据任意信息逻辑删除',description='输入任意信息删除')
def delete_other_tea_dao1(t:TeaRequest,db=Depends(get_db)):
def delete_other_tea_dao1(t:TeaRequest=Depends(),db=Depends(get_db)):
row1 = delete_other_tea_dao(t.model_dump(exclude_unset=True),db)
if not row1:
raise HTTPException(status_code=404,detail='没有找到符合条件的老师')
+23 -5
View File
@@ -4,14 +4,27 @@ from datetime import datetime
#增加
def add_tea_dao(t,db):
try:
not_delete = db.query(Tea).filter(Tea.phone ==t.get('phone'),Tea.is_delete == False).first()
if not_delete:
print('该老师已存在')
raise Exception('老师已存在')
existing = db.query(Tea).filter(Tea.phone == t.get('phone'),Tea.is_delete == True).first()
if existing:
for key,value in t.items():
if hasattr(existing,key) and value is not None and value != '':
setattr(existing,key,value)
existing.is_delete = False
db.commit()
return '恢复修改成功'
t1 = Tea(**t)
db.add(t1)
except:
db.rollback()
return False
else:
db.commit()
return True
except Exception as e:
db.rollback()
print('新增失败原因',e)
return '新增失败'
#更新
def update_tea_dao(id,t, db):
@@ -49,9 +62,12 @@ def get_tea_dao(t,db):
query = query.filter(Tea.education == t.get('education') )
if t.get('collage'):
query = query.filter(Tea.collage == t.get('collage') )
if t.get('phone'):
query = query.filter(Tea.phone == t.get('phone') )
r = query.all()
return [{'id':i.id,'name':i.name,'class_id':i.class_id,'sub':i.sub,'sex':i.sex,'home_place':i.home_place
,'specialty':i.specialty,'start_time':i.start_time,'work_experience':i.work_experience,'collage':i.collage} for i in r]
,'specialty':i.specialty,'start_time':i.start_time,'work_experience':i.work_experience
,'collage':i.collage,'phone':i.phone} for i in r]
#删除
def delete_tea_dao(id,db):
@@ -94,6 +110,8 @@ def delete_other_tea_dao(t,db):
query1 = query1.filter(Tea.start_time == t.get('start_time'))
if t.get('specialty'):
query1 = query1.filter(Tea.specialty == t.get('specialty'))
if t.get('phone'):
query1 = query1.filter(Tea.phone == t.get('phone'))
row = query1.update({'is_delete':True,'delete_time':datetime.now()})
db.commit()
return row
+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()
+4 -3
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
@@ -24,7 +23,9 @@ class Tea(Base_all):
class_id = Column(Integer
,nullable=False
,comment='班级id')
sub = Column(String(50)
phone = Column(String(50))
subject_id = Column(Integer
, ForeignKey('subject.id')
,nullable=False
,comment='教学科目')
home_place = Column(String(50)
@@ -47,7 +48,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
+18 -4
View File
@@ -1,31 +1,45 @@
from pydantic import BaseModel
from Teachers.model.tea_model import *
#查询使用请求体
#查询使用请求体,都可以为空
class TeaRequest(BaseModel):
id: int|None = None
name: str|None = None
sex: Gender|None = None
class_id: int | None = None
sub: str|None = None
phone: str|None = None
home_place: str|None = None
collage: str|None = None
education: str|None = None
work_experience: str|None = None
start_time: str|None = None
start_time: datetime|None = None
specialty: str|None = None
#更新、任意逻辑删除、新增使用请求体,没有自增键
#更新、任意逻辑删除、新增使用请求体,没有自增键,电话号码不能为空
class NewTeaRequest(BaseModel):
name: str | None = None
sex: Gender
sex: Gender|None = None
class_id: int | None = None
sub: str | None = None
home_place: str | None = None
phone: str
collage: str | None = None
education: str | None = None
work_experience: str | None = None
start_time: datetime | None = None
specialty: str | None = None
class NewTeaRequest1(BaseModel):
name: str | None = None
sex: Gender|None = None
class_id: int | None = None
sub: str | None = None
home_place: str | None = None
phone: str|None = None
collage: str | None = None
education: str | None = None
work_experience: str | None = None
start_time: datetime | None = None
specialty: str | None = None
+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!")
+61
View File
@@ -0,0 +1,61 @@
#scores模块解释
##项目层
web框架:FastAPI(生成接口)
ORM:sqlalchemy
校验:MYSQL(通过PyMysql驱动)
运行:uvicorn,端口12346
用FastAPI显露HTTP接口 ,对MysQL的scores表进行一个增,删,改,查的动作,删除是软删除,
api是接口层,成绩信息的增加,删除,更新,查询
dao是数据操作层,查询get_scores_dao
更新add_scores_dao
增加update_scores_dao
删除delete_scores_dao
统计查询80分以上的get_top_students_dao
查询连续两次不及格的get_failing_students_dao
班级平均分get_class_avg_dao
model是数据库表模型层,字段信息 id *pk*
sid 链接学生表的学生ID
cid 链接班级表的班级ID
num 考试序次
score 考试成绩
t_subject 链接科目表的科目ID
create_date 创建数据的时间
update_date 更新数据的是时间
is_deleted 逻辑删除
deleted_date 删除的时间
schema是请求体和响应体模型层, 查询的ScoreQuery
更新,增加,删除的ScoreRequest
databases是数据库定义配置文件, 链接引擎对象db_url,链接地址engine,
建表的基类Base,数据库会话管理Session
会话实例def get_db()
main是主程序文件,将配置文件的接口导入,创建接口运行
+7 -7
View File
@@ -4,7 +4,7 @@ from scores.dao.score_dao import get_scores_dao,add_scores_dao,update_scores_dao
from scores.model.score_model import Score
from scores.schema.score_request import ScoreRequest, ScoreResponse,ScoreQuery
score_api = APIRouter(tags=['成绩'])
score_api = APIRouter()
@score_api.get('/Score',summary='成绩查询',description=f'查询条件为空即查询所有成绩')
def get_scores(score:ScoreQuery=Depends(),db=Depends(get_db)):
@@ -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,9 +35,9 @@ 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)
if aaa==1:
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:
raise HTTPException(status_code=404,detail='记录不存在')
+26
View File
@@ -0,0 +1,26 @@
from fastapi import APIRouter, Depends, HTTPException
from scores.database import get_db
from scores.dao.statistic_dao import get_top_students_dao,get_failing_students_dao,get_class_avg_dao
statistic_api = APIRouter()
@statistic_api.get('/statistic', summary='查询每次考试都在80分以上的学生')
def get_top_students(db=Depends(get_db)):
q = get_top_students_dao(db)
if not q:
return []
return q
@statistic_api.get('/Score/failing', summary='查询两次以上不及格的学生')
def get_failing_students(db=Depends(get_db)):
result = get_failing_students_dao(db)
if not result:
return []
return result
@statistic_api.get('/Score/class-avg', summary='统计每次考试每个班级的平均分')
def get_class_avg(db=Depends(get_db)):
result = get_class_avg_dao(db)
if not result:
return []
return result
+8 -9
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.t_subject
,'create_date':i.create_date,'update_date':i.update_date
,'is_deleted': i.is_deleted,'deleted_date': i.deleted_date
}for i in aa]
@@ -28,8 +28,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()
aa = db.query(Score).filter(Score.t_subject==b['t_subject']).all()
if aa:
raise ValueError
else:
@@ -43,7 +42,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 +50,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 +58,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()})
+78
View File
@@ -0,0 +1,78 @@
from sqlalchemy import func
from scores.model.score_model import Score
from students.model.students_model import Students
from class_management.model.class_management_model import ClassInfo
def get_top_students_dao(db):
top_sids = (db.query(Score.sid)
.filter(Score.is_deleted == 0)
.group_by(Score.sid, Score.num)
.having(func.min(Score.score) >= 80)
.subquery() )
results = (db.query(Students.id,
Students.name,
Score.num,
Score.t_subject,
Score.score,)
.join(Score, Students.id == Score.sid)
.filter( Score.sid.in_(top_sids),
Score.is_deleted == 0,)
.order_by(Students.id, Score.num)
.all())
return [{"sid": r.sid,
"name": r.name,
"score": r.score,}
for r in results]
def get_failing_students_dao(db):
failing_sids = (db.query(Score.sid)
.filter(Score.score < 60,
Score.is_deleted == 0,)
.group_by(Score.sid)
.having(func.count() >= 2)
.subquery())
results = (db.query(
Students.id,
Students.name,
ClassInfo.name.label("class_name"),
Score.num,
Score.t_subject,
Score.score,)
.join(Score, Students.id == Score.sid)
.join(ClassInfo, Score.cid == ClassInfo.id)
.filter(Score.sid.in_(failing_sids),
Score.score < 60,
Score.is_deleted == 0,)
.order_by(ClassInfo.id, Score.num)
.all())
return [{"sid": r.sid,
"name": r.name,
"class_name": r.class_name,
"num": r.num,
"t_subject": r.tsub,
"score": r.score,}
for r in results]
def get_class_avg_dao(db):
results = (db.query(Score.num,
Score.cid,
ClassInfo.name.label("class_name"),
func.avg(Score.score).label("avg_score"))
.join(ClassInfo, Score.cid == ClassInfo.id)
.filter(Score.is_deleted == 0)
.group_by(Score.num, Score.cid, ClassInfo.name)
.order_by(func.avg(Score.score).desc())
.all())
return [ {"num": r.num,
"cid": r.cid,
"class_name": r.class_name,
"avg_score": round(float(r.avg_score), 2),}
for r in results]
+7 -3
View File
@@ -1,17 +1,21 @@
from fastapi import FastAPI,APIRouter
from scores.api.score_api import score_api
from scores.database import engine,Base
from scores.api.statistic_api import statistic_api
# 合并接口
Scores_API = APIRouter()
Scores_API.include_router(score_api)
# 自测接口
app = FastAPI(title='成绩管理系统')
app = FastAPI(tags=['成绩'], title='成绩管理系统')
app.include_router(score_api)
app.include_router(statistic_api)
Base.metadata.create_all(engine)
if __name__ == '__main__':
Base.metadata.create_all(engine)
import uvicorn
uvicorn.run('main:app',host='127.0.0.1',port=12346)
uvicorn.run('scores.main:app',host='127.0.0.1',port=12346)
+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
+16 -10
View File
@@ -1,4 +1,4 @@
import datetime
from datetime import date
from fastapi import APIRouter,Depends,HTTPException,Query
from stu_jiuye.dao import *
@@ -10,20 +10,20 @@ CURD=APIRouter()
@CURD.get('/emp',summary='查询就业信息')
def get_stuinfo( #查询学生就业信息
sname:str| None = Query(None,description='学生姓名')
,class_num:int| None = Query(None,description='班级编号')
,class_id:int| None = Query(None,description='班级编号')
,employment_company:str|None=Query(None,description='公司名称')
,min_salary:int|None=Query(None,description='最小薪资范围')
,max_salary:int|None=Query(None,description='最大薪资范围')
,somewhere:str|None=Query(None,description='公司地区')
,employment_open_start: datetime.date | None = Query(None,description='就业开放起始时间')
,employment_open_end: datetime.date | None = Query(None,description='就业开放结束时间')
,offer_recived_start: datetime.date | None = Query(None,description='offer下发起始时间')
,offer_recived_end: datetime.date | None = Query(None,description='offer下发结束时间')
,employment_open_start: date | None = Query(None,description='就业开放起始时间')
,employment_open_end: date | None = Query(None,description='就业开放结束时间')
,offer_recived_start: date | None = Query(None,description='offer下发起始时间')
,offer_recived_end: date | None = Query(None,description='offer下发结束时间')
,db=Depends(get_db)
): #查询条件
r=get_emp_dao( #调用函数
sname,
class_num,
class_id,
employment_company,
min_salary,
max_salary,
@@ -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)
}
}
'''
+11 -9
View File
@@ -1,7 +1,7 @@
from stu_jiuye.model import Employments,Address,Company
from students.model.students_model import *
from class_management.model.class_management_model import *
def add_employment_dao(o,db): #新增就业信息函数
try:
# r = db.query(Employments).filter(Employments.id == o['id'] ).all() #
@@ -68,7 +68,7 @@ def update_emp_dao(id,update_data,db): #更新数据函数
def get_emp_dao( #获取学生就业信息函数
# stuid,
sname
,class_num
,class_id
,employment_company
,min_salary
,max_salary
@@ -82,7 +82,9 @@ def get_emp_dao( #获取学生
# ,page
# ,page_size
): #根据选择条件获取信息
q = db.query(Employments,Company.employment_company,Address.somewhere)\
q = db.query(Employments,Company.employment_company,Address.somewhere) \
.outerjoin(Company, Students.id == Employments.stuid) \
.outerjoin(Company, ClassInfo.id == Employments.class_id)\
.outerjoin(Company,Employments.company_id==Company.id)\
.outerjoin(Address,Company.address_id==Address.id)\
.filter(Employments.is_deleted == 0) #连接公司表和地址表,筛选未被删除信息
@@ -90,9 +92,9 @@ def get_emp_dao( #获取学生
# q = q.filter( Employments.id == stuid )
if sname: #根据学生姓名筛选
q = q.filter( Employments.sname == sname )
if class_num:
q = q.filter(Employments.class_num == class_num)
q = q.filter( Students.name == sname )
if class_id:
q = q.filter(ClassInfo.id == class_id)
if somewhere:
q = q.filter(Address.somewhere.like(f'%{somewhere}%'))
if employment_company: #根据公司姓名筛选
@@ -115,7 +117,7 @@ def get_emp_dao( #获取学生
if r:
return [ {"id": i.id,
'学生姓名':i.sname,
'学生班级编号':i.class_num,
'学生班级编号':i.class_id,
"公司": employment_company or '未就业',
"公司区域":somewhere or '-',
# "company_id": i.company_id,
@@ -126,7 +128,7 @@ def get_emp_dao( #获取学生
# , "创建时间": i.create_time,
# "更新时间": i.update_time,
# "是否删除":i.is_deleted
} for i,employment_company,somewhere in r ] #返回信息列表
} for i,sname,class_id,employment_company,somewhere in r ] #返回信息列表
def delete_emp_dao(id,db): #删除函数
+7 -15
View File
@@ -4,8 +4,6 @@ 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 +12,19 @@ class Employments(Base_all): #学生
# , ForeignKey('student.id')
, comment='自增主键'
)
sname = Column(String(50)
# , ForeignKey='student.name'
) #学生姓名,冗余字段
class_num = Column(Integer
# , ForeignKey='class.id'
) #学生班级,冗余字段
# compname=Column(String(50)
# ,nullable=False
# )
stuid = Column(Integer
, ForeignKey('students.id')
) #学生姓名,冗余字段
class_id = Column(Integer
, ForeignKey('classes.id')
) #学生班级,冗余字段
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) #就业开放时间
+1 -1
View File
@@ -5,7 +5,7 @@ from pydantic import BaseModel
class PostRequest(BaseModel): #学生就业信息请求体模型
# compname: str|None=None
sname: str|None=None
class_num: int|None=None
class_id: int|None=None
company_id:int|None=None
# address_id: int|None=None
employment_salary: int|None=None
+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