1
This commit is contained in:
@@ -1,19 +1,28 @@
|
||||
from fastapi import Depends
|
||||
from util.database import get_db
|
||||
from model.all_model import Student_Model
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
def add_student_dao(o,db):
|
||||
if o.get('id_card'):
|
||||
conflict = (db.query(Student_Model)
|
||||
.filter(Student_Model.id_card == o['id_card'],
|
||||
Student_Model.delete_status == 0)
|
||||
.first())
|
||||
if conflict:
|
||||
return 'conflict'
|
||||
try:
|
||||
o1 = Student_Model( **o)
|
||||
db.add(o1)
|
||||
o2 = Student_Model(**o)
|
||||
db.add(o2)
|
||||
db.commit()
|
||||
stu_id=o1.stu_id
|
||||
return db.query(Student_Model).filter(Student_Model.stu_id == stu_id).first()
|
||||
except:
|
||||
db.refresh(o2) # 回填自增的 stu_id
|
||||
return o2
|
||||
except IntegrityError:
|
||||
db.rollback()
|
||||
return None
|
||||
return 'conflict'
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return 'error'
|
||||
|
||||
def delete_student_dao(stu_id,db):
|
||||
try:
|
||||
@@ -28,14 +37,14 @@ def delete_student_dao(stu_id,db):
|
||||
|
||||
def update_student_dao(stu_id,update_data,db):
|
||||
try:
|
||||
rows = (db.query( Student_Model )
|
||||
.filter( Student_Model.stu_id == stu_id,Student_Model.delete_status == 0)
|
||||
.update( update_data ))
|
||||
db.commit()
|
||||
rows=(db.query(Student_Model)
|
||||
.fiter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0)
|
||||
.update(update_data))
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
db.commit()
|
||||
return rows
|
||||
|
||||
def get_student_dao(stu_id:Optional[int]
|
||||
|
||||
Reference in New Issue
Block a user