Merge remote-tracking branch 'origin/conding' into conding
This commit is contained in:
@@ -49,7 +49,7 @@ def add_emp_dao(o,db):
|
||||
e1 = Employment_info(**o)
|
||||
db.add(e1)
|
||||
db.commit()
|
||||
return e1
|
||||
return o
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
||||
|
||||
@@ -5,11 +5,11 @@ from sqlalchemy.exc import IntegrityError
|
||||
|
||||
def add_student_dao(o,db):
|
||||
if o.get('id_card'):
|
||||
conflict = (db.query(Student_Model)
|
||||
o1 = (db.query(Student_Model)
|
||||
.filter(Student_Model.id_card == o['id_card'],
|
||||
Student_Model.delete_status == 0)
|
||||
.first())
|
||||
if conflict:
|
||||
if o1:
|
||||
return 'conflict'
|
||||
try:
|
||||
o2 = Student_Model(**o)
|
||||
@@ -23,35 +23,6 @@ def add_student_dao(o,db):
|
||||
db.rollback()
|
||||
return 'error'
|
||||
|
||||
def delete_student_dao(stu_id, db):
|
||||
try:
|
||||
rows = (db.query(Student_Model)
|
||||
.filter(Student_Model.stu_id == stu_id,
|
||||
Student_Model.delete_status == 0)
|
||||
.update({'delete_status': 1, 'delete_time': datetime.now()}))
|
||||
db.commit()
|
||||
return rows
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
def update_student_dao(stu_id, update_data, db):
|
||||
if not update_data:
|
||||
return 0
|
||||
try:
|
||||
rows = (db.query(Student_Model)
|
||||
.filter(Student_Model.stu_id == stu_id,
|
||||
Student_Model.delete_status == 0)
|
||||
.update(update_data))
|
||||
db.commit()
|
||||
except IntegrityError:
|
||||
db.rollback()
|
||||
return 'conflict'
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return 'error'
|
||||
return rows
|
||||
|
||||
def get_student_dao(stu_id:Optional[int]
|
||||
,stu_name:Optional[str]
|
||||
,class_id:Optional[int]
|
||||
@@ -69,3 +40,32 @@ def get_student_dao(stu_id:Optional[int]
|
||||
total = q.count()
|
||||
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
||||
return r, total
|
||||
|
||||
def update_student_dao(stu_id, update_data, db):
|
||||
if not update_data:
|
||||
return 0
|
||||
try:
|
||||
rows = (db.query(Student_Model)
|
||||
.filter(Student_Model.stu_id == stu_id,
|
||||
Student_Model.delete_status == 0)
|
||||
.update(update_data))
|
||||
db.commit()
|
||||
except IntegrityError:
|
||||
db.rollback()
|
||||
return 'conflict'
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return 'error'
|
||||
return rows
|
||||
|
||||
def delete_student_dao(stu_id, db):
|
||||
try:
|
||||
rows = (db.query(Student_Model)
|
||||
.filter(Student_Model.stu_id == stu_id,
|
||||
Student_Model.delete_status == 0)
|
||||
.update({'delete_status': 1, 'delete_time': datetime.now()}))
|
||||
db.commit()
|
||||
return rows
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user