2026-08-03 05:52:02 +00:00
|
|
|
package usecase
|
|
|
|
|
|
2026-08-19 02:01:15 +00:00
|
|
|
import "context"
|
2026-08-03 05:52:02 +00:00
|
|
|
|
|
|
|
|
// AppNotifWriter is satisfied by appnotif usecase for system notifications.
|
|
|
|
|
type AppNotifWriter interface {
|
|
|
|
|
// InsertSystem creates a one-shot system notification.
|
|
|
|
|
InsertSystem(ctx context.Context, ownerUID int64, title, body, refType, refID string) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NotifierFromAppNotif builds SweepNotifier from appnotif bridge.
|
|
|
|
|
func NotifierFromAppNotif(w AppNotifWriter) SweepNotifier {
|
|
|
|
|
return sweepNotifyFunc(func(ctx context.Context, ownerUID int64, sweepID, watchID, reason string) error {
|
|
|
|
|
if w == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
title := "雷達巡檢失敗"
|
|
|
|
|
body := reason
|
|
|
|
|
if body == "" {
|
|
|
|
|
body = "今天的雷達巡檢沒有完成,請稍後重試或檢查抓取設定。"
|
|
|
|
|
}
|
|
|
|
|
return w.InsertSystem(ctx, ownerUID, title, body, "sweep", sweepID)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type sweepNotifyFunc func(ctx context.Context, ownerUID int64, sweepID, watchID, reason string) error
|
|
|
|
|
|
|
|
|
|
func (f sweepNotifyFunc) NotifySweepFailed(ctx context.Context, ownerUID int64, sweepID, watchID, reason string) error {
|
|
|
|
|
return f(ctx, ownerUID, sweepID, watchID, reason)
|
|
|
|
|
}
|