Files
hfb_sys/backend/internal/modules/notification/service.go
T
yml2213 4461e7929e feat(distribution): 站内信与通知体系多租户独立分支隔离
- 新增 000071 数据库迁移:notifications 表支持 distribution_site_id 并自动回填历史分销订单通知
- 通知自动归属:在事务内根据订单或申诉自动关联当前分销站点 ID
- 隔离查询与已读控制:列表、未读统计与批量已读均严格按站点隔离,防止主站与分站交叉泄漏
- 前台界面联动:消息中心通知 Tab 及移动端/PC端站内信页面展示分站专属标识与精准过滤
2026-09-07 19:10:02 +08:00

50 lines
1.3 KiB
Go

package notification
import (
"context"
"errors"
)
var ErrDependencyUnavailable = errors.New("dependency unavailable")
var ErrNotificationNotFound = errors.New("notification not found")
type Service struct {
repo *Repository
}
func NewService(repo *Repository) *Service {
return &Service{repo: repo}
}
func (s *Service) List(ctx context.Context, userID uint64, page, pageSize int, siteCode ...string) (*PaginatedResult, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.List(ctx, userID, page, pageSize, siteCode...)
}
func (s *Service) MarkRead(ctx context.Context, userID uint64, id uint64, siteCode ...string) error {
if s.repo == nil {
return ErrDependencyUnavailable
}
return s.repo.MarkRead(ctx, userID, id, siteCode...)
}
func (s *Service) UnreadCount(ctx context.Context, userID uint64, siteCode ...string) (*UnreadCountDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
count, err := s.repo.UnreadCount(ctx, userID, siteCode...)
if err != nil {
return nil, err
}
return &UnreadCountDTO{UnreadCount: count}, nil
}
func (s *Service) MarkAllRead(ctx context.Context, userID uint64, siteCode ...string) (int64, error) {
if s.repo == nil {
return 0, ErrDependencyUnavailable
}
return s.repo.MarkAllRead(ctx, userID, siteCode...)
}