From 73b78a817dcff81ded6d7c401a864d173677131d Mon Sep 17 00:00:00 2001 From: mlogclub Date: Mon, 27 Apr 2026 18:40:25 +0800 Subject: [PATCH] refactor: remove ExternalType from CustomerIdentity and related structures --- .../controllers/api/channel_controller.go | 29 +++++++++---------- internal/models/models.go | 1 - internal/pkg/dto/response/widget_response.go | 15 +++++----- internal/pkg/enums/customer.go | 20 ------------- internal/pkg/enums/external_identity.go | 4 +-- internal/pkg/openidentity/openidentity.go | 2 -- internal/services/conversation_service.go | 1 - web/lib/generated/enums.ts | 9 ------ 8 files changed, 23 insertions(+), 58 deletions(-) diff --git a/internal/controllers/api/channel_controller.go b/internal/controllers/api/channel_controller.go index 8c59302..e84f9d7 100644 --- a/internal/controllers/api/channel_controller.go +++ b/internal/controllers/api/channel_controller.go @@ -19,20 +19,19 @@ func (c *ChannelController) AnyConfig() *web.JsonResult { if channel == nil { return web.JsonErrorMsg("接入渠道未初始化") } - cfg, externalSource, err := resolveWidgetConfig(channel.ChannelType, channel.ConfigJSON) + cfg, err := resolveWidgetConfig(channel.ChannelType, channel.ConfigJSON) if err != nil { return web.JsonError(err) } ret := response.WidgetConfigResponse{ - ChannelID: channel.ChannelID, - ChannelType: channel.ChannelType, - ExternalSource: externalSource, - Title: cfg.Title, - Subtitle: cfg.Subtitle, - ThemeColor: cfg.ThemeColor, - Position: cfg.Position, - Width: cfg.Width, + ChannelID: channel.ChannelID, + ChannelType: channel.ChannelType, + Title: cfg.Title, + Subtitle: cfg.Subtitle, + ThemeColor: cfg.ThemeColor, + Position: cfg.Position, + Width: cfg.Width, } return web.JsonData(ret) } @@ -45,12 +44,12 @@ type webLikeWidgetConfig struct { Width string } -func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, string, error) { +func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, error) { switch channelType { case enums.ChannelTypeWeb: cfg, err := services.ChannelService.ParseWebChannelConfig(rawConfig) if err != nil { - return nil, "", err + return nil, err } return &webLikeWidgetConfig{ Title: cfg.Title, @@ -58,11 +57,11 @@ func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, s ThemeColor: cfg.ThemeColor, Position: cfg.Position, Width: cfg.Width, - }, string(enums.ExternalSourceWebChat), nil + }, nil case enums.ChannelTypeWechatMP: cfg, err := services.ChannelService.ParseWechatMPChannelConfig(rawConfig) if err != nil { - return nil, "", err + return nil, err } return &webLikeWidgetConfig{ Title: cfg.Title, @@ -70,8 +69,8 @@ func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, s ThemeColor: cfg.ThemeColor, Position: "right", Width: "100%", - }, string(enums.ExternalSourceWechatMP), nil + }, nil default: - return nil, "", errorsx.InvalidParam("该渠道不支持开放客服配置") + return nil, errorsx.InvalidParam("该渠道不支持开放客服配置") } } diff --git a/internal/models/models.go b/internal/models/models.go index d318b79..79e6aa9 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -188,7 +188,6 @@ type Customer struct { type CustomerIdentity struct { ID int64 `gorm:"primaryKey;autoIncrement"` CustomerID int64 `gorm:"type:bigint;not null;uniqueIndex:uk_customer_external"` // 为所属客户ID。 - ExternalType enums.ExternalType `gorm:"type:varchar(30);not null;default:'guest';index"` // ExternalType 为外部身份类型:guest访客,user主动设置的用户信息。 ExternalSource enums.ExternalSource `gorm:"type:varchar(30);uniqueIndex:uk_customer_external"` // 为外部身份来源 ExternalID string `gorm:"type:varchar(128);index:idx_external_id;uniqueIndex:uk_customer_external"` // 为平台侧用户唯一ID,与访客 ExternalID 对齐。 RawProfile string `gorm:"type:text"` // 为第三方原始资料JSON。 diff --git a/internal/pkg/dto/response/widget_response.go b/internal/pkg/dto/response/widget_response.go index e6f4ba4..a423668 100644 --- a/internal/pkg/dto/response/widget_response.go +++ b/internal/pkg/dto/response/widget_response.go @@ -1,12 +1,11 @@ package response type WidgetConfigResponse struct { - ChannelID string `json:"channelId"` - ChannelType string `json:"channelType"` - ExternalSource string `json:"externalSource"` - Title string `json:"title"` - Subtitle string `json:"subtitle"` - ThemeColor string `json:"themeColor"` - Position string `json:"position"` - Width string `json:"width"` + ChannelID string `json:"channelId"` + ChannelType string `json:"channelType"` + Title string `json:"title"` + Subtitle string `json:"subtitle"` + ThemeColor string `json:"themeColor"` + Position string `json:"position"` + Width string `json:"width"` } diff --git a/internal/pkg/enums/customer.go b/internal/pkg/enums/customer.go index ad1930a..2a7d153 100644 --- a/internal/pkg/enums/customer.go +++ b/internal/pkg/enums/customer.go @@ -6,26 +6,6 @@ func GetCustomerSourceTypeLabel(sourceType ExternalSource) string { return GetExternalSourceLabel(ExternalSource(sourceType)) } -// ExternalType 客户外部身份类型。 -type ExternalType string - -const ( - ExternalTypeGuest ExternalType = "guest" - ExternalTypeUser ExternalType = "user" -) - -var externalTypeLabelMap = map[ExternalType]string{ - ExternalTypeGuest: "访客", - ExternalTypeUser: "用户", -} - -func GetExternalTypeLabel(externalType ExternalType) string { - if s, ok := externalTypeLabelMap[externalType]; ok { - return s - } - return string(externalType) -} - // 联系方式类型 type ContactType string diff --git a/internal/pkg/enums/external_identity.go b/internal/pkg/enums/external_identity.go index 203ff3c..f15d445 100644 --- a/internal/pkg/enums/external_identity.go +++ b/internal/pkg/enums/external_identity.go @@ -6,13 +6,13 @@ package enums type ExternalSource string const ( - ExternalSourceWebChat ExternalSource = "web_chat" + ExternalSourceWebChat ExternalSource = "guest" ExternalSourceWechatMP ExternalSource = "wechat_mp" ExternalSourceWxWorkKF ExternalSource = "wxwork_kf" ) var externalSourceLabelMap = map[ExternalSource]string{ - ExternalSourceWebChat: "网页客服", + ExternalSourceWebChat: "访客", ExternalSourceWechatMP: "微信公众号", ExternalSourceWxWorkKF: "企业微信客服", } diff --git a/internal/pkg/openidentity/openidentity.go b/internal/pkg/openidentity/openidentity.go index 2fe1021..e2ca501 100644 --- a/internal/pkg/openidentity/openidentity.go +++ b/internal/pkg/openidentity/openidentity.go @@ -15,7 +15,6 @@ import ( // ExternalInfo 外部访客身份(IM 客户),与站内 AuthPrincipal 区分。 type ExternalInfo struct { ExternalSource enums.ExternalSource `json:"externalSource"` - ExternalType enums.ExternalType `json:"externalType"` ExternalID string `json:"externalId"` ExternalName string `json:"externalName"` } @@ -36,7 +35,6 @@ func GetExternalInfo(ctx iris.Context) (*ExternalInfo, error) { return &ExternalInfo{ ExternalSource: externalSource, // TODO: 对接业务系统后,根据业务系统用户信息识别 user;未对接时统一按访客处理。 - ExternalType: enums.ExternalTypeGuest, ExternalID: externalID, ExternalName: parseExternalName(ctx), }, nil diff --git a/internal/services/conversation_service.go b/internal/services/conversation_service.go index e2df8ab..888ab21 100644 --- a/internal/services/conversation_service.go +++ b/internal/services/conversation_service.go @@ -744,7 +744,6 @@ func (s *conversationService) LinkConversationCustomer(conversationID, customerI } else { idRow := &models.CustomerIdentity{ CustomerID: customerID, - ExternalType: enums.ExternalTypeGuest, ExternalSource: enums.ExternalSource(extSrc), ExternalID: extID, Status: enums.StatusOk, diff --git a/web/lib/generated/enums.ts b/web/lib/generated/enums.ts index c303f1e..03de15e 100644 --- a/web/lib/generated/enums.ts +++ b/web/lib/generated/enums.ts @@ -82,15 +82,6 @@ export const ExternalSourceLabels: Record = { [ExternalSource.WxWorkKF]: "企业微信客服", } -export enum ExternalType { - Guest = "guest", - User = "user", -} -export const ExternalTypeLabels: Record = { - [ExternalType.Guest]: "访客", - [ExternalType.User]: "用户", -} - export enum Gender { Unknown = 0, Male = 1,