Record Class NotificationRequest

java.lang.Object
java.lang.Record
io.leandev.appfuse.notification.NotificationRequest
Record Components:
type - 通知型別鍵(消費端自定義,如 product.low-stock),必填; 驅動範本查找、預設通道與偏好(Phase 2)
model - 範本資料袋(供 NotificationTemplateResolver 插值;缺省空 Map)
recipients - 顯式收件人(非空時略過 RecipientResolver;可為 null)
ccRecipients - EMAIL 副本收件人(最多 100 位;與每位正本共用相同內容;不另建 Outbox 列;可為 null)
channels - 遞送通道(缺省 {EMAIL};可為 null)
deepLink - 隨通知附帶的深連結 URL(最多 2000 字元;如簽章連結;可為 null)
dedupeKey - 顯式通知等價鍵(同鍵在 Outbox 視為同一則;最多 100 字元;可為 null)。技術重試/ 多節點遞送保護由 Outbox 機制承擔;一般應用除非已明確決定獨立提交可合併,否則 應省略本值。框架/Feature core 封裝的 opaque technical token 不在此限
localeName - 語系覆寫(IETF BCP 47,如 zh-TW;null 表示用收件人 / 系統語系)

public record NotificationRequest(String type, Map<String,Object> model, List<Recipient> recipients, List<Recipient> ccRecipients, Set<ChannelType> channels, String deepLink, String dedupeKey, String localeName) extends Record

一則通知請求(描述「發生了什麼」,不描述「怎麼遞送」)

呼叫端只需提供 typemodel;由 RecipientResolver 解析收件人、 NotificationTemplateResolver 依 type×channel×locale 渲染內容、NotificationChannel 遞送。recipients 為選用——非空時略過 RecipientResolver(呼叫端已知收件人時用, 如免密碼登入指定 email);ccRecipients 僅套用於 EMAIL,會與每位正本收件人形成同一封 郵件的 CC 標頭,不另建獨立遞送列;channels 缺省為 {EMAIL};model 缺省為空 Map。

CC 收件人會看到正本收件人的相同渲染內容與深連結,因此只適合內容完全相同、沒有 per-recipient 私密資訊的郵件。若 recipients 有多人,既有語意維持「每位正本各一封」, 每封都帶同一組 CC。

與簽章連結正交組合:deepLink 帶一條已簽好的連結(由 io.leandev.appfuse.security.link 原語產生),框架原樣放進渲染脈絡與遞送訊息,不碰其簽章。

容量契約由 NotificationService 在落庫前統一把關:type 100 字元、recipient user id 36 字元、各通道位址 320 字元、CC 最多 100 位、渲染後 subject 500 字元、deep link 2000 字元、呼叫端 dedupe key 100 字元。body 使用大型文字,不另設框架上限。

範例:

NotificationRequest.builder()
    .type("product.low-stock")
    .model(Map.of("productName", "玫瑰花束", "stock", 3))
    .deepLink(signedLinkUrl)
    .build();
Since:
4.0.0
  • Constructor Details

  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • type

      public String type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • model

      public Map<String,Object> model()
      Returns the value of the model record component.
      Returns:
      the value of the model record component
    • recipients

      public List<Recipient> recipients()
      Returns the value of the recipients record component.
      Returns:
      the value of the recipients record component
    • ccRecipients

      public List<Recipient> ccRecipients()
      Returns the value of the ccRecipients record component.
      Returns:
      the value of the ccRecipients record component
    • channels

      public Set<ChannelType> channels()
      Returns the value of the channels record component.
      Returns:
      the value of the channels record component
    • deepLink

      public String deepLink()
      Returns the value of the deepLink record component.
      Returns:
      the value of the deepLink record component
    • dedupeKey

      public String dedupeKey()
      Returns the value of the dedupeKey record component.
      Returns:
      the value of the dedupeKey record component
    • localeName

      public String localeName()
      Returns the value of the localeName record component.
      Returns:
      the value of the localeName record component