1
This commit is contained in:
27
model/entity/conversation.go
Normal file
27
model/entity/conversation.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
const ConversationCollection = "conversation"
|
||||
|
||||
// Conversation 对话记录实体
|
||||
type Conversation struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // 嵌入基础字段
|
||||
|
||||
// 业务字段
|
||||
UserId string `bson:"userId" json:"userId"` // 用户ID(含平台前缀)
|
||||
Platform string `bson:"platform" json:"platform"` // 平台标识
|
||||
SessionId string `bson:"sessionId" json:"sessionId"` // RAGFlow Session ID
|
||||
CustomerServiceId string `bson:"customerServiceId" json:"customerServiceId"` // 客服账号ID
|
||||
Role string `bson:"role" json:"role"` // 角色:user/assistant
|
||||
Content string `bson:"content" json:"content"` // 消息内容
|
||||
Question string `bson:"question" json:"question"` // 用户问题(兼容旧字段)
|
||||
Answer string `bson:"answer" json:"answer"` // AI 回复(兼容旧字段)
|
||||
MessageId string `bson:"messageId" json:"messageId"` // 消息ID
|
||||
MessageType string `bson:"messageType" json:"messageType"` // 消息类型(TEXT/IMAGE/VIDEO等)
|
||||
MsgTime *time.Time `bson:"msgTime" json:"msgTime"` // 消息时间
|
||||
}
|
||||
71
model/entity/conversation_archive.go
Normal file
71
model/entity/conversation_archive.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// ConversationArchiveTempCollection 归档临时表名
|
||||
const ConversationArchiveTempCollection = "conversation_archive_temp"
|
||||
|
||||
// ConversationArchiveTemp 归档临时表实体(与 Conversation 结构相同)
|
||||
type ConversationArchiveTemp struct {
|
||||
beans.MongoBaseDO `bson:",inline"`
|
||||
|
||||
UserId string `bson:"userId" json:"userId"`
|
||||
Platform string `bson:"platform" json:"platform"`
|
||||
SessionId string `bson:"sessionId" json:"sessionId"`
|
||||
Question string `bson:"question" json:"question"`
|
||||
Answer string `bson:"answer" json:"answer"`
|
||||
MessageId string `bson:"messageId" json:"messageId"`
|
||||
MsgTime *time.Time `bson:"msgTime" json:"msgTime"` // 指针类型,与MongoBaseDO一致
|
||||
|
||||
// 原始文档 ID,用于删除原表数据
|
||||
OriginalId string `bson:"originalId" json:"originalId"`
|
||||
}
|
||||
|
||||
// ConversationES ES 索引文档结构
|
||||
type ConversationES struct {
|
||||
Id string `json:"id"` // MongoDB 原始 ID
|
||||
UserId string `json:"userId"` // 用户ID
|
||||
Platform string `json:"platform"` // 平台
|
||||
SessionId string `json:"sessionId"` // Session ID
|
||||
Question string `json:"question"` // 问题
|
||||
Answer string `json:"answer"` // 回复
|
||||
MessageId string `json:"messageId"` // 消息ID
|
||||
MsgTime time.Time `json:"msgTime"` // 消息时间
|
||||
TenantId string `json:"tenantId"` // 租户ID
|
||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
|
||||
ArchivedAt time.Time `json:"archivedAt"` // 归档时间
|
||||
}
|
||||
|
||||
// ConversationESMapping ES 索引映射
|
||||
const ConversationESMapping = `
|
||||
{
|
||||
"settings": {
|
||||
"number_of_shards": 3,
|
||||
"number_of_replicas": 1
|
||||
},
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"id": { "type": "keyword" },
|
||||
"userId": { "type": "keyword" },
|
||||
"platform": { "type": "keyword" },
|
||||
"sessionId": { "type": "keyword" },
|
||||
"question": { "type": "text", "analyzer": "standard" },
|
||||
"answer": { "type": "text", "analyzer": "standard" },
|
||||
"messageId": { "type": "keyword" },
|
||||
"msgTime": { "type": "date" },
|
||||
"tenantId": { "type": "keyword" },
|
||||
"createdAt": { "type": "date" },
|
||||
"updatedAt": { "type": "date" },
|
||||
"archivedAt": { "type": "date" }
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
// ConversationESIndex ES 索引名
|
||||
const ConversationESIndex = "conversations"
|
||||
33
model/entity/customer_service_account.go
Normal file
33
model/entity/customer_service_account.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// CustomerServiceAccount 客服账号实体
|
||||
const CustomerServiceAccountCollection = "customer_service_account"
|
||||
|
||||
type CustomerServiceAccount struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||
|
||||
// 业务字段
|
||||
AccountName string `bson:"accountName" json:"accountName"` // 客服账号名称(如cs_xhs_qixue)
|
||||
IsDisabled bool `bson:"isDisabled" json:"isDisabled"` // 是否禁用(true-禁用,false-启用)
|
||||
Greeting string `bson:"greeting" json:"greeting"` // 开场白(WebSocket连接时自动发送)
|
||||
Prompt string `bson:"-" json:"prompt"` // 提示词(不存储到MongoDB,查询时从ragflow_config关联获取)
|
||||
SelfIdentity string `bson:"selfIdentity" json:"selfIdentity"` // AI身份描述(前端显示为"AI身份")
|
||||
|
||||
// 绑定的资源(主体持有关系)
|
||||
SpeechcraftIds []string `bson:"speechcraftIds" json:"speechcraftIds"` // 绑定的话术ID列表
|
||||
ProductIds []string `bson:"productIds" json:"productIds"` // 绑定的产品ID列表
|
||||
Platform string `bson:"platform" json:"platform"` // 客服平台(如:xiaohongshu、douyin、kuaishou)
|
||||
|
||||
// 小红书平台专属字段(仅platform=xiaohongshu时有效)
|
||||
AccessToken string `bson:"accessToken,omitempty" json:"accessToken,omitempty"` // 小红书AccessToken(14天有效期)
|
||||
AppId int64 `bson:"appId,omitempty" json:"appId,omitempty"` // 小红书应用ID
|
||||
SecretKey string `bson:"secretKey,omitempty" json:"secretKey,omitempty"` // 小红书加解密密钥
|
||||
XhsUserId string `bson:"xhsUserId,omitempty" json:"xhsUserId,omitempty"` // 小红书用户ID
|
||||
ContactCardMessage string `bson:"contactCardMessage,omitempty" json:"contactCardMessage,omitempty"` // 留资卡文案(不同领域客服使用不同文案)
|
||||
NameCardMessage string `bson:"nameCardMessage,omitempty" json:"nameCardMessage,omitempty"` // 名片文案(不同领域客服使用不同文案)
|
||||
CardTriggerCount int `bson:"cardTriggerCount,omitempty" json:"cardTriggerCount,omitempty"` // 卡片触发次数(默认5,不同客服可定制)
|
||||
}
|
||||
25
model/entity/data.go
Normal file
25
model/entity/data.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
const DataCollection = "data"
|
||||
|
||||
type Data struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||
|
||||
// 业务字段
|
||||
CustomerId string `bson:"customerId" json:"customerId"` // 客户ID
|
||||
AccountName string `bson:"accountName" json:"accountName"` // 客服账号名称
|
||||
CustomerServicePlatform string `bson:"customerServicePlatform" json:"customerServicePlatform"` // 客服平台
|
||||
CustomerServiceName string `bson:"customerServiceName" json:"customerServiceName"` // 客服名称
|
||||
IsInbound bool `bson:"isInbound" json:"isInbound"` // 用户是否点开了客服页面
|
||||
IsActive bool `bson:"isActive" json:"isActive"` // 用户是否开口询问
|
||||
IsServed bool `bson:"isServed" json:"isServed"` // 客服是否回答了用户
|
||||
HasSentContactCard bool `bson:"hasSentContactCard" json:"hasSentContactCard"` // 客服是否发送了联系卡
|
||||
HasSentNameCard bool `bson:"hasSentNameCard" json:"hasSentNameCard"` // 客服是否发送了名称卡
|
||||
HasLeftContactInfo bool `bson:"hasLeftContactInfo" json:"hasLeftContactInfo"` // 用户是否留下了联系信息
|
||||
SessionStartTime int64 `bson:"sessionStartTime" json:"sessionStartTime"` // 业务数据的时间
|
||||
MessageTime int64 `bson:"messageTime" json:"messageTime"` // 消息时间
|
||||
}
|
||||
30
model/entity/data_statistics.go
Normal file
30
model/entity/data_statistics.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
const DataStatisticsCollection = "data_statistics"
|
||||
|
||||
// DataStatistics 数据统计实体 (用于存储每天/每位客服的汇总数据)
|
||||
type DataStatistics struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||
Date *time.Time `bson:"date" json:"date"` // 统计日期 (格式: YYYY-MM-DD)
|
||||
AccountName string `bson:"accountName" json:"accountName"` // 客服账号名称
|
||||
CustomerServiceName string `bson:"customerServiceName" json:"customerServiceName"` // 客服名称
|
||||
CustomerServicePlatform string `bson:"customerServicePlatform" json:"customerServicePlatform"` // 客服平台
|
||||
|
||||
// 以下字段由 Data 表中的 bool 字段累加统计得出
|
||||
InboundCount int `bson:"inboundCount" json:"inboundCount"` // 进线人数 (汇总 IsInbound)
|
||||
ActiveCount int `bson:"activeCount" json:"activeCount"` // 开口人数 (汇总 IsActive)
|
||||
ServedCount int `bson:"servedCount" json:"servedCount"` // 接待人数 (汇总 IsServed)
|
||||
ContactCardSentCount int `bson:"contactCardSentCount" json:"contactCardSentCount"` // 留资卡发送数量 (汇总 HasSentContactCard)
|
||||
NameCardSentCount int `bson:"nameCardSentCount" json:"nameCardSentCount"` // 名片发送数量 (汇总 HasSentNameCard)
|
||||
LeftContactInfoCount int `bson:"leftContactInfoCount" json:"leftContactInfoCount"` // 留资人数 (汇总 HasLeftContactInfo)
|
||||
|
||||
ResponseRate30s float64 `bson:"responseRate30s" json:"responseRate30s"` // 30秒响应率
|
||||
ResponseRate60s float64 `bson:"responseRate60s" json:"responseRate60s"` // 60秒响应率
|
||||
ResponseRate360s float64 `bson:"responseRate360s" json:"responseRate360s"` // 360秒响应率
|
||||
}
|
||||
25
model/entity/product.go
Normal file
25
model/entity/product.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Package entity - 产品实体
|
||||
// 功能:定义产品表结构,支持多客服账号绑定、RAGFlow同步记录
|
||||
package entity
|
||||
|
||||
import (
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// Product 产品实体
|
||||
const ProductCollection = "product"
|
||||
|
||||
type Product struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||
|
||||
// 业务字段
|
||||
Name string `bson:"name" json:"name"` // 产品名称
|
||||
Description string `bson:"description" json:"description"` // 产品详情
|
||||
|
||||
// 客服账号绑定(一个产品可以被多个账号使用)
|
||||
AccountNames []string `bson:"accountNames" json:"accountNames"` // 绑定的客服账号名称列表
|
||||
|
||||
// RAGFlow同步字段(租户级知识库,每个客服账号独立同步记录)
|
||||
RagSyncRecords []RagSyncRecord `bson:"ragSyncRecords" json:"ragSyncRecords"` // RAGFlow同步记录(按客服账号)
|
||||
RagLastSyncTime string `bson:"ragLastSyncTime" json:"ragLastSyncTime"` // 最后同步时间
|
||||
}
|
||||
13
model/entity/ragflow_binding.go
Normal file
13
model/entity/ragflow_binding.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// Package entity - RAGFlow同步相关实体
|
||||
// 功能:RAGFlow同步记录(话术和产品共用)
|
||||
package entity
|
||||
|
||||
// RagSyncRecord RAGFlow同步记录
|
||||
// 说明:租户级知识库,每个客服账号独立的文档ID
|
||||
type RagSyncRecord struct {
|
||||
AccountName string `bson:"accountName" json:"accountName"` // 客服账号名称
|
||||
RagDocumentId string `bson:"ragDocumentId" json:"ragDocumentId"` // RAGFlow文档ID(租户级知识库中的文档)
|
||||
RagSyncStatus string `bson:"ragSyncStatus" json:"ragSyncStatus"` // 同步状态:synced/pending/failed
|
||||
SyncTime string `bson:"syncTime" json:"syncTime"` // 同步时间
|
||||
RetryCount int `bson:"retryCount" json:"retryCount"` // 重试次数
|
||||
}
|
||||
46
model/entity/ragflow_config.go
Normal file
46
model/entity/ragflow_config.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Package entity - RAGFlow配置实体
|
||||
// 功能:客服账号级RAGFlow配置,每个客服账号一个独立的对话实例
|
||||
// 架构说明:
|
||||
// - 租户级:一个知识库(dataset),存储所有话术
|
||||
// - 客服级:每个客服有独立的Chat实例,通过document_ids筛选使用哪些话术
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
const RAGFlowConfigCollection = "ragflow_config"
|
||||
|
||||
// RAGFlowConfig RAGFlow配置实体(客服账号级别)
|
||||
type RAGFlowConfig struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // TenantId继承自基础DO
|
||||
|
||||
// 客服账号标识
|
||||
AccountName string `bson:"accountName" json:"accountName"` // 客服账号名称
|
||||
Platform string `bson:"platform" json:"platform"` // 平台(xiaohongshu、douyin)
|
||||
|
||||
// 租户级知识库(整个租户共享)
|
||||
DatasetId string `bson:"datasetId" json:"datasetId"` // 话术知识库ID(RAGFlow)
|
||||
DatasetIds []string `bson:"datasetIds" json:"datasetIds"` // Chat绑定的知识库ID列表(与RAGFlow API保持一致)
|
||||
DatasetName string `bson:"datasetName" json:"datasetName"` // 话术知识库名称
|
||||
|
||||
// 客服账号级对话实例(每个客服独立)
|
||||
ChatId string `bson:"chatId" json:"chatId"` // RAGFlow对话实例ID
|
||||
Prompt string `bson:"prompt" json:"prompt"` // 提示词内容(完整)
|
||||
|
||||
// 文档筛选(该客服使用哪些话术文档)
|
||||
DocumentIds []string `bson:"documentIds" json:"documentIds"` // 绑定的话术文档ID列表(从租户知识库中筛选)
|
||||
|
||||
// 检索参数
|
||||
SimilarityThreshold float64 `bson:"similarityThreshold" json:"similarityThreshold"` // 相似度阈值(默认0.2)
|
||||
KeywordsSimilarityWeight float64 `bson:"keywordsSimilarityWeight" json:"keywordsSimilarityWeight"` // 关键词权重(默认0.7)
|
||||
TopN int `bson:"topN" json:"topN"` // 返回chunk数量(默认8)
|
||||
EmptyResponse string `bson:"emptyResponse" json:"emptyResponse"` // 无匹配时回复
|
||||
|
||||
// 同步状态
|
||||
SyncStatus string `bson:"syncStatus" json:"syncStatus"` // synced/pending/failed
|
||||
LastSyncTime *time.Time `bson:"lastSyncTime" json:"lastSyncTime"` // 最后同步时间
|
||||
SyncError string `bson:"syncError" json:"syncError"` // 同步错误信息
|
||||
}
|
||||
29
model/entity/session.go
Normal file
29
model/entity/session.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
const SessionCollection = "session"
|
||||
|
||||
// SessionStatus 会话状态
|
||||
const (
|
||||
SessionStatusActive = "active" // 活跃中
|
||||
SessionStatusArchived = "archived" // 已归档
|
||||
)
|
||||
|
||||
// Session 会话实体
|
||||
type Session struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // 嵌入基础字段
|
||||
|
||||
// 业务字段
|
||||
UserId string `bson:"userId" json:"userId"` // 用户ID(含平台前缀)
|
||||
Platform string `bson:"platform" json:"platform"` // 平台标识
|
||||
SessionId string `bson:"sessionId" json:"sessionId"` // RAGFlow Session ID
|
||||
Status string `bson:"status" json:"status"` // 状态:active/archived
|
||||
MessageCount int `bson:"messageCount" json:"messageCount"` // 消息数量
|
||||
LastActiveAt *time.Time `bson:"lastActiveAt" json:"lastActiveAt"` // 最后活跃时间
|
||||
ArchivedAt *time.Time `bson:"archivedAt" json:"archivedAt"` // 归档时间
|
||||
}
|
||||
32
model/entity/speechcraft.go
Normal file
32
model/entity/speechcraft.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Package entity - 话术实体
|
||||
// 功能:定义话术表结构,支持多客服账号绑定、RAGFlow同步记录
|
||||
package entity
|
||||
|
||||
import (
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// Speechcraft 话术实体
|
||||
const SpeechcraftCollection = "speechcraft"
|
||||
|
||||
type Speechcraft struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // 嵌入基础字段:Id, Creator, CreatedAt, Updater, UpdatedAt, TenantId, IsDeleted
|
||||
|
||||
// 原有字段
|
||||
Tag string `bson:"tag" json:"tag"` // 标签(用于分类)
|
||||
Content string `bson:"content" json:"content"` // 话术内容
|
||||
|
||||
// 状态机字段
|
||||
Stage int `bson:"stage" json:"stage"` // 触发阶段(0=初始)
|
||||
Status string `bson:"status" json:"status"` // 触发行为(click/keyword/空=任意)
|
||||
Keywords []string `bson:"keywords" json:"keywords"` // 触发关键字(空=任意)
|
||||
NextStage int `bson:"nextStage" json:"nextStage"` // 下一阶段(-1=结束)
|
||||
Platform string `bson:"platform" json:"platform"` // 平台(xiaohongshu)
|
||||
|
||||
// 业务分类
|
||||
Direction string `bson:"direction" json:"direction"` // 咨询方向(气血、减肥、护肤等)
|
||||
|
||||
// RAGFlow同步字段(租户级知识库,每个客服账号独立同步记录)
|
||||
RagSyncRecords []RagSyncRecord `bson:"ragSyncRecords" json:"ragSyncRecords"` // RAGFlow同步记录(按客服账号)
|
||||
RagLastSyncTime string `bson:"ragLastSyncTime" json:"ragLastSyncTime"` // 最后同步时间
|
||||
}
|
||||
45
model/entity/user_stage.go
Normal file
45
model/entity/user_stage.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// UserStage 用户阶段实体(记录用户在话术引导流程中的当前阶段)
|
||||
const UserStageCollection = "user_stage"
|
||||
|
||||
type UserStage struct {
|
||||
beans.MongoBaseDO `bson:",inline"` // 嵌入基础字段
|
||||
|
||||
// 业务字段
|
||||
UserId string `bson:"userId" json:"userId"` // 用户ID(含平台前缀)
|
||||
Platform string `bson:"platform" json:"platform"` // 平台标识
|
||||
Stage int `bson:"stage" json:"stage"` // 当前阶段(0=初始)
|
||||
Status string `bson:"status" json:"status"` // 最近行为(click/keyword 等)
|
||||
LastMsgAt *time.Time `bson:"lastMsgAt" json:"lastMsgAt"` // 最后消息时间
|
||||
AccountName string `bson:"accountName" json:"accountName"` // 用户选择的方向对应的客服账号名称
|
||||
}
|
||||
|
||||
// 阶段常量
|
||||
const (
|
||||
StageInit = 0 // 初始
|
||||
StageAutoComment = 1 // 自动跟评
|
||||
StageClick = 2 // 点击
|
||||
StageAutoReply = 3 // 点击自动回复
|
||||
StageSendImage = 4 // 发图
|
||||
StageOpenDoor = 5 // 开口询问
|
||||
StageReply1 = 6 // 回复1
|
||||
StageReply2 = 7 // 回复2
|
||||
StageReply3 = 8 // 回复3
|
||||
StageReply4 = 9 // 回复4
|
||||
StageFollowUp = 10 // 追问
|
||||
StageEnd = 99 // 结束
|
||||
)
|
||||
|
||||
// 用户行为常量
|
||||
const (
|
||||
StatusIdle = "" // 空闲/任意
|
||||
StatusClick = "click" // 点击
|
||||
StatusKeyword = "keyword" // 发关键字
|
||||
)
|
||||
Reference in New Issue
Block a user