refact: update list api
This commit is contained in:
1175
docs/superpowers/plans/2026-03-30-pdf-recognition-glm-ocr.md
Normal file
1175
docs/superpowers/plans/2026-03-30-pdf-recognition-glm-ocr.md
Normal file
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@ type EvaluateTaskRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TaskListRequest 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"`
|
Page int `json:"page" form:"page"`
|
||||||
PageSize int `json:"page_size" form:"page_size"`
|
PageSize int `json:"page_size" form:"page_size"`
|
||||||
UserID int64 `json:"-"`
|
UserID int64 `json:"-"`
|
||||||
@@ -21,10 +21,6 @@ type TaskListDTO struct {
|
|||||||
OriginURL string `json:"origin_url"`
|
OriginURL string `json:"origin_url"`
|
||||||
TaskType string `json:"task_type"`
|
TaskType string `json:"task_type"`
|
||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
Latex string `json:"latex"`
|
|
||||||
Markdown string `json:"markdown"`
|
|
||||||
MathML string `json:"mathml"`
|
|
||||||
MML string `json:"mml"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskListResponse struct {
|
type TaskListResponse struct {
|
||||||
|
|||||||
@@ -68,47 +68,16 @@ func (svc *TaskService) GetTaskList(ctx context.Context, req *task.TaskListReque
|
|||||||
return nil, err
|
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{
|
resp := &task.TaskListResponse{
|
||||||
TaskList: make([]*task.TaskListDTO, 0, len(tasks)),
|
TaskList: make([]*task.TaskListDTO, 0, len(tasks)),
|
||||||
Total: total,
|
Total: total,
|
||||||
}
|
}
|
||||||
for _, item := range tasks {
|
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)
|
originURL, err := oss.GetDownloadURL(ctx, item.FileURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(ctx, "func", "GetTaskList", "msg", "get origin url failed", "error", err)
|
log.Error(ctx, "func", "GetTaskList", "msg", "get origin url failed", "error", err)
|
||||||
}
|
}
|
||||||
resp.TaskList = append(resp.TaskList, &task.TaskListDTO{
|
resp.TaskList = append(resp.TaskList, &task.TaskListDTO{
|
||||||
Latex: latex,
|
|
||||||
Markdown: markdown,
|
|
||||||
MathML: mathML,
|
|
||||||
MML: mml,
|
|
||||||
TaskID: item.TaskUUID,
|
TaskID: item.TaskUUID,
|
||||||
FileName: item.FileName,
|
FileName: item.FileName,
|
||||||
Status: int(item.Status),
|
Status: int(item.Status),
|
||||||
|
|||||||
@@ -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) {
|
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 = ?", userID)
|
||||||
query := tx.Model(RecognitionTask{}).Where("user_id = ? AND task_type = ?", userID, taskType)
|
if taskType != "" {
|
||||||
|
query = query.Where("task_type = ?", taskType)
|
||||||
|
}
|
||||||
err = query.Count(&total).Error
|
err = query.Count(&total).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
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
|
return tasks, total, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user