feat(training): 出国规则培训完成推送企微通知!
This commit is contained in:
1 parent
258098ea7b
commit
77851288f7
8 files changed
+60
-5
No files matched your search
@@ -552,7 +552,7 @@ class Config:
|
||||
WECOM_PUBLIC_BASE_URL = os.getenv('WECOM_PUBLIC_BASE_URL')
|
||||
WECOM_NOTIFY_ENABLED = os.getenv('WECOM_NOTIFY_ENABLED', 'true').lower() == 'true'
|
||||
WECOM_NOTIFY_BASE_URL = os.getenv('WECOM_NOTIFY_BASE_URL')
|
||||
WECOM_NOTIFY_EVENTS = os.getenv('WECOM_NOTIFY_EVENTS', 'task_completed,schedule_completed,password_reset,contract_payment_warning,training_lean_overdue,training_lean_task_initial,training_lean_targeted_reminder')
|
||||
WECOM_NOTIFY_EVENTS = os.getenv('WECOM_NOTIFY_EVENTS', 'task_completed,schedule_completed,password_reset,contract_payment_warning,training_lean_overdue,training_lean_task_initial,training_lean_targeted_reminder,training_overseas_thailand_guidelines')
|
||||
# 精益培训企微提醒卡片跳转的员工培训聊天页 agent id(前端路由 /chat/<id>,默认 27=员工培训)。
|
||||
# 注意:默认值必须指向 content_profile=training 的培训 agent;历史默认 16 实为「通用入口」,
|
||||
# 会导致卡片落地非培训 agent、前端精益页签深链不消费([FIX] 2026-09-11)。
|
||||
|
||||
@@ -21,6 +21,7 @@ from app.core.errors import ValidationError
|
||||
from app.extensions import db
|
||||
from app.models import Agent, TrainingRecord, User
|
||||
from app.services.training_config_service import get_published_config
|
||||
from app.services.wecom_notify import send_wecom_event_message
|
||||
|
||||
TRAINING_STAGES = {"video", "summary", "exam", "result"}
|
||||
TRAINING_TYPES = {"onboarding", "safety"}
|
||||
@@ -609,6 +610,18 @@ def upsert_user_training_record(user: User, payload: dict[str, Any]) -> Training
|
||||
record.started_at = datetime.utcnow()
|
||||
|
||||
db.session.commit()
|
||||
if stage == "result" and _is_overseas_regulations_training(training_type):
|
||||
try:
|
||||
send_wecom_event_message(
|
||||
event_type="training_overseas_thailand_guidelines",
|
||||
user=user,
|
||||
title="中国员工出差泰国的行为准则",
|
||||
content="中国员工出差泰国的行为准则",
|
||||
jump_path="/workspace",
|
||||
)
|
||||
db.session.commit()
|
||||
except Exception:
|
||||
db.session.rollback()
|
||||
return record
|
||||
|
||||
|
||||
|
||||
@@ -268,6 +268,43 @@ def test_overseas_regulations_video_completion_creates_passed_result(client, app
|
||||
assert isinstance(body["completion_time"], str) and body["completion_time"]
|
||||
|
||||
|
||||
def test_overseas_regulations_video_completion_sends_wecom_notice_each_time(client, app, monkeypatch):
|
||||
"""关键断言:每次出国规章视频完成都必须生成一次泰国出差准则企微通知,不能按历史完成记录去重。"""
|
||||
sent_messages = []
|
||||
monkeypatch.setattr(
|
||||
training_service,
|
||||
"send_wecom_event_message",
|
||||
lambda **kwargs: sent_messages.append(kwargs) or {"ok": True, "trace_id": "training-notice-trace"},
|
||||
)
|
||||
with app.app_context():
|
||||
user = _create_user(username="overseas_wecom_notice")
|
||||
db.session.add(TrainingConfig(
|
||||
training_type="overseas_notice_v1",
|
||||
name="出国规章培训",
|
||||
version="v1",
|
||||
status="published",
|
||||
))
|
||||
db.session.commit()
|
||||
|
||||
payload = {
|
||||
"type": "overseas_notice_v1",
|
||||
"stage": "result",
|
||||
"score": 100,
|
||||
"passed": True,
|
||||
"attempt_count": 0,
|
||||
"answer_details": [],
|
||||
}
|
||||
first_response = client.put("/api/user/training-record/progress", headers=_auth_headers(user), json=payload)
|
||||
second_response = client.put("/api/user/training-record/progress", headers=_auth_headers(user), json=payload)
|
||||
|
||||
assert first_response.status_code == 200
|
||||
assert second_response.status_code == 200
|
||||
assert len(sent_messages) == 2
|
||||
assert all(message["event_type"] == "training_overseas_thailand_guidelines" for message in sent_messages)
|
||||
assert all(message["title"] == "中国员工出差泰国的行为准则" for message in sent_messages)
|
||||
assert all(message["content"] == "中国员工出差泰国的行为准则" for message in sent_messages)
|
||||
|
||||
|
||||
def test_safety_training_progress_round_trip(client, app):
|
||||
"""安全培训应持久化培训版本、考试模式、三级状态和级别进度。"""
|
||||
with app.app_context():
|
||||
|
||||
Reference in new issue
Block a user