refactor: remove ExternalType from CustomerIdentity and related structures

This commit is contained in:
mlogclub
2026-04-27 18:40:25 +08:00
parent f8b44ab127
commit 73b78a817d
8 changed files with 23 additions and 58 deletions
+14 -15
View File
@@ -19,20 +19,19 @@ func (c *ChannelController) AnyConfig() *web.JsonResult {
if channel == nil { if channel == nil {
return web.JsonErrorMsg("接入渠道未初始化") return web.JsonErrorMsg("接入渠道未初始化")
} }
cfg, externalSource, err := resolveWidgetConfig(channel.ChannelType, channel.ConfigJSON) cfg, err := resolveWidgetConfig(channel.ChannelType, channel.ConfigJSON)
if err != nil { if err != nil {
return web.JsonError(err) return web.JsonError(err)
} }
ret := response.WidgetConfigResponse{ ret := response.WidgetConfigResponse{
ChannelID: channel.ChannelID, ChannelID: channel.ChannelID,
ChannelType: channel.ChannelType, ChannelType: channel.ChannelType,
ExternalSource: externalSource, Title: cfg.Title,
Title: cfg.Title, Subtitle: cfg.Subtitle,
Subtitle: cfg.Subtitle, ThemeColor: cfg.ThemeColor,
ThemeColor: cfg.ThemeColor, Position: cfg.Position,
Position: cfg.Position, Width: cfg.Width,
Width: cfg.Width,
} }
return web.JsonData(ret) return web.JsonData(ret)
} }
@@ -45,12 +44,12 @@ type webLikeWidgetConfig struct {
Width string Width string
} }
func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, string, error) { func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, error) {
switch channelType { switch channelType {
case enums.ChannelTypeWeb: case enums.ChannelTypeWeb:
cfg, err := services.ChannelService.ParseWebChannelConfig(rawConfig) cfg, err := services.ChannelService.ParseWebChannelConfig(rawConfig)
if err != nil { if err != nil {
return nil, "", err return nil, err
} }
return &webLikeWidgetConfig{ return &webLikeWidgetConfig{
Title: cfg.Title, Title: cfg.Title,
@@ -58,11 +57,11 @@ func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, s
ThemeColor: cfg.ThemeColor, ThemeColor: cfg.ThemeColor,
Position: cfg.Position, Position: cfg.Position,
Width: cfg.Width, Width: cfg.Width,
}, string(enums.ExternalSourceWebChat), nil }, nil
case enums.ChannelTypeWechatMP: case enums.ChannelTypeWechatMP:
cfg, err := services.ChannelService.ParseWechatMPChannelConfig(rawConfig) cfg, err := services.ChannelService.ParseWechatMPChannelConfig(rawConfig)
if err != nil { if err != nil {
return nil, "", err return nil, err
} }
return &webLikeWidgetConfig{ return &webLikeWidgetConfig{
Title: cfg.Title, Title: cfg.Title,
@@ -70,8 +69,8 @@ func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, s
ThemeColor: cfg.ThemeColor, ThemeColor: cfg.ThemeColor,
Position: "right", Position: "right",
Width: "100%", Width: "100%",
}, string(enums.ExternalSourceWechatMP), nil }, nil
default: default:
return nil, "", errorsx.InvalidParam("该渠道不支持开放客服配置") return nil, errorsx.InvalidParam("该渠道不支持开放客服配置")
} }
} }
-1
View File
@@ -188,7 +188,6 @@ type Customer struct {
type CustomerIdentity struct { type CustomerIdentity struct {
ID int64 `gorm:"primaryKey;autoIncrement"` ID int64 `gorm:"primaryKey;autoIncrement"`
CustomerID int64 `gorm:"type:bigint;not null;uniqueIndex:uk_customer_external"` // 为所属客户ID。 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"` // 为外部身份来源 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 对齐。 ExternalID string `gorm:"type:varchar(128);index:idx_external_id;uniqueIndex:uk_customer_external"` // 为平台侧用户唯一ID,与访客 ExternalID 对齐。
RawProfile string `gorm:"type:text"` // 为第三方原始资料JSON。 RawProfile string `gorm:"type:text"` // 为第三方原始资料JSON。
+7 -8
View File
@@ -1,12 +1,11 @@
package response package response
type WidgetConfigResponse struct { type WidgetConfigResponse struct {
ChannelID string `json:"channelId"` ChannelID string `json:"channelId"`
ChannelType string `json:"channelType"` ChannelType string `json:"channelType"`
ExternalSource string `json:"externalSource"` Title string `json:"title"`
Title string `json:"title"` Subtitle string `json:"subtitle"`
Subtitle string `json:"subtitle"` ThemeColor string `json:"themeColor"`
ThemeColor string `json:"themeColor"` Position string `json:"position"`
Position string `json:"position"` Width string `json:"width"`
Width string `json:"width"`
} }
-20
View File
@@ -6,26 +6,6 @@ func GetCustomerSourceTypeLabel(sourceType ExternalSource) string {
return GetExternalSourceLabel(ExternalSource(sourceType)) 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 type ContactType string
+2 -2
View File
@@ -6,13 +6,13 @@ package enums
type ExternalSource string type ExternalSource string
const ( const (
ExternalSourceWebChat ExternalSource = "web_chat" ExternalSourceWebChat ExternalSource = "guest"
ExternalSourceWechatMP ExternalSource = "wechat_mp" ExternalSourceWechatMP ExternalSource = "wechat_mp"
ExternalSourceWxWorkKF ExternalSource = "wxwork_kf" ExternalSourceWxWorkKF ExternalSource = "wxwork_kf"
) )
var externalSourceLabelMap = map[ExternalSource]string{ var externalSourceLabelMap = map[ExternalSource]string{
ExternalSourceWebChat: "网页客服", ExternalSourceWebChat: "访客",
ExternalSourceWechatMP: "微信公众号", ExternalSourceWechatMP: "微信公众号",
ExternalSourceWxWorkKF: "企业微信客服", ExternalSourceWxWorkKF: "企业微信客服",
} }
@@ -15,7 +15,6 @@ import (
// ExternalInfo 外部访客身份(IM 客户),与站内 AuthPrincipal 区分。 // ExternalInfo 外部访客身份(IM 客户),与站内 AuthPrincipal 区分。
type ExternalInfo struct { type ExternalInfo struct {
ExternalSource enums.ExternalSource `json:"externalSource"` ExternalSource enums.ExternalSource `json:"externalSource"`
ExternalType enums.ExternalType `json:"externalType"`
ExternalID string `json:"externalId"` ExternalID string `json:"externalId"`
ExternalName string `json:"externalName"` ExternalName string `json:"externalName"`
} }
@@ -36,7 +35,6 @@ func GetExternalInfo(ctx iris.Context) (*ExternalInfo, error) {
return &ExternalInfo{ return &ExternalInfo{
ExternalSource: externalSource, ExternalSource: externalSource,
// TODO: 对接业务系统后,根据业务系统用户信息识别 user;未对接时统一按访客处理。 // TODO: 对接业务系统后,根据业务系统用户信息识别 user;未对接时统一按访客处理。
ExternalType: enums.ExternalTypeGuest,
ExternalID: externalID, ExternalID: externalID,
ExternalName: parseExternalName(ctx), ExternalName: parseExternalName(ctx),
}, nil }, nil
@@ -744,7 +744,6 @@ func (s *conversationService) LinkConversationCustomer(conversationID, customerI
} else { } else {
idRow := &models.CustomerIdentity{ idRow := &models.CustomerIdentity{
CustomerID: customerID, CustomerID: customerID,
ExternalType: enums.ExternalTypeGuest,
ExternalSource: enums.ExternalSource(extSrc), ExternalSource: enums.ExternalSource(extSrc),
ExternalID: extID, ExternalID: extID,
Status: enums.StatusOk, Status: enums.StatusOk,
-9
View File
@@ -82,15 +82,6 @@ export const ExternalSourceLabels: Record<ExternalSource, string> = {
[ExternalSource.WxWorkKF]: "企业微信客服", [ExternalSource.WxWorkKF]: "企业微信客服",
} }
export enum ExternalType {
Guest = "guest",
User = "user",
}
export const ExternalTypeLabels: Record<ExternalType, string> = {
[ExternalType.Guest]: "访客",
[ExternalType.User]: "用户",
}
export enum Gender { export enum Gender {
Unknown = 0, Unknown = 0,
Male = 1, Male = 1,