v2.0.1更新

This commit is contained in:
2026-05-26 08:39:12 +08:00
parent cb0c367eb7
commit c575d711ee
34 changed files with 750 additions and 204 deletions

View File

@@ -42,7 +42,6 @@ class HomeworkModel:
"""
return await execute_query(sql, tuple(subject_ids))
@staticmethod
@staticmethod
async def get_student_homework(student_id: int) -> List[Dict[str, Any]]:
sql = """

View File

@@ -126,6 +126,18 @@ class SemesterModel:
"""
return await execute_query(sql, (semester_id, start_date, end_date))
@staticmethod
async def count_records_by_semester(semester_id: int) -> Dict[str, int]:
"""统计学期关联的记录数"""
conduct_sql = "SELECT COUNT(*) as cnt FROM conduct_records WHERE semester_id = %s"
attendance_sql = "SELECT COUNT(*) as cnt FROM attendance_records WHERE semester_id = %s"
conduct_result = await execute_one(conduct_sql, (semester_id,))
attendance_result = await execute_one(attendance_sql, (semester_id,))
return {
"conduct_count": conduct_result['cnt'] if conduct_result else 0,
"attendance_count": attendance_result['cnt'] if attendance_result else 0
}
@staticmethod
async def get_homework_stats_by_date_range(start_date: str, end_date: str) -> List[Dict]:
"""通过作业截止日期范围查询所有学生的作业提交统计"""

View File

@@ -69,6 +69,13 @@ class SubjectModel:
result = await execute_update(sql, tuple(params))
return result > 0
@staticmethod
async def has_related_data(subject_id: int) -> bool:
"""检查科目是否有关联数据assignments表"""
sql = "SELECT COUNT(*) as cnt FROM assignments WHERE subject_id = %s"
result = await execute_one(sql, (subject_id,))
return result['cnt'] > 0
@staticmethod
async def delete(subject_id: int) -> bool:
sql = "UPDATE subjects SET is_active = 0 WHERE subject_id = %s"

View File

@@ -212,7 +212,8 @@ async def add_conduct_points(request: Request, req: AddPointsRequest):
points_change=req.points_change,
reason=req.reason,
recorder_id=user["user_id"],
recorder_name=user["username"]
recorder_name=user["real_name"],
related_type=req.related_type
)
if result["success"]:
try:

View File

@@ -37,6 +37,10 @@ async def debug_add_admin(request: Request, req: AddAdminDebugRequest):
from fastapi.responses import JSONResponse
return JSONResponse(status_code=404, content={"detail": "Not Found"})
# 生产环境警告
if settings.APP_ENV == "production":
logger.warning(f"调试入口在生产环境中被调用!路径: {settings.DEBUG_PATH}, 来源IP: {request.client.host}")
from models.user import UserModel
valid_roles = ["班主任", "班长", "学习委员", "考勤委员", "劳动委员", "志愿委员"]

View File

@@ -19,6 +19,7 @@ class AddPointsRequest(BaseModel):
student_ids: List[int] = Field(..., min_length=1, max_length=200, description="学生ID列表")
points_change: int = Field(..., gt=-100, lt=100, description="分数变动")
reason: str = Field(..., min_length=1, max_length=255, description="原因")
related_type: Optional[str] = Field(default='manual', pattern=r'^(manual|homework|attendance)$', description="关联类型: manual/homework/attendance")
class AddPointsResponse(BaseModel):

View File

@@ -31,7 +31,8 @@ class ConductService:
points_change: int,
reason: str,
recorder_id: int,
recorder_name: str
recorder_name: str,
related_type: str = 'manual'
) -> Dict[str, Any]:
"""批量加减分"""
# 输入校验
@@ -94,13 +95,13 @@ class ConductService:
fail_count += 1
continue
# 创建记录
record_id = await ConductModel.create_record(
student_id=student_id,
points_change=points_change,
reason=reason,
recorder_id=recorder_id,
recorder_name=recorder_name
recorder_name=recorder_name,
related_type=related_type
)
# 更新学生总分

View File

@@ -30,6 +30,10 @@ class SemesterService:
"""获取学期列表"""
try:
semesters = await SemesterModel.get_all()
for sem in semesters:
counts = await SemesterModel.count_records_by_semester(sem['semester_id'])
sem['conduct_count'] = counts['conduct_count']
sem['attendance_count'] = counts['attendance_count']
return {
"success": True,
"semesters": semesters

View File

@@ -68,6 +68,11 @@ class SubjectService:
@staticmethod
async def delete_subject(subject_id: int) -> Dict[str, Any]:
"""删除科目(软删除)"""
# 检查科目是否有关联数据
has_data = await SubjectModel.has_related_data(subject_id)
if has_data:
return {"success": False, "message": "该科目下已有作业数据,无法删除"}
result = await SubjectModel.delete(subject_id)
if result: