From 44155c058d97263c683642076411112684579c4e Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Fri, 9 Jan 2026 18:01:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E7=9A=84=20TaskIndex=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/entitys/chat_history.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/internal/entitys/chat_history.go b/internal/entitys/chat_history.go index b50148e..50bbb0b 100644 --- a/internal/entitys/chat_history.go +++ b/internal/entitys/chat_history.go @@ -33,9 +33,10 @@ type ChatHisQueryResponse struct { Files string `gorm:"column:files;not null" json:"files"` Useful int32 `gorm:"column:useful;not null;comment:0不评价,1有用,其他为无用" json:"useful"` // 0不评价,1有用,其他为无用 CreateAt string `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"` - TaskID int32 `gorm:"column:task_id;not null" json:"task_id"` // 任务ID - TaskName string `gorm:"column:task_name;not null" json:"task_name"` // 任务名称 - Contents []string `gorm:"column:contents" json:"contents"` // 前端回传数据 + TaskID int32 `gorm:"column:task_id;not null" json:"task_id"` // 任务ID + TaskName string `gorm:"column:task_name;not null" json:"task_name"` // 任务名称 + Contents []string `gorm:"column:contents" json:"contents"` // 前端回传数据 + TaskIndex string `gorm:"column:task_index;not null" json:"task_index"` // 任务索引 } func (c *ChatHisQueryResponse) FromModel(chat model.AiChatHi, task model.AiTask) { @@ -49,6 +50,7 @@ func (c *ChatHisQueryResponse) FromModel(chat model.AiChatHi, task model.AiTask) c.TaskID = chat.TaskID c.TaskName = task.Name c.Contents = make([]string, 0) + c.TaskIndex = c.parseTaskIndex(task.Index, chat.Ans) // 解析Content if "" != chat.Content { @@ -60,6 +62,28 @@ func (c *ChatHisQueryResponse) FromModel(chat model.AiChatHi, task model.AiTask) } } +func (c *ChatHisQueryResponse) parseTaskIndex(taskIndex string, ans string) string { + if taskIndex != "" { + return taskIndex + } + + if ans == "" { + return "" + } + var resp []Response + err := json.Unmarshal([]byte(ans), &resp) + if err != nil { + log.Println("解析Ans失败 error: ", err) + return "" + } + + if 0 < len(resp) { + return resp[0].Index + } + + return "" +} + type UpdateContentRequest struct { HisID int64 `json:"his_id" validate:"required"` Content string `json:"content" validate:"required"`