feat(health): 消息推送集成 — 定时任务启动 + 预约提醒事件
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- erp-server: 启动逾期随访检查(6h)、积分过期(24h)、预约提醒(1h) 定时任务
- appointment_service: 新增 send_reminders 扫描明日确认预约发送事件
- erp-message: 订阅 appointment.reminder 事件,向患者发送提醒消息
This commit is contained in:
iven
2026-04-27 14:51:40 +08:00
parent dc5879228e
commit 13b23e90f4
4 changed files with 109 additions and 2 deletions

View File

@@ -62,6 +62,28 @@ impl HealthModule {
})
}
/// 启动预约提醒调度(每 1 小时运行一次),扫描明天有预约的患者发送提醒
pub fn start_appointment_reminder(db: sea_orm::DatabaseConnection, event_bus: erp_core::events::EventBus) -> tokio::task::JoinHandle<()> {
tokio::spawn(async move {
let mut interval = tokio::time::interval(std::time::Duration::from_secs(3600));
loop {
tokio::select! {
_ = interval.tick() => {
match crate::service::appointment_service::send_reminders(&db, &event_bus).await {
Ok(count) if count > 0 => tracing::info!(count = count, "预约提醒发送完成"),
Ok(_) => {}
Err(e) => tracing::warn!(error = %e, "预约提醒发送失败"),
}
}
_ = tokio::signal::ctrl_c() => {
tracing::info!("预约提醒调度任务收到关闭信号,正在停止");
break;
}
}
}
})
}
pub fn public_routes<S>() -> Router<S>
where
crate::state::HealthState: axum::extract::FromRef<S>,