v2.6更新

This commit is contained in:
2026-05-29 21:35:27 +08:00
parent 69adb30fa0
commit 5805b11834
4 changed files with 14 additions and 22 deletions

View File

@@ -71,18 +71,18 @@ class SubjectModel:
@staticmethod
async def has_related_data(subject_id: int) -> bool:
"""检查科目是否有关联数据"""
return False
"""检查科目是否有关联的作业数据"""
sql = "SELECT COUNT(*) AS cnt FROM assignments WHERE subject_id = %s"
result = await execute_one(sql, (subject_id,))
return result and result.get("cnt", 0) > 0
@staticmethod
async def delete(subject_id: int) -> bool:
"""删除科目(设置 is_active = 0如果已禁用也返回成功"""
"""真正删除科目记录"""
subject = await SubjectModel.get_by_id(subject_id)
if not subject:
return False
if subject.get("is_active") == 0:
return True # 已禁用,视为成功
sql = "UPDATE subjects SET is_active = 0 WHERE subject_id = %s"
sql = "DELETE FROM subjects WHERE subject_id = %s"
result = await execute_update(sql, (subject_id,))
return result > 0