refactor: 将客服后端重构为宿主可嵌入模块

- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。

- 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。

- 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。

- 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
This commit is contained in:
t
2026-08-28 22:23:13 +08:00
parent 6845c728f8
commit 18c9354095
377 changed files with 13199 additions and 22881 deletions
@@ -28,8 +28,8 @@ func ConversationAnyList(ctx *gin.Context) {
cnd := params.NewPagedSqlCnd(ctx,
params.QueryFilter{ParamName: "status"},
params.QueryFilter{ParamName: "serviceMode"},
params.QueryFilter{ParamName: "currentAssigneeId"},
params.QueryFilter{ParamName: "service_mode"},
params.QueryFilter{ParamName: "current_assignee_id"},
).Desc("last_message_at").Desc("id")
paging := params.GetPaging(ctx)
@@ -39,19 +39,7 @@ func ConversationAnyList(ctx *gin.Context) {
cnd.Where("customer_name LIKE ? OR last_message_summary LIKE ?", keywordLike, keywordLike)
}
// 标签搜索
if tagID, _ := params.GetInt64(ctx, "tagId"); tagID > 0 {
tagIDs := services.TagService.GetSelfAndDescendantIDs(tagID)
if len(tagIDs) == 0 {
httpx.WriteJSON(ctx, &web.PageResult{
Results: []response.ConversationResponse{},
Page: paging,
})
return
}
cnd.Where("id IN (SELECT conversation_id FROM conversation_tag_rels WHERE tag_id IN (?))", tagIDs)
}
if agentTeamID, _ := params.GetInt64(ctx, "agentTeamId"); agentTeamID > 0 {
if agentTeamID, _ := params.GetInt64(ctx, "agent_team_id"); agentTeamID > 0 {
userIDs := services.AgentProfileService.GetUserIDsByTeamID(agentTeamID)
if len(userIDs) == 0 {
httpx.WriteJSON(ctx, &web.PageResult{
@@ -130,9 +118,9 @@ func ConversationAnyMessage_list(ctx *gin.Context) {
}
var (
conversationID, _ = params.GetInt64(ctx, "conversationId")
senderType, _ = params.Get(ctx, "senderType")
messageType, _ = params.Get(ctx, "messageType")
conversationID, _ = params.GetInt64(ctx, "conversation_id")
senderType, _ = params.Get(ctx, "sender_type")
messageType, _ = params.Get(ctx, "message_type")
cursor, _ = params.GetInt64(ctx, "cursor")
limit, _ = params.GetInt(ctx, "limit")
)
@@ -225,24 +213,6 @@ func ConversationPostClose(ctx *gin.Context) {
httpx.WriteJSON(ctx, nil)
}
func ConversationPostLink_customer(ctx *gin.Context) {
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionConversationLinkCustomer)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.LinkConversationCustomerRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
if err := services.ConversationService.LinkConversationCustomer(req.ConversationID, req.CustomerID, operator); err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, nil)
}
func ConversationPostSend_message(ctx *gin.Context) {
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionConversationSend)
if err != nil {
@@ -309,7 +279,7 @@ func ConversationPostUpload_image(ctx *gin.Context) {
return
}
rawConv := strings.TrimSpace(params.FormValue(ctx, "conversationId"))
rawConv := strings.TrimSpace(params.FormValue(ctx, "conversation_id"))
if rawConv == "" {
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
@@ -334,7 +304,7 @@ func ConversationPostUpload_image(ctx *gin.Context) {
return
}
item, err := services.AssetService.UploadFile(header, "images", operator)
item, err := services.AssetService.UploadConversationImageFile(header, "images", conversationID, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
return
@@ -349,7 +319,7 @@ func ConversationPostUpload_attachment(ctx *gin.Context) {
return
}
rawConv := strings.TrimSpace(params.FormValue(ctx, "conversationId"))
rawConv := strings.TrimSpace(params.FormValue(ctx, "conversation_id"))
if rawConv == "" {
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
@@ -369,47 +339,10 @@ func ConversationPostUpload_attachment(ctx *gin.Context) {
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0324"))
return
}
item, err := services.AssetService.UploadFile(header, "attachments", operator)
item, err := services.AssetService.UploadConversationFile(header, "attachments", conversationID, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, builders.BuildAsset(item))
}
func ConversationPostAdd_tag(ctx *gin.Context) {
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionConversationTag)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.AddConversationTagRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
if err := services.ConversationTagService.AddTag(req, operator); err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, nil)
}
func ConversationPostRemove_tag(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionConversationTag); err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.RemoveConversationTagRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
if err := services.ConversationTagService.RemoveTag(req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, nil)
}