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

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
}