Refactor error handling in services to use internationalized error messages

- Updated OSSStorage validation errors to use internationalized messages.
- Changed error messages in provider.go for unsupported file storage types.
- Refactored tag_service.go to replace hardcoded error messages with internationalized versions.
- Updated ticket_service.go to use internationalized error messages for various validation checks.
- Refactored ticket_tag_service.go to use internationalized error messages for tag validation.
- Changed ticket_view_service.go to use internationalized error messages for view validation.
- Updated tool_catalog_service.go to use internationalized error messages for tool code validation.
- Refactored user_service.go to replace error messages with internationalized versions.
- Updated ws_service.go to use internationalized error messages for WebSocket handling.
- Refactored wxwork_kf_inbound_service.go to use internationalized error messages for message handling.
- Updated wxwork_kf_outbound_service.go to use internationalized error messages for outbound message handling.
- Refactored wxwork_login_service.go to use internationalized error messages for login handling.
- Updated login.go in wxwork package to use internationalized error messages for login state and ticket validation.
This commit is contained in:
mlogclub
2026-06-02 20:51:13 +08:00
parent 77be1b4f5e
commit 0b4a1b4594
103 changed files with 1688 additions and 1350 deletions
+2 -3
View File
@@ -8,13 +8,12 @@ import (
"agent-desk/internal/services"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
)
func ChannelAnyConfig(ctx *gin.Context) {
channel := services.ChannelService.GetEnabledChannel(ctx)
if channel == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
cfg, err := resolveWidgetConfig(channel.ChannelType, channel.ConfigJSON)
@@ -70,6 +69,6 @@ func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, e
Width: "100%",
}, nil
default:
return nil, errorsx.InvalidParam("该渠道不支持开放客服配置")
return nil, errorsx.InvalidParamI18n("error.e0313")
}
}
@@ -11,7 +11,6 @@ import (
"agent-desk/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
)
func ConversationGetBy(ctx *gin.Context) {
@@ -20,22 +19,22 @@ func ConversationGetBy(ctx *gin.Context) {
return
}
if services.ChannelService.GetEnabledChannel(ctx) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
external := httpx.GetExternalUser(ctx)
if external == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("外部身份未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0150"))
return
}
item := services.ConversationService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("会话不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0116"))
return
}
if !services.ConversationService.IsCustomerConversationOwner(item, *external) {
httpx.WriteJSON(ctx, web.JsonErrorMsg("无权访问该会话"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0222"))
return
}
@@ -49,12 +48,12 @@ func ConversationGetBy(ctx *gin.Context) {
func ConversationPostCreate_or_match(ctx *gin.Context) {
channel := services.ChannelService.GetEnabledChannel(ctx)
if channel == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
external := httpx.GetExternalUser(ctx)
if external == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("外部身份未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0150"))
return
}
@@ -68,12 +67,12 @@ func ConversationPostCreate_or_match(ctx *gin.Context) {
func ConversationPostClose(ctx *gin.Context) {
if services.ChannelService.GetEnabledChannel(ctx) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
external := httpx.GetExternalUser(ctx)
if external == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("外部身份未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0150"))
return
}
+1 -2
View File
@@ -6,13 +6,12 @@ import (
"agent-desk/internal/services"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
)
func CustomerPostSession_exchange(ctx *gin.Context) {
channel := services.ChannelService.GetEnabledChannel(ctx)
if channel == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道不存在或已停用"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0209"))
return
}
externalUser, err := openidentity.GetExternalUser(ctx, services.ChannelService.GetUserTokenSecret(channel))
+22 -23
View File
@@ -13,33 +13,32 @@ import (
"agent-desk/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
"github.com/spf13/cast"
)
func MessageAnyList(ctx *gin.Context) {
if services.ChannelService.GetEnabledChannel(ctx) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
external := httpx.GetExternalUser(ctx)
if external == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("外部身份未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0150"))
return
}
conversationID, _ := params.GetInt64(ctx, "conversationId")
if conversationID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
conversation := services.ConversationService.Get(conversationID)
if conversation == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("会话不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0116"))
return
}
if !services.ConversationService.IsCustomerConversationOwner(conversation, *external) {
httpx.WriteJSON(ctx, web.JsonErrorMsg("无权访问该会话"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0222"))
return
}
@@ -58,12 +57,12 @@ func MessageAnyList(ctx *gin.Context) {
func MessagePostSend(ctx *gin.Context) {
if services.ChannelService.GetEnabledChannel(ctx) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
external := httpx.GetExternalUser(ctx)
if external == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("外部身份未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0150"))
return
}
@@ -83,12 +82,12 @@ func MessagePostSend(ctx *gin.Context) {
func MessagePostRead(ctx *gin.Context) {
if services.ChannelService.GetEnabledChannel(ctx) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
external := httpx.GetExternalUser(ctx)
if external == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("外部身份未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0150"))
return
}
@@ -106,32 +105,32 @@ func MessagePostRead(ctx *gin.Context) {
func MessagePostUpload_image(ctx *gin.Context) {
if services.ChannelService.GetEnabledChannel(ctx) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
external := httpx.GetExternalUser(ctx)
if external == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("外部身份未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0150"))
return
}
rawConv := strings.TrimSpace(params.FormValue(ctx, "conversationId"))
if rawConv == "" {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
conversationID, err := strconv.ParseInt(rawConv, 10, 64)
if err != nil || conversationID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
conversation := services.ConversationService.Get(conversationID)
if conversation == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("会话不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0116"))
return
}
if !services.ConversationService.IsCustomerConversationOwner(conversation, *external) {
httpx.WriteJSON(ctx, web.JsonErrorMsg("无权访问该会话"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0222"))
return
}
if _, err := services.MessageService.ValidateConversationSender(conversationID, enums.IMSenderTypeCustomer, nil, external); err != nil {
@@ -141,11 +140,11 @@ func MessagePostUpload_image(ctx *gin.Context) {
header, err := ctx.FormFile("file")
if err != nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("请选择上传图片"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0322"))
return
}
if !strings.HasPrefix(strings.ToLower(header.Header.Get("Content-Type")), "image/") {
httpx.WriteJSON(ctx, web.JsonErrorMsg("仅支持上传图片文件"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0090"))
return
}
@@ -159,23 +158,23 @@ func MessagePostUpload_image(ctx *gin.Context) {
func MessagePostUpload_attachment(ctx *gin.Context) {
if services.ChannelService.GetEnabledChannel(ctx) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("接入渠道未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
}
external := httpx.GetExternalUser(ctx)
if external == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("外部身份未初始化"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0150"))
return
}
rawConv := strings.TrimSpace(params.FormValue(ctx, "conversationId"))
if rawConv == "" {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
conversationID, err := strconv.ParseInt(rawConv, 10, 64)
if err != nil || conversationID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
if _, err := services.MessageService.ValidateConversationSender(conversationID, enums.IMSenderTypeCustomer, nil, external); err != nil {
@@ -185,7 +184,7 @@ func MessagePostUpload_attachment(ctx *gin.Context) {
header, err := ctx.FormFile("file")
if err != nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("请选择上传附件"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0324"))
return
}
item, err := services.AssetService.UploadFile(header, "attachments", nil)
+1 -1
View File
@@ -55,7 +55,7 @@ func AgentGetBy(ctx *gin.Context) {
}
item := services.AgentProfileService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("客服档案不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0164"))
return
}
httpx.WriteJSON(ctx, builders.BuildAgentProfileResponse(item))
@@ -59,7 +59,7 @@ func AgentRunLogGetBy(ctx *gin.Context) {
item := services.AgentRunLogService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("Agent 运行日志不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0013"))
return
}
httpx.WriteJSON(ctx, builders.BuildAgentRunLog(item))
@@ -13,7 +13,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web"
)
func AgentTeamAnyList(ctx *gin.Context) {
@@ -61,7 +60,7 @@ func AgentTeamGetBy(ctx *gin.Context) {
}
item := services.AgentTeamService.Get(id)
if item == nil || item.Status == enums.StatusDeleted {
httpx.WriteJSON(ctx, web.JsonErrorMsg("客服组不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0169"))
return
}
httpx.WriteJSON(ctx, buildAgentTeamResponse(item))
@@ -7,6 +7,7 @@ import (
"agent-desk/internal/pkg/dto/request"
"agent-desk/internal/pkg/dto/response"
"agent-desk/internal/pkg/httpx"
"agent-desk/internal/pkg/i18nx"
"agent-desk/internal/services"
"agent-desk/internal/pkg/httpx/params"
@@ -66,6 +67,7 @@ func AgentTeamSchedulePostBatch_preview(ctx *gin.Context) {
httpx.WriteJSON(ctx, err)
return
}
req.Locale = i18nx.Locale(ctx)
ret, err := services.AgentTeamScheduleService.BatchPreview(req, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
@@ -85,6 +87,7 @@ func AgentTeamSchedulePostBatch_generate(ctx *gin.Context) {
httpx.WriteJSON(ctx, err)
return
}
req.Locale = i18nx.Locale(ctx)
ret, err := services.AgentTeamScheduleService.BatchGenerate(req, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
@@ -104,7 +107,7 @@ func AgentTeamScheduleGetBy(ctx *gin.Context) {
}
item := services.AgentTeamScheduleService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("客服组排班不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0172"))
return
}
httpx.WriteJSON(ctx, buildAgentTeamScheduleResponse(item))
@@ -64,7 +64,7 @@ func AIAgentGetBy(ctx *gin.Context) {
}
item := services.AIAgentService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("AI Agent 不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0002"))
return
}
httpx.WriteJSON(ctx, buildAIAgentResponseWithLocale(item, i18nx.Locale(ctx)))
@@ -62,7 +62,7 @@ func AIConfigGetBy(ctx *gin.Context) {
item := services.AIConfigService.Get(id)
if item == nil || item.Status == enums.StatusDeleted {
httpx.WriteJSON(ctx, web.JsonErrorMsg("AI配置不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0012"))
return
}
httpx.WriteJSON(ctx, response.BuildAIConfigResponse(item))
+2 -2
View File
@@ -51,7 +51,7 @@ func AssetGetBy(ctx *gin.Context) {
}
item := services.AssetService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("文件不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0214"))
return
}
httpx.WriteJSON(ctx, builders.BuildAsset(item))
@@ -71,7 +71,7 @@ func AssetPostCreate(ctx *gin.Context) {
}
header, err := ctx.FormFile("file")
if err != nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("请选择上传文件"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0323"))
return
}
item, err := services.AssetService.UploadFile(header, req.Prefix, operator)
@@ -44,7 +44,7 @@ func ChannelGetBy(ctx *gin.Context) {
}
item := services.ChannelService.Get(id)
if item == nil || item.Status == enums.StatusDeleted {
httpx.WriteJSON(ctx, web.JsonErrorMsg("channel not found"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0062"))
return
}
httpx.WriteJSON(ctx, buildChannelResponse(item))
@@ -112,7 +112,7 @@ func ConversationGetBy(ctx *gin.Context) {
item := services.ConversationService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("会话不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0116"))
return
}
@@ -137,7 +137,7 @@ func ConversationAnyMessage_list(ctx *gin.Context) {
limit, _ = params.GetInt(ctx, "limit")
)
if conversation := services.ConversationService.Get(conversationID); conversation == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("会话不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0116"))
return
}
@@ -311,12 +311,12 @@ func ConversationPostUpload_image(ctx *gin.Context) {
rawConv := strings.TrimSpace(params.FormValue(ctx, "conversationId"))
if rawConv == "" {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
conversationID, err := strconv.ParseInt(rawConv, 10, 64)
if err != nil || conversationID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
if _, err := services.MessageService.ValidateConversationSender(conversationID, enums.IMSenderTypeAgent, operator, nil); err != nil {
@@ -326,11 +326,11 @@ func ConversationPostUpload_image(ctx *gin.Context) {
header, err := ctx.FormFile("file")
if err != nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("请选择上传图片"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0322"))
return
}
if !strings.HasPrefix(strings.ToLower(header.Header.Get("Content-Type")), "image/") {
httpx.WriteJSON(ctx, web.JsonErrorMsg("仅支持上传图片文件"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0090"))
return
}
@@ -351,12 +351,12 @@ func ConversationPostUpload_attachment(ctx *gin.Context) {
rawConv := strings.TrimSpace(params.FormValue(ctx, "conversationId"))
if rawConv == "" {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
conversationID, err := strconv.ParseInt(rawConv, 10, 64)
if err != nil || conversationID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("conversationId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0064"))
return
}
if _, err := services.MessageService.ValidateConversationSender(conversationID, enums.IMSenderTypeAgent, operator, nil); err != nil {
@@ -366,7 +366,7 @@ func ConversationPostUpload_attachment(ctx *gin.Context) {
header, err := ctx.FormFile("file")
if err != nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("请选择上传附件"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0324"))
return
}
item, err := services.AssetService.UploadFile(header, "attachments", operator)
@@ -10,7 +10,6 @@ import (
"agent-desk/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
)
// AnyList GET/POST /customer-contact/list?customerId=
@@ -21,7 +20,7 @@ func CustomerContactAnyList(ctx *gin.Context) {
}
customerID, _ := params.GetInt64(ctx, "customerId")
if customerID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("customerId 必填"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0065"))
return
}
list := services.CustomerContactService.FindActiveByCustomerID(customerID)
@@ -72,7 +72,7 @@ func KnowledgeBaseGetBy(ctx *gin.Context) {
item := services.KnowledgeBaseService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("知识库不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0283"))
return
}
resp := builders.BuildKnowledgeBase(item)
@@ -169,7 +169,7 @@ func KnowledgeBasePostRebuild_index(ctx *gin.Context) {
knowledgeBase := services.KnowledgeBaseService.Get(req.ID)
if knowledgeBase == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("知识库不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0283"))
return
}
@@ -21,7 +21,7 @@ func KnowledgeDirectoryGetList_all(ctx *gin.Context) {
}
knowledgeBaseID, ok := params.GetInt64(ctx, "knowledgeBaseId")
if !ok || knowledgeBaseID <= 0 {
httpx.WriteJSON(ctx, errorsx.InvalidParam("知识库不存在"))
httpx.WriteJSON(ctx, errorsx.InvalidParamI18n("error.e0283"))
return
}
list := services.KnowledgeDirectoryService.FindAllByKnowledgeBaseID(knowledgeBaseID)
@@ -37,7 +37,7 @@ func KnowledgeDocumentAnyList(ctx *gin.Context) {
}
if indexStatus, ok := params.Get(ctx, "indexStatus"); ok {
if !enums.IsValidKnowledgeDocumentIndexStatus(indexStatus) {
httpx.WriteJSON(ctx, web.JsonErrorMsg("indexStatus参数不合法"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0067"))
return
}
cnd.Where("index_status = ?", indexStatus)
@@ -66,7 +66,7 @@ func KnowledgeDocumentGetBy(ctx *gin.Context) {
item := services.KnowledgeDocumentService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("文档不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0218"))
return
}
resp := builders.BuildKnowledgeDocument(item)
@@ -38,7 +38,7 @@ func KnowledgeFAQGetExport(ctx *gin.Context) {
}
knowledgeBaseID, ok := params.GetInt64(ctx, "knowledgeBaseId")
if !ok || knowledgeBaseID <= 0 {
httpx.WriteJSON(ctx, errorsx.InvalidParam("知识库不存在"))
httpx.WriteJSON(ctx, errorsx.InvalidParamI18n("error.e0283"))
return
}
file, err := services.KnowledgeFAQService.ExportKnowledgeFAQs(knowledgeBaseID)
@@ -64,17 +64,17 @@ func KnowledgeFAQPostImport(ctx *gin.Context) {
}
knowledgeBaseID, ok := params.GetInt64(ctx, "knowledgeBaseId")
if !ok || knowledgeBaseID <= 0 {
httpx.WriteJSON(ctx, errorsx.InvalidParam("知识库不存在"))
httpx.WriteJSON(ctx, errorsx.InvalidParamI18n("error.e0283"))
return
}
header, err := ctx.FormFile("file")
if err != nil {
httpx.WriteJSON(ctx, errorsx.InvalidParam("请选择导入文件"))
httpx.WriteJSON(ctx, errorsx.InvalidParamI18n("error.e0327"))
return
}
file, err := header.Open()
if err != nil {
httpx.WriteJSON(ctx, errorsx.InvalidParam("导入文件读取失败"))
httpx.WriteJSON(ctx, errorsx.InvalidParamI18n("error.e0176"))
return
}
defer file.Close()
@@ -83,12 +83,12 @@ func KnowledgeFAQPostImport(ctx *gin.Context) {
Mode: mode,
Filename: header.Filename,
Reader: file,
Locale: i18nx.Locale(ctx),
}, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
translateKnowledgeFAQImportResult(i18nx.Locale(ctx), result)
httpx.WriteJSON(ctx, result)
}
@@ -130,7 +130,7 @@ func KnowledgeFAQGetBy(ctx *gin.Context) {
item := services.KnowledgeFAQService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("FAQ不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0025"))
return
}
resp := builders.BuildKnowledgeFAQ(item)
@@ -235,15 +235,6 @@ func writeKnowledgeFAQExcelFile(ctx *gin.Context, file *response.KnowledgeFAQExp
ctx.Data(http.StatusOK, file.ContentType, file.Data)
}
func translateKnowledgeFAQImportResult(locale string, result *response.KnowledgeFAQImportResult) {
if result == nil || len(result.Errors) == 0 {
return
}
for i := range result.Errors {
result.Errors[i].Message = i18nx.TranslateKnownMessage(locale, result.Errors[i].Message)
}
}
func fillKnowledgeFAQDirectory(resp *response.KnowledgeFAQResponse, directoryPaths map[int64]string) {
resp.DirectoryPath = directoryPaths[resp.DirectoryID]
resp.DirectoryName = resp.DirectoryPath
@@ -12,7 +12,6 @@ import (
"agent-desk/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/web"
)
func KnowledgeRetrievePostDebugSearch(ctx *gin.Context) {
@@ -92,5 +91,5 @@ func KnowledgeRetrievePostBuild(ctx *gin.Context) {
return
}
httpx.WriteJSON(ctx, web.JsonErrorMsg("documentId或faqId不能为空"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0066"))
}
@@ -60,7 +60,7 @@ func KnowledgeRetrieveLogGetBy(ctx *gin.Context) {
logItem := services.KnowledgeRetrieveLogService.Get(id)
if logItem == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("检索日志不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0241"))
return
}
@@ -59,7 +59,7 @@ func PermissionGetBy(ctx *gin.Context) {
item := services.PermissionService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("权限不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0236"))
return
}
httpx.WriteJSON(ctx, &response.PermissionResponse{
@@ -44,7 +44,7 @@ func QuickReplyGetBy(ctx *gin.Context) {
item := services.QuickReplyService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("快捷回复不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0203"))
return
}
httpx.WriteJSON(ctx, builders.BuildQuickReplyResponse(item))
+1 -1
View File
@@ -71,7 +71,7 @@ func RoleGetBy(ctx *gin.Context) {
item := services.RoleService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("角色不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0305"))
return
}
@@ -73,7 +73,7 @@ func SkillDefinitionGetBy(ctx *gin.Context) {
item := services.SkillDefinitionService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("Skill 不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0053"))
return
}
httpx.WriteJSON(ctx, builders.BuildSkillDefinitionResponse(item))
@@ -131,24 +131,24 @@ func SkillDefinitionPostUpdate_status(ctx *gin.Context) {
return
}
if req.ID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("Skill ID 不合法"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0052"))
return
}
if !enums.IsValidStatus(req.Status) {
httpx.WriteJSON(ctx, web.JsonErrorMsg("状态值不合法"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0254"))
return
}
item := services.SkillDefinitionService.Get(req.ID)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("Skill 不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0053"))
return
}
if item.Status == enums.StatusDeleted {
httpx.WriteJSON(ctx, web.JsonErrorMsg("已删除的 Skill 不能直接修改状态,请先恢复"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0184"))
return
}
if req.Status == int(enums.StatusDeleted) {
httpx.WriteJSON(ctx, web.JsonErrorMsg("请使用删除接口处理删除状态"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0319"))
return
}
@@ -177,11 +177,11 @@ func SkillDefinitionPostDelete(ctx *gin.Context) {
return
}
if req.ID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("Skill ID 不合法"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0052"))
return
}
if services.SkillDefinitionService.Get(req.ID) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("Skill 不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0053"))
return
}
if err := services.SkillDefinitionService.Updates(req.ID, map[string]any{
@@ -209,17 +209,17 @@ func SkillDefinitionPostRestore(ctx *gin.Context) {
return
}
if req.ID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("Skill ID 不合法"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0052"))
return
}
item := services.SkillDefinitionService.Get(req.ID)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("Skill 不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0053"))
return
}
if item.Status != enums.StatusDeleted {
httpx.WriteJSON(ctx, web.JsonErrorMsg("仅已删除的 Skill 支持恢复"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0088"))
return
}
+1 -1
View File
@@ -49,7 +49,7 @@ func TagGetBy(ctx *gin.Context) {
item := services.TagService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("标签不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0238"))
return
}
result := builders.BuildTagResponse(item)
@@ -252,11 +252,11 @@ func TicketAnyProgressList(ctx *gin.Context) {
}
ticketID, _ := params.GetInt64(ctx, "ticketId")
if ticketID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("工单不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0178"))
return
}
if services.TicketService.Get(ticketID) == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("工单不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0178"))
return
}
progresses := services.TicketProgressService.Find(sqls.NewCnd().Eq("ticket_id", ticketID).Asc("id"))
+2 -2
View File
@@ -68,7 +68,7 @@ func UserGetBy(ctx *gin.Context) {
item := services.UserService.Get(id)
if item == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("用户不存在"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0255"))
return
}
httpx.WriteJSON(ctx, builders.BuildUserResponse(item, builders.UserBuildOptions{
@@ -191,7 +191,7 @@ func UserPostChange_password(ctx *gin.Context) {
principal = services.AuthService.GetAuthPrincipal(ctx)
}
if principal == nil {
httpx.WriteJSON(ctx, web.JsonErrorMsg("未登录或登录已过期"))
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.auth.expired"))
return
}