diff --git a/crates/erp-diary/src/service/class_service.rs b/crates/erp-diary/src/service/class_service.rs index d3cdfd2..0426db0 100644 --- a/crates/erp-diary/src/service/class_service.rs +++ b/crates/erp-diary/src/service/class_service.rs @@ -12,6 +12,8 @@ use crate::entity::{class_member, school_class}; use crate::error::{DiaryError, DiaryResult}; use erp_core::events::{DomainEvent, EventBus}; +use crate::event::DiaryEvent; + /// 班级服务 — 6 位码生成、过期控制、成员管理 pub struct ClassService; @@ -84,14 +86,11 @@ impl ClassService { // 发布 ClassCreated 事件 event_bus .publish( - DomainEvent::new( - "diary.class.created", - tenant_id, - serde_json::json!({ - "class_id": id, - "teacher_id": teacher_id, - }), - ), + DiaryEvent::ClassCreated { + class_id: id, + teacher_id, + } + .to_domain_event(tenant_id), db, ) .await; @@ -229,14 +228,11 @@ impl ClassService { // 8. 发布 StudentJoinedClass 事件 event_bus .publish( - DomainEvent::new( - "diary.class.student_joined", - tenant_id, - serde_json::json!({ - "class_id": class_id, - "student_id": user_id, - }), - ), + DiaryEvent::StudentJoinedClass { + class_id, + student_id: user_id, + } + .to_domain_event(tenant_id), db, ) .await; diff --git a/crates/erp-diary/src/service/comment_service.rs b/crates/erp-diary/src/service/comment_service.rs index f5e8a55..221e2e4 100644 --- a/crates/erp-diary/src/service/comment_service.rs +++ b/crates/erp-diary/src/service/comment_service.rs @@ -11,7 +11,9 @@ use crate::entity::{class_member, comment, journal_entry}; use crate::error::{DiaryError, DiaryResult}; use crate::service::content_safety_service::ContentSafetyService; use crate::service::notification_service::NotificationService; -use erp_core::events::{DomainEvent, EventBus}; +use erp_core::events::EventBus; + +use crate::event::DiaryEvent; /// 评语服务 — 老师对学生日记的点评 /// @@ -81,17 +83,13 @@ impl CommentService { // 5. 发布 CommentCreated 事件 event_bus .publish( - DomainEvent::new( - "diary.comment.created", - tenant_id, - serde_json::json!({ - "comment_id": id, - "journal_id": journal_id, - "teacher_id": author_id, - "student_id": journal.author_id, - "content_preview": content.chars().take(50).collect::(), - }), - ), + DiaryEvent::CommentCreated { + comment_id: id, + journal_id, + teacher_id: author_id, + student_id: journal.author_id, + } + .to_domain_event(tenant_id), db, ) .await; diff --git a/crates/erp-diary/src/service/journal_service.rs b/crates/erp-diary/src/service/journal_service.rs index 16f95f6..7dd4474 100644 --- a/crates/erp-diary/src/service/journal_service.rs +++ b/crates/erp-diary/src/service/journal_service.rs @@ -11,7 +11,9 @@ use crate::dto::{CreateJournalReq, JournalResp, UpdateJournalReq}; use crate::entity::journal_entry; use crate::error::{DiaryError, DiaryResult}; use erp_core::error::check_version; -use erp_core::events::{DomainEvent, EventBus}; +use erp_core::events::EventBus; + +use crate::event::DiaryEvent; /// 日记 CRUD 服务 — 创建、读取、更新、软删除日记条目 pub struct JournalService; @@ -57,15 +59,12 @@ impl JournalService { // 发布领域事件 event_bus .publish( - DomainEvent::new( - "diary.created", - tenant_id, - serde_json::json!({ - "journal_id": id, - "author_id": author_id, - "class_id": req.class_id, - }), - ), + DiaryEvent::JournalCreated { + journal_id: id, + author_id, + class_id: req.class_id, + } + .to_domain_event(tenant_id), db, ) .await; @@ -153,15 +152,12 @@ impl JournalService { // 发布领域事件 event_bus .publish( - DomainEvent::new( - "diary.updated", - tenant_id, - serde_json::json!({ - "journal_id": id, - "author_id": operator_id, - "version": new_version, - }), - ), + DiaryEvent::JournalUpdated { + journal_id: id, + author_id: operator_id, + version: new_version, + } + .to_domain_event(tenant_id), db, ) .await; @@ -206,14 +202,11 @@ impl JournalService { // 发布领域事件 event_bus .publish( - DomainEvent::new( - "diary.deleted", - tenant_id, - serde_json::json!({ - "journal_id": id, - "author_id": operator_id, - }), - ), + DiaryEvent::JournalDeleted { + journal_id: id, + author_id: operator_id, + } + .to_domain_event(tenant_id), db, ) .await; diff --git a/crates/erp-diary/src/service/parent_service.rs b/crates/erp-diary/src/service/parent_service.rs index 01d9708..8a7492e 100644 --- a/crates/erp-diary/src/service/parent_service.rs +++ b/crates/erp-diary/src/service/parent_service.rs @@ -12,6 +12,8 @@ use crate::entity::parent_child_binding; use crate::error::{DiaryError, DiaryResult}; use erp_core::events::{DomainEvent, EventBus}; +use crate::event::DiaryEvent; + /// 家长中心服务 — 绑定管理、数据查阅、导出、删除 pub struct ParentService; @@ -127,15 +129,11 @@ impl ParentService { event_bus .publish( - DomainEvent::new( - "diary.parent.binding_confirmed", - tenant_id, - serde_json::json!({ - "parent_id": updated.parent_id, - "child_id": child_id, - "binding_id": binding_id, - }), - ), + DiaryEvent::ParentBound { + parent_id: updated.parent_id, + child_id, + } + .to_domain_event(tenant_id), db, ) .await; diff --git a/crates/erp-diary/src/service/topic_service.rs b/crates/erp-diary/src/service/topic_service.rs index 3f3c66a..34ec615 100644 --- a/crates/erp-diary/src/service/topic_service.rs +++ b/crates/erp-diary/src/service/topic_service.rs @@ -11,7 +11,9 @@ use crate::dto::{CreateTopicReq, TopicResp, UpdateTopicReq}; use crate::entity::topic_assignment; use crate::error::{DiaryError, DiaryResult}; use crate::service::notification_service::NotificationService; -use erp_core::events::{DomainEvent, EventBus}; +use erp_core::events::EventBus; + +use crate::event::DiaryEvent; /// 主题布置服务 — 老师发布日记主题,学生提交对应日记 pub struct TopicService; @@ -67,15 +69,12 @@ impl TopicService { // 发布 TopicAssigned 事件 event_bus .publish( - DomainEvent::new( - "diary.topic.assigned", - tenant_id, - serde_json::json!({ - "topic_id": id, - "class_id": class_id, - "teacher_id": teacher_id, - }), - ), + DiaryEvent::TopicAssigned { + topic_id: id, + class_id, + teacher_id, + } + .to_domain_event(tenant_id), db, ) .await;