2026-03-13 09:38:18 +08:00
|
|
|
|
package wire
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-15 02:25:10 +08:00
|
|
|
|
"time"
|
|
|
|
|
|
|
2026-03-13 09:38:18 +08:00
|
|
|
|
"carrot_bbs/internal/cache"
|
|
|
|
|
|
"carrot_bbs/internal/config"
|
2026-03-13 20:40:20 +08:00
|
|
|
|
"carrot_bbs/internal/grpc/runner"
|
2026-03-13 09:38:18 +08:00
|
|
|
|
"carrot_bbs/internal/pkg/email"
|
2026-03-20 12:23:28 +08:00
|
|
|
|
"carrot_bbs/internal/pkg/hook"
|
2026-03-13 09:38:18 +08:00
|
|
|
|
"carrot_bbs/internal/pkg/openai"
|
2026-03-20 12:23:28 +08:00
|
|
|
|
"carrot_bbs/internal/pkg/redis"
|
2026-03-13 09:38:18 +08:00
|
|
|
|
"carrot_bbs/internal/pkg/s3"
|
2026-04-21 22:31:30 +08:00
|
|
|
|
"carrot_bbs/internal/pkg/tencent"
|
2026-03-26 21:17:49 +08:00
|
|
|
|
"carrot_bbs/internal/pkg/ws"
|
2026-03-13 09:38:18 +08:00
|
|
|
|
"carrot_bbs/internal/repository"
|
|
|
|
|
|
"carrot_bbs/internal/service"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/google/wire"
|
2026-03-13 20:40:20 +08:00
|
|
|
|
"go.uber.org/zap"
|
2026-03-13 09:38:18 +08:00
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// ServiceSet Service 层 Provider Set
|
|
|
|
|
|
var ServiceSet = wire.NewSet(
|
|
|
|
|
|
// JWT 服务(需要配置参数)
|
|
|
|
|
|
ProvideJWTService,
|
|
|
|
|
|
|
|
|
|
|
|
// 基础服务
|
|
|
|
|
|
ProvideEmailService,
|
|
|
|
|
|
ProvidePostAIService,
|
|
|
|
|
|
|
|
|
|
|
|
// 核心服务(按依赖顺序)
|
|
|
|
|
|
ProvidePushService,
|
|
|
|
|
|
ProvideSystemMessageService,
|
|
|
|
|
|
ProvidePostService,
|
|
|
|
|
|
ProvideCommentService,
|
|
|
|
|
|
ProvideMessageService,
|
|
|
|
|
|
ProvideNotificationService,
|
|
|
|
|
|
ProvideUserService,
|
|
|
|
|
|
ProvideStickerService,
|
|
|
|
|
|
ProvideVoteService,
|
2026-03-24 22:27:53 +08:00
|
|
|
|
ProvideChannelService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
ProvideChatService,
|
|
|
|
|
|
ProvideScheduleService,
|
2026-03-13 20:40:20 +08:00
|
|
|
|
ProvideScheduleSyncService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
ProvideGroupService,
|
|
|
|
|
|
ProvideUploadService,
|
2026-03-14 02:09:38 +08:00
|
|
|
|
ProvideUserActivityService,
|
|
|
|
|
|
ProvideRoleService,
|
2026-03-14 18:01:55 +08:00
|
|
|
|
ProvideAdminUserService,
|
|
|
|
|
|
ProvideAdminPostService,
|
|
|
|
|
|
ProvideAdminCommentService,
|
|
|
|
|
|
ProvideAdminGroupService,
|
|
|
|
|
|
ProvideAdminDashboardService,
|
2026-03-20 12:23:28 +08:00
|
|
|
|
ProvideQRCodeLoginService,
|
2026-03-24 05:18:30 +08:00
|
|
|
|
ProvideHotRankWorker,
|
2026-03-25 20:44:12 +08:00
|
|
|
|
ProvideMaterialService,
|
2026-03-27 01:54:34 +08:00
|
|
|
|
ProvideCallService,
|
2026-03-29 20:18:36 +08:00
|
|
|
|
ProvideReportService,
|
|
|
|
|
|
ProvideAdminReportService,
|
2026-04-05 20:27:03 +08:00
|
|
|
|
ProvideVerificationService,
|
|
|
|
|
|
ProvideAdminVerificationService,
|
2026-04-07 00:07:40 +08:00
|
|
|
|
ProvideSensitiveService,
|
2026-04-15 11:50:47 +08:00
|
|
|
|
ProvideUserProfileAuditService,
|
2026-03-15 02:25:10 +08:00
|
|
|
|
|
|
|
|
|
|
// 日志服务
|
|
|
|
|
|
ProvideAsyncLogManager,
|
|
|
|
|
|
ProvideOperationLogService,
|
|
|
|
|
|
ProvideLoginLogService,
|
|
|
|
|
|
ProvideDataChangeLogService,
|
|
|
|
|
|
ProvideLogCleanupService,
|
|
|
|
|
|
ProvideLogService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideJWTService 提供 JWT 服务
|
|
|
|
|
|
func ProvideJWTService(cfg *config.Config) *service.JWTService {
|
|
|
|
|
|
return service.NewJWTService(
|
|
|
|
|
|
cfg.JWT.Secret,
|
|
|
|
|
|
int64(cfg.JWT.AccessTokenExpire.Seconds()),
|
|
|
|
|
|
int64(cfg.JWT.RefreshTokenExpire.Seconds()),
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideEmailService 提供邮件服务
|
|
|
|
|
|
func ProvideEmailService(client email.Client) service.EmailService {
|
|
|
|
|
|
return service.NewEmailService(client)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvidePostAIService 提供 AI 服务
|
2026-04-21 22:31:30 +08:00
|
|
|
|
func ProvidePostAIService(openAIClient openai.Client, tencentClient tencent.Client, cfg *config.Config) *service.PostAIService {
|
|
|
|
|
|
return service.NewPostAIService(openAIClient, tencentClient, cfg.OpenAI.StrictModeration)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvidePushService 提供推送服务
|
|
|
|
|
|
func ProvidePushService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
pushRepo repository.PushRecordRepository,
|
|
|
|
|
|
deviceTokenRepo repository.DeviceTokenRepository,
|
|
|
|
|
|
messageRepo repository.MessageRepository,
|
2026-03-26 21:17:49 +08:00
|
|
|
|
wsHub *ws.Hub,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
) service.PushService {
|
2026-03-26 21:17:49 +08:00
|
|
|
|
return service.NewPushService(pushRepo, deviceTokenRepo, messageRepo, wsHub)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideSystemMessageService 提供系统消息服务
|
|
|
|
|
|
func ProvideSystemMessageService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
notifyRepo repository.SystemNotificationRepository,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
pushService service.PushService,
|
2026-03-26 18:14:16 +08:00
|
|
|
|
userRepo repository.UserRepository,
|
|
|
|
|
|
postRepo repository.PostRepository,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
cacheBackend cache.Cache,
|
|
|
|
|
|
) service.SystemMessageService {
|
|
|
|
|
|
return service.NewSystemMessageService(notifyRepo, pushService, userRepo, postRepo, cacheBackend)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ProvidePostService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
postRepo repository.PostRepository,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
systemMessageService service.SystemMessageService,
|
|
|
|
|
|
postAIService *service.PostAIService,
|
|
|
|
|
|
cacheBackend cache.Cache,
|
|
|
|
|
|
txManager repository.TransactionManager,
|
2026-03-20 12:23:28 +08:00
|
|
|
|
hookManager *hook.Manager,
|
2026-03-21 02:53:38 +08:00
|
|
|
|
_ *hook.ModerationHooks,
|
|
|
|
|
|
_ *hook.BuiltinHooks,
|
2026-03-28 07:03:21 +08:00
|
|
|
|
logService *service.LogService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
) service.PostService {
|
2026-03-28 07:03:21 +08:00
|
|
|
|
return service.NewPostService(postRepo, systemMessageService, postAIService, cacheBackend, txManager, hookManager, logService)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ProvideCommentService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
commentRepo repository.CommentRepository,
|
|
|
|
|
|
postRepo repository.PostRepository,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
systemMessageService service.SystemMessageService,
|
|
|
|
|
|
postAIService *service.PostAIService,
|
|
|
|
|
|
cacheBackend cache.Cache,
|
2026-03-20 12:23:28 +08:00
|
|
|
|
hookManager *hook.Manager,
|
2026-03-28 07:03:21 +08:00
|
|
|
|
logService *service.LogService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
) *service.CommentService {
|
2026-03-28 07:03:21 +08:00
|
|
|
|
return service.NewCommentService(commentRepo, postRepo, systemMessageService, postAIService, cacheBackend, hookManager, logService)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideMessageService 提供消息服务
|
|
|
|
|
|
func ProvideMessageService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
messageRepo repository.MessageRepository,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
cacheBackend cache.Cache,
|
2026-03-25 03:57:40 +08:00
|
|
|
|
uploadService *service.UploadService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
) *service.MessageService {
|
2026-03-26 18:14:16 +08:00
|
|
|
|
return service.NewMessageService(messageRepo, cacheBackend, uploadService)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideNotificationService 提供通知服务
|
|
|
|
|
|
func ProvideNotificationService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
notificationRepo repository.NotificationRepository,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
cacheBackend cache.Cache,
|
|
|
|
|
|
) *service.NotificationService {
|
|
|
|
|
|
return service.NewNotificationService(notificationRepo, cacheBackend)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideUserService 提供用户服务
|
|
|
|
|
|
func ProvideUserService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
userRepo repository.UserRepository,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
systemMessageService service.SystemMessageService,
|
|
|
|
|
|
emailService service.EmailService,
|
|
|
|
|
|
cacheBackend cache.Cache,
|
2026-03-28 07:03:21 +08:00
|
|
|
|
logService *service.LogService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
) service.UserService {
|
2026-03-28 07:03:21 +08:00
|
|
|
|
return service.NewUserService(userRepo, systemMessageService, emailService, cacheBackend, logService)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideStickerService 提供表情服务
|
|
|
|
|
|
func ProvideStickerService(
|
|
|
|
|
|
stickerRepo repository.StickerRepository,
|
|
|
|
|
|
) service.StickerService {
|
|
|
|
|
|
return service.NewStickerService(stickerRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideVoteService 提供投票服务
|
|
|
|
|
|
func ProvideVoteService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
voteRepo repository.VoteRepository,
|
|
|
|
|
|
postRepo repository.PostRepository,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
cache cache.Cache,
|
|
|
|
|
|
postAIService *service.PostAIService,
|
|
|
|
|
|
systemMessageService service.SystemMessageService,
|
2026-04-11 04:23:24 +08:00
|
|
|
|
hookManager *hook.Manager,
|
|
|
|
|
|
logService *service.LogService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
) *service.VoteService {
|
2026-04-11 04:23:24 +08:00
|
|
|
|
return service.NewVoteService(voteRepo, postRepo, cache, postAIService, systemMessageService, hookManager, logService)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-26 18:14:16 +08:00
|
|
|
|
func ProvideChannelService(channelRepo repository.ChannelRepository, cacheBackend cache.Cache) service.ChannelService {
|
2026-03-25 01:03:34 +08:00
|
|
|
|
return service.NewChannelService(channelRepo, cacheBackend)
|
2026-03-24 22:27:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 09:38:18 +08:00
|
|
|
|
// ProvideChatService 提供聊天服务
|
|
|
|
|
|
// Note: sensitiveService 传 nil,与 main.go 保持一致
|
|
|
|
|
|
func ProvideChatService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
messageRepo repository.MessageRepository,
|
|
|
|
|
|
userRepo repository.UserRepository,
|
2026-03-26 21:17:49 +08:00
|
|
|
|
wsHub *ws.Hub,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
cacheBackend cache.Cache,
|
2026-03-25 03:57:40 +08:00
|
|
|
|
uploadService *service.UploadService,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
) service.ChatService {
|
2026-03-26 21:17:49 +08:00
|
|
|
|
return service.NewChatService(messageRepo, userRepo, nil, wsHub, cacheBackend, uploadService)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideScheduleService 提供日程服务
|
|
|
|
|
|
func ProvideScheduleService(
|
|
|
|
|
|
scheduleRepo repository.ScheduleRepository,
|
|
|
|
|
|
) service.ScheduleService {
|
|
|
|
|
|
return service.NewScheduleService(scheduleRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 20:40:20 +08:00
|
|
|
|
// ProvideScheduleSyncService 提供课表同步服务
|
|
|
|
|
|
func ProvideScheduleSyncService(
|
|
|
|
|
|
taskManager *runner.TaskManager,
|
|
|
|
|
|
scheduleRepo repository.ScheduleRepository,
|
|
|
|
|
|
logger *zap.Logger,
|
|
|
|
|
|
) service.ScheduleSyncService {
|
|
|
|
|
|
return service.NewScheduleSyncService(taskManager, scheduleRepo, logger)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 09:38:18 +08:00
|
|
|
|
// ProvideGroupService 提供群组服务
|
|
|
|
|
|
func ProvideGroupService(
|
|
|
|
|
|
groupRepo repository.GroupRepository,
|
2026-03-26 18:14:16 +08:00
|
|
|
|
userRepo repository.UserRepository,
|
|
|
|
|
|
messageRepo repository.MessageRepository,
|
|
|
|
|
|
requestRepo repository.GroupJoinRequestRepository,
|
|
|
|
|
|
notifyRepo repository.SystemNotificationRepository,
|
2026-03-26 21:17:49 +08:00
|
|
|
|
wsHub *ws.Hub,
|
2026-03-13 09:38:18 +08:00
|
|
|
|
cacheBackend cache.Cache,
|
|
|
|
|
|
) service.GroupService {
|
2026-03-26 21:17:49 +08:00
|
|
|
|
return service.NewGroupService(groupRepo, userRepo, messageRepo, requestRepo, notifyRepo, wsHub, cacheBackend)
|
2026-03-13 09:38:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideUploadService 提供上传服务
|
|
|
|
|
|
func ProvideUploadService(
|
|
|
|
|
|
s3Client *s3.Client,
|
|
|
|
|
|
userService service.UserService,
|
|
|
|
|
|
) *service.UploadService {
|
|
|
|
|
|
return service.NewUploadService(s3Client, userService)
|
|
|
|
|
|
}
|
2026-03-14 02:09:38 +08:00
|
|
|
|
|
|
|
|
|
|
// ProvideUserActivityService 提供用户活跃统计服务
|
2026-03-26 18:14:16 +08:00
|
|
|
|
func ProvideUserActivityService(repo repository.UserActivityRepository) service.UserActivityService {
|
2026-03-14 02:09:38 +08:00
|
|
|
|
return service.NewUserActivityService(repo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideRoleService 提供角色管理服务
|
|
|
|
|
|
func ProvideRoleService(
|
|
|
|
|
|
roleRepo repository.RoleRepository,
|
|
|
|
|
|
casbinSvc service.CasbinService,
|
|
|
|
|
|
) service.RoleService {
|
|
|
|
|
|
return service.NewRoleService(roleRepo, casbinSvc)
|
|
|
|
|
|
}
|
2026-03-14 18:01:55 +08:00
|
|
|
|
|
|
|
|
|
|
// ProvideAdminUserService 提供管理端用户服务
|
2026-03-26 18:14:16 +08:00
|
|
|
|
func ProvideAdminUserService(userRepo repository.UserRepository) service.AdminUserService {
|
2026-03-14 18:01:55 +08:00
|
|
|
|
return service.NewAdminUserService(userRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideAdminPostService 提供管理端帖子服务
|
2026-03-28 07:03:21 +08:00
|
|
|
|
func ProvideAdminPostService(postRepo repository.PostRepository, cacheBackend cache.Cache, logService *service.LogService) service.AdminPostService {
|
|
|
|
|
|
return service.NewAdminPostService(postRepo, cacheBackend, logService)
|
2026-03-14 18:01:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideAdminCommentService 提供管理端评论服务
|
2026-03-26 18:14:16 +08:00
|
|
|
|
func ProvideAdminCommentService(commentRepo repository.CommentRepository, postRepo repository.PostRepository) service.AdminCommentService {
|
2026-03-14 18:01:55 +08:00
|
|
|
|
return service.NewAdminCommentService(commentRepo, postRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideAdminGroupService 提供管理端群组服务
|
|
|
|
|
|
func ProvideAdminGroupService(
|
|
|
|
|
|
groupRepo repository.GroupRepository,
|
2026-03-26 18:14:16 +08:00
|
|
|
|
userRepo repository.UserRepository,
|
2026-03-14 18:01:55 +08:00
|
|
|
|
) service.AdminGroupService {
|
|
|
|
|
|
return service.NewAdminGroupService(groupRepo, userRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideAdminDashboardService 提供管理端仪表盘服务
|
|
|
|
|
|
func ProvideAdminDashboardService(
|
|
|
|
|
|
db *gorm.DB,
|
2026-03-26 18:14:16 +08:00
|
|
|
|
userRepo repository.UserRepository,
|
|
|
|
|
|
postRepo repository.PostRepository,
|
|
|
|
|
|
commentRepo repository.CommentRepository,
|
2026-03-14 18:01:55 +08:00
|
|
|
|
groupRepo repository.GroupRepository,
|
2026-03-26 18:14:16 +08:00
|
|
|
|
activityRepo repository.UserActivityRepository,
|
2026-03-14 18:01:55 +08:00
|
|
|
|
) service.AdminDashboardService {
|
|
|
|
|
|
return service.NewAdminDashboardService(db, userRepo, postRepo, commentRepo, groupRepo, activityRepo)
|
|
|
|
|
|
}
|
2026-03-15 02:25:10 +08:00
|
|
|
|
|
|
|
|
|
|
// ProvideAsyncLogManager 提供异步日志管理器
|
|
|
|
|
|
func ProvideAsyncLogManager(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
operationRepo repository.OperationLogRepository,
|
|
|
|
|
|
loginRepo repository.LoginLogRepository,
|
|
|
|
|
|
dataChangeRepo repository.DataChangeLogRepository,
|
2026-03-15 02:25:10 +08:00
|
|
|
|
logger *zap.Logger,
|
|
|
|
|
|
cfg *config.Config,
|
|
|
|
|
|
) *service.AsyncLogManager {
|
|
|
|
|
|
asyncCfg := &service.AsyncLogConfig{
|
|
|
|
|
|
BufferSize: cfg.Log.Async.BufferSize,
|
|
|
|
|
|
BatchSize: cfg.Log.Async.BatchSize,
|
|
|
|
|
|
WorkerCount: cfg.Log.Async.WorkerCount,
|
|
|
|
|
|
EnableFallback: cfg.Log.Async.EnableFallback,
|
|
|
|
|
|
FallbackPath: cfg.Log.Async.FallbackPath,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解析刷新间隔
|
|
|
|
|
|
if duration, err := parseDuration(cfg.Log.Async.FlushInterval); err == nil {
|
|
|
|
|
|
asyncCfg.FlushInterval = duration
|
|
|
|
|
|
} else {
|
|
|
|
|
|
asyncCfg.FlushInterval = 3 * time.Second
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-26 18:14:16 +08:00
|
|
|
|
return service.NewAsyncLogManager(operationRepo, loginRepo, dataChangeRepo, logger, asyncCfg)
|
2026-03-15 02:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideOperationLogService 提供操作日志服务
|
|
|
|
|
|
func ProvideOperationLogService(
|
|
|
|
|
|
asyncManager *service.AsyncLogManager,
|
2026-03-26 18:14:16 +08:00
|
|
|
|
operationRepo repository.OperationLogRepository,
|
2026-03-15 02:25:10 +08:00
|
|
|
|
) service.OperationLogService {
|
|
|
|
|
|
return service.NewOperationLogService(asyncManager, operationRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideLoginLogService 提供登录日志服务
|
|
|
|
|
|
func ProvideLoginLogService(
|
|
|
|
|
|
asyncManager *service.AsyncLogManager,
|
2026-03-26 18:14:16 +08:00
|
|
|
|
loginRepo repository.LoginLogRepository,
|
2026-03-15 02:25:10 +08:00
|
|
|
|
) service.LoginLogService {
|
|
|
|
|
|
return service.NewLoginLogService(asyncManager, loginRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideDataChangeLogService 提供数据变更日志服务
|
|
|
|
|
|
func ProvideDataChangeLogService(
|
|
|
|
|
|
asyncManager *service.AsyncLogManager,
|
2026-03-26 18:14:16 +08:00
|
|
|
|
dataChangeRepo repository.DataChangeLogRepository,
|
2026-03-15 02:25:10 +08:00
|
|
|
|
) service.DataChangeLogService {
|
|
|
|
|
|
return service.NewDataChangeLogService(asyncManager, dataChangeRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideLogCleanupService 提供日志清理服务
|
|
|
|
|
|
func ProvideLogCleanupService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
operationRepo repository.OperationLogRepository,
|
|
|
|
|
|
loginRepo repository.LoginLogRepository,
|
|
|
|
|
|
dataChangeRepo repository.DataChangeLogRepository,
|
2026-03-15 02:25:10 +08:00
|
|
|
|
logger *zap.Logger,
|
|
|
|
|
|
cfg *config.Config,
|
|
|
|
|
|
) service.LogCleanupService {
|
|
|
|
|
|
cleanupCfg := &service.LogCleanupConfig{
|
|
|
|
|
|
Enabled: true,
|
|
|
|
|
|
OperationLog: cfg.Log.Retention.OperationLog,
|
|
|
|
|
|
LoginLog: cfg.Log.Retention.LoginLog,
|
|
|
|
|
|
DataChangeLog: cfg.Log.Retention.DataChange,
|
|
|
|
|
|
CleanupTime: "02:00",
|
|
|
|
|
|
}
|
|
|
|
|
|
return service.NewLogCleanupService(operationRepo, loginRepo, dataChangeRepo, cleanupCfg, logger)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideLogService 提供日志服务组合
|
|
|
|
|
|
func ProvideLogService(
|
|
|
|
|
|
operationLogService service.OperationLogService,
|
|
|
|
|
|
loginLogService service.LoginLogService,
|
|
|
|
|
|
dataChangeLogService service.DataChangeLogService,
|
|
|
|
|
|
) *service.LogService {
|
|
|
|
|
|
return service.NewLogService(operationLogService, loginLogService, dataChangeLogService)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:23:28 +08:00
|
|
|
|
// ProvideQRCodeLoginService 提供二维码登录服务
|
2026-03-26 18:14:16 +08:00
|
|
|
|
func ProvideHotRankWorker(cfg *config.Config, postRepo repository.PostRepository, cacheBackend cache.Cache) *service.HotRankWorker {
|
2026-03-24 05:18:30 +08:00
|
|
|
|
return service.NewHotRankWorker(cfg, postRepo, cacheBackend)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:23:28 +08:00
|
|
|
|
func ProvideQRCodeLoginService(
|
|
|
|
|
|
redisClient *redis.Client,
|
2026-03-26 21:17:49 +08:00
|
|
|
|
wsHub *ws.Hub,
|
2026-03-20 12:23:28 +08:00
|
|
|
|
jwtService *service.JWTService,
|
|
|
|
|
|
userService service.UserService,
|
|
|
|
|
|
activityService service.UserActivityService,
|
|
|
|
|
|
logService *service.LogService,
|
|
|
|
|
|
) *service.QRCodeLoginService {
|
2026-03-26 21:17:49 +08:00
|
|
|
|
return service.NewQRCodeLoginService(redisClient, wsHub, jwtService, userService, activityService, logService)
|
2026-03-20 12:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-25 20:44:12 +08:00
|
|
|
|
// ProvideMaterialService 提供学习资料服务
|
|
|
|
|
|
func ProvideMaterialService(
|
2026-03-26 18:14:16 +08:00
|
|
|
|
subjectRepo repository.MaterialSubjectRepository,
|
|
|
|
|
|
fileRepo repository.MaterialFileRepository,
|
2026-03-25 20:44:12 +08:00
|
|
|
|
) service.MaterialService {
|
|
|
|
|
|
return service.NewMaterialService(subjectRepo, fileRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-15 02:25:10 +08:00
|
|
|
|
// parseDuration 解析时长字符串
|
|
|
|
|
|
func parseDuration(s string) (time.Duration, error) {
|
|
|
|
|
|
return time.ParseDuration(s)
|
|
|
|
|
|
}
|
2026-03-27 01:54:34 +08:00
|
|
|
|
|
|
|
|
|
|
// ProvideCallService 提供通话服务
|
|
|
|
|
|
func ProvideCallService(
|
|
|
|
|
|
callRepo repository.CallRepository,
|
|
|
|
|
|
wsHub *ws.Hub,
|
|
|
|
|
|
cfg *config.Config,
|
2026-03-28 00:20:56 +08:00
|
|
|
|
db *gorm.DB,
|
2026-03-27 01:54:34 +08:00
|
|
|
|
) service.CallService {
|
2026-03-28 00:20:56 +08:00
|
|
|
|
return service.NewCallService(callRepo, wsHub, cfg, db)
|
2026-03-27 01:54:34 +08:00
|
|
|
|
}
|
2026-03-29 20:18:36 +08:00
|
|
|
|
|
|
|
|
|
|
// ProvideReportService 提供举报服务
|
|
|
|
|
|
func ProvideReportService(
|
|
|
|
|
|
reportRepo repository.ReportRepository,
|
|
|
|
|
|
postRepo repository.PostRepository,
|
|
|
|
|
|
commentRepo repository.CommentRepository,
|
|
|
|
|
|
messageRepo repository.MessageRepository,
|
|
|
|
|
|
userRepo repository.UserRepository,
|
2026-03-30 03:44:24 +08:00
|
|
|
|
notifyRepo repository.SystemNotificationRepository,
|
|
|
|
|
|
pushService service.PushService,
|
2026-03-29 20:18:36 +08:00
|
|
|
|
txManager repository.TransactionManager,
|
2026-03-30 03:44:24 +08:00
|
|
|
|
logService service.OperationLogService,
|
2026-03-29 20:18:36 +08:00
|
|
|
|
cfg *config.Config,
|
|
|
|
|
|
) service.ReportService {
|
2026-03-30 03:44:24 +08:00
|
|
|
|
return service.NewReportService(reportRepo, postRepo, commentRepo, messageRepo, userRepo, notifyRepo, pushService, txManager, logService, cfg)
|
2026-03-29 20:18:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideAdminReportService 提供管理端举报服务
|
|
|
|
|
|
func ProvideAdminReportService(
|
|
|
|
|
|
reportRepo repository.ReportRepository,
|
|
|
|
|
|
postRepo repository.PostRepository,
|
|
|
|
|
|
commentRepo repository.CommentRepository,
|
|
|
|
|
|
messageRepo repository.MessageRepository,
|
|
|
|
|
|
userRepo repository.UserRepository,
|
2026-03-30 03:44:24 +08:00
|
|
|
|
notifyRepo repository.SystemNotificationRepository,
|
|
|
|
|
|
pushService service.PushService,
|
2026-03-29 20:18:36 +08:00
|
|
|
|
txManager repository.TransactionManager,
|
2026-03-30 03:44:24 +08:00
|
|
|
|
logService service.OperationLogService,
|
2026-03-29 20:18:36 +08:00
|
|
|
|
) service.AdminReportService {
|
2026-03-30 03:44:24 +08:00
|
|
|
|
return service.NewAdminReportService(reportRepo, postRepo, commentRepo, messageRepo, userRepo, notifyRepo, pushService, txManager, logService)
|
2026-03-29 20:18:36 +08:00
|
|
|
|
}
|
2026-04-05 20:27:03 +08:00
|
|
|
|
|
|
|
|
|
|
// ProvideVerificationService 提供身份认证服务
|
|
|
|
|
|
func ProvideVerificationService(
|
|
|
|
|
|
verificationRepo repository.VerificationRepository,
|
|
|
|
|
|
userRepo repository.UserRepository,
|
|
|
|
|
|
) service.VerificationService {
|
|
|
|
|
|
return service.NewVerificationService(verificationRepo, userRepo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ProvideAdminVerificationService 提供管理端身份认证服务
|
|
|
|
|
|
func ProvideAdminVerificationService(
|
|
|
|
|
|
verificationRepo repository.VerificationRepository,
|
|
|
|
|
|
userRepo repository.UserRepository,
|
|
|
|
|
|
) service.AdminVerificationService {
|
|
|
|
|
|
return service.NewAdminVerificationService(verificationRepo, userRepo)
|
|
|
|
|
|
}
|
2026-04-07 00:07:40 +08:00
|
|
|
|
|
|
|
|
|
|
// ProvideSensitiveService 提供敏感词服务
|
|
|
|
|
|
func ProvideSensitiveService(
|
|
|
|
|
|
sensitiveWordRepo repository.SensitiveWordRepository,
|
|
|
|
|
|
redisClient *redis.Client,
|
|
|
|
|
|
cfg *config.Config,
|
|
|
|
|
|
) service.SensitiveService {
|
|
|
|
|
|
sensitiveCfg := &service.SensitiveConfig{
|
|
|
|
|
|
Enabled: cfg.Sensitive.Enabled,
|
|
|
|
|
|
ReplaceStr: cfg.Sensitive.ReplaceStr,
|
|
|
|
|
|
MinMatchLen: cfg.Sensitive.MinMatchLen,
|
|
|
|
|
|
LoadFromDB: cfg.Sensitive.LoadFromDB,
|
|
|
|
|
|
LoadFromRedis: cfg.Sensitive.LoadFromRedis,
|
|
|
|
|
|
RedisKeyPrefix: cfg.Sensitive.RedisKeyPrefix,
|
|
|
|
|
|
}
|
|
|
|
|
|
return service.NewSensitiveService(sensitiveWordRepo, redisClient, sensitiveCfg)
|
|
|
|
|
|
}
|
2026-04-15 11:50:47 +08:00
|
|
|
|
|
|
|
|
|
|
func ProvideUserProfileAuditService(
|
|
|
|
|
|
auditRepo repository.UserProfileAuditRepository,
|
|
|
|
|
|
userRepo repository.UserRepository,
|
|
|
|
|
|
hookManager *hook.Manager,
|
|
|
|
|
|
moderationHooks *hook.ModerationHooks,
|
|
|
|
|
|
) service.UserProfileAuditService {
|
|
|
|
|
|
return service.NewUserProfileAuditService(auditRepo, userRepo, hookManager, moderationHooks)
|
|
|
|
|
|
}
|