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"`