fix(training): 修复出国培训规则培训bug

This commit is contained in:
runny committed 2026-09-15 09:55:47 +08:00
1 parent 683f602475
commit 258098ea7b
13 files changed
+280 -26

No files matched your search

+24 -3
View File
@@ -24,6 +24,11 @@ from app.services.training_config_service import get_published_config
TRAINING_STAGES = {"video", "summary", "exam", "result"}
TRAINING_TYPES = {"onboarding", "safety"}
VIDEO_ONLY_TRAINING_TYPES = {
"overseas_regulations",
"overseas_regulations_training",
"overseas_training",
}
TRAINING_EXAM_MODES = {"unified", "per_level"}
SAFETY_STAGES = {"company", "department", "team", "exam", "result"}
SAFETY_LEVEL_KEYS = ("company", "department", "team")
@@ -69,6 +74,21 @@ def _normalize_training_type(value: Any) -> str:
return text
def _is_overseas_regulations_training(training_type: str) -> bool:
"""
判断培训类型是否为出国规章视频培训。
Args:
training_type: 已标准化的培训类型编码。
Returns:
是否应以完整观看视频作为一次培训完成。
"""
if training_type in VIDEO_ONLY_TRAINING_TYPES:
return True
published = get_published_config(training_type)
return "出国规章培训" in str((published or {}).get("name") or "")
def _normalize_training_version(value: Any, training_type: str) -> str:
"""
规范培训版本号,未传时按培训类型补默认值。
@@ -538,7 +558,7 @@ def upsert_user_training_record(user: User, payload: dict[str, Any]) -> Training
else:
passed = bool(payload.get("passed")) or (stage == "result" and score >= pass_score)
if stage == "result" and question_bank and not answer_details:
if stage == "result" and question_bank and not answer_details and not _is_overseas_regulations_training(training_type):
raise ValidationError("answer_details is required when submitting result", details={"field": "answer_details"})
join_date = _parse_iso_date(payload.get("join_date") or payload.get("joinDate"))
safety_stage = None
@@ -661,19 +681,20 @@ def export_training_records_excel(records: Iterable[TrainingRecord]) -> tuple[by
workbook = Workbook()
worksheet = workbook.active
worksheet.title = "training"
worksheet.append(["入职日期", "完成日期", "部门", "姓名", "工号", "分数", "考试次数", "状态"])
worksheet.append(["入职日期", "完成日期", "培训类型", "部门", "姓名", "工号", "分数", "考试次数", "状态"])
for record in records:
worksheet.append(
[
record.join_date.isoformat() if record.join_date else "",
record.completion_time.date().isoformat() if record.completion_time else "",
record.training_type or "",
record.department or "",
record.name or "",
record.employee_id or "",
record.score if record.score is not None else "",
record.attempt_count or 0,
_derive_status(record),
{"passed": "已通过", "failed": "未通过", "in_progress": "进行中"}.get(_derive_status(record), _derive_status(record)),
]
)