From 77851288f7e9332f85a0149cfcf1459cea2ef422 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Wed, 16 Sep 2026 13:16:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(training):=20=E5=87=BA=E5=9B=BD=E8=A7=84?= =?UTF-8?q?=E5=88=99=E5=9F=B9=E8=AE=AD=E5=AE=8C=E6=88=90=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E4=BC=81=E5=BE=AE=E9=80=9A=E7=9F=A5=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.prod | 2 +- .env.shared | 2 +- .env.test | 2 +- backend/app/core/config/settings.py | 2 +- backend/app/services/training_service.py | 13 +++++++++ backend/tests/test_training_api.py | 37 ++++++++++++++++++++++++ docs/demand.md | 5 ++++ docs/funclist.md | 2 +- 8 files changed, 60 insertions(+), 5 deletions(-) diff --git a/.env.prod b/.env.prod index b4c323e4..ab1f247e 100644 --- a/.env.prod +++ b/.env.prod @@ -70,7 +70,7 @@ GUNICORN_WORKERS=20 # 企业微信通知配置(如果不使用企业微信通知,留空即可) # WECOM_NOTIFY_BASE_URL:历史内网/端口地址,仅作兼容;textcard 跳转优先 WECOM_PUBLIC_BASE_URL WECOM_NOTIFY_BASE_URL=http://ai.well-trust.com:8890/ -WECOM_NOTIFY_EVENTS=permission_request_approved,permission_request_rejected,permission_batch_updated,task_completed,schedule_completed,password_reset,contract_payment_warning,training_lean_overdue,training_lean_task_initial,training_lean_targeted_reminder,training_lean_video_push +WECOM_NOTIFY_EVENTS=permission_request_approved,permission_request_rejected,permission_batch_updated,task_completed,schedule_completed,password_reset,contract_payment_warning,training_lean_overdue,training_lean_task_initial,training_lean_targeted_reminder,training_lean_video_push,training_overseas_thailand_guidelines WECOM_PUBLIC_BASE_URL=https://ai.well-trust.com # --- 5. 数据库与基础设施 --- diff --git a/.env.shared b/.env.shared index 16366526..e24123c2 100644 --- a/.env.shared +++ b/.env.shared @@ -150,7 +150,7 @@ WECOM_TRUSTED_DOMAIN= WECOM_PUBLIC_BASE_URL= WECOM_NOTIFY_ENABLED=true WECOM_NOTIFY_BASE_URL= -WECOM_NOTIFY_EVENTS=permission_request_approved,permission_request_rejected,permission_batch_updated,task_completed,schedule_completed,password_reset,contract_payment_warning,training_lean_overdue,training_lean_task_initial,training_lean_targeted_reminder,training_lean_video_push +WECOM_NOTIFY_EVENTS=permission_request_approved,permission_request_rejected,permission_batch_updated,task_completed,schedule_completed,password_reset,contract_payment_warning,training_lean_overdue,training_lean_task_initial,training_lean_targeted_reminder,training_lean_video_push,training_overseas_thailand_guidelines WECOM_FEEDBACK_NOTIFY_ENABLED=true WECOM_FEEDBACK_NOTIFY_BASE_URL=http://ai.well-trust.com:8881 # 企业微信群机器人 webhook,按环境写入 .env. 或部署平台变量;不要提交真实 URL。 diff --git a/.env.test b/.env.test index 032ae572..6dd878ae 100644 --- a/.env.test +++ b/.env.test @@ -70,7 +70,7 @@ GUNICORN_WORKERS=6 # 企业微信通知配置(如果不使用企业微信通知,留空即可) # WECOM_NOTIFY_BASE_URL:历史内网/端口地址,仅作兼容;textcard 跳转优先 WECOM_PUBLIC_BASE_URL WECOM_NOTIFY_BASE_URL=http://ait.well-trust.com:8890/ -WECOM_NOTIFY_EVENTS=permission_request_approved,permission_request_rejected,permission_batch_updated,task_completed,schedule_completed,password_reset,contract_payment_warning,training_lean_overdue,training_lean_task_initial,training_lean_targeted_reminder,training_lean_video_push +WECOM_NOTIFY_EVENTS=permission_request_approved,permission_request_rejected,permission_batch_updated,task_completed,schedule_completed,password_reset,contract_payment_warning,training_lean_overdue,training_lean_task_initial,training_lean_targeted_reminder,training_lean_video_push,training_overseas_thailand_guidelines WECOM_PUBLIC_BASE_URL=https://ait.well-trust.com HXOPS_PUBLIC_BASE_URL=https://ait.well-trust.com diff --git a/backend/app/core/config/settings.py b/backend/app/core/config/settings.py index 1e147fa4..965ac847 100644 --- a/backend/app/core/config/settings.py +++ b/backend/app/core/config/settings.py @@ -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/,默认 27=员工培训)。 # 注意:默认值必须指向 content_profile=training 的培训 agent;历史默认 16 实为「通用入口」, # 会导致卡片落地非培训 agent、前端精益页签深链不消费([FIX] 2026-09-11)。 diff --git a/backend/app/services/training_service.py b/backend/app/services/training_service.py index 5722fc2e..a7f29f6c 100644 --- a/backend/app/services/training_service.py +++ b/backend/app/services/training_service.py @@ -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 diff --git a/backend/tests/test_training_api.py b/backend/tests/test_training_api.py index 3ecd82a7..cbc5690e 100644 --- a/backend/tests/test_training_api.py +++ b/backend/tests/test_training_api.py @@ -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(): diff --git a/docs/demand.md b/docs/demand.md index ae38fa2e..26e2f45c 100644 --- a/docs/demand.md +++ b/docs/demand.md @@ -1,5 +1,10 @@ # 智能HR请假管理需求 +## 员工培训企微通知(2026-09) + +- 员工在“员工培训”完成“出国规章培训”视频观看后,系统立即向该员工推送一条标题和正文均为“中国员工出差泰国的行为准则”的企业微信通知。 +- 推送以每次视频观看完成事实为准:同一员工重复完整观看时,每次均发送一次,不因既有培训完成记录而去重;企业微信事件开关关闭、通知总开关关闭或员工未绑定企业微信时,不影响培训完成记录落库,并由既有企微审计记录原因。 + ## 合同付款预警 Agent(2026-08) - 覆盖预付款、出货款、验收款、质保款四阶段:预付款为合同申请单归档后第 7/14/21 天;出货款为交货期限前 7 天、当天、后 14 天;验收款为验收归档后第 30/40/60 天;质保款为质保到期前 7 天、当天、后 14 天。 diff --git a/docs/funclist.md b/docs/funclist.md index 2f7e316a..897796b6 100644 --- a/docs/funclist.md +++ b/docs/funclist.md @@ -55,7 +55,7 @@ | 功能项 | 状态 | 说明 | | -------------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Chat 内培训工作区 | 前端已实现 | 在培训 Agent 聊天页顶部提供视频学习、知识点复盘、逐题考试、成绩结算的一体化工作区;“出国规章培训”每次进入均从视频开始,完整播放一次后记录为一次学习完成 | +| Chat 内培训工作区 | 前端已实现 | 在培训 Agent 聊天页顶部提供视频学习、知识点复盘、逐题考试、成绩结算的一体化工作区;“出国规章培训”每次进入均从视频开始,完整播放一次后记录为一次学习完成,并立即推送一条“中国员工出差泰国的行为准则”企业微信通知;重复完整观看按次推送,不因既有完成记录去重 | | Chat 内 HR 管理面板 | 已实现 | 仅具备培训 HR 管理权限的用户可在同一聊天页查看真实培训统计、筛选记录并导出 Excel;【导出 Excel】复用当前关键字、培训类型、状态和部门筛选条件,导出全部匹配记录,字段与列表一致(入职日期、完成日期、培训类型、部门、姓名、工号、分数、考试次数、状态);管理端顶部提供【全部培训】/【精益管理】页签,统计卡片随页签按各自实际数据切换(全部培训=考试通过统计;精益管理=按看板三态计数的完成率统计);精益页签展示单表格明细(已完成+未完成合并为一张表,仅靠状态列区分已完成/已延期/进行中),并提供期次下拉可区分/切换第几期任务(期号按周次升序,最早为第 1 期),切换后重拉对应期看板与精益统计;状态列统一中文显示;权限支持角色默认值与前端用户配置共同控制 | | Chat 附件发送前预览 | 已实现 | 附件列表显示在输入框上方,展示文件类型、名称、真实大小和逐文件处理状态;支持右上角删除,上传中保护删除,发货通知保留解析重试与重复处理入口 | | 培训题库后台配置 | 已实现 | Agent 管理表单支持维护及格线、复盘要点、考前清单与题库;员工培训页优先读取 `extra_config.training_config`,未配置时才回退前端默认题库 |