同步业务名称导致需要同步修改业务代码,现全部更新完毕,初步测试增删改查没有问题。
This commit is contained in:
@@ -31,8 +31,8 @@ def get_student_dao( s , db):
|
||||
q = q.filter( Students.education == s.get("education") )
|
||||
if s.get('class_id'):
|
||||
q = q.filter(Students.class_id == s.get("class_id") )
|
||||
if s.get('adnisor_id'):
|
||||
q = q.filter(Students.adnisor_id == s.get("adnisor_id") )
|
||||
if s.get('advisor_id'):
|
||||
q = q.filter(Students.advisor_id == s.get("advisor_id") )
|
||||
if s.get('phone'):
|
||||
q = q.filter(Students.phone == s.get("phone"))
|
||||
s1 = q.all()
|
||||
@@ -50,7 +50,7 @@ def get_student_dao( s , db):
|
||||
, 'education':i.education
|
||||
# 外键字段
|
||||
, 'class_id':i.class_id
|
||||
, 'adnisor_id':i.adnisor_id
|
||||
, 'advisor_id':i.advisor_id
|
||||
# 额外字段
|
||||
, 'phone':i.phone
|
||||
} for i in s1
|
||||
@@ -77,7 +77,7 @@ def add_student_dao( s , db):
|
||||
s1_deleted.education = s.get("education")
|
||||
# 外键字段
|
||||
s1_deleted.class_id = s.get("class_id")
|
||||
s1_deleted.adnisor_id = s.get("adnisor_id")
|
||||
s1_deleted.advisor_id = s.get("advisor_id")
|
||||
# 额外字段
|
||||
s1_deleted.phone = s.get("phone")
|
||||
|
||||
@@ -102,78 +102,112 @@ def add_student_dao( s , db):
|
||||
# 更新
|
||||
def update_student_dao( s , db):
|
||||
try:
|
||||
phone = s.get("student_phone")
|
||||
phone = s.get("phone")
|
||||
if phone is not None and phone != '':
|
||||
s1_con = db.query( Students ).filter( Students.phone == phone
|
||||
,Students.id != s.get("id")
|
||||
,Students.is_deleted == False ).first()
|
||||
if s1_con:
|
||||
return False
|
||||
raise HTTPException(status_code=409, detail=f'手机号已被其他学生使用:{phone}')
|
||||
s1_id = db.query( Students ).filter( Students.id == s.get("id")
|
||||
,Students.is_deleted == False ).first()
|
||||
if not s1_id:
|
||||
return False
|
||||
raise HTTPException(status_code=404, detail=f'学生不存在:id={s.get("id")}')
|
||||
if s.get("num") is not None:
|
||||
s1_id.name = s.get("num")
|
||||
if s.get("name") is not None:
|
||||
s1_id.name = s.get("name")
|
||||
if s.get("age") is not None:
|
||||
s1_id.age = s.get("age")
|
||||
if s.get("sex") is not None:
|
||||
s1_id.sex = s.get("sex")
|
||||
if s.get("home_Place") is not None:
|
||||
s1_id.home_Place = s.get("home_Place")
|
||||
if s.get("college") is not None:
|
||||
s1_id.college = s.get("college")
|
||||
if s.get("specialty") is not None:
|
||||
s1_id.specialty = s.get("specialty")
|
||||
if s.get("enrollment_time") is not None:
|
||||
s1_id.enrollment_time = s.get("enrollment_time")
|
||||
if s.get("graduate_time") is not None:
|
||||
s1_id.graduate_time = s.get("graduate_time")
|
||||
if s.get("education") is not None:
|
||||
s1_id.education = s.get("education")
|
||||
# 外键字段
|
||||
if s.get("class_id") is not None:
|
||||
s1_id.class_id = s.get("class_id")
|
||||
if s.get("advisor_id") is not None:
|
||||
s1_id.advisor_id = s.get("advisor_id")
|
||||
# 额外字段
|
||||
if s.get("phone") is not None:
|
||||
s1_id.student_phone = s.get("phone")
|
||||
if s.get("class_name") is not None:
|
||||
s1_id.class_name = s.get("class_name")
|
||||
if s.get("job_open_time") is not None:
|
||||
s1_id.job_open_time = s.get("job_open_time")
|
||||
if s.get("offer_issue_time") is not None:
|
||||
s1_id.offer_issue_time = s.get("offer_issue_time")
|
||||
if s.get("company_name") is not None:
|
||||
s1_id.company_name = s.get("company_name")
|
||||
if s.get("salary") is not None:
|
||||
s1_id.salary = s.get("salary")
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return False
|
||||
raise
|
||||
else:
|
||||
s1_sid.update_date = datetime.now()
|
||||
s1_id.update_date = datetime.now()
|
||||
db.commit()
|
||||
db.refresh(s1_sid) # 从数据库再拉一次数据
|
||||
return s1_sid
|
||||
db.refresh(s1_id) # 从数据库再拉一次数据
|
||||
return s1_id
|
||||
|
||||
|
||||
# 逻辑删除/软删除
|
||||
def delete_student_dao( s , db):
|
||||
try:
|
||||
if not any([s.get('sid')
|
||||
,s.get("student_name")
|
||||
,s.get("student_phone")
|
||||
,s.get("class_name")
|
||||
,s.get("job_open_time")
|
||||
,s.get("offer_issue_time")
|
||||
,s.get("company_name")
|
||||
,s.get("salary")
|
||||
if not any([ s.get("id")
|
||||
,s.get("num")
|
||||
,s.get("name")
|
||||
,s.get("age")
|
||||
,s.get("sex")
|
||||
,s.get("home_Place")
|
||||
,s.get("college")
|
||||
,s.get("specialty")
|
||||
,s.get("enrollment_time")
|
||||
,s.get("graduate_time")
|
||||
,s.get("education")
|
||||
,s.get("class_id")
|
||||
,s.get("advisor_id")
|
||||
,s.get("phone")
|
||||
]):
|
||||
raise HTTPException(status_code=400, detail="输入需要删除的学生信息,删除条件任选,但不可全为空。")
|
||||
q = db.query(Students).filter(Students.is_deleted == False)
|
||||
if s.get('sid'):
|
||||
q = q.filter(Students.sid == s.get("sid") )
|
||||
if s.get('student_name'):
|
||||
q = q.filter(Students.student_name == s.get("student_name") )
|
||||
if s.get("student_phone"):
|
||||
q = q.filter(Students.student_phone == s.get("student_phone") )
|
||||
if s.get('class_name'):
|
||||
q = q.filter(Students.class_name == s.get("class_name") )
|
||||
if s.get('job_open_time'):
|
||||
q = q.filter(Students.job_open_time == s.get("job_open_time") )
|
||||
if s.get('offer_issue_time'):
|
||||
q = q.filter(Students.offer_issue_time == s.get("offer_issue_time") )
|
||||
if s.get('company_name'):
|
||||
q = q.filter(Students.company_name == s.get("company_name") )
|
||||
if s.get('salary'):
|
||||
q = q.filter(Students.salary >= s.get("salary") )
|
||||
if s.get('id'):
|
||||
q = q.filter(Students.id == s.get("id") )
|
||||
if s.get('num'):
|
||||
q = q.filter(Students.num == s.get("num"))
|
||||
if s.get('name'):
|
||||
q = q.filter(Students.name == s.get("name") )
|
||||
if s.get('age'):
|
||||
q = q.filter(Students.age == s.get("age") )
|
||||
if s.get('sex'):
|
||||
q = q.filter(Students.sex == s.get("sex"))
|
||||
if s.get('home_Place'):
|
||||
q = q.filter(Students.home_Place == s.get("home_Place") )
|
||||
if s.get('college'):
|
||||
q = q.filter(Students.college == s.get("college") )
|
||||
if s.get('specialty'):
|
||||
q = q.filter(Students.specialty == s.get("specialty"))
|
||||
if s.get('enrollment_time'):
|
||||
q = q.filter(Students.enrollment_time == s.get("enrollment_time") )
|
||||
if s.get('graduate_time'):
|
||||
q = q.filter(Students.graduate_time == s.get("graduate_time"))
|
||||
if s.get('education'):
|
||||
q = q.filter(Students.education == s.get("education") )
|
||||
if s.get('class_id'):
|
||||
q = q.filter(Students.class_id == s.get("class_id") )
|
||||
if s.get('advisor_id'):
|
||||
q = q.filter(Students.advisor_id == s.get("v") )
|
||||
if s.get("phone"):
|
||||
q = q.filter(Students.phone == s.get("phone") )
|
||||
s1_delete = q.all()
|
||||
if not s1_delete:
|
||||
raise HTTPException(status_code=404, detail="没有找到该学生。")
|
||||
for i in s1_delete:
|
||||
i.is_deleted = True
|
||||
i.deleted_date = datetime.now()
|
||||
s2_deleted =[{"sid":i.sid,"student_name":i.student_name,"student_phone":i.student_phone}for i in s1_delete]
|
||||
# s2_deleted =[{"id":i.id,"name":i.name,"phone":i.phone}for i in s1_delete]
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
@@ -181,4 +215,4 @@ def delete_student_dao( s , db):
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
else:
|
||||
db.commit()
|
||||
return s2_deleted
|
||||
return s1_delete
|
||||
|
||||
Reference in New Issue
Block a user