Merge remote-tracking branch 'origin/geyuan1' into lon_students_merge_code_test
# Conflicts: # class_management/dao/class_management_dao.py # class_management/main.py # students/README_students.md
This commit is contained in:
+11
-7
@@ -28,13 +28,17 @@ def delete_tea(id:int|None,db=Depends(get_db)):
|
||||
raise HTTPException(status_code=500,detail='删除失败!')
|
||||
return {'detail':'删除成功!'}
|
||||
|
||||
@tea_api.put('/tea/{id}',summary='更新老师信息',description='输入更改的信息,可以为空')
|
||||
def update_tea(id:int,tea:NewTeaRequest,db=Depends(get_db)):
|
||||
t = tea.model_dump(exclude_unset= True)
|
||||
r = update_tea_dao(id=id,t=t,db=db)
|
||||
if not r:
|
||||
raise HTTPException(status_code=404,detail='老师不存在')
|
||||
return {'detail':'更新成功'}
|
||||
@tea_api.put('/tea/{id}', summary='更新老师信息', description='输入更改的信息,可以为空')
|
||||
def update_tea(id: int, tea: NewTeaRequest = Depends(), db=Depends(get_db)):
|
||||
t = tea.model_dump(exclude_unset=True)
|
||||
r = update_tea_dao(id=id, t=t, db=db)
|
||||
if r == 'NOT_FOUND':
|
||||
raise HTTPException(status_code=404, detail='老师不存在')
|
||||
if r == 'NO_CHANGE':
|
||||
raise HTTPException(status_code=400, detail='没有要更新的内容')
|
||||
if isinstance(r, str) and r.startswith('ERROR'):
|
||||
raise HTTPException(status_code=400, detail=r)
|
||||
return {'detail': '更新成功'}
|
||||
|
||||
#根据任意信息删除
|
||||
@tea_api.delete('/tea',summary='根据任意信息逻辑删除',description='输入任意信息删除')
|
||||
|
||||
+19
-12
@@ -29,15 +29,22 @@ def add_tea_dao(t,db):
|
||||
|
||||
|
||||
#更新
|
||||
def update_tea_dao(id,t, db):
|
||||
def update_tea_dao(id, t, db):
|
||||
try:
|
||||
row = db.query(Tea).filter(Tea.id == id,Tea.is_delete ==False ).update(t)
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
if not t:
|
||||
return 'NO_CHANGE'
|
||||
obj = db.query(Tea).filter(Tea.id == id, Tea.is_delete == False).first()
|
||||
if not obj:
|
||||
return 'NOT_FOUND'
|
||||
for k, v in t.items():
|
||||
if hasattr(obj, k):
|
||||
setattr(obj, k, v)
|
||||
db.commit()
|
||||
return row
|
||||
return 'OK'
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print('更新失败原因', repr(e))
|
||||
return f'ERROR: {e}'
|
||||
|
||||
#查询
|
||||
def get_tea_dao(t,db):
|
||||
@@ -50,8 +57,8 @@ def get_tea_dao(t,db):
|
||||
query = query.filter(Tea.sex == t.get('sex') )
|
||||
if t.get('class_id'):
|
||||
query = query.filter(Tea.class_id == t.get('class_id') )
|
||||
if t.get('sub'):
|
||||
query = query.filter(Tea.sub == t.get('sub') )
|
||||
if t.get('subject_id'):
|
||||
query = query.filter(Tea.subject_id == t.get('subject_id') )
|
||||
if t.get('home_place'):
|
||||
query = query.filter(Tea.home_place == t.get('home_place') )
|
||||
if t.get('specialty'):
|
||||
@@ -67,7 +74,7 @@ def get_tea_dao(t,db):
|
||||
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
|
||||
return [{'id':i.id,'name':i.name,'class_id':i.class_id,'sub':i.subject_id,'sex':i.sex,'home_place':i.home_place
|
||||
,'specialty':i.specialty,'start_time':i.start_time,'work_experience':i.work_experience
|
||||
,'collage':i.collage,'phone':i.phone} for i in r]
|
||||
|
||||
@@ -98,8 +105,8 @@ def delete_other_tea_dao(t,db):
|
||||
query1 = query1.filter(Tea.sex == t.get('sex'))
|
||||
if t.get('class_id'):
|
||||
query1 = query1.filter(Tea.class_id == t.get('class_id'))
|
||||
if t.get('sub'):
|
||||
query1 = query1.filter(Tea.sub == t.get('sub'))
|
||||
if t.get('subject_id'):
|
||||
query1 = query1.filter(Tea.subject_id == t.get('subject_id'))
|
||||
if t.get('home_place'):
|
||||
query1 = query1.filter(Tea.home_place == t.get('home_place'))
|
||||
if t.get('collage'):
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ if __name__ == "__main__":
|
||||
Base.metadata.create_all(engine1)
|
||||
|
||||
import uvicorn
|
||||
uvicorn.run('main:app', host='0.0.0.0', port=57000)
|
||||
uvicorn.run('main:app', host='0.0.0.0', port=56000)
|
||||
"""
|
||||
IPv4 地址 . . . . . . . . . . . . : 192.168.1.51
|
||||
子网掩码 . . . . . . . . . . . . : 255.255.255.0
|
||||
|
||||
@@ -17,6 +17,7 @@ def add_class_dao(c,db):
|
||||
return False
|
||||
else:
|
||||
db.commit()
|
||||
db.refresh(c1)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ DB_HOST = os.getenv("DB_HOST", "localhost")
|
||||
DB_PORT = os.getenv("DB_PORT", "3306")
|
||||
DB_NAME = os.getenv("DB_NAME", "student_manage_system")
|
||||
|
||||
class_management_rul = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}?charset=utf8mb4"
|
||||
class_management_url = "mysql+pymysql://root:123456@localhost:3306/student_manage_system?charset=utf8mb4"
|
||||
|
||||
engine = create_engine(class_management_rul)
|
||||
engine = create_engine(class_management_url)
|
||||
SessionLocal = sessionmaker(bind=engine,autocommit=False, autoflush=False)
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
@@ -3,16 +3,18 @@ from class_management.api.class_management_api import class_api
|
||||
from class_management.model.class_management_model import ClassInfo
|
||||
from class_management.database import Base,engine
|
||||
|
||||
|
||||
# 合并接口
|
||||
Classes_API = APIRouter()
|
||||
Classes_API.include_router(class_api)
|
||||
|
||||
|
||||
# 自测接口
|
||||
app = FastAPI()
|
||||
|
||||
app.include_router(class_api)
|
||||
|
||||
if __name__ =='__main__':
|
||||
# 自测接口
|
||||
app = FastAPI()
|
||||
|
||||
app.include_router(class_api)
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
import uvicorn
|
||||
|
||||
@@ -15,10 +15,10 @@ def get_stuinfo( #查询学生就业信息
|
||||
,min_salary:int|None=Query(None,description='最小薪资范围')
|
||||
,max_salary:int|None=Query(None,description='最大薪资范围')
|
||||
,somewhere:str|None=Query(None,description='公司地区')
|
||||
,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下发结束时间')
|
||||
,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( #调用函数
|
||||
|
||||
@@ -30,7 +30,7 @@ class Students(Base_all):
|
||||
, comment='年龄'
|
||||
, nullable=False)
|
||||
|
||||
sex = Column(Enum(SexEnum, values_callable=lambda e: [i.value for i in e])
|
||||
sex = Column(Enum(SexEnum)
|
||||
, comment='性别'
|
||||
, nullable=False)
|
||||
|
||||
@@ -49,7 +49,7 @@ class Students(Base_all):
|
||||
graduate_time = Column(DATETIME
|
||||
, comment='毕业时间')
|
||||
|
||||
education = Column(Enum(EducationEnum, values_callable=lambda e: [i.value for i in e])
|
||||
education = Column(Enum(EducationEnum)
|
||||
, comment='学历'
|
||||
, nullable=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user