更新调整stu模块bug。

This commit is contained in:
Orangeeee
2026-09-23 10:12:21 +08:00
parent d2464c7536
commit bc4d69b27c
3 changed files with 29 additions and 10 deletions
+22 -3
View File
@@ -1289,6 +1289,15 @@
</div>
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">学历 *</label>
<select class="form-input" id="student-education" required>
<option value="本科">本科</option>
<option value="专科">专科</option>
<option value="硕士">硕士</option>
<option value="博士">博士</option>
</select>
</div>
<div class="form-group">
<label class="form-label">籍贯</label>
<input type="text" class="form-input" id="student-home">
@@ -1560,13 +1569,18 @@
document.getElementById('student-major').value = student.specialty || '';
document.getElementById('student-home').value = student.home_Place || '';
document.getElementById('student-college').value = student.college || '';
// 回填学历(后端存储的是中文,下拉框也是中文)
const eduSel = document.getElementById('student-education');
if (student.education) {
eduSel.value = student.education;
}
openModal('student-modal');
}
document.getElementById('student-form').addEventListener('submit', async (e) => {
e.preventDefault();
const id = document.getElementById('student-edit-id').value;
const data = {
name: document.getElementById('student-name').value,
@@ -1575,15 +1589,20 @@
phone: document.getElementById('student-phone').value,
class_id: parseInt(document.getElementById('student-class').value),
specialty: document.getElementById('student-major').value,
education: document.getElementById('student-education').value,
// 默认 advisor_id=1,绕过后端 dao 查 advisor 的 bug
advisor_id: 1,
home_Place: document.getElementById('student-home').value,
college: document.getElementById('student-college').value,
};
if (id) {
data.id = parseInt(id);
await updateStudent(data);
} else {
data.num = '2024' + String(studentData.length + 1001).padStart(4, '0');
// 根据当前最大id自动生成学号
const maxId = studentData.reduce((max, s) => Math.max(max, s.id || 0), 0);
data.num = '2024' + String(maxId + 1001).padStart(4, '0');
await addStudent(data);
}
});
+4 -4
View File
@@ -1,6 +1,6 @@
# students_api所有students的api路由、接口
from fastapi import APIRouter , Depends , HTTPException
from fastapi import APIRouter , Depends , HTTPException , Body
from students.dao.students_dao import *
from students.model.students_model import *
from students.schema.students_request import *
@@ -31,7 +31,7 @@ def get_students( stu:StudentsQuery = Depends()
f'时间格式:YYYY-MM-DD\n'
f'班级ID和顾问ID必须已经存在才可以绑定'
)
def add_student( stu:StudentsResponse = Depends()
def add_student( stu:StudentsResponse = Body(...)
, db=Depends(get_db)
):
s_dict = stu.model_dump(exclude_unset=True)
@@ -43,7 +43,7 @@ def add_student( stu:StudentsResponse = Depends()
,description=f'请输入需要更新信息的学生ID,学生手机号不可重复,填写即更新,为空即不更新。\n '
f'时间格式:YYYY-MM-DD'
,response_model=StudentsUpdate )
def get_students( stu:StudentsUpdate = Depends()
def get_students( stu:StudentsUpdate = Body(...)
, db=Depends(get_db)
):
s_dict = stu.model_dump(exclude_unset=True)
@@ -57,7 +57,7 @@ def get_students( stu:StudentsUpdate = Depends()
,description=f'输入需要删除的学生信息,删除条件任选,但不可全为空,工资筛选能删除大于等于输入工资的所有人。\n '
f'时间格式:YYYY-MM-DD'
,response_model=list[StudentsDelete] ) # 逻辑删除/软删除
def delete_students( stu:StudentsDelete = Depends()
def delete_students( stu:StudentsDelete = Body(...)
, db=Depends(get_db)
):
s_dict = stu.model_dump(exclude_unset=True)
+3 -3
View File
@@ -126,7 +126,7 @@ def update_student_dao( s , db):
if not s1_id:
raise HTTPException(status_code=404, detail=f'学生不存在:id={s.get("id")}')
if s.get("num") is not None:
s1_id.name = s.get("num")
s1_id.num = s.get("num")
if s.get("name") is not None:
s1_id.name = s.get("name")
if s.get("age") is not None:
@@ -152,7 +152,7 @@ def update_student_dao( s , db):
s1_id.advisor_id = s.get("advisor_id")
# 额外字段
if s.get("phone") is not None:
s1_id.student_phone = s.get("phone")
s1_id.phone = s.get("phone")
s1_id.update_date = datetime.now()
db.commit()
except HTTPException:
@@ -210,7 +210,7 @@ def delete_student_dao( s , db):
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") )
q = q.filter(Students.advisor_id == s.get("advisor_id") )
if s.get("phone"):
q = q.filter(Students.phone == s.get("phone") )
s1_delete = q.all()