refact: update list api

This commit is contained in:
2026-03-31 22:32:14 +08:00
parent 697da06f14
commit 1214c91448
4 changed files with 1181 additions and 39 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@ type EvaluateTaskRequest struct {
}
type TaskListRequest struct {
TaskType string `json:"task_type" form:"task_type" binding:"required"`
TaskType string `json:"task_type" form:"task_type"`
Page int `json:"page" form:"page"`
PageSize int `json:"page_size" form:"page_size"`
UserID int64 `json:"-"`
@@ -21,10 +21,6 @@ type TaskListDTO struct {
OriginURL string `json:"origin_url"`
TaskType string `json:"task_type"`
CreatedAt string `json:"created_at"`
Latex string `json:"latex"`
Markdown string `json:"markdown"`
MathML string `json:"mathml"`
MML string `json:"mml"`
}
type TaskListResponse struct {

View File

@@ -68,47 +68,16 @@ func (svc *TaskService) GetTaskList(ctx context.Context, req *task.TaskListReque
return nil, err
}
taskIDs := make([]int64, 0, len(tasks))
for _, item := range tasks {
taskIDs = append(taskIDs, item.ID)
}
recognitionResults, err := svc.recognitionResultDao.GetByTaskIDs(dao.DB.WithContext(ctx), taskIDs)
if err != nil {
log.Error(ctx, "func", "GetTaskList", "msg", "get recognition results failed", "error", err)
return nil, err
}
recognitionResultMap := make(map[int64]*dao.RecognitionResult)
for _, item := range recognitionResults {
recognitionResultMap[item.TaskID] = item
}
resp := &task.TaskListResponse{
TaskList: make([]*task.TaskListDTO, 0, len(tasks)),
Total: total,
}
for _, item := range tasks {
var latex, markdown, mathML, mml string
recognitionResult := recognitionResultMap[item.ID]
if recognitionResult != nil && recognitionResult.TaskType == dao.TaskTypeFormula {
if fc, err := recognitionResult.GetFormulaContent(); err == nil {
latex = fc.Latex
markdown = fc.Markdown
mathML = fc.MathML
mml = fc.MML
}
}
// PDF 类型的 TaskListDTO 暂不展开 content列表页只显示状态
originURL, err := oss.GetDownloadURL(ctx, item.FileURL)
if err != nil {
log.Error(ctx, "func", "GetTaskList", "msg", "get origin url failed", "error", err)
}
resp.TaskList = append(resp.TaskList, &task.TaskListDTO{
Latex: latex,
Markdown: markdown,
MathML: mathML,
MML: mml,
TaskID: item.TaskUUID,
FileName: item.FileName,
Status: int(item.Status),

View File

@@ -89,12 +89,14 @@ func (dao *RecognitionTaskDao) GetTaskByID(tx *gorm.DB, id int64) (task *Recogni
}
func (dao *RecognitionTaskDao) GetTaskList(tx *gorm.DB, userID int64, taskType TaskType, page int, pageSize int) (tasks []*RecognitionTask, total int64, err error) {
offset := (page - 1) * pageSize
query := tx.Model(RecognitionTask{}).Where("user_id = ? AND task_type = ?", userID, taskType)
query := tx.Model(RecognitionTask{}).Where("user_id = ?", userID)
if taskType != "" {
query = query.Where("task_type = ?", taskType)
}
err = query.Count(&total).Error
if err != nil {
return nil, 0, err
}
err = query.Offset(offset).Limit(pageSize).Order(clause.OrderByColumn{Column: clause.Column{Name: "id"}, Desc: true}).Find(&tasks).Error
err = query.Order(clause.OrderByColumn{Column: clause.Column{Name: "id"}, Desc: true}).Offset((page - 1) * pageSize).Limit(pageSize).Find(&tasks).Error
return tasks, total, err
}