feat(tenant): 隔离客服通知文件与后台任务
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/middleware"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
"hfb_sys/backend/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -38,7 +39,7 @@ func (h *Handler) UserEvents(c *gin.Context) {
|
||||
response.Unauthorized(c, "用户上下文无效")
|
||||
return
|
||||
}
|
||||
h.serveSSE(c, "user", userID)
|
||||
h.serveSSE(c, "user", userID, tenancy.IDFromContext(c.Request.Context()), false)
|
||||
}
|
||||
|
||||
// AdminEvents 处理管理端 SSE 连接: GET /api/admin/chats/events
|
||||
@@ -53,14 +54,20 @@ func (h *Handler) AdminEvents(c *gin.Context) {
|
||||
response.Unauthorized(c, "管理员上下文无效")
|
||||
return
|
||||
}
|
||||
h.serveSSE(c, "admin", adminID)
|
||||
platform := h.hub.IsPlatformAdmin(adminID)
|
||||
h.serveSSE(c, "admin", adminID, tenancy.IDFromContext(c.Request.Context()), platform)
|
||||
}
|
||||
|
||||
func (h *Handler) serveSSE(c *gin.Context, pType string, pID uint64) {
|
||||
func (h *Handler) serveSSE(c *gin.Context, pType string, pID, tenantID uint64, platform bool) {
|
||||
startedAt := time.Now()
|
||||
disconnectReason := "handler_completed"
|
||||
var disconnectErr error
|
||||
ch := h.hub.Subscribe(pType, pID)
|
||||
var ch <-chan *ChatEvent
|
||||
if pType == "admin" {
|
||||
ch = h.hub.SubscribeAdmin(pID, tenantID, platform)
|
||||
} else {
|
||||
ch = h.hub.SubscribeForTenant(pType, pID, tenantID)
|
||||
}
|
||||
h.logger.Info("SSE 连接建立", h.connectionLogFields(c, pType, pID)...)
|
||||
defer func() {
|
||||
h.hub.Unsubscribe(pType, pID, ch)
|
||||
|
||||
Reference in New Issue
Block a user