refactor(server): 会话/访客/设置业务逻辑下沉 internal/service 层,handler 瘦身
- handler 只保留请求绑定、权限检查与响应映射;业务校验顺序、状态码与文案逐字保留 - 新增 service.Error 语义错误,由 handler 统一映射 HTTP 响应 - session 875→361 行、widget 745→321 行、settings 540→73 行 - 自动分配/租户设置(工作时间、欢迎语)/消息校验/黑名单检查/联系方式提取随迁 service 包 - 相关单元测试随迁 service 包,go test ./... 全部通过
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"kefu-cloud/server/internal/middleware"
|
||||
"kefu-cloud/server/internal/model"
|
||||
"kefu-cloud/server/internal/service"
|
||||
)
|
||||
|
||||
type CustomerHandler struct{}
|
||||
@@ -85,7 +86,7 @@ func (h *CustomerHandler) Get(c *gin.Context) {
|
||||
sessionQuery = sessionQuery.Where("agent_id = ?", middleware.GetUserID(c))
|
||||
}
|
||||
sessionQuery.Order("created_at desc").Limit(20).Find(&sessions)
|
||||
contacts := listCustomerContacts(customer.ID)
|
||||
contacts := service.ListCustomerContacts(customer.ID)
|
||||
|
||||
middleware.JSON(c, gin.H{
|
||||
"customer": customer,
|
||||
@@ -207,18 +208,18 @@ func (h *CustomerHandler) Create(c *gin.Context) {
|
||||
}
|
||||
syncCustomerPhones(tenantID, customer.ID, phones)
|
||||
// 主字段微信/邮箱/QQ 也写入 contacts(便于统一展示)
|
||||
var extras []extractedContact
|
||||
var extras []service.ExtractedContact
|
||||
if customer.Wechat != "" {
|
||||
extras = append(extras, extractedContact{Kind: "wechat", Value: customer.Wechat})
|
||||
extras = append(extras, service.ExtractedContact{Kind: "wechat", Value: customer.Wechat})
|
||||
}
|
||||
if customer.QQ != "" {
|
||||
extras = append(extras, extractedContact{Kind: "qq", Value: customer.QQ})
|
||||
extras = append(extras, service.ExtractedContact{Kind: "qq", Value: customer.QQ})
|
||||
}
|
||||
if customer.Email != "" {
|
||||
extras = append(extras, extractedContact{Kind: "email", Value: customer.Email})
|
||||
extras = append(extras, service.ExtractedContact{Kind: "email", Value: customer.Email})
|
||||
}
|
||||
if len(extras) > 0 {
|
||||
_, _ = mergeCustomerContacts(tenantID, customer.ID, extras, "agent")
|
||||
_, _ = service.MergeCustomerContacts(tenantID, customer.ID, extras, "agent")
|
||||
}
|
||||
|
||||
middleware.JSON(c, customer)
|
||||
|
||||
Reference in New Issue
Block a user