SSE 推送替代轮训

This commit is contained in:
yml2213
2026-05-27 06:18:55 +08:00
parent 1458fc279c
commit a002987784
9 changed files with 493 additions and 42 deletions
+19 -1
View File
@@ -12,6 +12,7 @@ import (
"hfb_sys/backend/internal/modules/adminuser"
"hfb_sys/backend/internal/modules/auth"
"hfb_sys/backend/internal/modules/chat"
"hfb_sys/backend/internal/modules/chathub"
"hfb_sys/backend/internal/modules/dispute"
filemodule "hfb_sys/backend/internal/modules/file"
"hfb_sys/backend/internal/modules/listing"
@@ -98,12 +99,23 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
}
notificationService := notification.NewService(notificationRepo)
notificationHandler := notification.NewHandler(notificationService)
var chatHub *chathub.Hub
if deps.DB != nil {
chatHub = chathub.NewHub(deps.DB)
}
var chatRepo *chat.Repository
if deps.DB != nil {
chatRepo = chat.NewRepository(deps.DB)
chatRepo = chat.NewRepository(deps.DB, chatHub)
}
chatService := chat.NewService(chatRepo)
chatHandler := chat.NewHandler(chatService)
var chatHubHandler *chathub.Handler
if chatHub != nil {
chatHubHandler = chathub.NewHandler(chatHub)
}
if orderRepo != nil && chatRepo != nil {
orderRepo.SetChatRepo(chatRepo)
}
var disputeRepo *dispute.Repository
if deps.DB != nil {
disputeRepo = dispute.NewRepository(deps.DB)
@@ -232,6 +244,9 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
chatRoutes := api.Group("/chats", requireAuth)
{
if chatHubHandler != nil {
chatRoutes.GET("/events", chatHubHandler.UserEvents)
}
chatRoutes.GET("", chatHandler.List)
chatRoutes.GET("/:id", chatHandler.Detail)
chatRoutes.GET("/:id/messages", chatHandler.Messages)
@@ -280,6 +295,9 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
adminRoutes.GET("/system-configs", requirePerm("system_config:view"), systemConfigHandler.List)
adminRoutes.PUT("/system-configs/:key", requirePerm("system_config:update"), systemConfigHandler.Update)
adminRoutes.GET("/audit-logs", requirePerm("audit_log:view"), adminAuditHandler.List)
if chatHubHandler != nil {
adminRoutes.GET("/chats/events", requirePerm("chat:view"), chatHubHandler.AdminEvents)
}
adminRoutes.GET("/chats", requirePerm("chat:view"), chatHandler.AdminList)
adminRoutes.GET("/chats/:id", requirePerm("chat:view"), chatHandler.AdminDetail)
adminRoutes.GET("/chats/:id/messages", requirePerm("chat:view"), chatHandler.AdminMessages)