feat(health): 消息推送集成 — 定时任务启动 + 预约提醒事件
- erp-server: 启动逾期随访检查(6h)、积分过期(24h)、预约提醒(1h) 定时任务 - appointment_service: 新增 send_reminders 扫描明日确认预约发送事件 - erp-message: 订阅 appointment.reminder 事件,向患者发送提醒消息
This commit is contained in:
@@ -547,3 +547,43 @@ pub async fn calendar_view(
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// 扫描明天有预约的患者,通过事件总线发送预约提醒
|
||||
/// 由定时任务每小时调用一次
|
||||
pub async fn send_reminders(
|
||||
db: &sea_orm::DatabaseConnection,
|
||||
event_bus: &erp_core::events::EventBus,
|
||||
) -> crate::error::HealthResult<usize> {
|
||||
use chrono::{Local, NaiveDate};
|
||||
use serde_json::json;
|
||||
|
||||
let tomorrow = Local::now().date_naive() + chrono::Duration::days(1);
|
||||
|
||||
// 查找明天所有确认状态的预约
|
||||
let apps = appointment::Entity::find()
|
||||
.filter(appointment::Column::AppointmentDate.eq(tomorrow))
|
||||
.filter(appointment::Column::Status.eq("confirmed"))
|
||||
.filter(appointment::Column::DeletedAt.is_null())
|
||||
.all(db)
|
||||
.await?;
|
||||
|
||||
let count = apps.len();
|
||||
for app in apps {
|
||||
event_bus.publish(
|
||||
DomainEvent::new(
|
||||
"appointment.reminder",
|
||||
app.tenant_id,
|
||||
json!({
|
||||
"appointment_id": app.id,
|
||||
"patient_id": app.patient_id,
|
||||
"doctor_id": app.doctor_id,
|
||||
"appointment_date": app.appointment_date,
|
||||
"time_slot": format!("{}-{}", app.start_time.format("%H:%M"), app.end_time.format("%H:%M")),
|
||||
}),
|
||||
),
|
||||
db,
|
||||
).await;
|
||||
}
|
||||
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user