Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60a72dd297 | ||
|
|
6515bd811c | ||
|
|
ff03df7d8d | ||
|
|
98d08cff64 | ||
|
|
9c39c69fa1 | ||
|
|
91d86d4ea9 | ||
|
|
d7ac0027af | ||
|
|
be1edae34c | ||
|
|
7839178625 | ||
|
|
c88c6bc27e | ||
|
|
35bfdb56eb | ||
|
|
b497e6e2a1 |
@@ -22,9 +22,10 @@ def get_students(db=Depends(get_db)):
|
||||
,summary='人数统计'
|
||||
,description=f'统计每个班级的人数以及男生女生的人数。'
|
||||
)
|
||||
def get_students(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="没有找到符合条件的学生")
|
||||
@@ -33,11 +34,8 @@ def get_students(db=Depends(get_db)):
|
||||
,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="没有找到符合条件的学生")
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
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
|
||||
|
||||
@@ -7,12 +12,37 @@ 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,)
|
||||
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
|
||||
return q
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 = "班级中男女人数"
|
||||
|
||||
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -23,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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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是主程序文件,将配置文件的接口导入,创建接口运行
|
||||
@@ -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)):
|
||||
@@ -37,7 +37,7 @@ def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,t_subject:int,db=De
|
||||
@score_api.delete('/Score',summary='成绩删除',description=f'查询条件为学号,班级号,考试科目,然后进行删除')
|
||||
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:
|
||||
if aaa==-1:
|
||||
raise HTTPException(status_code=500,detail='删除失败')
|
||||
if aaa==0:
|
||||
raise HTTPException(status_code=404,detail='记录不存在')
|
||||
|
||||
@@ -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
|
||||
@@ -19,7 +19,7 @@ def get_scores_dao(s,db):
|
||||
if aa:
|
||||
return [{'id':i.id,'sid':i.sid
|
||||
,'cid':i.cid,'num':i.num
|
||||
,'score': i.score,'t_subject':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.t_subject==b['t_subject']).all()
|
||||
aa = db.query(Score).filter(Score.t_subject==b['t_subject']).all()
|
||||
if aa:
|
||||
raise ValueError
|
||||
else:
|
||||
|
||||
@@ -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
@@ -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)
|
||||
@@ -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,
|
||||
|
||||
+11
-9
@@ -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): #删除函数
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
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
|
||||
|
||||
@@ -12,10 +13,10 @@ class Employments(Base_all): #学生
|
||||
, comment='自增主键'
|
||||
)
|
||||
|
||||
num = Column(Integer
|
||||
, ForeignKey('students.num')
|
||||
stuid = Column(Integer
|
||||
, ForeignKey('students.id')
|
||||
) #学生姓名,冗余字段
|
||||
class_num = Column(Integer
|
||||
class_id = Column(Integer
|
||||
, ForeignKey('classes.id')
|
||||
) #学生班级,冗余字段
|
||||
company_id = Column(Integer #公司id,外键匹配公司表
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user